Files
palemoon27/dom/html/test/forms/test_pattern_attribute.html
roytam1 37dc78596e import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1203058 - Set the paint sync id on the top-level window rather than the tab's window, because then it won't get lost during page unload. r=rbarker (977f8909e2)
- Bug 1199283 - nsContentUtils::sIsFrameTimingPrefEnabled should default to false. r=smaug (510c4c4ed1)
- Bug 1237714.  Make nsContentUtils::IsCustomElementName faster in the common case of a non-custom-element name.  r=smaug (397409f308)
- Bug 1237831 - Use a non-format argument in LogMessageToConsole. r=jst (cc9d2cd390)
- Bug 1208517 - Use the legacy opt-out in CanAccessNativeAnon for now to avoid crashes. r=me (79bd55b387)
- Bug 1230353: P1. Ensure type and subtype of MIME are lowercase. r=bz (09f9a067a6)
- Bug 1230353: P2. Update webref test expected results. r=karlt (4c10a9604c)
- Bug 1227906 - Use unicode flag in pattern attribute. r=jst (d5b4fbae46)
- Bug 1223041 - Emit console warning when document.execCommand('copy'/'cut') is triggered outside of a short-lived user-initiated event, r=bz (b590f3eb86)
- Bug 1235159 - Report pattern compliation failure to web console. r=jst,jorendorff (f4b1ddd863)
- Bug 1000004 - Part a: Remove the unused nsContentUtils::HasPluginWithUncontrolledEventDispatch(nsIDocument*) function; r=jst (d873b1a93e)
- Bug 1000004 - Part b: Inline CheckForWindowedPlugins in its only caller; r=jst (f9a2e5cf64)
- Bug 583170 - Handling IPv6 literal address differently to other browsers r=bz (92abdd56ac)
- Bug 1225829 - Use a temporary string to avoid string type confusion via references. r=jimm (47ae4a8b37)
- Bug 1209841 - Support mouse long tap in SendMouseEvent(). r=smaug (23f308d336)
- Bug 1230563 - Part 1: Cookie permissions should override the CookiesL ifetimePolicy, r=ehsan (d7ecd5e7e0)
- Bug 1230563 - Part 2: Test for corrected cookie permission behavior, r=ehsan (f22ef46565)
- Bug 1241078 - Only treat items as backface hidden if they are 3D-transformed. r=tlee (c52f6804cc)
- Bug 1233098 - Refactor CSP upgrade insecure requests flag within loadInfo (r=sicking) (816d36e5d8)
- remove specific PM hack (a0ed71f7f4)
- Bug 1239397: Send Internal ContentPolicyType to CSP and MixedContent (r=sicking) (7c8da2f1df)
- Bug 1236258 part 1. Remove the unused nsDOMAttributeMap::RemoveAttribute. r=smaug (968d788197)
- Bug 1236258 part 3. Remove the unused aNsAware argument of nsDOMAttributeMap::GetAttribute. r=smaug (224d2e1e91)
- Bug 1236258 part 4. Change nsDOMAttributeMap::SetNamedItemNS to not remove the existing attribute when there is one. r=smaug (f1176918a6)
- Bug 1222079. Fix the behavior of Object.getOwnPropertyNames for nsDOMAttributeMap. r=bzbarsky (3b649bf948)
- Bug 1237580. NamedNodeMap should only claim to support a name if that name has no uppercase ASCII chars, for HTML elements in HTML documents. r=bkelly (216aa3ead6)
- just enable visibilityAPI (3df2d50b5d)
- bits of Bug 1153322 (85ba6268b4)
- Bug 1220160 - part 1: add chromeonly getter for documenturi that returns the original document when on an error page, r=bz (d0c256c29f)
- Bug 1219861 - Remove not-allowed cursor on disabled buttons on in-content pages. r=dao (fa9b2ef2d0)
- Bug 1207146 - Add a link to expert technical information in the cert error page. r=Gijs,keeler (c3292b3fc7)
- Bug 1224433 - Part 3: Compute the invalidation area for preserve-3d layers by accumulating the leaves. r=roc (fffc5a7dfb)
- Bug 1245306: Devirtualize RefreshCompartmentPrincipal. r=smaug (4fa906b7fe)
- Bug 1205298 - Date.parse() should accept a wider range of potential formats; r=jandem (11a0377372)
- Bug 1247807 - Fix Mixed Content UI when using upgrade-insecure-requests (r=bz) (10a0aba8d4)
- Bug 1224694 - Unify and clean up initialization of CSP (r=sicking) (45b6f0a865)
- Bug 1190093 - Stop throttling frame requests for loading pages by checking Hidden(), not isShowing. r=tnikkel (343d2b39fd)
- Bug 1234554 - verify pointer validity and if valid dereference it otherwise use default value. r=jst (8c3265ef33)
- Bug 1240283 - Slim down JSDate instances by not caching cheaply-computed values. r=Waldo (0148f646a2)
- Bug 1217049 - Make Date.prototype.toString.call(<primitive value>) throw a TypeError. r=arai (e8ec69b296)
- Bug 1187233 part 1 - Date constructor should create a copy when called with a Date object. Original patch by Giovanni Sferro. r=jwalden (6a3125c081)
- Bug 1187233 part 2 - Fix test_networkstats_service_proxy.js to not rely on the old behavior. r=jwalden (86461c8aa0)
- Bug 1208023 - Avoid using a bad initial-scale when computing the CSS viewport. r=botond (42e370ce6a)
- Bug 1234025 - Part 1: Move ObjectBox::isModuleBox definition to ParseNode.cpp. (ac4454c20a)
- Bug 1234025 - Part 2: Remove unused functions from ScriptedDirectProxyHandler.cpp. (0ea17c2395)
- Bug 1234025 - Part 3: Remove unused constant from Statistics.cpp (8986c23751)
2023-11-23 23:57:50 +08:00

