blob: 8f70cce37daca73093cbf4752458683d9b11bce2 [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 rangeOverflow flag with time input fields');
var input = document.createElement('input');
function checkOverflow(value, max, disabled)
{
input.value = value;
input.max = max;
input.disabled = !!disabled;
var overflow = input.validity.rangeOverflow;
var resultText = 'The value "' + input.value + '" ' +
(overflow ? 'overflows' : 'doesn\'t overflow') +
' the maximum value "' + input.max + '"' + (disabled ? ' when disabled.' : '.');
if (overflow)
testPassed(resultText);
else
testFailed(resultText);
}
function checkNotOverflow(value, max, disabled, sanitized)
{
input.value = value;
input.max = max;
input.disabled = !!disabled;
var overflow = input.validity.rangeOverflow;
var resultText = 'The value "' + input.value + '" ' +
(sanitized ? 'sanitized from "' + value + '" ' : '') +
(overflow ? 'overflows' : 'doesn\'t overflow') +
' the maximum value "' + input.max + '"' + (disabled ? ' when disabled.' : '.');
if (overflow)
testFailed(resultText);
else
testPassed(resultText);
}
function checkSanitizedValueNotOverflow(value, max, disabled)
{
// For date types, invalid values are sanitized to "".
checkNotOverflow(value, max, disabled, true);
}
input.type = 'time';
input.min = '';
// No overflow cases
checkNotOverflow('13:16', null);
checkNotOverflow('13:16', '');
checkNotOverflow('13:16', 'foo');
checkNotOverflow('13:16', '13:16');
checkNotOverflow('13:16', '13:17');
checkNotOverflow('13:16', '14:15');
checkSanitizedValueNotOverflow('foo', '13:16');
// Overflow cases
checkOverflow('13:16', '13:15');
checkOverflow('23:59:59.999', '13:16');
input.min = '14:00'; // value < min && value > max
checkOverflow('13:16', '12:00');
// Disabled
checkNotOverflow('23:59:59.999', '13:16', true);
checkOverflow('13:17:59.999', '13:16', true);
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>