blob: 03519e5a8d2875a73673cd809c2f987c0b360446 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('This test aims to check for rangeUnderflow flag with input fields');
var input = document.createElement('input');
function checkUnderflow(value, min, disabled)
{
input.value = value;
input.min = min;
input.disabled = !!disabled;
var underflow = input.validity.rangeUnderflow;
var resultText = 'The value "' + input.value + '" ' +
(underflow ? 'undeflows' : 'doesn\'t underflow') +
' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
if (underflow)
testPassed(resultText);
else
testFailed(resultText);
}
function checkNotUnderflow(value, min, disabled, sanitized)
{
input.value = value;
input.min = min;
input.disabled = !!disabled;
var underflow = input.validity.rangeUnderflow;
var resultText = 'The value "' + input.value + '" ' +
(sanitized ? 'sanitized from "' + value + '" ' : '') +
(underflow ? 'underflows' : 'doesn\'t underflow') +
' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
if (underflow)
testFailed(resultText);
else
testPassed(resultText);
}
function checkSanitizedValueNotUnderflow(value, max, disabled)
{
// For date types, invalid values are sanitized to "".
checkNotUnderflow(value, max, disabled, true);
}
input.type = 'datetime';
input.max = '';
// No underflow cases
checkNotUnderflow('2010-01-27T12:34Z', null);
checkNotUnderflow('2010-01-27T12:34Z', '');
checkNotUnderflow('2010-01-27T12:34Z', 'foo');
// 1000-01-01 is smaller than the implicit minimum value.
// But the date parser rejects it before comparing the minimum value.
checkNotUnderflow('1000-01-01T12:34Z', '');
checkNotUnderflow('1582-10-15T00:00Z', '');
checkNotUnderflow('2010-01-27T12:34Z', '2010-01-26T00:00Z');
checkNotUnderflow('2010-01-27T12:34Z', '2009-01-28T00:00Z');
checkSanitizedValueNotUnderflow('foo', '2011-01-26T00:00Z');
// Underflow cases
checkUnderflow('2010-01-27T12:34Z', '2010-01-27T13:00Z');
checkUnderflow('9999-01-01T12:00Z', '10000-12-31T12:00Z');
input.max = '2010-01-01T12:00Z'; // value < min && value > max
checkUnderflow('2010-01-27T12:00Z', '2010-02-01T12:00Z');
// Disabled
checkNotUnderflow('9999-01-01T12:00Z', '10000-12-31T12:00Z', true);
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>