325 lines
9.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=345512
-->
<head>
<title>Test for Bug 345512</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style>
input { background-color: rgb(0,0,0) !important; }
input:valid { background-color: rgb(0,255,0) !important; }
input:invalid { background-color: rgb(255,0,0) !important; }
</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=345512">Mozilla Bug 345512</a>
<p id="display"></p>
<div id="content" style="display: none">
<input id='i' pattern="tulip" oninvalid="invalidEventHandler(event);">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 345512 **/
var gInvalid = false;
function invalidEventHandler(e)
{
is(e.type, "invalid", "Invalid event type should be invalid");
gInvalid = true;
}
function completeValidityCheck(element, alwaysValid, isBarred)
{
// Check when pattern matches.
if (element.type == 'email') {
element.pattern = ".*@bar.com";
element.value = "foo@bar.com";
} else if (element.type == 'url') {
element.pattern = "http://.*\\.com$";
element.value = "http://mozilla.com";
} else if (element.type == 'file') {
element.pattern = "foo";
SpecialPowers.wrap(element).mozSetFileArray([new File(["foo"], "foo")]);
} else {
element.pattern = "foo";
element.value = "foo";
}
checkValidPattern(element, true, isBarred);
// Check when pattern does not match.
if (element.type == 'email') {
element.pattern = ".*@bar.com";
element.value = "foo@foo.com";
} else if (element.type == 'url') {
element.pattern = "http://.*\\.com$";
element.value = "http://mozilla.org";
} else if (element.type == 'file') {
element.pattern = "foo";
SpecialPowers.wrap(element).mozSetFileArray([new File(["bar"], "bar")]);
} else {
element.pattern = "foo";
element.value = "bar";
}
if (!alwaysValid) {
checkInvalidPattern(element, true);
} else {
checkValidPattern(element, true, isBarred);
}
}
function checkValidPattern(element, completeCheck, isBarred)
{
if (completeCheck) {
gInvalid = false;
ok(!element.validity.patternMismatch,
"Element should not suffer from pattern mismatch");
ok(element.validity.valid, "Element should be valid");
ok(element.checkValidity(), "Element should be valid");
ok(!gInvalid, "Invalid event shouldn't have been thrown");
is(element.validationMessage, '',
"Validation message should be the empty string");
if (element.type != 'radio' && element.type != 'checkbox') {
is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
isBarred ? "rgb(0, 0, 0)" : "rgb(0, 255, 0)",
"The pseudo-class is not correctly applied");
}
} else {
ok(!element.validity.patternMismatch,
"Element should not suffer from pattern mismatch");
}
}
function checkInvalidPattern(element, completeCheck)
{
if (completeCheck) {
gInvalid = false;
ok(element.validity.patternMismatch,
"Element should suffer from pattern mismatch");
ok(!element.validity.valid, "Element should not be valid");
ok(!element.checkValidity(), "Element should not be valid");
ok(gInvalid, "Invalid event should have been thrown");
is(element.validationMessage,
"Please match the requested format.",
"Validation message is not valid");
} else {
ok(element.validity.patternMismatch,
"Element should suffer from pattern mismatch");
}
if (element.type != 'radio' && element.type != 'checkbox') {
is(window.getComputedStyle(element, null).getPropertyValue('background-color'),
"rgb(255, 0, 0)", ":invalid pseudo-class should apply");
}
}
function checkSyntaxError(element)
{
ok(!element.validity.patternMismatch,
"On SyntaxError, element should not suffer");
}
function checkPatternValidity(element)
{
element.pattern = "foo";
element.value = '';
checkValidPattern(element);
element.value = "foo";
checkValidPattern(element);
element.value = "bar";
checkInvalidPattern(element);
element.value = "foobar";
checkInvalidPattern(element);
element.value = "foofoo";
checkInvalidPattern(element);
element.pattern = "foo\"bar";
element.value = "foo\"bar";
checkValidPattern(element);
element.value = 'foo"bar';
checkValidPattern(element);
element.pattern = "foo'bar";
element.value = "foo\'bar";
checkValidPattern(element);
element.pattern = "foo\\(bar";
element.value = "foo(bar";
checkValidPattern(element);
element.value = "foo";
checkInvalidPattern(element);
element.pattern = "foo\\)bar";
element.value = "foo)bar";
checkValidPattern(element);
element.value = "foo";
checkInvalidPattern(element);
// Check for 'i' flag disabled. Should be case sensitive.
element.value = "Foo";
checkInvalidPattern(element);
// We can't check for the 'g' flag because we only test, we don't execute.
// We can't check for the 'm' flag because .value shouldn't contain line breaks.
// We need '\\\\' because '\\' will produce '\\' and we want to escape the '\'
// for the regexp.
element.pattern = "foo\\\\bar";
element.value = "foo\\bar";
checkValidPattern(element);
// We may want to escape the ' in the pattern, but this is a SyntaxError
// when unicode flag is set.
element.pattern = "foo\\'bar";
element.value = "foo'bar";
checkSyntaxError(element);
element.value = "baz";
checkSyntaxError(element);
// We should check the pattern attribute do not pollute |RegExp.lastParen|.
is(RegExp.lastParen, "", "RegExp.lastParen should be the empty string");
element.pattern = "(foo)";
element.value = "foo";
checkValidPattern(element);
is(RegExp.lastParen, "", "RegExp.lastParen should be the empty string");
// That may sound weird but the empty string is a valid pattern value.
element.pattern = "";
element.value = "";
checkValidPattern(element);
element.value = "foo";
checkInvalidPattern(element);
// Checking some complex patterns. As we are using js regexp mechanism, these
// tests doesn't aim to test the regexp mechanism.
element.pattern = "\\d{2}\\s\\d{2}\\s\\d{4}"
element.value = "01 01 2010"
checkValidPattern(element);
element.value = "01/01/2010"
checkInvalidPattern(element);
element.pattern = "[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z_+])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9}";
element.value = "foo@bar.com";
checkValidPattern(element);
element.value = "...@bar.com";
checkInvalidPattern(element);
element.pattern = "^(?:\\w{3,})$";
element.value = "foo";
checkValidPattern(element);
element.value = "f";
checkInvalidPattern(element);
// If @title is specified, it should be added in the validation message.
if (element.type == 'email') {
element.pattern = "foo@bar.com"
element.value = "bar@foo.com";
} else if (element.type == 'url') {
element.pattern = "http://mozilla.com";
element.value = "http://mozilla.org";
} else {
element.pattern = "foo";
element.value = "bar";
}
element.title = "this is an explanation of the regexp";
is(element.validationMessage,
"Please match the requested format: " + element.title + ".",
"Validation message is not valid");
element.title = "";
is(element.validationMessage,
"Please match the requested format.",
"Validation message is not valid");
element.pattern = "foo";
if (element.type == 'email') {
element.value = "bar@foo.com";
} else if (element.type == 'url') {
element.value = "http://mozilla.org";
} else {
element.value = "bar";
}
checkInvalidPattern(element);
element.removeAttribute('pattern');
checkValidPattern(element, true);
// Unicode pattern
for (var pattern of ["\\u{1F438}{2}", "\u{1F438}{2}",
"\\uD83D\\uDC38{2}", "\uD83D\uDC38{2}",
"\u{D83D}\u{DC38}{2}"]) {
element.pattern = pattern;
element.value = "\u{1F438}\u{1F438}";
checkValidPattern(element);
element.value = "\uD83D\uDC38\uD83D\uDC38";
checkValidPattern(element);
element.value = "\uD83D\uDC38\uDC38";
checkInvalidPattern(element);
}
element.pattern = "\\u{D83D}\\u{DC38}{2}";
element.value = "\u{1F438}\u{1F438}";
checkInvalidPattern(element);
element.value = "\uD83D\uDC38\uD83D\uDC38";
checkInvalidPattern(element);
element.value = "\uD83D\uDC38\uDC38";
checkInvalidPattern(element);
}
var input = document.getElementById('i');
// |validTypes| are the types which accept @pattern
// and |invalidTypes| are the ones which do not accept it.
var validTypes = Array('text', 'password', 'search', 'tel', 'email', 'url');
var barredTypes = Array('hidden', 'reset', 'button');
var invalidTypes = Array('checkbox', 'radio', 'file', 'number', 'range', 'date', 'time', 'color', 'submit', 'image');
// TODO: 'datetime', 'month', 'week', and 'datetime-local'
// do not accept the @pattern too but are not implemented yet.
for (type of validTypes) {
input.type = type;
completeValidityCheck(input, false);
checkPatternValidity(input);
}
for (type of barredTypes) {
input.type = type;
completeValidityCheck(input, true, true);
}
for (type of invalidTypes) {
input.type = type;
completeValidityCheck(input, true);
}
</script>
</pre>
</body>
</html>