Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: LayoutTests/fast/forms/range/range-stepup-stepdown.html

Issue 152753002: Update input[type=range]'s step base handling to match spec. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../../../resources/js-test.js"></script> 4 <script src="../../../resources/js-test.js"></script>
5 </head> 5 </head>
6 <body> 6 <body>
7 <p id="description"></p> 7 <p id="description"></p>
8 <div id="console"></div> 8 <div id="console"></div>
9 <script> 9 <script>
10 description('Check stepUp() and stepDown() bahevior for range type.'); 10 description('Check stepUp() and stepDown() bahevior for range type.');
11 11
12 var input = document.createElement('input'); 12 var input;
13
14 function createRangeElement() {
15 input = document.createElement('input');
16 input.type = 'range';
17 }
13 18
14 function setInputAttributes(min, max, step, value) { 19 function setInputAttributes(min, max, step, value) {
15 input.min = min; 20 input.min = min;
16 input.max = max; 21 input.max = max;
17 input.step = step; 22 input.step = step;
18 input.value = value; 23 input.value = value;
19 } 24 }
20 25
26 function createInputWithContentAttributes(min, max, step, value) {
27 createRangeElement();
28 function setIfNonNull(attribute, value) {
29 if (typeof value !== "null")
30 input.setAttribute(attribute, value);
31 }
32 setIfNonNull("min", min);
33 setIfNonNull("max", max);
34 setIfNonNull("step", step);
35 setIfNonNull("value", value);
36 }
37
21 function stepUp(value, step, max, optionalStepCount) { 38 function stepUp(value, step, max, optionalStepCount) {
22 setInputAttributes(null, max, step, value); 39 setInputAttributes(null, max, step, value);
23 if (typeof optionalStepCount != "undefined") 40 if (typeof optionalStepCount != "undefined")
24 input.stepUp(optionalStepCount); 41 input.stepUp(optionalStepCount);
25 else 42 else
26 input.stepUp(); 43 input.stepUp();
27 return input.value; 44 return input.value;
28 } 45 }
29 46
30 function stepDown(value, step, min, optionalStepCount) { 47 function stepDown(value, step, min, optionalStepCount) {
(...skipping 19 matching lines...) Expand all
50 67
51 function stepDownExplicitBounds(min, max, step, value, stepCount) { 68 function stepDownExplicitBounds(min, max, step, value, stepCount) {
52 setInputAttributes(min, max, step, value); 69 setInputAttributes(min, max, step, value);
53 if (typeof stepCount !== 'undefined') 70 if (typeof stepCount !== 'undefined')
54 input.stepDown(stepCount); 71 input.stepDown(stepCount);
55 else 72 else
56 input.stepDown(); 73 input.stepDown();
57 return input.value; 74 return input.value;
58 } 75 }
59 76
60 input.type = 'range'; 77 createRangeElement();
61 debug('function arguments are (min, max, step, value, [stepCount])'); 78 debug('function arguments are (min, max, step, value, [stepCount])');
62 debug('Using the default values'); 79 debug('Using the default values');
63 shouldBe('stepUpExplicitBounds(null, null, null, "")', '"51"'); 80 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "")', '51');
64 shouldBe('stepDownExplicitBounds(null, null, null, "")', '"49"'); 81 shouldBeEqualToString('stepDownExplicitBounds(null, null, null, "")', '49');
65 debug('Non-number arguments (stepCount)'); 82 debug('Non-number arguments (stepCount)');
66 shouldBe('stepUpExplicitBounds(null, null, null, "0", "0")', '"0"'); 83 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "0", "0")', '0');
67 shouldBe('stepDownExplicitBounds(null, null, null, "0", "0")', '"0"'); 84 shouldBeEqualToString('stepDownExplicitBounds(null, null, null, "0", "0")', '0') ;
68 shouldBe('stepUpExplicitBounds(null, null, null, "0", "foo")', '"0"'); 85 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "0", "foo")', '0') ;
69 shouldBe('stepDownExplicitBounds(null, null, null, "0", "foo")', '"0"'); 86 shouldBeEqualToString('stepDownExplicitBounds(null, null, null, "0", "foo")', '0 ');
70 shouldBe('stepUpExplicitBounds(null, null, null, "0", null)', '"0"'); 87 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "0", null)', '0');
71 shouldBe('stepDownExplicitBounds(null, null, null, "0", null)', '"0"'); 88 shouldBeEqualToString('stepDownExplicitBounds(null, null, null, "0", null)', '0' );
72 debug('Normal cases'); 89 debug('Normal cases');
73 shouldBe('stepUpExplicitBounds(null, null, null, "0")', '"1"'); 90 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "0")', '1');
74 shouldBe('stepUpExplicitBounds(null, null, null, "1", 2)', '"3"'); 91 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "1", 2)', '3');
75 shouldBe('stepUpExplicitBounds(null, null, null, "3", -1)', '"2"'); 92 shouldBeEqualToString('stepUpExplicitBounds(null, null, null, "3", -1)', '2');
76 shouldBe('stepDownExplicitBounds("-100", null, null, "2")', '"1"'); 93 shouldBeEqualToString('stepDownExplicitBounds("-100", null, null, "2")', '1');
77 shouldBe('stepDownExplicitBounds("-100", null, null, "1", 2)', '"-1"'); 94 shouldBeEqualToString('stepDownExplicitBounds("-100", null, null, "1", 2)', '-1' );
78 shouldBe('stepDownExplicitBounds("-100", null, null, "-1", -1)', '"0"'); 95 shouldBeEqualToString('stepDownExplicitBounds("-100", null, null, "-1", -1)', '0 ');
79 debug('Extra arguments'); 96 debug('Extra arguments');
80 shouldBe('setInputAttributes(null, null, null, "0"); input.stepUp(1,2); input.va lue', '"1"'); 97 shouldBeEqualToString('setInputAttributes(null, null, null, "0"); input.stepUp(1 ,2); input.value', '1');
81 shouldBe('setInputAttributes(null, null, null, "1"); input.stepDown(1,3); input. value', '"0"'); 98 shouldBeEqualToString('setInputAttributes(null, null, null, "1"); input.stepDown (1,3); input.value', '0');
82 debug('Invalid step value'); 99 debug('Invalid step value');
83 shouldBe('stepUpExplicitBounds(null, null, "foo", "0")', '"1"'); 100 shouldBeEqualToString('stepUpExplicitBounds(null, null, "foo", "0")', '1');
84 shouldBe('stepUpExplicitBounds(null, null, "0", "1")', '"2"'); 101 shouldBeEqualToString('stepUpExplicitBounds(null, null, "0", "1")', '2');
85 shouldBe('stepUpExplicitBounds(null, null, "-1", "2")', '"3"'); 102 shouldBeEqualToString('stepUpExplicitBounds(null, null, "-1", "2")', '3');
86 shouldBe('stepDownExplicitBounds(null, null, "foo", "1")', '"0"'); 103 shouldBeEqualToString('stepDownExplicitBounds(null, null, "foo", "1")', '0');
87 shouldBe('stepDownExplicitBounds(null, null, "0", "2")', '"1"'); 104 shouldBeEqualToString('stepDownExplicitBounds(null, null, "0", "2")', '1');
88 shouldBe('stepDownExplicitBounds(null, null, "-1", "3")', '"2"'); 105 shouldBeEqualToString('stepDownExplicitBounds(null, null, "-1", "3")', '2');
106 debug('Step bases');
107 shouldBeEqualToString('createInputWithContentAttributes(0, 100, "20", "50"); inp ut.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 // FIXME: these shouldn't throw according to the spec; commented-out version giv e its expected outcomes.
112 shouldThrow('createInputWithContentAttributes(null, null, "50", "25"); input.ste pUp(2); input.stepDown(2);');
113 shouldThrow('createInputWithContentAttributes(null, null, "7", "22"); input.step Up(40);');
114 //shouldBeEqualToString('createInputWithContentAttributes(null, null, "50", "25" ); input.stepUp(2); input.stepDown(2); input.value', '25');
115 //shouldBeEqualToString('createInputWithContentAttributes(null, null, "7", "22") ; input.stepUp(40); input.value', '99');
116
117 // Reset 'input' for follow-on tests.
118 createRangeElement();
89 debug('Step=any'); 119 debug('Step=any');
90 shouldThrow('stepUpExplicitBounds(null, null, "any", "1")'); 120 shouldThrow('stepUpExplicitBounds(null, null, "any", "1")');
91 shouldThrow('stepDownExplicitBounds(null, null, "any", "1")'); 121 shouldThrow('stepDownExplicitBounds(null, null, "any", "1")');
92 debug('Overflow/underflow'); 122 debug('Overflow/underflow');
93 shouldBe('stepUpExplicitBounds(null, "100", "1", "99")', '"100"'); 123 shouldBeEqualToString('stepUpExplicitBounds(null, "100", "1", "99")', '100');
94 shouldThrow('stepUpExplicitBounds(null, "100", "1", "100")'); 124 shouldThrow('stepUpExplicitBounds(null, "100", "1", "100")');
95 shouldBe('input.value', '"100"'); 125 shouldBeEqualToString('input.value', '100');
96 shouldThrow('stepUpExplicitBounds(null, "100", "1", "99", "2")'); 126 shouldThrow('stepUpExplicitBounds(null, "100", "1", "99", "2")');
97 shouldBe('input.value', '"99"'); 127 shouldBeEqualToString('input.value', '99');
98 shouldBe('stepDownExplicitBounds("0", null, "1", "1")', '"0"'); 128 shouldBeEqualToString('stepDownExplicitBounds("0", null, "1", "1")', '0');
99 shouldThrow('stepDownExplicitBounds("0", null, "1", "0")'); 129 shouldThrow('stepDownExplicitBounds("0", null, "1", "0")');
100 shouldBe('input.value', '"0"'); 130 shouldBeEqualToString('input.value', '0');
101 shouldThrow('stepDownExplicitBounds("0", null, "1", "1", "2")'); 131 shouldThrow('stepDownExplicitBounds("0", null, "1", "1", "2")');
102 shouldBe('input.value', '"1"'); 132 shouldBeEqualToString('input.value', '1');
103 shouldThrow('stepDownExplicitBounds(null, null, "3.40282346e+38", "1", "2")'); 133 shouldThrow('stepDownExplicitBounds(null, null, "3.40282346e+38", "1", "2")');
104 shouldBe('stepUpExplicitBounds(-100, 0, 1, -1)', '"0"'); 134 shouldBeEqualToString('stepUpExplicitBounds(-100, 0, 1, -1)', '0');
105 shouldThrow('stepUpExplicitBounds(null, 0, 1, 0)'); 135 shouldThrow('stepUpExplicitBounds(null, 0, 1, 0)');
106 shouldThrow('stepUpExplicitBounds(-100, 0, 1, -1, 2)'); 136 shouldThrow('stepUpExplicitBounds(-100, 0, 1, -1, 2)');
107 shouldBe('input.value', '"-1"'); 137 shouldBeEqualToString('input.value', '-1');
108 shouldThrow('stepUpExplicitBounds(null, null, "3.40282346e+38", "1", "2")'); 138 shouldThrow('stepUpExplicitBounds(null, null, "3.40282346e+38", "1", "2")');
109 debug('stepDown()/stepUp() for stepMismatch values'); 139 debug('stepDown()/stepUp() for stepMismatch values');
110 shouldBe('stepUpExplicitBounds(null, null, 2, 1)', '"4"'); 140 shouldBeEqualToString('stepUpExplicitBounds(null, null, 2, 1)', '4');
111 shouldBe('input.stepDown(); input.value', '"2"'); 141 shouldBeEqualToString('input.stepDown(); input.value', '2');
112 shouldBe('stepUpExplicitBounds(0, null, 10, 9, 9)', '"100"'); 142 shouldBeEqualToString('stepUpExplicitBounds(0, null, 10, 9, 9)', '100');
113 shouldBe('stepDownExplicitBounds(0, null, 10, 19)', '"10"'); 143 shouldBeEqualToString('stepDownExplicitBounds(0, null, 10, 19)', '10');
114 debug('value + step is <= max, but rounded result would be > max.'); 144 debug('value + step is <= max, but rounded result would be > max.');
115 shouldThrow('stepUpExplicitBounds(null, 99, 10, 89)'); 145 shouldThrow('stepUpExplicitBounds(null, 99, 10, 89)');
116 debug('Huge value and small step'); 146 debug('Huge value and small step');
117 shouldBe('stepUpExplicitBounds(0, 1e38, 1, 1e38, 999999)', '"1e+38"'); 147 shouldBeEqualToString('stepUpExplicitBounds(0, 1e38, 1, 1e38, 999999)', '1e+38') ;
118 shouldBe('stepDownExplicitBounds(0, 1e38, 1, 1e38, 999999)', '"1e+38"'); 148 shouldBeEqualToString('stepDownExplicitBounds(0, 1e38, 1, 1e38, 999999)', '1e+38 ');
119 debug('Fractional numbers'); 149 debug('Fractional numbers');
120 shouldBe('stepUpExplicitBounds(null, null, 0.33333333333333333, 0, 3)', '"1"'); 150 shouldBeEqualToString('stepUpExplicitBounds(null, null, 0.33333333333333333, 0, 3)', '1');
121 shouldBe('stepUpExplicitBounds(null, null, 0.1, 1)', '"1.1"'); 151 shouldBeEqualToString('stepUpExplicitBounds(null, null, 0.1, 1)', '1.1');
122 shouldBe('stepUpExplicitBounds(null, null, 0.1, 1, 8)', '"1.8"'); 152 shouldBeEqualToString('stepUpExplicitBounds(null, null, 0.1, 1, 8)', '1.8');
123 shouldBe('stepUpExplicitBounds(null, null, 0.1, 1, 10)', '"2"'); 153 shouldBeEqualToString('stepUpExplicitBounds(null, null, 0.1, 1, 10)', '2');
124 shouldBe('input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input. stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input. stepUp(); input.value', '"3"'); 154 shouldBeEqualToString('input.stepUp(); input.stepUp(); input.stepUp(); input.ste pUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.ste pUp(); input.stepUp(); input.value', '3');
125 shouldBe('stepUpExplicitBounds(0, 1, 0.003921568627450980, 0, 255)', '"1"'); 155 shouldBeEqualToString('stepUpExplicitBounds(0, 1, 0.003921568627450980, 0, 255)' , '1');
126 shouldBe('for (var i = 0; i < 255; i++) { input.stepDown(); }; input.value', '"0 "'); 156 shouldBeEqualToString('for (var i = 0; i < 255; i++) { input.stepDown(); }; inpu t.value', '0');
127 shouldBe('stepDownExplicitBounds(null, null, 0.1, 1, 8)', '"0.2"'); 157 shouldBeEqualToString('stepDownExplicitBounds(null, null, 0.1, 1, 8)', '0.2');
128 shouldBe('stepDownExplicitBounds(null, null, 0.1, 1)', '"0.9"'); 158 shouldBeEqualToString('stepDownExplicitBounds(null, null, 0.1, 1)', '0.9');
129 </script> 159 </script>
130 </body> 160 </body>
131 </html> 161 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698