-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added input[type=email] test #158
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Input Email</title> | ||
<link rel="author" title="Kazuki Kanamori" href="mailto:yogurito@gmail.com"> | ||
<link rel="help" href="http://www.w3.org/TR/2012/CR-html5-20121217/forms.html#e-mail-state-(type=email)"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<h1>Input email</h1> | ||
<input type="email" id="single_email" value="user@example.com"/> | ||
<input type="email" id="multiple_email" value="user1@example.com, user2@test.com" multiple/> | ||
|
||
<div id="log"> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
// Regexp from http://www.w3.org/html/wg/drafts/html/master/forms.html#e-mail-state-(type=email) | ||
var validEmailRegexp = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/; | ||
test(function(){ | ||
assert_equals(document.getElementById('single_email').type, 'email') | ||
}, 'email type supported on input element'); | ||
test(function(){ | ||
var attributes = document.getElementById('multiple_email').attributes; | ||
assert_equals(attributes.length, 4); | ||
for (var i = 0; i < attributes.length; i++) { | ||
if (attributes[i].name === 'multiple') { | ||
assert_true(true); | ||
return; | ||
} | ||
} | ||
assert_unreached(); | ||
}, '"multiple" attribute supported for input:email element'); | ||
|
||
test(function(){ | ||
var element = document.getElementsByTagName('input')[0]; | ||
test(function(){ | ||
element.value = ''; | ||
assert_equals(element.value, ''); | ||
}, 'User agents should allow the user to set the value to the empty string'); | ||
test(function(){ | ||
element.value = 'user@example.com\u000A'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should probably use |
||
assert_equals(element.value, 'user@example.com'); | ||
}, 'User agents must not allow users to insert "LF" (U+000A) character into the value'); | ||
test(function(){ | ||
element.value = 'user@example.com\u000D'; | ||
assert_equals(element.value, 'user@example.com'); | ||
}, 'User agents must not allow users to insert "CR" (U+000D) character into the value'); | ||
test(function(){ | ||
element.value = 'user@example.com'; | ||
assert_true(validEmailRegexp.test(element.value)); | ||
}, 'The value attribute, if specified and not empty, must have a value that is a single valid e-mail address'); | ||
test(function(){ | ||
element.setAttribute('multiple', null); | ||
element.value = ' user@example.com , user2@example.com '; | ||
element.removeAttribute('multiple'); | ||
assert_equals(element.value, 'user@example.com'); | ||
assert_true(validEmailRegexp.test(element.value)); | ||
}, 'When the multiple attribute is removed, the user agent must run the value sanitization algorithm') | ||
}, | ||
'When the multiple attribute is NOT specified on the element'); | ||
|
||
test(function(){ | ||
var element = document.getElementById('multiple_email'); | ||
test(function(){ | ||
var values = element.values; | ||
assert_not_equals(typeof values, 'undefined', 'type of values'); | ||
assert_equals(values.length, 2); | ||
assert_equals(values[0], 'user1@example.com'); | ||
assert_equals(values[1], 'user2@test.com'); | ||
}, 'The element\'s values are the result of splitting on commas the element\'s value.'); | ||
test(function(){ | ||
element.value = ''; | ||
var values = element.values; | ||
assert_not_equals(typeof values, 'undefined', 'type of values'); | ||
values.push('user,@example.com'); | ||
assert_equals(values.length, 0); | ||
}, 'User agents must not allow users to set any individual value to a string containing "," (U+002C) character'); | ||
test(function(){ | ||
element.value = ''; | ||
var values = element.values; | ||
assert_not_equals(typeof values, 'undefined', 'type of values'); | ||
values.push('user@e\u000Axample.com'); | ||
assert_equals(values.length, 0); | ||
}, 'User agents must not allow users to set any individual value to a string containing "LF" (U+000A) character'); | ||
test(function(){ | ||
element.value = ''; | ||
var values = element.values; | ||
assert_not_equals(typeof values, 'undefined', 'type of values'); | ||
values.push('user@e\u000Dxample.com'); | ||
assert_equals(values.length, 0); | ||
}, 'User agents must not allow users to set any individual value to a string containing "CR" (U+000D) character'); | ||
test(function(){ | ||
element.value = ' user1@example.com , user2@test.com, user3@test.com '; | ||
var values = element.values; | ||
assert_not_equals(typeof values, 'undefined', 'type of values'); | ||
test(function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests inside tests is bad form, because you get different number of tests whether you pass or fail other tests. It's possible to create a wrapper around it that checks prerequisite stuff (that can actually change, no reason if not). The reason is that some of the big testing systems expect the tests to be equal in number (they track the status of tests), if they just disappear, that's different from a new fail. |
||
assert_equals(values.length, 3); | ||
}, 'Let latest values be a copy of the element\'s values.'); | ||
test(function(){ | ||
assert_equals(values[0], 'user1@example.com'); | ||
assert_equals(values[1], 'user2@test.com'); | ||
assert_equals(values[2], 'user3@test.com'); | ||
}, 'Strip leading and trailing whitespace from each value in latest values') | ||
test(function(){ | ||
assert_equals(element.value, 'user1@example.com,user2@test.com,user3@test.com'); | ||
}, 'Let the element\'s value be the result of concatenating all the values in latest values, separating each value from the next by a single "," (U+002C) character, maintaining the list\'s order.'); | ||
}, 'Whenever the user changes the element\'s values, the user agent must run the following steps'); | ||
test(function(){ | ||
element.value = ' user1@example.com , user2@test.com, user3@test.com '; | ||
var values = element.values; | ||
assert_not_equals(typeof values, 'undefined', 'type of values'); | ||
test(function(){ | ||
assert_equals(values[0], 'user1@example.com'); | ||
assert_equals(values[1], 'user2@test.com'); | ||
assert_equals(values[2], 'user3@test.com'); | ||
}, 'Split on commas the element\'s value, strip leading and trailing whitespace from each resulting token, if any, and let the element\'s values be the (possibly empty) resulting list of (possibly empty) tokens, maintaining the original order.'); | ||
test(function(){ | ||
assert_equals(element.value, 'user1@example.com,user2@test.com,user3@test.com'); | ||
}, 'Let the element\'s value be the result of concatenating the element\'s values, separating each value from the next by a single "," (U+002C) character, maintaining the list\'s order'); | ||
}, 'When the multiple attribute is set, the user agent must run the value sanitization algorithm'); | ||
}, 'When the mutiple attribute is specified on the element'); | ||
</script> | ||
|
||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed.