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 <p id="description"></p> | 7 <p id="description"></p> |
8 <div id="console"></div> | 8 <div id="console"></div> |
9 <script> | 9 <script> |
10 description('Tests for .valueAsNumber with <input type=range>.'); | 10 description('Tests for .valueAsNumber with <input type=range>.'); |
11 | 11 |
12 var input = document.createElement('input'); | 12 var input = document.createElement('input'); |
13 input.type = 'range'; | 13 input.type = 'range'; |
14 document.body.appendChild(input); | 14 document.body.appendChild(input); |
15 | 15 |
16 function valueAsNumberFor(stringValue) { | 16 function valueAsNumberFor(stringValue) { |
17 input.value = stringValue; | 17 input.value = stringValue; |
18 input.offsetWidth; // Force to make a renderer work. | |
19 return input.valueAsNumber; | 18 return input.valueAsNumber; |
20 } | 19 } |
21 | 20 |
22 function setValueAsNumberAndGetValue(num) { | 21 function setValueAsNumberAndGetValue(num) { |
23 input.valueAsNumber = num; | 22 input.valueAsNumber = num; |
24 input.offsetWidth; // Force to make a renderer work. | |
25 return input.value; | 23 return input.value; |
26 } | 24 } |
27 | 25 |
28 // The default values for type=range: min=0 max=100 step=1 | 26 // The default values for type=range: min=0 max=100 step=1 |
29 // Values are modifies for these restrictions. | 27 // Values are modifies for these restrictions. |
30 shouldBe('valueAsNumberFor("0")', '0'); | 28 shouldBe('valueAsNumberFor("0")', '0'); |
31 shouldBe('valueAsNumberFor("10")', '10'); | 29 shouldBe('valueAsNumberFor("10")', '10'); |
32 shouldBe('valueAsNumberFor("01")', '1'); | 30 shouldBe('valueAsNumberFor("01")', '1'); |
33 shouldBe('valueAsNumberFor("-0")', '0'); | 31 shouldBe('valueAsNumberFor("-0")', '0'); |
34 shouldBe('valueAsNumberFor("-1.2")', '0'); | 32 shouldBe('valueAsNumberFor("-1.2")', '0'); |
(...skipping 17 matching lines...) Expand all Loading... |
52 shouldBe('valueAsNumberFor("nan")', '50'); | 50 shouldBe('valueAsNumberFor("nan")', '50'); |
53 shouldBe('valueAsNumberFor("Inf")', '50'); | 51 shouldBe('valueAsNumberFor("Inf")', '50'); |
54 shouldBe('valueAsNumberFor("inf")', '50'); | 52 shouldBe('valueAsNumberFor("inf")', '50'); |
55 shouldBe('valueAsNumberFor("Infinity")', '50'); | 53 shouldBe('valueAsNumberFor("Infinity")', '50'); |
56 shouldBe('valueAsNumberFor("infinity")', '50'); | 54 shouldBe('valueAsNumberFor("infinity")', '50'); |
57 | 55 |
58 debug('Too huge exponent to support'); | 56 debug('Too huge exponent to support'); |
59 shouldBe('valueAsNumberFor("1.2E65535")', '50'); | 57 shouldBe('valueAsNumberFor("1.2E65535")', '50'); |
60 | 58 |
61 debug('Tests for the valueAsNumber setter:'); | 59 debug('Tests for the valueAsNumber setter:'); |
62 shouldBe('setValueAsNumberAndGetValue(0)', '"0"'); | 60 shouldBeEqualToString('setValueAsNumberAndGetValue(0)', '0'); |
63 shouldBe('setValueAsNumberAndGetValue(10)', '"10"'); | 61 shouldBeEqualToString('setValueAsNumberAndGetValue(10)', '10'); |
64 shouldBe('setValueAsNumberAndGetValue(01)', '"1"'); | 62 shouldBeEqualToString('setValueAsNumberAndGetValue(01)', '1'); |
65 shouldBe('setValueAsNumberAndGetValue(-0)', '"0"'); | 63 shouldBeEqualToString('setValueAsNumberAndGetValue(-0)', '0'); |
66 shouldBe('setValueAsNumberAndGetValue(-1.2)', '"0"'); | 64 shouldBeEqualToString('setValueAsNumberAndGetValue(-1.2)', '0'); |
67 shouldBe('setValueAsNumberAndGetValue(1.2e10)', '"100"'); | 65 shouldBeEqualToString('setValueAsNumberAndGetValue(1.2e10)', '100'); |
68 shouldBe('setValueAsNumberAndGetValue(1.2e-10)', '"0"'); | 66 shouldBeEqualToString('setValueAsNumberAndGetValue(1.2e-10)', '0'); |
69 shouldBe('setValueAsNumberAndGetValue(1.2345678901234567e+38)', '"100"'); | 67 shouldBeEqualToString('setValueAsNumberAndGetValue(1.2345678901234567e+38)', '10
0'); |
70 | 68 |
71 debug('Tests to set invalid values to valueAsNumber:'); | 69 debug('Tests to set invalid values to valueAsNumber:'); |
72 shouldBe('setValueAsNumberAndGetValue(null)', '"0"'); | 70 shouldBeEqualToString('setValueAsNumberAndGetValue(null)', '0'); |
73 shouldThrow('setValueAsNumberAndGetValue("foo")', '"NotSupportedError: Failed to
set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided
is not a number."'); | 71 shouldBeEqualToString('setValueAsNumberAndGetValue(0)', '0'); |
74 shouldThrow('setValueAsNumberAndGetValue(NaN)', '"NotSupportedError: Failed to s
et the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is
not a number."'); | 72 |
75 shouldThrow('setValueAsNumberAndGetValue(Number.NaN)', '"NotSupportedError: Fail
ed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value prov
ided is not a number."'); | 73 // if .valueAsNumber is passed a NaN, the value is set as the empty string. Whic
h resets the range value to its default. |
76 shouldThrow('setValueAsNumberAndGetValue(Infinity)', '"NotSupportedError: Failed
to set the \'valueAsNumber\' property on \'HTMLInputElement\': The value provid
ed is infinite."'); | 74 var minValue = Number(input.min) || 0; |
77 shouldThrow('setValueAsNumberAndGetValue(Number.POSITIVE_INFINITY)', '"NotSuppor
tedError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\':
The value provided is infinite."'); | 75 var maxValue = Number(input.max) || 100; |
78 shouldThrow('setValueAsNumberAndGetValue(Number.NEGATIVE_INFINITY)', '"NotSuppor
tedError: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\':
The value provided is infinite."'); | 76 var defaultValue = String(minValue > maxValue ? minValue : (minValue + (maxValue
- minValue) / 2.0)); |
| 77 shouldBeEqualToString('setValueAsNumberAndGetValue("foo")', defaultValue); |
| 78 shouldBeEqualToString('setValueAsNumberAndGetValue(NaN)', defaultValue); |
| 79 shouldBeEqualToString('setValueAsNumberAndGetValue(Number.NaN)', defaultValue); |
| 80 shouldThrow('setValueAsNumberAndGetValue(Infinity)', '"TypeError: Failed to set
the \'valueAsNumber\' property on \'HTMLInputElement\': The value provided is in
finite."'); |
| 81 shouldThrow('setValueAsNumberAndGetValue(Number.POSITIVE_INFINITY)', '"TypeError
: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The valu
e provided is infinite."'); |
| 82 shouldThrow('setValueAsNumberAndGetValue(Number.NEGATIVE_INFINITY)', '"TypeError
: Failed to set the \'valueAsNumber\' property on \'HTMLInputElement\': The valu
e provided is infinite."'); |
79 </script> | 83 </script> |
80 </body> | 84 </body> |
81 </html> | 85 </html> |
OLD | NEW |