tkent@chromium.org | 95fb1aa | 2011-08-10 08:06:14 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
tkent@chromium.org | 95fb1aa | 2011-08-10 08:06:14 +0000 | [diff] [blame] | 4 | <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> |
| 10 | description('This test aims to check for rangeUnderflow flag with datetime-local input fields'); |
| 11 | |
| 12 | var input = document.createElement('input'); |
| 13 | |
| 14 | function 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 | |
| 29 | function 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 | |
| 44 | input.type = 'datetime-local'; |
| 45 | input.max = ''; |
| 46 | // No underflow cases |
| 47 | checkNotUnderflow('2010-01-27T12:34', null); |
| 48 | checkNotUnderflow('2010-01-27T12:34', ''); |
| 49 | checkNotUnderflow('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. |
| 52 | checkNotUnderflow('1000-01-01T12:34', ''); |
| 53 | checkNotUnderflow('1582-10-15T00:00', ''); |
| 54 | checkNotUnderflow('2010-01-27T12:34', '2010-01-26T00:00'); |
| 55 | checkNotUnderflow('2010-01-27T12:34', '2009-01-28T00:00'); |
| 56 | checkNotUnderflow('foo', '2011-01-26T00:00'); |
| 57 | |
| 58 | // Underflow cases |
| 59 | checkUnderflow('2010-01-27T12:34', '2010-01-27T13:00'); |
| 60 | checkUnderflow('9999-01-01T12:00', '10000-12-31T12:00'); |
| 61 | input.max = '2010-01-01T12:00'; // value < min && value > max |
| 62 | checkUnderflow('2010-01-27T12:00', '2010-02-01T12:00'); |
| 63 | |
| 64 | // Disabled |
| 65 | checkNotUnderflow('9999-01-01T12:00', '10000-12-31T12:00', true); |
| 66 | |
| 67 | var successfullyParsed = true; |
| 68 | </script> |
| 69 | <script src="../../js/resources/js-test-post.js"></script> |
| 70 | </body> |
| 71 | </html> |