Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / range / range-stepup-stepdown.html
blob69fb694765d3f6d58fd9363b833ab951b3195614
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9 <script>
10 description('Check stepUp() and stepDown() behavior for range type.');
12 var input;
14 function createRangeElement() {
15 input = document.createElement('input');
16 input.type = 'range';
19 function setInputAttributes(min, max, step, value) {
20 input.min = min;
21 input.max = max;
22 input.step = step;
23 input.value = value;
26 function createInputWithContentAttributes(min, max, step, value) {
27 createRangeElement();
28 function setIfNonNull(attribute, value) {
29 if (typeof value !== "null")
30 input.setAttribute(attribute, value);
32 setIfNonNull("min", min);
33 setIfNonNull("max", max);
34 setIfNonNull("step", step);
35 setIfNonNull("value", value);
38 function stepUp(value, step, max, optionalStepCount) {
39 setInputAttributes(null, max, step, value);
40 if (typeof optionalStepCount != "undefined")
41 input.stepUp(optionalStepCount);
42 else
43 input.stepUp();
44 return input.value;
47 function stepDown(value, step, min, optionalStepCount) {
48 setInputAttributes(min, null, step, value);
49 if (typeof optionalStepCount != "undefined")
50 input.stepDown(optionalStepCount);
51 else
52 input.stepDown();
53 return input.value;
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')
62 input.stepUp(stepCount);
63 else
64 input.stepUp();
65 return input.value;
68 function stepDownExplicitBounds(min, max, step, value, stepCount) {
69 setInputAttributes(min, max, step, value);
70 if (typeof stepCount !== 'undefined')
71 input.stepDown(stepCount);
72 else
73 input.stepDown();
74 return input.value;
77 createRangeElement();
78 debug('function arguments are (min, max, step, value, [stepCount])');
79 debug('Using the default values');
80 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "")', '51');
81 shouldBeEqualToString('stepDownExplicitBounds(null, null, null, "")', '49');
82 debug('Non-number arguments (stepCount)');
83 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "0", "0")', '0');
84 shouldBeEqualToString('stepDownExplicitBounds(null, null, null, "0", "0")', '0');
85 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "0", "foo")', '0');
86 shouldBeEqualToString('stepDownExplicitBounds(null, null, null, "0", "foo")', '0');
87 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "0", null)', '0');
88 shouldBeEqualToString('stepDownExplicitBounds(null, null, null, "0", null)', '0');
89 debug('Normal cases');
90 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "0")', '1');
91 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "1", 2)', '3');
92 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "3", -1)', '2');
93 shouldBeEqualToString('stepDownExplicitBounds("-100", null, null, "2")', '1');
94 shouldBeEqualToString('stepDownExplicitBounds("-100", null, null, "1", 2)', '-1');
95 shouldBeEqualToString('stepDownExplicitBounds("-100", null, null, "-1", -1)', '0');
96 debug('Extra arguments');
97 shouldBeEqualToString('setInputAttributes(null, null, null, "0"); input.stepUp(1,2); input.value', '1');
98 shouldBeEqualToString('setInputAttributes(null, null, null, "1"); input.stepDown(1,3); input.value', '0');
99 debug('Invalid step value');
100 shouldBeEqualToString('stepUpExplicitBounds(null, null, "foo", "0")', '1');
101 shouldBeEqualToString('stepUpExplicitBounds(null, null, "0", "1")', '2');
102 shouldBeEqualToString('stepUpExplicitBounds(null, null, "-1", "2")', '3');
103 shouldBeEqualToString('stepDownExplicitBounds(null, null, "foo", "1")', '0');
104 shouldBeEqualToString('stepDownExplicitBounds(null, null, "0", "2")', '1');
105 shouldBeEqualToString('stepDownExplicitBounds(null, null, "-1", "3")', '2');
106 debug('Step bases');
107 shouldBeEqualToString('createInputWithContentAttributes(0, 100, "20", "50"); input.value', '60');
108 shouldBeEqualToString('createInputWithContentAttributes(null, null, "50", "25"); input.value', '25');
109 shouldBeEqualToString('createInputWithContentAttributes(null, null, "50", "25"); input.stepUp(1); input.value', '75');
110 shouldBeEqualToString('createInputWithContentAttributes(null, null, "50", "25"); input.stepUp(1); input.stepDown(1); input.value', '25');
111 shouldBeEqualToString('createInputWithContentAttributes(null, null, "50", "25"); input.stepUp(2); input.stepDown(2); input.value', '25');
112 shouldBeEqualToString('createInputWithContentAttributes(null, null, "7", "22"); input.stepUp(40); input.value', '99');
114 // Reset 'input' for follow-on tests.
115 createRangeElement();
116 debug('Step=any');
117 shouldThrow('stepUpExplicitBounds(null, null, "any", "1")');
118 shouldThrow('stepDownExplicitBounds(null, null, "any", "1")');
119 debug('Overflow/underflow');
120 shouldBeEqualToString('stepUpExplicitBounds(null, "100", "1", "99")', '100');
121 shouldBeEqualToString('stepUpExplicitBounds(null, "100", "1", "100")', '100');
122 shouldBeEqualToString('stepUpExplicitBounds(null, "100", "1", "99", "2")', '100');
123 shouldBeEqualToString('stepDownExplicitBounds("0", null, "1", "1")', '0');
124 shouldBeEqualToString('stepDownExplicitBounds("0", null, "1", "0")', '0');
125 shouldBeEqualToString('stepDownExplicitBounds("0", null, "1", "1", "2")', '0');
126 shouldBeEqualToString('stepDownExplicitBounds(null, null, "3.40282346e+38", "1", "2")', '0');
127 shouldBeEqualToString('stepUpExplicitBounds(-100, 0, 1, -1)', '0');
128 shouldBeEqualToString('stepUpExplicitBounds(null, 0, 1, 0)', '0');
129 shouldBeEqualToString('stepUpExplicitBounds(-100, 0, 1, -1, 2)', '0');
130 shouldBeEqualToString('stepUpExplicitBounds(null, null, "3.40282346e+38", "1", "2")', '0');
131 debug('stepDown()/stepUp() for stepMismatch values');
132 shouldBeEqualToString('stepUpExplicitBounds(null, null, 2, 1)', '4');
133 shouldBeEqualToString('input.stepDown(); input.value', '2');
134 shouldBeEqualToString('stepUpExplicitBounds(0, null, 10, 9, 9)', '100');
135 shouldBeEqualToString('stepDownExplicitBounds(0, null, 10, 19)', '10');
136 debug('value + step is <= max, but rounded result would be > max.');
137 shouldBeEqualToString('stepUpExplicitBounds(null, 99, 10, 89)', '90');
138 shouldBeEqualToString('stepUpExplicitBounds(null, 99, 10, 89, 21)', '90');
139 shouldBeEqualToString('stepUpExplicitBounds(null, 99, 10, 77, 2)', '90');
140 debug('Huge value and small step');
141 shouldBeEqualToString('stepUpExplicitBounds(0, 1e38, 1, 1e38, 999999)', '1e+38');
142 shouldBeEqualToString('stepDownExplicitBounds(0, 1e38, 1, 1e38, 999999)', '1e+38');
143 debug('Fractional numbers');
144 shouldBeEqualToString('stepUpExplicitBounds(null, null, 0.33333333333333333, 0, 3)', '1');
145 shouldBeEqualToString('stepUpExplicitBounds(null, null, 0.1, 1)', '1.1');
146 shouldBeEqualToString('stepUpExplicitBounds(null, null, 0.1, 1, 8)', '1.8');
147 shouldBeEqualToString('stepUpExplicitBounds(null, null, 0.1, 1, 10)', '2');
148 shouldBeEqualToString('input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.value', '3');
149 shouldBeEqualToString('stepUpExplicitBounds(0, 1, 0.003921568627450980, 0, 255)', '1');
150 shouldBeEqualToString('for (var i = 0; i < 255; i++) { input.stepDown(); }; input.value', '0');
151 shouldBeEqualToString('stepDownExplicitBounds(null, null, 0.1, 1, 8)', '0.2');
152 shouldBeEqualToString('stepDownExplicitBounds(null, null, 0.1, 1)', '0.9');
153 </script>
154 </body>
155 </html>