4 <script src=
"../../../resources/js-test.js"></script>
5 <script src=
"../../forms/resources/picker-common.js"></script>
6 <script src=
"resources/calendar-picker-common.js"></script>
9 <p id=
"description"></p>
10 <div id=
"console"></div>
11 <input type=week id=week
value=
"2000-W01">
13 description("Tests if month picker key bindings work as expected.");
15 debug('Check that page popup doesn\'t exist at first.');
16 shouldBeNull('document.getElementById("mock-page-popup")');
18 openPicker(document
.getElementById('week'), test1
);
21 debug('Check that page popup exists.');
22 shouldBeEqualToString('popupWindow.pagePopupController.toString()', '[object PagePopupController]');
24 shouldBeFalse('isCalendarTableScrollingWithAnimation()');
25 shouldBeEqualToString('currentMonth()', '2000-01');
26 shouldBeEqualToString('selectedValue()', '2000-W01');
27 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
28 shouldBeEqualToString('highlightedValue()', '2000-W01');
29 shouldBeEqualToString('highlightedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
31 debug('Check that arrow keys work properly.');
34 eventSender
.keyDown('upArrow');
35 shouldBeEqualToString('currentMonth()', '2000-01');
36 shouldBeEqualToString('selectedValue()', '2000-W01');
37 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
38 shouldBeEqualToString('highlightedValue()', '1999-W52');
39 shouldBeEqualToString('highlightedDayCells()', '1999-12-27,1999-12-28,1999-12-29,1999-12-30,1999-12-31,2000-01-01,2000-01-02');
42 eventSender
.keyDown('upArrow');
43 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
44 shouldBeEqualToString('currentMonth()', '1999-12');
45 shouldBeEqualToString('selectedValue()', '2000-W01');
46 shouldBeEqualToString('selectedDayCells()', '');
47 shouldBeEqualToString('highlightedValue()', '1999-W51');
48 shouldBeEqualToString('highlightedDayCells()', '1999-12-20,1999-12-21,1999-12-22,1999-12-23,1999-12-24,1999-12-25,1999-12-26');
51 eventSender
.keyDown('downArrow');
52 shouldBeEqualToString('currentMonth()', '1999-12');
53 shouldBeEqualToString('selectedValue()', '2000-W01');
54 shouldBeEqualToString('selectedDayCells()', '');
55 shouldBeEqualToString('highlightedValue()', '1999-W52');
56 shouldBeEqualToString('highlightedDayCells()', '1999-12-27,1999-12-28,1999-12-29,1999-12-30,1999-12-31,2000-01-01');
59 eventSender
.keyDown('downArrow');
60 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
61 shouldBeEqualToString('currentMonth()', '2000-01');
62 shouldBeEqualToString('selectedValue()', '2000-W01');
63 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
64 shouldBeEqualToString('highlightedValue()', '2000-W01');
65 shouldBeEqualToString('highlightedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
68 eventSender
.keyDown('downArrow');
69 shouldBeEqualToString('currentMonth()', '2000-01');
70 shouldBeEqualToString('selectedValue()', '2000-W01');
71 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
72 shouldBeEqualToString('highlightedValue()', '2000-W02');
73 shouldBeEqualToString('highlightedDayCells()', '2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16');
76 eventSender
.keyDown('leftArrow');
77 shouldBeEqualToString('currentMonth()', '2000-01');
78 shouldBeEqualToString('selectedValue()', '2000-W01');
79 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
80 shouldBeEqualToString('highlightedValue()', '2000-W01');
81 shouldBeEqualToString('highlightedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
84 eventSender
.keyDown('rightArrow');
85 shouldBeEqualToString('currentMonth()', '2000-01');
86 shouldBeEqualToString('selectedValue()', '2000-W01');
87 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
88 shouldBeEqualToString('highlightedValue()', '2000-W02');
89 shouldBeEqualToString('highlightedDayCells()', '2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16');
91 debug("press pageDown");
92 eventSender
.keyDown('pageDown');
93 shouldBeEqualToString('currentMonth()', '2000-02');
94 shouldBeEqualToString('selectedValue()', '2000-W01');
95 shouldBeEqualToString('selectedDayCells()', '');
96 shouldBeEqualToString('highlightedValue()', '2000-W02');
97 shouldBeEqualToString('highlightedDayCells()', '');
99 debug("press pageUp");
100 eventSender
.keyDown('pageUp');
101 shouldBeEqualToString('currentMonth()', '2000-01');
102 shouldBeEqualToString('selectedValue()', '2000-W01');
103 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
104 shouldBeEqualToString('highlightedValue()', '2000-W02');
105 shouldBeEqualToString('highlightedDayCells()', '2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16');
108 eventSender
.keyDown('m');
109 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
110 shouldBeEqualToString('currentMonth()', '2000-02');
111 shouldBeEqualToString('selectedValue()', '2000-W01');
112 shouldBeEqualToString('selectedDayCells()', '');
113 shouldBeEqualToString('highlightedValue()', '2000-W07');
114 shouldBeEqualToString('highlightedDayCells()', '2000-02-14,2000-02-15,2000-02-16,2000-02-17,2000-02-18,2000-02-19,2000-02-20');
116 debug("press shift + m");
117 eventSender
.keyDown('M');
118 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
119 shouldBeEqualToString('currentMonth()', '2000-01');
120 shouldBeEqualToString('selectedValue()', '2000-W01');
121 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
122 shouldBeEqualToString('highlightedValue()', '2000-W02');
123 shouldBeEqualToString('highlightedDayCells()', '2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16');
126 eventSender
.keyDown('y');
127 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
128 shouldBeEqualToString('currentMonth()', '2001-01');
129 shouldBeEqualToString('selectedValue()', '2000-W01');
130 shouldBeEqualToString('selectedDayCells()', '');
131 shouldBeEqualToString('highlightedValue()', '2001-W03');
132 shouldBeEqualToString('highlightedDayCells()', '2001-01-15,2001-01-16,2001-01-17,2001-01-18,2001-01-19,2001-01-20,2001-01-21');
134 debug("press shift + y");
135 eventSender
.keyDown('Y');
136 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
137 shouldBeEqualToString('currentMonth()', '2000-01');
138 shouldBeEqualToString('selectedValue()', '2000-W01');
139 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
140 shouldBeEqualToString('highlightedValue()', '2000-W02');
141 shouldBeEqualToString('highlightedDayCells()', '2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16');
144 eventSender
.keyDown('d');
145 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
146 shouldBeEqualToString('currentMonth()', '2010-01');
147 shouldBeEqualToString('selectedValue()', '2000-W01');
148 shouldBeEqualToString('selectedDayCells()', '');
149 shouldBeEqualToString('highlightedValue()', '2010-W02');
150 shouldBeEqualToString('highlightedDayCells()', '2010-01-11,2010-01-12,2010-01-13,2010-01-14,2010-01-15,2010-01-16,2010-01-17');
152 debug("press shift + d");
153 eventSender
.keyDown('D');
154 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
155 shouldBeEqualToString('currentMonth()', '2000-01');
156 shouldBeEqualToString('selectedValue()', '2000-W01');
157 shouldBeEqualToString('selectedDayCells()', '2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09');
158 shouldBeEqualToString('highlightedValue()', '2000-W02');
159 shouldBeEqualToString('highlightedDayCells()', '2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16');
161 debug("press enter");
162 setNoCloseOnCommit();
163 eventSender
.keyDown('\n');
164 shouldBeEqualToString('currentMonth()', '2000-01');
165 shouldBeEqualToString('selectedValue()', '2000-W02');
166 shouldBeEqualToString('selectedDayCells()', '2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16');
167 shouldBeEqualToString('highlightedValue()', '2000-W02');
168 shouldBeEqualToString('highlightedDayCells()', '2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16');
169 shouldBeEqualToString('document.getElementById("week").value', '2000-W02');
171 debug('Check if tabbing works.');
172 shouldBeEqualToString('focusedElement()', '.list-view calendar-table-view');
173 eventSender
.keyDown('\t', ['shiftKey']);
174 shouldBeEqualToString('focusedElement()', '.calendar-navigation-button');
175 eventSender
.keyDown('\t', ['shiftKey']);
176 shouldBeEqualToString('focusedElement()', '.calendar-navigation-button today-button');
177 eventSender
.keyDown('\t', ['shiftKey']);
178 shouldBeEqualToString('focusedElement()', '.calendar-navigation-button');
179 eventSender
.keyDown('\t', ['shiftKey']);
180 shouldBeEqualToString('focusedElement()', '.month-popup-button');
182 debug('open the month popup');
183 eventSender
.keyDown('\n');
184 shouldBeTrue('popupWindow.global.picker.monthPopupView.isVisible');
185 shouldBeEqualToString('highlightedMonthButton()', '2000-01');
188 eventSender
.keyDown('downArrow');
189 shouldBeEqualToString('highlightedMonthButton()', '2000-05');
191 debug("press right");
192 eventSender
.keyDown('rightArrow');
193 shouldBeEqualToString('highlightedMonthButton()', '2000-06');
195 debug("press right");
196 eventSender
.keyDown('rightArrow');
197 shouldBeEqualToString('highlightedMonthButton()', '2000-07');
199 debug("press right");
200 eventSender
.keyDown('rightArrow');
201 shouldBeEqualToString('highlightedMonthButton()', '2000-08');
203 debug("press right");
204 eventSender
.keyDown('rightArrow');
205 shouldBeEqualToString('highlightedMonthButton()', '2000-09');
207 debug("press right");
208 eventSender
.keyDown('rightArrow');
209 shouldBeEqualToString('highlightedMonthButton()', '2000-10');
212 eventSender
.keyDown('leftArrow');
213 shouldBeEqualToString('highlightedMonthButton()', '2000-09');
216 eventSender
.keyDown('upArrow');
217 shouldBeEqualToString('highlightedMonthButton()', '2000-05');
219 debug("press pageDown");
220 eventSender
.keyDown('pageDown');
221 shouldBeEqualToString('highlightedMonthButton()', '2001-05');
223 debug("press pageUp");
224 eventSender
.keyDown('pageUp');
225 shouldBeEqualToString('highlightedMonthButton()', '2000-05');
227 debug('select month in the month popup');
228 eventSender
.keyDown('\n');
229 shouldBeFalse('popupWindow.global.picker.monthPopupView.isVisible');
230 shouldBeEqualToString('currentMonth()', '2000-05');
231 shouldBeEqualToString('selectedValue()', '2000-W02');
232 shouldBeEqualToString('selectedDayCells()', '');
233 shouldBeEqualToString('highlightedValue()', '2000-W02');
234 shouldBeEqualToString('highlightedDayCells()', '');
236 debug("focus calendar table");
237 popupWindow
.global
.picker
.calendarTableView
.element
.focus();
239 // Test twice in case midnight.
241 shouldBeTrue('testToday() || testToday()');
244 eventSender
.keyDown('escape');
245 waitUntilClosing(test2AfterClosing
);
248 function test2AfterClosing() {
249 shouldBeNull('document.getElementById("mock-page-popup")');
254 function testToday() {
255 eventSender
.keyDown('t');
256 shouldBeTrueQuiet('isCalendarTableScrollingWithAnimation()');
257 var now
= new Date();
258 var expectedWeek
= popupWindow
.Week
.createFromToday().toString();
259 return selectedValue() === expectedWeek
&& highlightedValue() === expectedWeek
;
262 function focusedElement() {
263 var element
= popupWindow
.document
.activeElement
;
266 var identifier
= "." + element
.className
;
268 identifier
+= "[value=" + element
.value
+ "]";