blob: cb90582f457c116673a16d07c140da81cd170e6a [file] [log] [blame]
tkent@chromium.org95fb1aa2011-08-10 08:06:14 +00001<!DOCTYPE html>
2<html>
3<head>
tkent@chromium.org95fb1aa2011-08-10 08:06:14 +00004<script src="../../js/resources/js-test-pre.js"></script>
5</head>
6<body>
7<p id="description"></p>
8<div id="console"></div>
9<script>
10description('This test aims to check for rangeUnderflow flag with datetime-local input fields');
11
12var input = document.createElement('input');
13
14function checkUnderflow(value, min, disabled)
15{
16 input.value = value;
17 input.min = min;
18 input.disabled = !!disabled;
19 var underflow = input.validity.rangeUnderflow;
20 var resultText = 'The value "' + input.value + '" ' +
21 (underflow ? 'undeflows' : 'doesn\'t underflow') +
22 ' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
23 if (underflow)
24 testPassed(resultText);
25 else
26 testFailed(resultText);
27}
28
29function checkNotUnderflow(value, min, disabled)
30{
31 input.value = value;
32 input.min = min;
33 input.disabled = !!disabled;
34 var underflow = input.validity.rangeUnderflow;
35 var resultText = 'The value "' + input.value + '" ' +
36 (underflow ? 'underflows' : 'doesn\'t underflow') +
37 ' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
38 if (underflow)
39 testFailed(resultText);
40 else
41 testPassed(resultText);
42}
43
44input.type = 'datetime-local';
45input.max = '';
46// No underflow cases
47checkNotUnderflow('2010-01-27T12:34', null);
48checkNotUnderflow('2010-01-27T12:34', '');
49checkNotUnderflow('2010-01-27T12:34', 'foo');
50// 1000-01-01 is smaller than the implicit minimum value.
51// But the date parser rejects it before comparing the minimum value.
52checkNotUnderflow('1000-01-01T12:34', '');
53checkNotUnderflow('1582-10-15T00:00', '');
54checkNotUnderflow('2010-01-27T12:34', '2010-01-26T00:00');
55checkNotUnderflow('2010-01-27T12:34', '2009-01-28T00:00');
56checkNotUnderflow('foo', '2011-01-26T00:00');
57
58// Underflow cases
59checkUnderflow('2010-01-27T12:34', '2010-01-27T13:00');
60checkUnderflow('9999-01-01T12:00', '10000-12-31T12:00');
61input.max = '2010-01-01T12:00'; // value < min && value > max
62checkUnderflow('2010-01-27T12:00', '2010-02-01T12:00');
63
64// Disabled
65checkNotUnderflow('9999-01-01T12:00', '10000-12-31T12:00', true);
66
67var successfullyParsed = true;
68</script>
69<script src="../../js/resources/js-test-post.js"></script>
70</body>
71</html>