Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / range / range-stepup-stepdown-from-renderer.html
blob0e88f4b7bdfb680d0590d5bb1b58a3e105b412fe
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 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) {
22 input.min = min;
23 input.max = max;
24 input.step = step;
25 input.value = 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++)
33 sendKey('Down');
34 else
35 for (var i = 0; i < optionalStepCount; i++)
36 sendKey('Up');
37 else
38 sendKey('Up');
39 return input.value;
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++)
47 sendKey('Up');
48 else
49 for (var i = 0; i < optionalStepCount; i++)
50 sendKey('Down');
51 else
52 sendKey('Down');
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 if (stepCount < 0) {
63 for (var i = 0; i < -stepCount; i++)
64 sendKey('Down');
65 } else {
66 for (var i = 0; i < stepCount; i++)
67 sendKey('Up');
69 else
70 sendKey('Up');
71 return input.value;
74 function stepDownExplicitBounds(min, max, step, value, stepCount) {
75 setInputAttributes(min, max, step, value);
76 if (typeof stepCount !== 'undefined')
77 if (stepCount < 0) {
78 for (var i = 0; i < -stepCount; i++)
79 sendKey('Up');
80 } else {
81 for (var i = 0; i < stepCount; i++)
82 sendKey('Down');
84 else
85 sendKey('Down');
86 return input.value;
89 input.type = 'range';
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"');
118 debug('Step=any');
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"');
151 debug('');
152 </script>
153 </body>
154 </html>