e03a6ebbf526215d040873d2bb914d2e36322c13
[WebKit-https.git] / LayoutTests / fast / forms / time-multiple-fields / time-multiple-fields-stepup-stepdown-from-renderer.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../js/resources/js-test-pre.js"></script>
5 <script src="../resources/common.js"></script>
6 </head>
7 <body>
8 <script>
9 description('Check stepping-up and -down for time input fields from renderer. No cases of empty initial values.');
10 if (!window.internals)
11     testFailed('This test requires window.internals.');
12
13 var input = document.createElement('input');
14 var invalidStateErr = '"Error: InvalidStateError: DOM Exception 11"';
15
16 document.body.appendChild(input);
17
18 function keyDown(key, modifiers)
19 {
20     if (!window.eventSender)
21         return;
22     eventSender.keyDown(key, modifiers);
23 }
24
25 function setDateTimeFormat(pattern) {
26     getElementByPseudoId(internals.youngestShadowRoot(input), '-webkit-datetime-edit').setAttribute('pattern', pattern);
27     input.value = '';  // Updates the element for new format
28 }
29
30 function setInputAttributes(value, min, max, step) {
31     input.value = value;
32     input.min = min;
33     input.max = max;
34     input.step = step;
35 }
36
37 function test(value, step, min, max, keySequence) {
38     setInputAttributes(value, min, max, step);
39     for (var i = 0; i < keySequence.length; i++)
40         keyDown(keySequence[i]);
41     return input.value;
42 }
43
44 function stepUp(value, step, min, max) {
45     return test(value, step, min, max, ['upArrow']);
46 }
47
48 function stepDown(value, step, min, max) {
49     return test(value, step, min, max, ['downArrow']);
50 }
51
52 input.type = 'time';
53 input.focus();
54 keyDown('rightArrow');
55 debug('Function arguments are (value, step, min, max, [keySequence]).');
56 debug('Normal cases');
57 shouldBeEqualToString('stepUp("07:13", null, null, null)', '07:14');
58 shouldBeEqualToString('stepDown("07:13", null, null, null)', '07:12');
59 shouldBeEqualToString('test("07:13", null, null, null, ["upArrow", "upArrow", "upArrow"])', '07:16');
60 shouldBeEqualToString('test("07:13", null, null, null, ["downArrow", "downArrow", "downArrow"])', '07:10');
61
62 debug('Milliseconds');
63 input.step = 0.001;
64 keyDown('rightArrow');
65 keyDown('rightArrow');
66 shouldBeEqualToString('stepUp("07:13:00.000", 0.001, null, null)', '07:13:00.001');
67 shouldBeEqualToString('stepDown("07:13:00.001", 0.001, null, null)', '07:13');
68 shouldBeEqualToString('stepUp("07:13:00.999", 0.001, null, null)', '07:13');
69 shouldBeEqualToString('stepDown("07:13:00.000", 0.001, null, null)', '07:13:00.999');
70 shouldBeEqualToString('stepUp("07:13:00.000", 0.250, null, null)', '07:13:00.250');
71 shouldBeEqualToString('stepDown("07:13:00.500", 0.250, null, null)', '07:13:00.250');
72 shouldBeEqualToString('stepUp("07:13:00.750", 0.250, null, null)', '07:13');
73 shouldBeEqualToString('stepDown("07:13:00.000", 0.250, null, null)', '07:13:00.750');
74 shouldBeEqualToString('stepUp("07:13:00.099", 0.100, null, null)', '07:13:00.100');
75 shouldBeEqualToString('stepDown("07:13:00.101", 0.100, null, null)', '07:13:00.100');
76 shouldBeEqualToString('stepUp("07:13:00.500", 0.0001, null, null)', '07:13:00.501');
77 shouldBeEqualToString('stepDown("07:13:00.500", 0.0001, null, null)', '07:13:00.499');
78 shouldBeEqualToString('stepUp("07:13:00.500", 0, null, null)', '07:13');
79 shouldBeEqualToString('stepDown("07:13:00.500", 0, null, null)', '07:13');
80 shouldBeEqualToString('stepUp("07:13:00.500", 60, null, null)', '07:13');
81 shouldBeEqualToString('stepDown("07:13:00.500", 60, null, null)', '07:13');
82 shouldBeEqualToString('stepUp("07:13:00.500", 0.100, "00:00:00.050", null)', '07:13:00.550');
83 shouldBeEqualToString('stepDown("07:13:00.500", 0.100, "00:00:00.050", null)', '07:13:00.450');
84 shouldBeEqualToString('test("07:13:00.500", 0.100, null, null, ["delete", "upArrow"])', '07:13');
85 shouldBeEqualToString('test("07:13:00.500", 0.100, null, null, ["delete", "downArrow"])', '07:13:00.900');
86 shouldBeEqualToString('test("07:13:00.500", 0.100, "00:00:00.050", null, ["delete", "upArrow"])', '07:13:00.050');
87 shouldBeEqualToString('test("07:13:00.500", 0.100, "00:00:00.050", null, ["delete", "downArrow"])', '07:13:00.950');
88
89 debug('Seconds');
90 keyDown('leftArrow');
91 shouldBeEqualToString('stepUp("07:13:00", 1, null, null)', '07:13:01');
92 shouldBeEqualToString('stepDown("07:13:01", 1, null, null)', '07:13');
93 shouldBeEqualToString('stepUp("07:13:59", 0.001, null, null)', '07:13');
94 shouldBeEqualToString('stepDown("07:13:00", 0.001, null, null)', '07:13:59');
95 shouldBeEqualToString('stepUp("07:13:00", 10, null, null)', '07:13:10');
96 shouldBeEqualToString('stepDown("07:13:30", 10, null, null)', '07:13:20');
97 shouldBeEqualToString('stepUp("07:13:50", 10, null, null)', '07:13');
98 shouldBeEqualToString('stepDown("07:13:00", 10, null, null)', '07:13:50');
99 shouldBeEqualToString('stepUp("07:13:09", 10, null, null)', '07:13:10');
100 shouldBeEqualToString('stepDown("07:13:11", 10, null, null)', '07:13:10');
101 shouldBeEqualToString('stepUp("07:13:30", 2.5, null, null)', '07:13:31');
102 shouldBeEqualToString('stepDown("07:13:30", 2.5, null, null)', '07:13:29');
103 shouldBeEqualToString('stepUp("07:13:30", 0, null, null)', '07:13');
104 shouldBeEqualToString('stepDown("07:13:30", 0, null, null)', '07:13');
105 shouldBeEqualToString('stepUp("07:13:30", 3600, null, null)', '07:13');
106 shouldBeEqualToString('stepDown("07:13:30", 3600, null, null)', '07:13');
107 shouldBeEqualToString('stepUp("07:13:30", 11, null, null)', '07:13:31');
108 shouldBeEqualToString('stepDown("07:13:30", 11, null, null)', '07:13:29');
109 shouldBeEqualToString('stepUp("07:13:30", 10, "00:00:05", null)', '07:13:35');
110 shouldBeEqualToString('stepDown("07:13:30", 10, "00:00:05", null)', '07:13:25');
111 shouldBeEqualToString('test("07:13:30", 10, null, null, ["delete", "upArrow"])', '07:13');
112 shouldBeEqualToString('test("07:13:30", 10, null, null, ["delete", "downArrow"])', '07:13:50');
113 shouldBeEqualToString('test("07:13:30", 10, "00:00:05", null, ["delete", "upArrow"])', '07:13:05');
114 shouldBeEqualToString('test("07:13:30", 10, "00:00:05", null, ["delete", "downArrow"])', '07:13:55');
115
116 debug('Minutes');
117 keyDown('leftArrow');
118 shouldBeEqualToString('stepUp("07:13", 1, null, null)', '07:14');
119 shouldBeEqualToString('stepDown("07:13", 1, null, null)', '07:12');
120 shouldBeEqualToString('stepUp("07:59", 0.001, null, null)', '07:00');
121 shouldBeEqualToString('stepDown("07:00", 0.001, null, null)', '07:59');
122 shouldBeEqualToString('stepUp("07:00", 600, null, null)', '07:10');
123 shouldBeEqualToString('stepDown("07:10", 600, null, null)', '07:00');
124 shouldBeEqualToString('stepUp("07:50", 600, null, null)', '07:00');
125 shouldBeEqualToString('stepDown("07:00", 600, null, null)', '07:50');
126 shouldBeEqualToString('stepUp("07:13", 600, null, null)', '07:20');
127 shouldBeEqualToString('stepDown("07:13", 600, null, null)', '07:10');
128 shouldBeEqualToString('stepUp("07:13", 150, null, null)', '07:14');
129 shouldBeEqualToString('stepDown("07:13", 150, null, null)', '07:12');
130 shouldBeEqualToString('stepUp("07:13", 0, null, null)', '07:14');
131 shouldBeEqualToString('stepDown("07:13", 0, null, null)', '07:12');
132 shouldBeEqualToString('stepUp("07:13", 36000, null, null)', '07:00');
133 shouldBeEqualToString('stepDown("07:13", 36000, null, null)', '07:00');
134 shouldBeEqualToString('stepUp("07:13", 660, null, null)', '07:14');
135 shouldBeEqualToString('stepDown("07:13", 660, null, null)', '07:12');
136 shouldBeEqualToString('stepUp("07:13", 600, "00:05", null)', '07:15');
137 shouldBeEqualToString('stepDown("07:13", 600, "00:05", null)', '07:05');
138 shouldBeEqualToString('test("07:13", 600, null, null, ["delete", "upArrow"])', '07:00');
139 shouldBeEqualToString('test("07:13", 600, null, null, ["delete", "downArrow"])', '07:50');
140 shouldBeEqualToString('test("07:13", 600, "00:05", null, ["delete", "upArrow"])', '07:05');
141 shouldBeEqualToString('test("07:13", 600, "00:05", null, ["delete", "downArrow"])', '07:55');
142
143 debug('Hours, 1-12');
144 keyDown('leftArrow');
145 shouldBeEqualToString('stepUp("07:00", 1, null, null)', '08:00');
146 shouldBeEqualToString('stepDown("07:00", 1, null, null)', '06:00');
147 shouldBeEqualToString('stepUp("11:00", 1, null, null)', '00:00');
148 shouldBeEqualToString('stepDown("00:00", 1, null, null)', '11:00');
149 shouldBeEqualToString('stepUp("06:00", 7200, null, null)', '08:00');
150 shouldBeEqualToString('stepDown("06:00", 7200, null, null)', '04:00');
151 shouldBeEqualToString('stepUp("10:00", 7200, null, null)', '00:00');
152 shouldBeEqualToString('stepDown("00:00", 7200, null, null)', '10:00');
153 shouldBeEqualToString('stepUp("07:00", 7200, null, null)', '08:00');
154 shouldBeEqualToString('stepDown("07:00", 7200, null, null)', '06:00');
155 shouldBeEqualToString('stepUp("06:00", 3601, null, null)', '07:00');
156 shouldBeEqualToString('stepDown("06:00", 3601, null, null)', '05:00');
157 shouldBeEqualToString('stepUp("06:00", 0, null, null)', '07:00');
158 shouldBeEqualToString('stepDown("06:00", 0, null, null)', '05:00');
159 shouldBeEqualToString('stepUp("06:00", 86400, null, null)', '00:00');
160 shouldBeEqualToString('stepDown("06:00", 86400, null, null)', '00:00');
161 shouldBeEqualToString('stepUp("06:00", 36000, null, null)', '07:00');
162 shouldBeEqualToString('stepDown("06:00", 36000, null, null)', '05:00');
163 shouldBeEqualToString('stepUp("06:00", 7200, "01:00", null)', '07:00');
164 shouldBeEqualToString('stepDown("06:00", 7200, "01:00", null)', '05:00');
165 shouldBeEqualToString('test("06:00", 7200, null, null, ["delete", "upArrow"])', '02:00');
166 shouldBeEqualToString('test("06:00", 7200, null, null, ["delete", "downArrow"])', '00:00');
167 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '12:00 AM');
168 shouldBeEqualToString('test("06:00", 7200, "01:00", null, ["delete", "upArrow"])', '01:00');
169 shouldBeEqualToString('test("06:00", 7200, "01:00", null, ["delete", "downArrow"])', '11:00');
170
171 debug('Hours, 0-11');
172 setDateTimeFormat('KK:mm a');
173 shouldBeEqualToString('stepUp("11:00", 1, null, null)', '00:00');
174 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '00:00 AM');
175 shouldBeEqualToString('stepDown("00:00", 1, null, null)', '11:00');
176 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '11:00 AM');
177 shouldBeEqualToString('stepUp("23:00", 1, null, null)', '12:00');
178 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '00:00 PM');
179 shouldBeEqualToString('stepDown("12:00", 1, null, null)', '23:00');
180 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '11:00 PM');
181 shouldBeEqualToString('test("06:00", 7200, null, null, ["delete", "upArrow"])', '00:00');
182 shouldBeEqualToString('test("06:00", 7200, null, null, ["delete", "downArrow"])', '10:00');
183 shouldBeEqualToString('test("06:00", 7200, "01:00", null, ["delete", "upArrow"])', '01:00');
184 shouldBeEqualToString('test("06:00", 7200, "01:00", null, ["delete", "downArrow"])', '11:00');
185
186 debug('Hours, 0-23');
187 setDateTimeFormat('HH:mm');
188 shouldBeEqualToString('stepUp("07:00", 1, null, null)', '08:00');
189 shouldBeEqualToString('stepDown("07:00", 1, null, null)', '06:00');
190 shouldBeEqualToString('stepUp("23:00", 1, null, null)', '00:00');
191 shouldBeEqualToString('stepDown("00:00", 1, null, null)', '23:00');
192 shouldBeEqualToString('stepUp("06:00", 7200, null, null)', '08:00');
193 shouldBeEqualToString('stepDown("06:00", 7200, null, null)', '04:00');
194 shouldBeEqualToString('stepUp("22:00", 7200, null, null)', '00:00');
195 shouldBeEqualToString('stepDown("00:00", 7200, null, null)', '22:00');
196 shouldBeEqualToString('stepUp("07:00", 7200, null, null)', '08:00');
197 shouldBeEqualToString('stepDown("07:00", 7200, null, null)', '06:00');
198 shouldBeEqualToString('stepUp("06:00", 3601, null, null)', '07:00');
199 shouldBeEqualToString('stepDown("06:00", 3601, null, null)', '05:00');
200 shouldBeEqualToString('stepUp("06:00", 0, null, null)', '07:00');
201 shouldBeEqualToString('stepDown("06:00", 0, null, null)', '05:00');
202 shouldBeEqualToString('stepUp("06:00", 86400, null, null)', '00:00');
203 shouldBeEqualToString('stepDown("06:00", 86400, null, null)', '00:00');
204 shouldBeEqualToString('stepUp("06:00", 36000, null, null)', '07:00');
205 shouldBeEqualToString('stepDown("06:00", 36000, null, null)', '05:00');
206 shouldBeEqualToString('stepUp("06:00", 7200, "01:00", null)', '07:00');
207 shouldBeEqualToString('stepDown("06:00", 7200, "01:00", null)', '05:00');
208 shouldBeEqualToString('test("06:00", 7200, null, null, ["delete", "upArrow"])', '00:00');
209 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '00:00');
210 shouldBeEqualToString('test("06:00", 7200, null, null, ["delete", "downArrow"])', '22:00');
211 shouldBeEqualToString('test("06:00", 7200, "01:00", null, ["delete", "upArrow"])', '01:00');
212 shouldBeEqualToString('test("06:00", 7200, "01:00", null, ["delete", "downArrow"])', '23:00');
213
214 debug('Hours, 1-24');
215 setDateTimeFormat('kk:mm');
216 shouldBeEqualToString('stepUp("11:00", 1, null, null)', '12:00');
217 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '12:00');
218 shouldBeEqualToString('stepDown("00:00", 1, null, null)', '23:00');
219 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '23:00');
220 shouldBeEqualToString('stepUp("23:00", 1, null, null)', '00:00');
221 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '24:00');
222 shouldBeEqualToString('stepDown("12:00", 1, null, null)', '11:00');
223 shouldBeEqualToString('getUserAgentShadowTextContent(input)', '11:00');
224 shouldBeEqualToString('test("06:00", 7200, null, null, ["delete", "upArrow"])', '02:00');
225 shouldBeEqualToString('test("06:00", 7200, null, null, ["delete", "downArrow"])', '00:00');
226 shouldBeEqualToString('test("06:00", 7200, "01:00", null, ["delete", "upArrow"])', '01:00');
227 shouldBeEqualToString('test("06:00", 7200, "01:00", null, ["delete", "downArrow"])', '23:00');
228
229 setDateTimeFormat('');
230 debug('');
231 document.body.removeChild(input);
232 </script>
233 <script src="../../js/resources/js-test-post.js"></script>
234 </body>
235 </html>