mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-27 05:00:13 -10:00
This is split from the previous changeset since if we include dom/ the file size is too large for phabricator to handle. This is an autogenerated commit to handle scripts loading mochitest harness files, in the simple case where the script src is on the same line as the tag. This was generated with https://bug1544322.bmoattachments.org/attachment.cgi?id=9058170 using the `--part 2` argument. Differential Revision: https://phabricator.services.mozilla.com/D27457
238 lines
9.1 KiB
HTML
238 lines
9.1 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=555559
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=668817
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=854812
|
|
-->
|
|
<head>
|
|
<title>Test for <input type='email'> validity</title>
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=555559">Mozilla Bug 555559</a>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=668817">Mozilla Bug 668817</a>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=854812">Mozilla Bug 854812</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
<form>
|
|
<input type='email' name='email' id='i' oninvalid="invalidEventHandler(event);">
|
|
<form>
|
|
</div>
|
|
<pre id="test">
|
|
<script type="application/javascript">
|
|
|
|
/** Test for <input type='email'> validity **/
|
|
|
|
var gInvalid = false;
|
|
|
|
function invalidEventHandler(e)
|
|
{
|
|
is(e.type, "invalid", "Invalid event type should be invalid");
|
|
gInvalid = true;
|
|
}
|
|
|
|
function checkValidEmailAddress(element)
|
|
{
|
|
gInvalid = false;
|
|
ok(!element.validity.typeMismatch && !element.validity.badInput,
|
|
"Element should not suffer from type mismatch or bad input (with value='"+element.value+"')");
|
|
ok(element.validity.valid, "Element should be valid");
|
|
ok(element.checkValidity(), "Element should be valid");
|
|
ok(!gInvalid, "The invalid event should not have been thrown");
|
|
is(element.validationMessage, '',
|
|
"Validation message should be the empty string");
|
|
ok(element.matches(":valid"), ":valid pseudo-class should apply");
|
|
}
|
|
|
|
const VALID = 0;
|
|
const TYPE_MISMATCH = 1 << 0;
|
|
const BAD_INPUT = 1 << 1;
|
|
|
|
function checkInvalidEmailAddress(element, failedValidityStates)
|
|
{
|
|
info("Checking " + element.value);
|
|
gInvalid = false;
|
|
var expectTypeMismatch = !!(failedValidityStates & TYPE_MISMATCH);
|
|
var expectBadInput = !!(failedValidityStates & BAD_INPUT);
|
|
ok(element.validity.typeMismatch == expectTypeMismatch,
|
|
"Element should " + (expectTypeMismatch ? "" : "not ") + "suffer from type mismatch (with value='"+element.value+"')");
|
|
ok(element.validity.badInput == expectBadInput,
|
|
"Element should " + (expectBadInput ? "" : "not ") + "suffer from bad input (with value='"+element.value+"')");
|
|
ok(!element.validity.valid, "Element should not be valid");
|
|
ok(!element.checkValidity(), "Element should not be valid");
|
|
ok(gInvalid, "The invalid event should have been thrown");
|
|
is(element.validationMessage, "Please enter an email address.",
|
|
"Validation message is not valid");
|
|
ok(element.matches(":invalid"), ":invalid pseudo-class should apply");
|
|
}
|
|
|
|
function testEmailAddress(aElement, aValue, aMultiple, aValidityFailures)
|
|
{
|
|
aElement.multiple = aMultiple;
|
|
aElement.value = aValue;
|
|
|
|
if (!aValidityFailures) {
|
|
checkValidEmailAddress(aElement);
|
|
} else {
|
|
checkInvalidEmailAddress(aElement, aValidityFailures);
|
|
}
|
|
}
|
|
|
|
var email = document.forms[0].elements[0];
|
|
|
|
// Simple values, checking the e-mail syntax validity.
|
|
var values = [
|
|
[ '' ], // The empty string shouldn't be considered as invalid.
|
|
[ '[email protected]', VALID ],
|
|
[ ' [email protected]', VALID ],
|
|
[ '[email protected] ', VALID ],
|
|
[ '\r\n [email protected]', VALID ],
|
|
[ '[email protected] \n\r', VALID ],
|
|
[ '\n\n \r\[email protected]\n\n \r\r', VALID ],
|
|
[ '\n\r \n\[email protected]\n\r \n\r', VALID ],
|
|
[ 'tulip', TYPE_MISMATCH ],
|
|
// Some checks on the user part of the address.
|
|
[ '@bar.com', TYPE_MISMATCH ],
|
|
[ 'f\[email protected]', VALID ],
|
|
[ 'f\[email protected]', VALID ],
|
|
[ 'f\r\[email protected]', VALID ],
|
|
[ 'fü@foo.com', TYPE_MISMATCH ],
|
|
// Some checks for the domain part.
|
|
[ 'foo@bar', VALID ],
|
|
[ 'foo@b', VALID ],
|
|
[ 'foo@', TYPE_MISMATCH ],
|
|
[ 'foo@bar.', TYPE_MISMATCH ],
|
|
[ '[email protected]', VALID ],
|
|
[ '[email protected]', TYPE_MISMATCH ],
|
|
[ '[email protected]', TYPE_MISMATCH ],
|
|
[ '[email protected]', VALID ],
|
|
[ '[email protected]', VALID ],
|
|
[ '[email protected]', VALID ],
|
|
[ '[email protected]', VALID ],
|
|
[ '[email protected]', VALID ],
|
|
[ 'foo@b\nar.com', VALID ],
|
|
[ 'foo@b\rar.com', VALID ],
|
|
[ 'foo@b\r\nar.com', VALID ],
|
|
[ 'foo@.', TYPE_MISMATCH ],
|
|
[ 'foo@fü.com', VALID ],
|
|
[ '[email protected]üm', VALID ],
|
|
[ 'thisUsernameIsLongerThanSixtyThreeCharactersInLengthRightAboutNow@mozilla.tld', VALID ],
|
|
// Long strings with UTF-8 in username.
|
|
[ 'this.is.email.should.be.longer.than.sixty.four.characters.föö@mözillä.tld', TYPE_MISMATCH ],
|
|
[ 'this-is-email-should-be-longer-than-sixty-four-characters-föö@mözillä.tld', TYPE_MISMATCH, true ],
|
|
// Long labels (labels greater than 63 chars long are not allowed).
|
|
[ 'foo@thislabelisexactly63characterssssssssssssssssssssssssssssssssss', VALID ],
|
|
[ 'foo@thislabelisexactly63characterssssssssssssssssssssssssssssssssss.com', VALID ],
|
|
[ 'foo@foo.thislabelisexactly63characterssssssssssssssssssssssssssssssssss.com', VALID ],
|
|
[ 'foo@foo.thislabelisexactly63characterssssssssssssssssssssssssssssssssss', VALID ],
|
|
[ 'foo@thislabelisexactly64charactersssssssssssssssssssssssssssssssssss', TYPE_MISMATCH | BAD_INPUT ],
|
|
[ 'foo@thislabelisexactly64charactersssssssssssssssssssssssssssssssssss.com', TYPE_MISMATCH | BAD_INPUT ],
|
|
[ 'foo@foo.thislabelisexactly64charactersssssssssssssssssssssssssssssssssss.com', TYPE_MISMATCH | BAD_INPUT ],
|
|
[ 'foo@foo.thislabelisexactly64charactersssssssssssssssssssssssssssssssssss', TYPE_MISMATCH | BAD_INPUT ],
|
|
// Long labels with UTF-8 (punycode encoding will increase the label to more than 63 chars).
|
|
[ 'foo@thisläbelisexäctly63charäcterssssssssssssssssssssssssssssssssss', TYPE_MISMATCH | BAD_INPUT ],
|
|
[ 'foo@thisläbelisexäctly63charäcterssssssssssssssssssssssssssssssssss.com', TYPE_MISMATCH | BAD_INPUT ],
|
|
[ '[email protected]äbelisexäctly63charäcterssssssssssssssssssssssssssssssssss.com', TYPE_MISMATCH | BAD_INPUT ],
|
|
[ '[email protected]äbelisexäctly63charäcterssssssssssssssssssssssssssssssssss', TYPE_MISMATCH | BAD_INPUT ],
|
|
// The domains labels (sub-domains or tld) can't start or finish with a '-'
|
|
[ 'foo@foo-bar', VALID ],
|
|
[ 'foo@-foo', TYPE_MISMATCH ],
|
|
[ '[email protected]', TYPE_MISMATCH ],
|
|
[ '[email protected]', TYPE_MISMATCH ],
|
|
[ '[email protected]', VALID ],
|
|
[ '[email protected]', TYPE_MISMATCH ],
|
|
[ '[email protected]', TYPE_MISMATCH ],
|
|
[ '[email protected]', TYPE_MISMATCH ],
|
|
[ 'foo@fo--o', VALID ],
|
|
];
|
|
|
|
// Multiple values, we don't check e-mail validity, only multiple stuff.
|
|
var multipleValues = [
|
|
[ '[email protected], [email protected]', VALID ],
|
|
[ '[email protected],[email protected]', VALID ],
|
|
[ '[email protected],[email protected],[email protected]', VALID ],
|
|
[ ' [email protected] , [email protected] ', VALID ],
|
|
[ '\[email protected]\t,\[email protected]\t', VALID ],
|
|
[ '\[email protected]\r,\[email protected]\r', VALID ],
|
|
[ '\[email protected]\n,\[email protected]\n', VALID ],
|
|
[ '\[email protected]\f,\[email protected]\f', VALID ],
|
|
[ '\t [email protected]\r,\[email protected]\f', VALID ],
|
|
[ 'foo@b,ar.com,[email protected]', TYPE_MISMATCH ],
|
|
[ '[email protected],[email protected],', TYPE_MISMATCH ],
|
|
[ ' [email protected] , [email protected] , ', TYPE_MISMATCH ],
|
|
[ ',[email protected],[email protected]', TYPE_MISMATCH ],
|
|
[ ',[email protected],[email protected]', TYPE_MISMATCH ],
|
|
[ '[email protected],,,[email protected]', TYPE_MISMATCH ],
|
|
[ '[email protected];[email protected]', TYPE_MISMATCH ],
|
|
[ '<[email protected]>, <[email protected]>', TYPE_MISMATCH ],
|
|
[ 'foo@bar, [email protected]', VALID ],
|
|
[ '[email protected], foo', TYPE_MISMATCH ],
|
|
[ 'foo, [email protected]', TYPE_MISMATCH ],
|
|
];
|
|
|
|
/* Additional username checks. */
|
|
|
|
var legalCharacters = "abcdefghijklmnopqrstuvwxyz";
|
|
legalCharacters += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
legalCharacters += "0123456789";
|
|
legalCharacters += "!#$%&'*+-/=?^_`{|}~.";
|
|
|
|
// Add all username legal characters individually to the list.
|
|
for (c of legalCharacters) {
|
|
values.push([c + "@bar.com", VALID]);
|
|
}
|
|
// Add the concatenation of all legal characters too.
|
|
values.push([legalCharacters + "@bar.com", VALID]);
|
|
|
|
// Add username illegal characters, the same way.
|
|
var illegalCharacters = "()<>[]:;@\\, \t";
|
|
for (c of illegalCharacters) {
|
|
values.push([illegalCharacters + "@bar.com", TYPE_MISMATCH]);
|
|
}
|
|
|
|
/* Additional domain checks. */
|
|
|
|
legalCharacters = "abcdefghijklmnopqrstuvwxyz";
|
|
legalCharacters += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
legalCharacters += "0123456789";
|
|
|
|
// Add domain legal characters (except '.' and '-' because they are special).
|
|
for (c of legalCharacters) {
|
|
values.push(["[email protected]" + c, VALID]);
|
|
}
|
|
// Add the concatenation of all legal characters too.
|
|
values.push(["foo@bar." + legalCharacters, VALID]);
|
|
|
|
// Add domain illegal characters.
|
|
illegalCharacters = "()<>[]:;@\\,!#$%&'*+/=?^_`{|}~ \t";
|
|
for (c of illegalCharacters) {
|
|
values.push(['[email protected]' + c + 'r', TYPE_MISMATCH]);
|
|
}
|
|
|
|
values.forEach(function([value, valid, todo]) {
|
|
if (todo === true) {
|
|
email.value = value;
|
|
todo_is(email.validity.valid, true, "value should be valid");
|
|
} else {
|
|
testEmailAddress(email, value, false, valid);
|
|
}
|
|
});
|
|
|
|
multipleValues.forEach(function([value, valid]) {
|
|
testEmailAddress(email, value, true, valid);
|
|
});
|
|
|
|
// Make sure setting multiple changes the value.
|
|
email.multiple = false;
|
|
email.value = "[email protected], [email protected]";
|
|
checkInvalidEmailAddress(email, TYPE_MISMATCH);
|
|
email.multiple = true;
|
|
checkValidEmailAddress(email);
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|