| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../../resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| <script> |
| description('Tests for .valueAsNumber with <input type=month>.'); |
| |
| var input = document.createElement('input'); |
| input.type = 'month'; |
| |
| function valueAsNumberFor(stringValue) { |
| input.value = stringValue; |
| return input.valueAsNumber; |
| } |
| |
| function setValueAsNumberAndGetValue(y, m) { |
| input.valueAsNumber = (y - 1970) * 12 + m - 1; |
| return input.value; |
| } |
| |
| shouldBe('valueAsNumberFor("")', 'Number.NaN'); |
| shouldBe('valueAsNumberFor("1969-01")', '-12'); |
| shouldBe('valueAsNumberFor("1969-12")', '-1'); |
| shouldBe('valueAsNumberFor("1970-01")', '0'); |
| shouldBe('valueAsNumberFor("1970-12")', '11'); |
| shouldBe('valueAsNumberFor("1971-01")', '12'); |
| shouldBe('valueAsNumberFor("2009-12")', '(2009-1970)*12+11'); |
| |
| shouldBe('input.valueAsNumber = -1; input.value', '"1969-12"'); |
| shouldBe('input.valueAsNumber = 0; input.value', '"1970-01"'); |
| shouldBe('setValueAsNumberAndGetValue(2009, 12)', '"2009-12"'); |
| shouldBe('setValueAsNumberAndGetValue(10000, 1)', '"10000-01"'); |
| |
| shouldBe('setValueAsNumberAndGetValue(-1, 1)', '""'); |
| shouldBe('setValueAsNumberAndGetValue(0, 12)', '""'); |
| shouldBe('setValueAsNumberAndGetValue(1, 1)', '"0001-01"'); |
| shouldBe('setValueAsNumberAndGetValue(1, 2)', '"0001-02"'); |
| shouldBe('setValueAsNumberAndGetValue(275760, 9)', '"275760-09"'); |
| shouldBe('setValueAsNumberAndGetValue(275760, 10)', '""'); |
| |
| // Date.UTC() of V8 throws an exception for the following value though JavaScriptCore doesn't. |
| // shouldBe('setValueAsNumberAndGetValue(275760, 8, 14)', '"275760-09"'); |
| |
| debug('Tests to set invalid values to valueAsNumber:'); |
| shouldBe('input.value = ""; input.valueAsNumber = null; input.value', '"1970-01"'); |
| shouldThrowErrorName('input.valueAsNumber = "foo"', 'NotSupportedError'); |
| shouldThrowErrorName('input.valueAsNumber = NaN', 'NotSupportedError'); |
| shouldThrowErrorName('input.valueAsNumber = Number.NaN', 'NotSupportedError'); |
| shouldThrowErrorName('input.valueAsNumber = Infinity', 'NotSupportedError'); |
| shouldThrowErrorName('input.valueAsNumber = Number.POSITIVE_INFINITY', 'NotSupportedError'); |
| shouldThrowErrorName('input.valueAsNumber = Number.NEGATIVE_INFINITY', 'NotSupportedError'); |
| </script> |
| <script src="../../../resources/js-test-post.js"></script> |
| </body> |
| </html> |