Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / date / input-valueasdate-date.html
blob5faea360c1e3795633fa7632dd52d7d7928fdee9
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9 <script>
10 description('Tests for .valueAsDate with &lt;input type=date>.');
12 var input = document.createElement('input');
13 input.type = 'date';
15 function valueAsDateFor(stringValue) {
16 input.value = stringValue;
17 return input.valueAsDate;
20 function setValueAsDateAndGetValue(year, month, day) {
21 var date = new Date();
22 date.setTime(Date.UTC(year, month, day));
23 if (year < 100)
24 date.setUTCFullYear(year);
25 input.valueAsDate = date;
26 return input.value;
29 shouldBe('valueAsDateFor("")', 'null');
30 shouldBe('valueAsDateFor("1969-12-31").getTime()', 'Date.UTC(1969, 11, 31)');
31 shouldBe('valueAsDateFor("1970-01-01").getTime()', 'Date.UTC(1970, 0, 1)');
32 shouldBe('valueAsDateFor("2009-12-22").getTime()', 'Date.UTC(2009, 11, 22)');
34 shouldBeEqualToString('setValueAsDateAndGetValue(1969, 11, 1)', '1969-12-01');
35 shouldBeEqualToString('setValueAsDateAndGetValue(1970, 0, 1)', '1970-01-01');
36 shouldBeEqualToString('setValueAsDateAndGetValue(2009, 11, 31)', '2009-12-31');
37 shouldBeEqualToString('setValueAsDateAndGetValue(10000, 0, 1)', '10000-01-01');
39 shouldBeEqualToString('setValueAsDateAndGetValue(-1, 0, 1)', '');
40 shouldBeEqualToString('setValueAsDateAndGetValue(0, 11, 31)', '');
41 shouldBeEqualToString('setValueAsDateAndGetValue(1, 0, 1)', '0001-01-01');
42 shouldBeEqualToString('setValueAsDateAndGetValue(1582, 9, 15)', '1582-10-15');
43 shouldBeEqualToString('setValueAsDateAndGetValue(1582, 9, 31)', '1582-10-31');
44 shouldBeEqualToString('setValueAsDateAndGetValue(275760, 8, 13)', '275760-09-13');
45 shouldBeEqualToString('setValueAsDateAndGetValue(275760, 8, 14)', ''); // Date of JavaScript can't represent this.
47 debug('Invalid objects:');
48 shouldBeEqualToString('input.value = "2010-01-01"; input.valueAsDate = document; input.value', '');
49 shouldBeEqualToString('input.value = "2010-01-01"; input.valueAsDate = null; input.value', '');
50 </script>
51 </body>
52 </html>