4aaded4f6ed9481d712c2df0d9de33fff371a30b
[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)
6 {
7     i.value = value;
8     var actual = i.validity.typeMismatch;
9     var didPass = actual == mismatchExpected;
10     var resultText = '"' + value + '" is ' + (didPass ? 'a correct ' : 'an incorrect ') + (actual ? 'invalid' : 'valid') + ' time string.';
11     if (didPass)
12         testPassed(resultText);
13     else
14         testFailed(resultText);
15 }
16
17 function shouldBeValid(value)
18 {
19     check(value, false);
20 }
21
22 function shouldBeInvalid(value)
23 {
24     check(value, true);
25 }
26
27 // Valid values
28 shouldBeValid('');
29 shouldBeValid('00:00');
30 shouldBeValid('23:59');
31 shouldBeValid('23:59:59');
32 shouldBeValid('23:59:59.1');
33 shouldBeValid('23:59:59.12');
34 shouldBeValid('23:59:59.123');
35 shouldBeValid('23:59:59.1234567890');
36 shouldBeValid('00:00:00.0000000000');
37
38 // Invalid values
39 shouldBeInvalid(' 00:00 ');
40 shouldBeInvalid('1:23');
41 shouldBeInvalid('011:11');
42 shouldBeInvalid('ab:11');
43 shouldBeInvalid('-1:11');
44 shouldBeInvalid('24:11');
45 shouldBeInvalid('11');
46 shouldBeInvalid('11-');
47 shouldBeInvalid('11:-2');
48 shouldBeInvalid('11:60');
49 shouldBeInvalid('11:2b');
50 shouldBeInvalid('11:ab');
51 shouldBeInvalid('11:034');
52 shouldBeInvalid('23:45:');
53 shouldBeInvalid('23:45:6');
54 shouldBeInvalid('23:45:-1');
55 shouldBeInvalid('23:45:70');
56 shouldBeInvalid('23:45:zz');
57 shouldBeInvalid('23:45:06.');
58 shouldBeInvalid('23:45:06.abc');
59 shouldBeInvalid('23:45:06.789abc');
60
61 var successfullyParsed = true;