4 <script src=
"../../../resources/js-test.js"></script>
7 <p id=
"description"></p>
9 Please run this with DumpRenderTree.
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>
20 <input id=
"input" type=
"month">
22 <div id=
"console"></div>
24 description("Multiple fields UI of month input type with keyboard events");
26 internals
.settings
.setLangAttributeAwareFormControlUIEnabled(true);
27 var input
= document
.getElementById("input");
29 function keyDown(key
, modifiers
)
31 if (!window
.eventSender
)
33 eventSender
.keyDown(key
, modifiers
);
36 function beginTest(title
, value
, opt_min
, opt_max
)
38 debug("== " + title
+ " ==");
40 input
.min
= opt_min
? opt_min
: "";
41 input
.max
= opt_max
? opt_max
: "";
46 // We assume the year-month format is "MMM yyyy".
48 beginTest('Digit keys');
50 keyDown('rightArrow');
55 shouldBeEqualToString('input.value', '0012-09');
57 beginTest('Left/Right keys', '2012-09');
58 keyDown('rightArrow');
62 shouldBeEqualToString('input.value', '0005-06');
66 shouldBeEqualToString('document.activeElement.id', 'input');
68 beginTest('Up/Down keys', '2012-09');
70 shouldBeEqualToString('input.value', '2012-10');
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');
80 keyDown('rightArrow');
84 shouldBeEqualToString('input.value', '2012-11');
86 beginTest('Up/Down keys on empty value 2', '', undefined, '2012-01');
89 keyDown('rightArrow');
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');
108 keyDown('\t', ['shiftKey']);
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');
119 shouldBeEqualToString('input.value', '0001-10');
120 beginTest('Up key with a maximum attribute', '1999-12', undefined, '1999-12');
124 shouldBeEqualToString('input.value', '0001-01');
126 beginTest('Down key on minimum value', '0001-01', 'bad min', 'wrong max');
127 keyDown('downArrow'); // -> 0001-12
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
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');
140 shouldBeEqualToString('input.value', '1000-12');
141 keyDown('downArrow');
142 shouldBeEqualToString('input.value', '1999-12');
144 beginTest('Backspace key', '2012-09');
146 shouldBeEqualToString('input.value', '');
148 beginTest('Delete key', '2012-09');
150 shouldBeEqualToString('input.value', '');
152 beginTest('Typeahead', '2012-12');
153 keyDown('rightArrow');
155 shouldBeEqualToString('input.value', '0001-12');
156 keyDown('leftArrow');
157 keyDown('rightArrow');
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");