4 <script src=
"../../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
10 description('Check stepping-up and -down for range input from renderer.');
12 var input
= document
.createElement('input');
13 var invalidStateErr
= '"InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable."';
15 function sendKey(keyName
) {
16 var event
= document
.createEvent('KeyboardEvent');
17 event
.initKeyboardEvent('keydown', true, true, document
.defaultView
, keyName
);
18 input
.dispatchEvent(event
);
21 function setInputAttributes(min
, max
, step
, value
) {
28 function stepUp(value
, step
, max
, optionalStepCount
) {
29 setInputAttributes(null, max
, step
, value
);
30 if (typeof optionalStepCount
!= "undefined")
31 if (optionalStepCount
< 0)
32 for (var i
= 0; i
< -optionalStepCount
; i
++)
35 for (var i
= 0; i
< optionalStepCount
; i
++)
42 function stepDown(value
, step
, min
, optionalStepCount
) {
43 setInputAttributes(min
, null, step
, value
);
44 if (typeof optionalStepCount
!= "undefined")
45 if (optionalStepCount
< 0)
46 for (var i
= 0; i
< -optionalStepCount
; i
++)
49 for (var i
= 0; i
< optionalStepCount
; i
++)
56 // Range value gets automatically shifted based on bounds,
57 // So always set the min and max first to get expected behavior
59 function stepUpExplicitBounds(min
, max
, step
, value
, stepCount
) {
60 setInputAttributes(min
, max
, step
, value
);
61 if (typeof stepCount
!== 'undefined')
63 for (var i
= 0; i
< -stepCount
; i
++)
66 for (var i
= 0; i
< stepCount
; i
++)
74 function stepDownExplicitBounds(min
, max
, step
, value
, stepCount
) {
75 setInputAttributes(min
, max
, step
, value
);
76 if (typeof stepCount
!== 'undefined')
78 for (var i
= 0; i
< -stepCount
; i
++)
81 for (var i
= 0; i
< stepCount
; i
++)
90 debug('Function arguments are (min, max, step, value, [stepCount]).');
91 debug('Using the default values');
92 shouldBe('stepUpExplicitBounds(null, null, null, "")', '"51"');
93 shouldBe('stepDownExplicitBounds(null, null, null, "")', '"49"');
94 shouldBe('stepUpExplicitBounds(null, null, "any", "")', '"51"');
95 shouldBe('stepDownExplicitBounds(null, null, "any", "")', '"49"');
96 shouldBe('stepUpExplicitBounds(null, null, "foo", "")', '"51"');
97 shouldBe('stepDownExplicitBounds(null, null, "foo", "")', '"49"');
98 shouldBe('stepUpExplicitBounds(null, null, null, "foo")', '"51"');
99 shouldBe('stepDownExplicitBounds(null, null, null, "foo")', '"49"');
100 shouldBe('stepUpExplicitBounds(null, null, "any", "foo")', '"51"');
101 shouldBe('stepDownExplicitBounds(null, null, "any", "foo")', '"49"');
102 shouldBe('stepUpExplicitBounds(null, null, "foo", "foo")', '"51"');
103 shouldBe('stepDownExplicitBounds(null, null, "foo", "foo")', '"49"');
104 debug('Normal cases');
105 shouldBe('stepUpExplicitBounds(null, null, null, "0")', '"1"');
106 shouldBe('stepUpExplicitBounds(null, null, null, "1", 2)', '"3"');
107 shouldBe('stepUpExplicitBounds(null, null, null, "3", -1)', '"2"');
108 shouldBe('stepDownExplicitBounds("-100", null, null, "2")', '"1"');
109 shouldBe('stepDownExplicitBounds("-100", null, null, "1", 2)', '"-1"');
110 shouldBe('stepDownExplicitBounds("-100", null, null, "-1", -1)', '"0"');
111 debug('Invalid step value');
112 shouldBe('stepUpExplicitBounds(null, null, "foo", "0")', '"1"');
113 shouldBe('stepUpExplicitBounds(null, null, "0", "1")', '"2"');
114 shouldBe('stepUpExplicitBounds(null, null, "-1", "2")', '"3"');
115 shouldBe('stepDownExplicitBounds(null, null, "foo", "1")', '"0"');
116 shouldBe('stepDownExplicitBounds(null, null, "0", "2")', '"1"');
117 shouldBe('stepDownExplicitBounds(null, null, "-1", "3")', '"2"');
119 shouldBe('stepUpExplicitBounds(null, null, "any", "1")', '"2"');
120 shouldBe('stepDownExplicitBounds(null, null, "any", "1")', '"0"');
121 debug('Overflow/underflow');
122 shouldBe('stepUpExplicitBounds(null, "100", "1", "99")', '"100"');
123 shouldBe('stepUpExplicitBounds(null, "100", "1", "100")', '"100"');
124 shouldBe('stepUpExplicitBounds(null, "100", "1", "99", 2)', '"100"');
125 shouldBe('stepDownExplicitBounds("0", null, "1", "1")', '"0"');
126 shouldBe('stepDownExplicitBounds("0", null, "1", "0")', '"0"');
127 shouldBe('stepDownExplicitBounds("0", null, "1", "1", 2)', '"0"');
128 shouldBe('stepDownExplicitBounds(null, null, "3.40282346e+38", "1", 2)', '"0"');
129 shouldBe('stepUpExplicitBounds(-100, 0, 1, -1)', '"0"');
130 shouldBe('stepUpExplicitBounds(null, 0, 1, 0)', '"0"');
131 shouldBe('stepUpExplicitBounds(-100, 0, 1, -1, 2)', '"0"');
132 shouldBe('stepUpExplicitBounds(null, null, "3.40282346e+38", "1", 2)', '"0"');
133 debug('stepDown()/stepUp() for stepMismatch values');
134 shouldBe('stepUpExplicitBounds(null, null, 2, 1)', '"4"');
135 shouldBe('stepUpExplicitBounds(0, null, 10, 9, 9)', '"100"');
136 shouldBe('stepDownExplicitBounds(0, null, 10, 19)', '"10"');
137 debug('value + step is <= max, but rounded result would be > max.');
138 shouldBe('stepUpExplicitBounds(null, 99, 10, 89)', '"90"');
139 debug('Huge value and small step');
140 shouldBe('stepUpExplicitBounds(0, 1e38, 1, 1e38, 999)', '"1e+38"');
141 shouldBe('stepDownExplicitBounds(0, 1e38, 1, 1e38, 999)', '"1e+38"');
142 debug('Fractional numbers');
143 shouldBe('stepUpExplicitBounds(null, null, 0.33333333333333333, 0, 3)', '"1"');
144 shouldBe('stepUpExplicitBounds(null, null, 0.1, 1)', '"1.1"');
145 shouldBe('stepUpExplicitBounds(null, null, 0.1, 1, 8)', '"1.8"');
146 shouldBe('stepUpExplicitBounds(null, null, 0.1, 1, 10)', '"2"');
147 shouldBe('stepUpExplicitBounds(0, 1, 0.003921568627450980, 0, 255)', '"1"');
148 shouldBe('stepDownExplicitBounds(null, null, 0.1, 1, 8)', '"0.2"');
149 shouldBe('stepDownExplicitBounds(null, null, 0.1, 1)', '"0.9"');