4 <script src=
"../../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
10 description('Tests for .valueAsNumber with <input type=date>.');
12 var input
= document
.createElement('input');
15 function valueAsNumberFor(stringValue
) {
16 input
.value
= stringValue
;
17 return input
.valueAsNumber
;
20 function setValueAsNumberAndGetValue(year
, month
, day
) {
21 var date
= new Date();
22 date
.setTime(Date
.UTC(year
, month
, day
));
24 date
.setUTCFullYear(year
);
25 input
.valueAsNumber
= date
.getTime();
29 shouldBe('valueAsNumberFor("")', 'Number.NaN');
30 shouldBe('valueAsNumberFor("1969-12-31")', 'Date.UTC(1969, 11, 31)');
31 shouldBe('valueAsNumberFor("1970-01-01")', 'Date.UTC(1970, 0, 1)');
32 shouldBe('valueAsNumberFor("2009-12-22")', 'Date.UTC(2009, 11, 22)');
34 shouldBe('setValueAsNumberAndGetValue(1969, 11, 1)', '"1969-12-01"');
35 shouldBe('setValueAsNumberAndGetValue(1970, 0, 1)', '"1970-01-01"');
36 shouldBe('setValueAsNumberAndGetValue(2009, 11, 31)', '"2009-12-31"');
37 shouldBe('setValueAsNumberAndGetValue(10000, 0, 1)', '"10000-01-01"');
39 shouldBe('setValueAsNumberAndGetValue(-1, 0, 1)', '""');
40 shouldBe('setValueAsNumberAndGetValue(0, 11, 31)', '""');
41 shouldBe('setValueAsNumberAndGetValue(1, 0, 1)', '"0001-01-01"');
42 shouldBe('setValueAsNumberAndGetValue(275760, 8, 13)', '"275760-09-13"');
44 debug('Tests to set invalid values to valueAsNumber:');
45 shouldBe('input.value = ""; input.valueAsNumber = null; input.value', '"1970-01-01"');
46 shouldBeNaN('input.valueAsNumber = "foo"; input.valueAsNumber');
47 shouldBeEqualToString('input.valueAsNumber = "foo"; input.value', '');
48 shouldBeNaN('input.valueAsNumber = NaN; input.valueAsNumber');
49 shouldBeEqualToString('input.valueAsNumber = NaN; input.value', '');
50 shouldBeNaN('input.valueAsNumber = Number.NaN; input.valueAsNumber');
51 shouldBeEqualToString('input.valueAsNumber = Number.NaN; input.value', '');
52 shouldThrow('input.valueAsNumber = Infinity', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is infinite."');
53 shouldThrow('input.valueAsNumber = Number.POSITIVE_INFINITY', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is infinite."');
54 shouldThrow('input.valueAsNumber = Number.NEGATIVE_INFINITY', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is infinite."');
55 shouldBeNaN('input.valueAsNumber = Date.UTC(275760, 8, 14); input.valueAsNumber');
56 shouldBeEqualToString('input.valueAsNumber = Date.UTC(275760, 8, 14); input.value', '');