Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / month-multiple-fields / month-multiple-fields-keyboard-events.html
blob2828b779ff21be4d970f8b40e5adfb00efc02134
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 <p>
9 Please run this with DumpRenderTree.
10 </p>
11 Test following keys:
12 <ul>
13 <li>Digits</li>
14 <li>Left/Right - Move focus field inside element</li>
15 <li>Up/Down - Increment/decrement value of focus field</li>
16 <li>Tab - Move focus field</li>
17 <li>Backspace - Make value empty</li>
18 </ul>
19 <input id="before">
20 <input id="input" type="month">
21 <input id="another">
22 <div id="console"></div>
23 <script>
24 description("Multiple fields UI of month input type with keyboard events");
25 if (window.internals)
26 internals.settings.setLangAttributeAwareFormControlUIEnabled(true);
27 var input = document.getElementById("input");
29 function keyDown(key, modifiers)
31 if (!window.eventSender)
32 return;
33 eventSender.keyDown(key, modifiers);
36 function beginTest(title, value, opt_min, opt_max)
38 debug("== " + title + " ==");
39 input.value = value;
40 input.min = opt_min ? opt_min : "";
41 input.max = opt_max ? opt_max : "";
42 input.blur();
43 input.focus();
46 // We assume the year-month format is "MMM yyyy".
48 beginTest('Digit keys');
49 keyDown('s');
50 keyDown('rightArrow');
51 keyDown('0');
52 keyDown('1');
53 keyDown('2');
54 keyDown('A');
55 shouldBeEqualToString('input.value', '0012-09');
57 beginTest('Left/Right keys', '2012-09');
58 keyDown('rightArrow');
59 keyDown('5');
60 keyDown('leftArrow');
61 keyDown('6');
62 shouldBeEqualToString('input.value', '0005-06');
63 keyDown('leftArrow');
64 keyDown('leftArrow');
65 keyDown('leftArrow');
66 shouldBeEqualToString('document.activeElement.id', 'input');
68 beginTest('Up/Down keys', '2012-09');
69 keyDown('upArrow');
70 shouldBeEqualToString('input.value', '2012-10');
71 keyDown('downArrow');
72 keyDown('downArrow');
73 shouldBeEqualToString('input.value', '2012-08');
75 // Note that empty value for the year field without min/max attributes is not
76 // testable because its default value depends on the current date.
77 beginTest('Up/Down keys on empty value', '', '2012-01');
78 keyDown('downArrow');
79 keyDown('downArrow');
80 keyDown('rightArrow');
81 keyDown('upArrow');
82 keyDown('upArrow');
83 keyDown('downArrow');
84 shouldBeEqualToString('input.value', '2012-11');
86 beginTest('Up/Down keys on empty value 2', '', undefined, '2012-01');
87 keyDown('upArrow');
88 keyDown('upArrow');
89 keyDown('rightArrow');
90 keyDown('downArrow');
91 keyDown('downArrow');
92 keyDown('upArrow');
93 shouldBeEqualToString('input.value', '2012-02');
95 beginTest('Tab key', '2012-09');
96 keyDown('\t'); // -> Sep [2012]
97 keyDown('5'); // -> Sep [0005]
98 shouldBeEqualToString('input.value', '0005-09');
99 keyDown('\t', ['shiftKey']); // -> [Sep] [0005]
100 keyDown('J'); // -> [Jan] 0005
101 shouldBeEqualToString('input.value', '0005-01');
102 keyDown('\t'); // -> Jan [0005]
103 keyDown('\t'); // -> Jan 0005
104 shouldBeEqualToString('document.activeElement.id', 'another');
106 beginTest('Shfit+Tab key', '2012-09');
107 another.focus();
108 keyDown('\t', ['shiftKey']);
109 keyDown('3');
110 shouldBeEqualToString('input.value', '0003-09');
111 keyDown('\t', ['shiftKey']);
112 keyDown('\t', ['shiftKey']);
113 shouldBeEqualToString('document.activeElement.id', 'before');
115 beginTest('Up key on maximum value', '275760-09');
116 keyDown('upArrow');
117 keyDown('\t');
118 keyDown('upArrow');
119 shouldBeEqualToString('input.value', '0001-10');
120 beginTest('Up key with a maximum attribute', '1999-12', undefined, '1999-12');
121 keyDown('upArrow');
122 keyDown('\t');
123 keyDown('upArrow');
124 shouldBeEqualToString('input.value', '0001-01');
126 beginTest('Down key on minimum value', '0001-01', 'bad min', 'wrong max');
127 keyDown('downArrow'); // -> 0001-12
128 keyDown('\t');
129 keyDown('downArrow'); // -> 275760-12, which is greater than the hard limit.
130 shouldBeEqualToString('input.value', '');
131 beginTest('Down key with a minimum attribute', '0001-01', '0001-01');
132 keyDown('downArrow'); // -> 0001-12
133 keyDown('\t');
134 keyDown('downArrow'); // -> 275760-12, which is greater than the hard limit.
135 shouldBeEqualToString('input.value', '');
137 beginTest('Inconsistent min-max attributes', '1999-12', '1999-12', '1000-01');
138 keyDown('\t');
139 keyDown('upArrow');
140 shouldBeEqualToString('input.value', '1000-12');
141 keyDown('downArrow');
142 shouldBeEqualToString('input.value', '1999-12');
144 beginTest('Backspace key', '2012-09');
145 keyDown("\b");
146 shouldBeEqualToString('input.value', '');
148 beginTest('Delete key', '2012-09');
149 keyDown("delete");
150 shouldBeEqualToString('input.value', '');
152 beginTest('Typeahead', '2012-12');
153 keyDown('rightArrow');
154 keyDown('1');
155 shouldBeEqualToString('input.value', '0001-12');
156 keyDown('leftArrow');
157 keyDown('rightArrow');
158 keyDown('2');
159 shouldBeEqualToString('input.value', '0002-12');
161 beginTest('Typeahead cycle first character', '2012-09');
162 keyDown('j'); // -> [Jan] 2012
163 shouldBeEqualToString('input.value', '2012-01');
164 keyDown('j'); // -> [Jun] 2012
165 shouldBeEqualToString('input.value', '2012-06');
166 keyDown('j'); // -> [Jul] 2012
167 shouldBeEqualToString('input.value', '2012-07');
168 keyDown('j'); // -> [Jan] 2012
169 shouldBeEqualToString('input.value', '2012-01');
170 keyDown('x'); // -> [Jan] 2012
171 shouldBeEqualToString('input.value', '2012-01');
173 beginTest('Typeahead prefix match', '2012-09');
174 keyDown('m'); // -> [Mar] 2012
175 shouldBeEqualToString('input.value', '2012-03');
176 keyDown('a'); // -> [Mar] 2012
177 shouldBeEqualToString('input.value', '2012-03');
178 keyDown('y'); // -> [May] 2012
179 shouldBeEqualToString('input.value', '2012-05');
180 keyDown('x'); // -> [May] 2012
181 shouldBeEqualToString('input.value', '2012-05');
183 beginTest('Typeahead index match', '2012-09');
184 keyDown('1'); // -> [Jan] 2012
185 shouldBeEqualToString('input.value', '2012-01');
186 keyDown('2'); // -> [Dec] 2012
187 shouldBeEqualToString('input.value', '2012-12');
188 keyDown('x'); // -> [Dec] 2012
189 shouldBeEqualToString('input.value', '2012-12');
191 beginTest('Typeahead should search from current selection', '2012-01');
192 keyDown('j'); // -> [Jun] 2012
193 shouldBeEqualToString('input.value', '2012-06');
195 input.setAttribute("lang", "he-il");
196 beginTest('RTL focus navigation', '2012-09');
197 debug('The tests in this block fail on platforms without the lang-attribute-aware-form-control-UI feature.');
198 keyDown('upArrow'); // -> 2012 [M10]
199 shouldBeEqualToString('input.value', '2012-10');
200 keyDown('\t'); // -> [2012] M10
201 keyDown('2'); // -> [0002] M10
202 shouldBeEqualToString('input.value', '0002-10');
203 keyDown('\t', ['shiftKey']); // -> 0002 [M10]
204 keyDown('upArrow'); // -> 0002 [M11]
205 shouldBeEqualToString('input.value', '0002-11');
206 input.removeAttribute("lang");
207 </script>
208 </body>
209 </html>