chromium/third_party/blink/web_tests/fast/forms/time/time-validity-typemismatch.html

<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/testdriver.js"></script>
<script src="../../../resources/testdriver-vendor.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('This test aims to check for typeMismatch flag with type=time input fields');
var i = document.createElement('input');
i.type = 'time';

function check(value, disabled)
{
    i.value = value;
    i.disabled = !!disabled;

    if (i.validity.typeMismatch)
        testFailed('"' + value + '" had typeMismatch. This should not happen with sanitization.');
}

function shouldBeValid(value)
{
    check(value);
    if ((value === '' && i.value === '') || (value !== '' && i.value !== ""))
        testPassed('"' + value + '" is a correct valid time string.');
    else
        testFailed('"' + value + '" is a valid time string that failed to be set on the input.');
}

function shouldBeInvalid(value, disabled)
{
    check(value, disabled);
    if (i.value === '')
        testPassed('"' + value + '" is an invalid time string and was sanitized' + (disabled ? ' while disabled' : '') + '.');
    else
        testFailed('"' + value + '" is an invalid time string and was not sanitized' + (disabled ? ' while disabled' : '') + '.');
}

// Valid values
shouldBeValid('');
shouldBeValid('00:00');
shouldBeValid('23:59');
shouldBeValid('23:59:59');
shouldBeValid('23:59:59.1');
shouldBeValid('23:59:59.12');
shouldBeValid('23:59:59.123');

// Invalid values
shouldBeInvalid(' 00:00 ');
shouldBeInvalid('1:23');
shouldBeInvalid('011:11');
shouldBeInvalid('ab:11');
shouldBeInvalid('-1:11');
shouldBeInvalid('24:11');
shouldBeInvalid('11');
shouldBeInvalid('11-');
shouldBeInvalid('11:-2');
shouldBeInvalid('11:60');
shouldBeInvalid('11:2b');
shouldBeInvalid('11:ab');
shouldBeInvalid('11:034');
shouldBeInvalid('23:45:');
shouldBeInvalid('23:45:6');
shouldBeInvalid('23:45:-1');
shouldBeInvalid('23:45:70');
shouldBeInvalid('23:45:zz');
shouldBeInvalid('23:45:06.');
shouldBeInvalid('23:45:06.abc');
shouldBeInvalid('23:45:06.789abc');
shouldBeInvalid('23:59:59.1234567890');
shouldBeInvalid('00:00:00.0000000000');

// Disabled
shouldBeInvalid('invalid', true);
</script>
</body>
</html>