chromium/third_party/blink/web_tests/fast/forms/email-idn-conversion.html

<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/common.js"></script>
</head>
<body>
<input id="input" type="email">
<script>
description('Tests ascii-unicode conversion of IDN email addresses on input type=email.');

var i = document.getElementById('input');
var expectValid = false;
var expectInvalid = true;

function setText(text)
{
    i.focus();
    i.value = '';
    document.execCommand('InsertText', false, text);
}

function emailCheck(expectedValue, expectedVisibleValue, expectedMismatch)
{
    shouldBeEqualToString('i.value', expectedValue);
    shouldBeEqualToString('getUserAgentShadowTextContent(i)', expectedVisibleValue);
    if (expectedMismatch == expectValid)
        shouldBeFalse('i.validity.typeMismatch');
    else
        shouldBeTrue('i.validity.typeMismatch');
}

debug('Values from UI');
setText('foo@ma\u00F1ana.com');
emailCheck('[email protected]', 'foo@ma\u00F1ana.com', expectValid);

setText('ma\[email protected]');
emailCheck('ma\[email protected]', 'ma\[email protected]', expectInvalid);

setText('ma\u00F1ana.com');
emailCheck('ma\u00F1ana.com', 'ma\u00F1ana.com', expectInvalid);

debug('Values from script');
i.value = '[email protected]';
emailCheck('[email protected]', 'foo@\u304A.com', expectValid);

i.value = '[email protected]';
emailCheck('[email protected]', '[email protected]', expectValid);

i.value = 'xn--t8j.com';
emailCheck('xn--t8j.com', 'xn--t8j.com', expectInvalid);

i.value = 'foo@ma\u00F1ana.com';
emailCheck('foo@ma\u00F1ana.com', 'foo@ma\u00F1ana.com', expectInvalid);

debug('Multiple addresses');
i.multiple = true;
setText('foo@ma\u00F1ana.com, bar@\u304A.com');
emailCheck('[email protected],[email protected]', 'foo@ma\u00F1ana.com, bar@\u304A.com', expectValid);

i.value = '[email protected], [email protected]';
emailCheck('[email protected],[email protected]', 'bar@\u304A.com,foo@ma\u00F1ana.com', expectValid);

</script>
</body>
</html>