chromium/third_party/blink/web_tests/external/wpt/html/semantics/forms/the-input-element/email.html

<!DOCTYPE html>
<title>Input Email</title>
<link rel="author" title="Kazuki Kanamori" href="mailto:[email protected]">
<link rel="author" title="Denis Ah-Kang" href="mailto:[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#e-mail-state-(type=email)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<input type="email" id="single_email" value="[email protected]"/>
<input type="email" id="multiple_email" value="[email protected], [email protected]" multiple/>
<div id="log"></div>

<script type="text/javascript">
  var single = document.getElementById('single_email'),
      mult = document.getElementById('multiple_email');

  test(function(){
    assert_false(single.multiple);
  }, "single_email doesn't have the multiple attribute");

  test(function(){
    single.value = '[email protected]\u000A';
    assert_equals(single.value, '[email protected]');
    single.value = '[email protected]\u000D';
    assert_equals(single.value, '[email protected]');
  }, 'value should be sanitized: strip line breaks');

  test(function(){
    single.value = '[email protected]';
    assert_true(single.validity.valid);
    single.value = 'example.com';
    assert_false(single.validity.valid);
  }, 'Email address validity');

  test(function(){
    single.setAttribute('multiple', true);
    single.value = '  [email protected]  , [email protected]  ';
    assert_equals(single.value, '[email protected],[email protected]');
    single.removeAttribute('multiple');
    assert_equals(single.value, '[email protected],[email protected]');
  }, 'When the multiple attribute is removed, the user agent must run the value sanitization algorithm');

  test(function(){
    assert_true(mult.multiple);
  }, "multiple_email has the multiple attribute");

  test(function(){
    mult.value = '  [email protected]  , [email protected], [email protected]  ';
    assert_equals(mult.value, '[email protected],[email protected],[email protected]');
  }, "run the value sanitization algorithm after setting a new value");

  test(function(){
    mult.value = '[email protected],[email protected],[email protected]';
    assert_true(mult.validity.valid);

    mult.value = 'u,[email protected],[email protected],[email protected]';
    assert_false(mult.validity.valid);
  }, "valid value is a set of valid email addresses separated by a single ','");

  test(function(){
    mult.removeAttribute('multiple');
    mult.value = '[email protected] , [email protected]';
    assert_equals(mult.value, '[email protected] , [email protected]');
    mult.setAttribute('multiple', true);
    assert_equals(mult.value, '[email protected],[email protected]');
  }, 'When the multiple attribute is set, the user agent must run the value sanitization algorithm');
</script>