1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<!DOCTYPE html>
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('Tests for .valueAsNumber with <input type=range>.');
var input = document.createElement('input');
input.type = 'range';
document.body.appendChild(input);
function valueAsNumberFor(stringValue) {
input.value = stringValue;
input.offsetWidth; // Force to make a renderer work.
return input.valueAsNumber;
}
function setValueAsNumberAndGetValue(num) {
input.valueAsNumber = num;
input.offsetWidth; // Force to make a renderer work.
return input.value;
}
// The default values for type=range: min=0 max=100 step=1
// Values are modifies for these restrictions.
shouldBe('valueAsNumberFor("0")', '0');
shouldBe('valueAsNumberFor("10")', '10');
shouldBe('valueAsNumberFor("01")', '1');
shouldBe('valueAsNumberFor("-0")', '0');
shouldBe('valueAsNumberFor("-1.2")', '0');
shouldBe('valueAsNumberFor("0.2")', '0');
shouldBe('valueAsNumberFor(".2")', '0');
shouldBe('valueAsNumberFor("1.2E10")', '100');
shouldBe('valueAsNumberFor("1.2E-10")', '0');
shouldBe('valueAsNumberFor("1.2E+10")', '100');
shouldBe('valueAsNumberFor("123456789012345678901234567890123456789")', '100');
shouldBe('valueAsNumberFor("0.12345678901234567890123456789012345678901234567890")', '0');
debug('valueAsNumber for invalid string values:');
shouldBe('valueAsNumberFor("")', '50');
shouldBe('valueAsNumberFor("abc")', '50');
shouldBe('valueAsNumberFor("0xff")', '50');
shouldBe('valueAsNumberFor("+1")', '50');
shouldBe('valueAsNumberFor(" 10")', '50');
shouldBe('valueAsNumberFor("10 ")', '50');
shouldBe('valueAsNumberFor("1E")', '50');
shouldBe('valueAsNumberFor("NaN")', '50');
shouldBe('valueAsNumberFor("nan")', '50');
shouldBe('valueAsNumberFor("Inf")', '50');
shouldBe('valueAsNumberFor("inf")', '50');
shouldBe('valueAsNumberFor("Infinity")', '50');
shouldBe('valueAsNumberFor("infinity")', '50');
debug('Too huge exponent to support');
shouldBe('valueAsNumberFor("1.2E65535")', '50');
debug('Tests for the valueAsNumber setter:');
shouldBe('setValueAsNumberAndGetValue(0)', '"0"');
shouldBe('setValueAsNumberAndGetValue(10)', '"10"');
shouldBe('setValueAsNumberAndGetValue(01)', '"1"');
shouldBe('setValueAsNumberAndGetValue(-0)', '"0"');
shouldBe('setValueAsNumberAndGetValue(-1.2)', '"0"');
shouldBe('setValueAsNumberAndGetValue(1.2e10)', '"100"');
shouldBe('setValueAsNumberAndGetValue(1.2e-10)', '"0"');
shouldBe('setValueAsNumberAndGetValue(1.2345678901234567e+38)', '"100"');
debug('Tests to set invalid values to valueAsNumber:');
shouldBe('setValueAsNumberAndGetValue(null)', '"0"');
shouldThrow('setValueAsNumberAndGetValue("foo")', '"NotSupportedError: The implementation did not support the requested type of object or operation."');
shouldThrow('setValueAsNumberAndGetValue(NaN)', '"NotSupportedError: The implementation did not support the requested type of object or operation."');
shouldThrow('setValueAsNumberAndGetValue(Number.NaN)', '"NotSupportedError: The implementation did not support the requested type of object or operation."');
shouldThrow('setValueAsNumberAndGetValue(Infinity)', '"NotSupportedError: The implementation did not support the requested type of object or operation."');
shouldThrow('setValueAsNumberAndGetValue(Number.POSITIVE_INFINITY)', '"NotSupportedError: The implementation did not support the requested type of object or operation."');
shouldThrow('setValueAsNumberAndGetValue(Number.NEGATIVE_INFINITY)', '"NotSupportedError: The implementation did not support the requested type of object or operation."');
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>
|