blob: c79fe6ac773b2639bd5db5d10f29f255ec2bbea7 [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 time 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 ? 'underflows' : '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 = 'time';
input.max = '';
// No underflow cases
checkNotUnderflow('13:16', null);
checkNotUnderflow('13:16', '');
checkNotUnderflow('13:16', 'foo');
checkNotUnderflow('00:00:00.000', '');
checkNotUnderflow('23:59:59.999', '');
checkNotUnderflow('13:16', '11:00');
checkNotUnderflow('13:16', '13:16');
checkSanitizedValueNotUnderflow('foo', '11:00');
// Underflow cases
checkUnderflow('13:16', '13:17');
checkUnderflow('23:59', '23:59:30');
input.max = '11:00'; // value < min && value > max
checkUnderflow('13:16', '14:00');
// Disabled
checkUnderflow('23:59', '23:59:30', true);
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>