2010-12-13 Dai Mikurube <dmikurube@google.com>
[WebKit.git] / LayoutTests / fast / forms / script-tests / ValidityState-typeMismatch-week.js
1 description('This test aims to check for typeMismatch flag with type=week input fields');
2 var i = document.createElement('input');
3 i.type = 'week';
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') + ' week 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('0001-W01');
31 shouldBeValid('1583-W01');
32 shouldBeValid('9999-W52');
33 shouldBeValid('275760-W37');
34 shouldBeValid('2009-W01');
35 shouldBeValid('2004-W53');  // 2004 started on Thursday.
36 shouldBeValid('2003-W52');  // 2003 started on Wednesday, but wasn't a leap year.
37 shouldBeValid('1992-W53');  // 1992 started on Wednesday, and was a leap year.
38
39 // Invalid values
40 shouldBeInvalid(' 2009-W01 ');
41 shouldBeInvalid('2009W01');
42 shouldBeInvalid('2009-w01');
43 shouldBeInvalid('2009-W1');
44 shouldBeInvalid('2009-W001');
45 shouldBeInvalid('a');
46 shouldBeInvalid('-1-W09');
47 shouldBeInvalid('0000-W52');
48 shouldBeInvalid('2147483648-W01');
49 shouldBeInvalid('275760-W38');
50 shouldBeInvalid('2009-W00');
51 shouldBeInvalid('2009-W-1');
52 shouldBeInvalid('2004-W54');  // 2004 started on Thursday.
53 shouldBeInvalid('2003-W53');  // 2003 started on Wednesday, but wasn't a leap year.
54 shouldBeInvalid('1992-W54');  // 1992 started on Wednesday, and was a leap year.
55 shouldBeInvalid('2009/09');
56 shouldBeInvalid('200909');
57 shouldBeInvalid('2009-Wxx');
58 shouldBeInvalid('2009');
59
60 // Disabled
61 shouldBeValid('invalid', true);
62
63 var successfullyParsed = true;