4 <script src=
"../../../resources/js-test.js"></script>
8 description('Check stepping-up and -down for number input from renderer.');
10 var input
= document
.createElement('input');
11 var invalidStateErr
= '"InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable."';
13 function sendKey(keyName
) {
14 var event
= document
.createEvent('KeyboardEvent');
15 event
.initKeyboardEvent('keydown', true, true, document
.defaultView
, keyName
);
16 input
.dispatchEvent(event
);
19 function setInputAttributes(min
, max
, step
, value
) {
26 function stepUp(value
, step
, max
, optionalStepCount
) {
27 setInputAttributes(null, max
, step
, value
);
28 if (typeof optionalStepCount
!= "undefined")
29 if (optionalStepCount
< 0)
30 for (var i
= 0; i
< -optionalStepCount
; i
++)
33 for (var i
= 0; i
< optionalStepCount
; i
++)
40 function stepDown(value
, step
, min
, optionalStepCount
) {
41 setInputAttributes(min
, null, step
, value
);
42 if (typeof optionalStepCount
!= "undefined")
43 if (optionalStepCount
< 0)
44 for (var i
= 0; i
< -optionalStepCount
; i
++)
47 for (var i
= 0; i
< optionalStepCount
; i
++)
54 // Range value gets automatically shifted based on bounds,
55 // So always set the min and max first to get expected behavior
57 function stepUpExplicitBounds(min
, max
, step
, value
, stepCount
) {
58 setInputAttributes(min
, max
, step
, value
);
59 if (typeof stepCount
!== 'undefined')
61 for (var i
= 0; i
< -stepCount
; i
++)
64 for (var i
= 0; i
< stepCount
; i
++)
72 function stepDownExplicitBounds(min
, max
, step
, value
, stepCount
) {
73 setInputAttributes(min
, max
, step
, value
);
74 if (typeof stepCount
!== 'undefined')
76 for (var i
= 0; i
< -stepCount
; i
++)
79 for (var i
= 0; i
< stepCount
; i
++)
88 input
.type
= 'number';
89 debug('Function arguments are (value, step, {min or max}, [stepCount]).');
90 debug('Invalid value');
91 shouldBe('stepUp("", null, null)', '"1"');
92 shouldBe('stepDown("", null, null)', '"-1"');
93 shouldBe('stepUp("", "any", null)', '"1"');
94 shouldBe('stepDown("", "any", null)', '"-1"');
95 shouldBe('stepUp("", "foo", null)', '"1"');
96 shouldBe('stepDown("", "foo", null)', '"-1"');
97 shouldBe('stepUp("foo", null, null)', '"1"');
98 shouldBe('stepDown("foo", null, null)', '"-1"');
99 shouldBe('stepUp("foo", "any", null)', '"1"');
100 shouldBe('stepDown("foo", "any", null)', '"-1"');
101 shouldBe('stepUp("foo", "foo", null)', '"1"');
102 shouldBe('stepDown("foo", "foo", null)', '"-1"');
103 debug('Normal cases');
104 shouldBe('stepUp("0", null, null)', '"1"');
105 shouldBe('stepUp("1", null, null, 2)', '"3"');
106 shouldBe('stepUp("3", null, null, -1)', '"2"');
107 shouldBe('stepDown("2", null, null)', '"1"');
108 shouldBe('stepDown("1", null, null, 2)', '"-1"');
109 shouldBe('stepDown("-1", null, null, -1)', '"0"');
110 debug('Invalid step value');
111 shouldBe('stepUp("0", "foo", null)', '"1"');
112 shouldBe('stepUp("1", "0", null)', '"2"');
113 shouldBe('stepUp("2", "-1", null)', '"3"');
115 shouldBe('stepUp("0", "any", null)', '"1"');
116 shouldBe('stepDown("0", "any", null)', '"-1"');
117 debug('Step=any corner case');
118 shouldBe('stepUpExplicitBounds("0", "100", "any", "1.5", "1")', '"2.5"');
119 shouldBe('stepDownExplicitBounds("0", "100", "any", "1.5", "1")', '"0.5"');
120 debug('Overflow/underflow');
121 shouldBe('stepDown("1", "1", "0")', '"0"');
122 shouldBe('stepDown("0", "1", "0")', '"0"');
123 shouldBe('stepDown("1", "1", "0", 2)', '"0"');
124 shouldBe('stepDown("1", "1.797693134862315e+308", "", 2)', '"-1.797693134862315e+308"');
125 shouldBe('stepUp("-1", "1", "0")', '"0"');
126 shouldBe('stepUp("0", "1", "0")', '"0"');
127 shouldBe('stepUp("-1", "1", "0", 2)', '"0"');
128 shouldBe('stepUp("1", "1.797693134862315e+308", "", 2)', '"1.797693134862315e+308"');
129 debug('stepDown()/stepUp() for stepMismatch values');
130 shouldBe('stepUp("1", "2", "")', '"2"');
131 shouldBe('input.min = "0"; stepUp("9", "10", "")', '"10"');
132 shouldBe('stepDown("19", "10", "0")', '"10"');
133 shouldBe('stepUp("89", "10", "99")', '"90"');
134 shouldBe('stepUp("7", "300", "")', '"300"');
135 shouldBe('stepUp("-7", "300", "")', '"0"');
136 shouldBe('stepDown("7", "300", "")', '"0"');
137 shouldBe('stepDown("-7", "300", "")', '"-300"');
138 debug('Huge value and small step');
139 shouldBe('input.min = ""; stepUp("1e+308", "1", "", 999)', '"1e+308"');
140 shouldBe('input.max = ""; stepDown("1e+308", "1", "", 999)', '"1e+308"');
141 debug('Fractional numbers');
142 shouldBe('input.min = ""; stepUp("0", "0.33333333333333333", "", 3)', '"1"');
143 shouldBe('stepUp("1", "0.1", "", 10)', '"2"');
144 shouldBe('input.min = "0"; stepUp("0", "0.003921568627450980", "1", 255)', '"1"');
146 shouldBe('stepUp("5.005", "0.005", "", 2)', '"5.015"');
147 shouldBe('stepUp("5.005", "0.005", "", 11)', '"5.06"');
148 shouldBe('stepUp("5.005", "0.005", "", 12)', '"5.065"');
149 shouldBe('stepUpExplicitBounds("4", "9", "0.005", "5.005", 2)', '"5.015"');
150 shouldBe('stepUpExplicitBounds("4", "9", "0.005", "5.005", 11)', '"5.06"');
151 shouldBe('stepUpExplicitBounds("4", "9", "0.005", "5.005", 12)', '"5.065"');
152 shouldBe('stepUpExplicitBounds(-4, 4, 1, "")', '"1"');
153 shouldBe('stepDownExplicitBounds(-4, 4, 1, "")', '"-1"');
154 shouldBe('stepDownExplicitBounds(0, 4, 1, "")', '"0"');
155 shouldBe('stepUpExplicitBounds(-4, 0, 1, "")', '"0"');
156 shouldBe('stepDownExplicitBounds(1, 4, 1, "")', '"1"');
157 shouldBe('stepUpExplicitBounds(1, 4, 1, "")', '"1"');
158 shouldBe('stepDownExplicitBounds(-4, -1, 1, "")', '"-1"');
159 shouldBe('stepUpExplicitBounds(-4, -1, 1, "")', '"-1"');
160 shouldBe('stepUpExplicitBounds(-100, null, 3, "")', '"2"');
161 shouldBe('stepDownExplicitBounds(-100, null, 3, "")', '"-1"');
162 shouldBe('stepUpExplicitBounds(1, 4, 1, 0)', '"1"');
163 shouldBe('stepDownExplicitBounds(1, 4, 1, 0)', '"0"');
164 shouldBe('stepDownExplicitBounds(-4, -1, 1, 0)', '"-1"');
165 shouldBe('stepUpExplicitBounds(-4, -1, 1, 0)', '"0"');
166 shouldBe('stepUpExplicitBounds(-100, null, 3, 3)', '"5"');
167 shouldBe('stepDownExplicitBounds(-100, null, 3, 3)', '"2"');