Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../../resources/js-test.js"></script> | 4 <script src="../../../resources/js-test.js"></script> |
| 5 </head> | 5 </head> |
| 6 <body> | 6 <body> |
| 7 <script> | 7 <script> |
| 8 description('Tests for .valueAsNumber with <input type=number>.'); | 8 description('Tests for .valueAsNumber with <input type=number>.'); |
| 9 | 9 |
| 10 var input = document.createElement('input'); | 10 var input = document.createElement('input'); |
| 11 input.type = 'number'; | 11 input.type = 'number'; |
| 12 | 12 |
| 13 function valueAsNumberFor(stringValue) { | 13 function valueAsNumberFor(stringValue) { |
| 14 input.value = stringValue; | 14 input.value = stringValue; |
|
tkent
2014/04/14 00:47:37
This test should not be updated. The behavior of
| |
| 15 return input.valueAsNumber; | 15 return input.valueAsNumber; |
| 16 } | 16 } |
| 17 | 17 |
| 18 function setValueAsNumberAndGetValue(num) { | 18 function setValueAsNumberAndGetValue(num) { |
| 19 input.valueAsNumber = num; | 19 input.valueAsNumber = num; |
| 20 return input.value; | 20 return input.value; |
| 21 } | 21 } |
| 22 | 22 |
| 23 shouldBe('valueAsNumberFor("0")', '0'); | 23 shouldBe('valueAsNumberFor("0")', '0'); |
| 24 shouldBe('valueAsNumberFor("0.2")', '0.2'); | 24 shouldBe('valueAsNumberFor("0.2")', '0.2'); |
| 25 shouldBe('valueAsNumberFor(".2")', '0.2'); | 25 shouldBe('valueAsNumberFor(".2")', '0.2'); |
| 26 shouldBe('valueAsNumberFor("10")', '10'); | 26 shouldBe('valueAsNumberFor("10")', '10'); |
| 27 shouldBe('valueAsNumberFor(" 10")', '10'); | |
| 28 shouldBe('valueAsNumberFor("10 ")', '10'); | |
| 29 shouldBe('valueAsNumberFor("1 0")', '10'); | |
| 27 shouldBe('valueAsNumberFor("01")', '1'); | 30 shouldBe('valueAsNumberFor("01")', '1'); |
| 28 shouldBe('valueAsNumberFor("-0")', '0'); // "-0" is 0 in HTML5. | 31 shouldBe('valueAsNumberFor("-0")', '0'); // "-0" is 0 in HTML5. |
| 29 shouldBe('valueAsNumberFor("-1.2")', '-1.2'); | 32 shouldBe('valueAsNumberFor("-1.2")', '-1.2'); |
| 30 shouldBe('valueAsNumberFor("1.2E10")', '1.2E10'); | 33 shouldBe('valueAsNumberFor("1.2E10")', '1.2E10'); |
| 31 shouldBe('valueAsNumberFor("1.2E-10")', '1.2E-10'); | 34 shouldBe('valueAsNumberFor("1.2E-10")', '1.2E-10'); |
| 32 shouldBe('valueAsNumberFor("1.2E+10")', '1.2E10'); | 35 shouldBe('valueAsNumberFor("1.2E+10")', '1.2E10'); |
| 33 shouldBe('valueAsNumberFor("1234567890123456789012345678901234567890123456789012 34567890123456789012345678901234567890123456789012345678901234567890123456789012 34567890123456789012345678901234567890123456789012345678901234567890123456789012 34567890123456789012345678901234567890123456789012345678901234567890123456789012 34567890123456789")', '1.2345678901234568E+308'); | 36 shouldBe('valueAsNumberFor("1234567890123456789012345678901234567890123456789012 34567890123456789012345678901234567890123456789012345678901234567890123456789012 34567890123456789012345678901234567890123456789012345678901234567890123456789012 34567890123456789012345678901234567890123456789012345678901234567890123456789012 34567890123456789")', '1.2345678901234568E+308'); |
| 34 shouldBe('valueAsNumberFor("0.12345678901234567890123456789012345678901234567890 ")', '0.123456789012345678'); | 37 shouldBe('valueAsNumberFor("0.12345678901234567890123456789012345678901234567890 ")', '0.123456789012345678'); |
| 35 | 38 |
| 36 debug('valueAsNumber for invalid string values:'); | 39 debug('valueAsNumber for invalid string values:'); |
| 37 shouldBeTrue('isNaN(valueAsNumberFor(""))'); | 40 shouldBeTrue('isNaN(valueAsNumberFor(""))'); |
| 38 shouldBeTrue('isNaN(valueAsNumberFor("abc"))'); | 41 shouldBeTrue('isNaN(valueAsNumberFor("abc"))'); |
| 39 shouldBeTrue('isNaN(valueAsNumberFor("0xff"))'); | 42 shouldBeTrue('isNaN(valueAsNumberFor("0xff"))'); |
| 40 shouldBeTrue('isNaN(valueAsNumberFor("+1"))'); | 43 shouldBeTrue('isNaN(valueAsNumberFor("+1"))'); |
| 41 shouldBeTrue('isNaN(valueAsNumberFor(" 10"))'); | |
| 42 shouldBeTrue('isNaN(valueAsNumberFor("10 "))'); | |
| 43 shouldBeTrue('isNaN(valueAsNumberFor("."))'); | 44 shouldBeTrue('isNaN(valueAsNumberFor("."))'); |
| 44 shouldBeTrue('isNaN(valueAsNumberFor("1E"))'); | 45 shouldBeTrue('isNaN(valueAsNumberFor("1E"))'); |
| 45 shouldBeTrue('isNaN(valueAsNumberFor("NaN"))'); | 46 shouldBeTrue('isNaN(valueAsNumberFor("NaN"))'); |
| 46 shouldBeTrue('isNaN(valueAsNumberFor("nan"))'); | 47 shouldBeTrue('isNaN(valueAsNumberFor("nan"))'); |
| 47 shouldBeTrue('isNaN(valueAsNumberFor("Inf"))'); | 48 shouldBeTrue('isNaN(valueAsNumberFor("Inf"))'); |
| 48 shouldBeTrue('isNaN(valueAsNumberFor("inf"))'); | 49 shouldBeTrue('isNaN(valueAsNumberFor("inf"))'); |
| 49 shouldBeTrue('isNaN(valueAsNumberFor("Infinity"))'); | 50 shouldBeTrue('isNaN(valueAsNumberFor("Infinity"))'); |
| 50 shouldBeTrue('isNaN(valueAsNumberFor("infinity"))'); | 51 shouldBeTrue('isNaN(valueAsNumberFor("infinity"))'); |
| 51 | 52 |
| 52 debug('Too huge exponent to support'); | 53 debug('Too huge exponent to support'); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 70 shouldBeEqualToString('setValueAsNumberAndGetValue(null)', '0'); | 71 shouldBeEqualToString('setValueAsNumberAndGetValue(null)', '0'); |
| 71 shouldBeEqualToString('setValueAsNumberAndGetValue("foo")', ''); | 72 shouldBeEqualToString('setValueAsNumberAndGetValue("foo")', ''); |
| 72 shouldBeEqualToString('setValueAsNumberAndGetValue(NaN)', ''); | 73 shouldBeEqualToString('setValueAsNumberAndGetValue(NaN)', ''); |
| 73 shouldBeEqualToString('setValueAsNumberAndGetValue(Number.NaN)', ''); | 74 shouldBeEqualToString('setValueAsNumberAndGetValue(Number.NaN)', ''); |
| 74 shouldThrow('setValueAsNumberAndGetValue(Infinity)', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is in finite."'); | 75 shouldThrow('setValueAsNumberAndGetValue(Infinity)', '"TypeError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is in finite."'); |
| 75 shouldThrow('setValueAsNumberAndGetValue(Number.POSITIVE_INFINITY)', '"TypeError : Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The valu e provided is infinite."'); | 76 shouldThrow('setValueAsNumberAndGetValue(Number.POSITIVE_INFINITY)', '"TypeError : Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The valu e provided is infinite."'); |
| 76 shouldThrow('setValueAsNumberAndGetValue(Number.NEGATIVE_INFINITY)', '"TypeError : Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The valu e provided is infinite."'); | 77 shouldThrow('setValueAsNumberAndGetValue(Number.NEGATIVE_INFINITY)', '"TypeError : Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The valu e provided is infinite."'); |
| 77 </script> | 78 </script> |
| 78 </body> | 79 </body> |
| 79 </html> | 80 </html> |
| OLD | NEW |