2010-12-13 Dai Mikurube <dmikurube@google.com>
[WebKit.git] / LayoutTests / fast / forms / script-tests / ValidityState-typeMismatch-time.js
1 description('This test aims to check for typeMismatch flag with type=time input fields');
2 var i = document.createElement('input');
3 i.type = 'time';
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') + ' time 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('00:00');
31 shouldBeValid('23:59');
32 shouldBeValid('23:59:59');
33 shouldBeValid('23:59:59.1');
34 shouldBeValid('23:59:59.12');
35 shouldBeValid('23:59:59.123');
36 shouldBeValid('23:59:59.1234567890');
37 shouldBeValid('00:00:00.0000000000');
38
39 // Invalid values
40 shouldBeInvalid(' 00:00 ');
41 shouldBeInvalid('1:23');
42 shouldBeInvalid('011:11');
43 shouldBeInvalid('ab:11');
44 shouldBeInvalid('-1:11');
45 shouldBeInvalid('24:11');
46 shouldBeInvalid('11');
47 shouldBeInvalid('11-');
48 shouldBeInvalid('11:-2');
49 shouldBeInvalid('11:60');
50 shouldBeInvalid('11:2b');
51 shouldBeInvalid('11:ab');
52 shouldBeInvalid('11:034');
53 shouldBeInvalid('23:45:');
54 shouldBeInvalid('23:45:6');
55 shouldBeInvalid('23:45:-1');
56 shouldBeInvalid('23:45:70');
57 shouldBeInvalid('23:45:zz');
58 shouldBeInvalid('23:45:06.');
59 shouldBeInvalid('23:45:06.abc');
60 shouldBeInvalid('23:45:06.789abc');
61
62 // Disabled
63 shouldBeValid('invalid', true);
64
65 var successfullyParsed = true;