Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / month / input-valueasnumber-month.html
blob2ae1e973630deba0629fe8573e75efdd32575bdf
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 .valueAsNumber with &lt;input type=month>.');
12 var input = document.createElement('input');
13 input.type = 'month';
15 function valueAsNumberFor(stringValue) {
16 input.value = stringValue;
17 return input.valueAsNumber;
20 function setValueAsNumberAndGetValue(y, m) {
21 input.valueAsNumber = (y - 1970) * 12 + m - 1;
22 return input.value;
25 shouldBe('valueAsNumberFor("")', 'Number.NaN');
26 shouldBe('valueAsNumberFor("1969-01")', '-12');
27 shouldBe('valueAsNumberFor("1969-12")', '-1');
28 shouldBe('valueAsNumberFor("1970-01")', '0');
29 shouldBe('valueAsNumberFor("1970-12")', '11');
30 shouldBe('valueAsNumberFor("1971-01")', '12');
31 shouldBe('valueAsNumberFor("2009-12")', '(2009-1970)*12+11');
33 shouldBe('input.valueAsNumber = -1; input.value', '"1969-12"');
34 shouldBe('input.valueAsNumber = 0; input.value', '"1970-01"');
35 shouldBe('setValueAsNumberAndGetValue(2009, 12)', '"2009-12"');
36 shouldBe('setValueAsNumberAndGetValue(10000, 1)', '"10000-01"');
38 shouldBe('setValueAsNumberAndGetValue(-1, 1)', '""');
39 shouldBe('setValueAsNumberAndGetValue(0, 12)', '""');
40 shouldBe('setValueAsNumberAndGetValue(1, 1)', '"0001-01"');
41 shouldBe('setValueAsNumberAndGetValue(1, 2)', '"0001-02"');
42 shouldBe('setValueAsNumberAndGetValue(275760, 9)', '"275760-09"');
43 shouldBe('setValueAsNumberAndGetValue(275760, 10)', '""');
45 // Date.UTC() of V8 throws an exception for the following value though JavaScriptCore doesn't.
46 // shouldBe('setValueAsNumberAndGetValue(275760, 8, 14)', '"275760-09"');
48 debug('Tests to set invalid values to valueAsNumber:');
49 shouldBe('input.value = ""; input.valueAsNumber = null; input.value', '"1970-01"');
50 shouldBeNaN('input.valueAsNumber = "foo"; input.valueAsNumber');
51 shouldBeEqualToString('input.valueAsNumber = "foo"; input.value', '');
52 shouldBeNaN('input.valueAsNumber = NaN; input.valueAsNumber');
53 shouldBeEqualToString('input.valueAsNumber = NaN; input.value', '');
54 shouldBeNaN('input.valueAsNumber = Number.NaN; input.valueAsNumber');
55 shouldBeEqualToString('input.valueAsNumber = Number.NaN; input.value', '');
56 shouldThrow('input.valueAsNumber = Infinity', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is infinite."');
57 shouldThrow('input.valueAsNumber = Number.POSITIVE_INFINITY', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is infinite."');
58 shouldThrow('input.valueAsNumber = Number.NEGATIVE_INFINITY', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is infinite."');
59 </script>
60 </body>
61 </html>