2010-12-13 Dai Mikurube <dmikurube@google.com>
[WebKit.git] / LayoutTests / fast / forms / script-tests / ValidityState-typeMismatch-datetime.js
1 description('This test aims to check for typeMismatch flag with type=datetime input fields');
2 var i = document.createElement('input');
3 i.type = 'datetime';
4
5 function check(value, mismatchExpected, disabled)
6 {
7     i.value = value;
8     i.disabled = !!disabled;
9     var actual = i.validity.typeMismatch;
10     var didPass = actual == mismatchExpected;
11     var resultText = '"' + value + '" is ' + (didPass ? 'a correct ' : 'an incorrect ') + (actual ? 'invalid' : 'valid') + ' datetime string' + (disabled ? ' when disabled.' : '.');
12     if (didPass)
13         testPassed(resultText);
14     else
15         testFailed(resultText);
16 }
17
18 function shouldBeValid(value, disabled)
19 {
20     check(value, false, disabled);
21 }
22
23 function shouldBeInvalid(value)
24 {
25     check(value, true);
26 }
27
28 // Valid values
29 shouldBeValid('');
30 shouldBeValid('2009-09-07T16:49Z');
31 shouldBeValid('2009-09-07T16:49:31Z');
32 shouldBeValid('2009-09-07T16:49:31.1Z');
33 shouldBeValid('2009-09-07T16:49:31.12Z');
34 shouldBeValid('2009-09-07T16:49:31.123Z');
35 shouldBeValid('2009-09-07T16:49:31.1234567890Z');
36 shouldBeValid('275760-09-12T23:59:59.999Z');
37 shouldBeValid('275760-09-13T00:00:00.000Z');
38 shouldBeValid('0001-01-01T00:00:00.000Z');
39 shouldBeValid('0001-01-01T00:00:00.000+00:00');
40 shouldBeValid('0001-01-01T01:30+01:30');
41 shouldBeValid('0001-01-01T00:00+01:00');
42
43 // Invalid values
44 shouldBeInvalid(' 2009-09-07T16:49Z ');
45 shouldBeInvalid('2009-09-07T16:49z');
46 shouldBeInvalid('2009-09-07t16:49Z');
47 shouldBeInvalid('2009-09-07T16:49');
48 shouldBeInvalid('2009/09/07T16:49Z');
49 shouldBeInvalid('a');
50 shouldBeInvalid('-1-09-07T16:49Z');
51 shouldBeInvalid('2009-09-07T16:49+23');
52 shouldBeInvalid('2009-09-07T16:49+23:');
53 shouldBeInvalid('2009-09-07T16:49+24:00');
54 shouldBeInvalid('2009-09-07T16:49+23:60');
55 shouldBeInvalid('2009-09-07T16:49-23');
56 shouldBeInvalid('2009-09-07T16:49-23:');
57 shouldBeInvalid('2009-09-07T16:49-24:00');
58 shouldBeInvalid('2009-09-07T16:49-23:60');
59 shouldBeInvalid('0000-12-31T23:59:59Z');
60 shouldBeInvalid('2147483647-12-31T23:59-00:01');
61 shouldBeInvalid('2147483648-01-01T00:00:00Z');
62
63 // Disabled
64 shouldBeValid('invalid', true);
65
66 var successfullyParsed = true;