<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('This test aims to check for typeMismatch flag with type=datetime-local input fields');
var i = document.createElement('input');
i.type = 'datetime-local';
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 datetime-local string.');
else
testFailed('"' + value + '" is a valid datetime-local string that failed to be set on the input.');
}
function shouldBeInvalid(value, disabled)
{
check(value, disabled);
if (i.value === '')
testPassed('"' + value + '" is an invalid datetime-local string and was sanitized' + (disabled ? ' while disabled' : '') + '.');
else
testFailed('"' + value + '" is an invalid datetime-local string and was not sanitized' + (disabled ? ' while disabled' : '') + '.');
}
// Valid values
shouldBeValid('');
shouldBeValid('2009-09-07T16:49');
shouldBeValid('2009-09-07 16:49');
shouldBeValid('2009-09-07T16:49:31');
shouldBeValid('2009-09-07T16:49:31.1');
shouldBeValid('2009-09-07T16:49:31.12');
shouldBeValid('2009-09-07T16:49:31.123');
shouldBeValid('275760-09-13T00:00:00.000');
shouldBeValid('0001-01-01T00:00:00.000');
// Invalid values
shouldBeInvalid(' 2009-09-07T16:49 ');
shouldBeInvalid('2009-09-07t16:49');
shouldBeInvalid('2009/09/07T16:49');
shouldBeInvalid('2009-09-07T16:49:31.1234567890');
shouldBeInvalid('a');
shouldBeInvalid('-1-09-07T16:49');
shouldBeInvalid('0000-12-31T23:59:59.999');
shouldBeInvalid('275760-09-13T00:00:00.001');
// Disabled
shouldBeInvalid('invalid', true);
</script>
</body>
</html>