<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('Tests for .valueAsNumber with <input type=date>.');
var input = document.createElement('input');
input.type = 'date';
function valueAsNumberFor(stringValue) {
input.value = stringValue;
return input.valueAsNumber;
}
function setValueAsNumberAndGetValue(year, month, day) {
var date = new Date();
date.setTime(Date.UTC(year, month, day));
if (year < 100)
date.setUTCFullYear(year);
input.valueAsNumber = date.getTime();
return input.value;
}
shouldBe('valueAsNumberFor("")', 'Number.NaN');
shouldBe('valueAsNumberFor("1969-12-31")', 'Date.UTC(1969, 11, 31)');
shouldBe('valueAsNumberFor("1970-01-01")', 'Date.UTC(1970, 0, 1)');
shouldBe('valueAsNumberFor("2009-12-22")', 'Date.UTC(2009, 11, 22)');
shouldBe('setValueAsNumberAndGetValue(1969, 11, 1)', '"1969-12-01"');
shouldBe('setValueAsNumberAndGetValue(1970, 0, 1)', '"1970-01-01"');
shouldBe('setValueAsNumberAndGetValue(2009, 11, 31)', '"2009-12-31"');
shouldBe('setValueAsNumberAndGetValue(10000, 0, 1)', '"10000-01-01"');
shouldBe('setValueAsNumberAndGetValue(-1, 0, 1)', '""');
shouldBe('setValueAsNumberAndGetValue(0, 11, 31)', '""');
shouldBe('setValueAsNumberAndGetValue(1, 0, 1)', '"0001-01-01"');
shouldBe('setValueAsNumberAndGetValue(275760, 8, 13)', '"275760-09-13"');
debug('Tests to set invalid values to valueAsNumber:');
shouldBe('input.value = ""; input.valueAsNumber = null; input.value', '"1970-01-01"');
shouldBeNaN('input.valueAsNumber = "foo"; input.valueAsNumber');
shouldBeEqualToString('input.valueAsNumber = "foo"; input.value', '');
shouldBeNaN('input.valueAsNumber = NaN; input.valueAsNumber');
shouldBeEqualToString('input.valueAsNumber = NaN; input.value', '');
shouldBeNaN('input.valueAsNumber = Number.NaN; input.valueAsNumber');
shouldBeEqualToString('input.valueAsNumber = Number.NaN; input.value', '');
shouldThrow('input.valueAsNumber = Infinity', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is infinite."');
shouldThrow('input.valueAsNumber = Number.POSITIVE_INFINITY', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is infinite."');
shouldThrow('input.valueAsNumber = Number.NEGATIVE_INFINITY', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is infinite."');
shouldBeNaN('input.valueAsNumber = Date.UTC(275760, 8, 14); input.valueAsNumber');
shouldBeEqualToString('input.valueAsNumber = Date.UTC(275760, 8, 14); input.value', '');
</script>
</body>
</html>