Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / number / number-stepup-stepdown-from-renderer.html
blobc5023a3f856f0848f33b1df598a105286cc59bbf
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <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) {
20 input.min = min;
21 input.max = max;
22 input.step = step;
23 input.value = 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++)
31 sendKey('Down');
32 else
33 for (var i = 0; i < optionalStepCount; i++)
34 sendKey('Up');
35 else
36 sendKey('Up');
37 return input.value;
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++)
45 sendKey('Up');
46 else
47 for (var i = 0; i < optionalStepCount; i++)
48 sendKey('Down');
49 else
50 sendKey('Down');
51 return input.value;
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')
60 if (stepCount < 0) {
61 for (var i = 0; i < -stepCount; i++)
62 sendKey('Down');
63 } else {
64 for (var i = 0; i < stepCount; i++)
65 sendKey('Up');
67 else
68 sendKey('Up');
69 return input.value;
72 function stepDownExplicitBounds(min, max, step, value, stepCount) {
73 setInputAttributes(min, max, step, value);
74 if (typeof stepCount !== 'undefined')
75 if (stepCount < 0) {
76 for (var i = 0; i < -stepCount; i++)
77 sendKey('Up');
78 } else {
79 for (var i = 0; i < stepCount; i++)
80 sendKey('Down');
82 else
83 sendKey('Down');
84 return input.value;
87 debug('Number type');
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"');
114 debug('Step=any');
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"');
145 debug('Rounding');
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"');
169 debug('');
170 </script>
171 </body>
172 </html>