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=month id=month
value=
"2000-01">
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('month'), 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-01');
27 shouldBeEqualToString('selectedDayCells()', '2000-01-01,2000-01-02,2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09,2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16,2000-01-17,2000-01-18,2000-01-19,2000-01-20,2000-01-21,2000-01-22,2000-01-23,2000-01-24,2000-01-25,2000-01-26,2000-01-27,2000-01-28,2000-01-29,2000-01-30,2000-01-31');
28 shouldBeEqualToString('highlightedValue()', '2000-01');
29 shouldBeEqualToString('highlightedDayCells()', '2000-01-01,2000-01-02,2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09,2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16,2000-01-17,2000-01-18,2000-01-19,2000-01-20,2000-01-21,2000-01-22,2000-01-23,2000-01-24,2000-01-25,2000-01-26,2000-01-27,2000-01-28,2000-01-29,2000-01-30,2000-01-31');
31 debug('Check that arrow keys work properly.');
34 eventSender
.keyDown('upArrow');
35 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
36 shouldBeEqualToString('currentMonth()', '1999-12');
37 shouldBeEqualToString('selectedValue()', '2000-01');
38 shouldBeEqualToString('selectedDayCells()', '2000-01-01');
39 shouldBeEqualToString('highlightedValue()', '1999-12');
40 shouldBeEqualToString('highlightedDayCells()', '1999-12-01,1999-12-02,1999-12-03,1999-12-04,1999-12-05,1999-12-06,1999-12-07,1999-12-08,1999-12-09,1999-12-10,1999-12-11,1999-12-12,1999-12-13,1999-12-14,1999-12-15,1999-12-16,1999-12-17,1999-12-18,1999-12-19,1999-12-20,1999-12-21,1999-12-22,1999-12-23,1999-12-24,1999-12-25,1999-12-26,1999-12-27,1999-12-28,1999-12-29,1999-12-30,1999-12-31');
43 eventSender
.keyDown('downArrow');
44 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
45 shouldBeEqualToString('currentMonth()', '2000-01');
46 shouldBeEqualToString('selectedValue()', '2000-01');
47 shouldBeEqualToString('selectedDayCells()', '2000-01-01,2000-01-02,2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09,2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16,2000-01-17,2000-01-18,2000-01-19,2000-01-20,2000-01-21,2000-01-22,2000-01-23,2000-01-24,2000-01-25,2000-01-26,2000-01-27,2000-01-28,2000-01-29,2000-01-30,2000-01-31');
48 shouldBeEqualToString('highlightedValue()', '2000-01');
49 shouldBeEqualToString('highlightedDayCells()', '2000-01-01,2000-01-02,2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09,2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16,2000-01-17,2000-01-18,2000-01-19,2000-01-20,2000-01-21,2000-01-22,2000-01-23,2000-01-24,2000-01-25,2000-01-26,2000-01-27,2000-01-28,2000-01-29,2000-01-30,2000-01-31');
52 eventSender
.keyDown('downArrow');
53 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
54 shouldBeEqualToString('currentMonth()', '2000-02');
55 shouldBeEqualToString('selectedValue()', '2000-01');
56 shouldBeEqualToString('selectedDayCells()', '2000-01-30,2000-01-31');
57 shouldBeEqualToString('highlightedValue()', '2000-02');
58 shouldBeEqualToString('highlightedDayCells()', '2000-02-01,2000-02-02,2000-02-03,2000-02-04,2000-02-05,2000-02-06,2000-02-07,2000-02-08,2000-02-09,2000-02-10,2000-02-11,2000-02-12,2000-02-13,2000-02-14,2000-02-15,2000-02-16,2000-02-17,2000-02-18,2000-02-19,2000-02-20,2000-02-21,2000-02-22,2000-02-23,2000-02-24,2000-02-25,2000-02-26,2000-02-27,2000-02-28,2000-02-29');
61 eventSender
.keyDown('leftArrow');
62 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
63 shouldBeEqualToString('currentMonth()', '2000-01');
64 shouldBeEqualToString('selectedValue()', '2000-01');
65 shouldBeEqualToString('selectedDayCells()', '2000-01-01,2000-01-02,2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09,2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16,2000-01-17,2000-01-18,2000-01-19,2000-01-20,2000-01-21,2000-01-22,2000-01-23,2000-01-24,2000-01-25,2000-01-26,2000-01-27,2000-01-28,2000-01-29,2000-01-30,2000-01-31');
66 shouldBeEqualToString('highlightedValue()', '2000-01');
67 shouldBeEqualToString('highlightedDayCells()', '2000-01-01,2000-01-02,2000-01-03,2000-01-04,2000-01-05,2000-01-06,2000-01-07,2000-01-08,2000-01-09,2000-01-10,2000-01-11,2000-01-12,2000-01-13,2000-01-14,2000-01-15,2000-01-16,2000-01-17,2000-01-18,2000-01-19,2000-01-20,2000-01-21,2000-01-22,2000-01-23,2000-01-24,2000-01-25,2000-01-26,2000-01-27,2000-01-28,2000-01-29,2000-01-30,2000-01-31');
70 eventSender
.keyDown('rightArrow');
71 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
72 shouldBeEqualToString('currentMonth()', '2000-02');
73 shouldBeEqualToString('selectedValue()', '2000-01');
74 shouldBeEqualToString('selectedDayCells()', '2000-01-30,2000-01-31');
75 shouldBeEqualToString('highlightedValue()', '2000-02');
76 shouldBeEqualToString('highlightedDayCells()', '2000-02-01,2000-02-02,2000-02-03,2000-02-04,2000-02-05,2000-02-06,2000-02-07,2000-02-08,2000-02-09,2000-02-10,2000-02-11,2000-02-12,2000-02-13,2000-02-14,2000-02-15,2000-02-16,2000-02-17,2000-02-18,2000-02-19,2000-02-20,2000-02-21,2000-02-22,2000-02-23,2000-02-24,2000-02-25,2000-02-26,2000-02-27,2000-02-28,2000-02-29');
78 debug("press pageDown");
79 eventSender
.keyDown('pageDown');
80 shouldBeEqualToString('currentMonth()', '2000-03');
81 shouldBeEqualToString('selectedValue()', '2000-01');
82 shouldBeEqualToString('selectedDayCells()', '');
83 shouldBeEqualToString('highlightedValue()', '2000-02');
84 shouldBeEqualToString('highlightedDayCells()', '2000-02-27,2000-02-28,2000-02-29');
86 debug("press pageUp");
87 eventSender
.keyDown('pageUp');
88 shouldBeEqualToString('currentMonth()', '2000-02');
89 shouldBeEqualToString('selectedValue()', '2000-01');
90 shouldBeEqualToString('selectedDayCells()', '2000-01-30,2000-01-31');
91 shouldBeEqualToString('highlightedValue()', '2000-02');
92 shouldBeEqualToString('highlightedDayCells()', '2000-02-01,2000-02-02,2000-02-03,2000-02-04,2000-02-05,2000-02-06,2000-02-07,2000-02-08,2000-02-09,2000-02-10,2000-02-11,2000-02-12,2000-02-13,2000-02-14,2000-02-15,2000-02-16,2000-02-17,2000-02-18,2000-02-19,2000-02-20,2000-02-21,2000-02-22,2000-02-23,2000-02-24,2000-02-25,2000-02-26,2000-02-27,2000-02-28,2000-02-29');
95 eventSender
.keyDown('m');
96 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
97 shouldBeEqualToString('currentMonth()', '2000-03');
98 shouldBeEqualToString('selectedValue()', '2000-01');
99 shouldBeEqualToString('selectedDayCells()', '');
100 shouldBeEqualToString('highlightedValue()', '2000-03');
101 shouldBeEqualToString('highlightedDayCells()', '2000-03-01,2000-03-02,2000-03-03,2000-03-04,2000-03-05,2000-03-06,2000-03-07,2000-03-08,2000-03-09,2000-03-10,2000-03-11,2000-03-12,2000-03-13,2000-03-14,2000-03-15,2000-03-16,2000-03-17,2000-03-18,2000-03-19,2000-03-20,2000-03-21,2000-03-22,2000-03-23,2000-03-24,2000-03-25,2000-03-26,2000-03-27,2000-03-28,2000-03-29,2000-03-30,2000-03-31');
103 debug("press shift + m");
104 eventSender
.keyDown('M');
105 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
106 shouldBeEqualToString('currentMonth()', '2000-02');
107 shouldBeEqualToString('selectedValue()', '2000-01');
108 shouldBeEqualToString('selectedDayCells()', '2000-01-30,2000-01-31');
109 shouldBeEqualToString('highlightedValue()', '2000-02');
110 shouldBeEqualToString('highlightedDayCells()', '2000-02-01,2000-02-02,2000-02-03,2000-02-04,2000-02-05,2000-02-06,2000-02-07,2000-02-08,2000-02-09,2000-02-10,2000-02-11,2000-02-12,2000-02-13,2000-02-14,2000-02-15,2000-02-16,2000-02-17,2000-02-18,2000-02-19,2000-02-20,2000-02-21,2000-02-22,2000-02-23,2000-02-24,2000-02-25,2000-02-26,2000-02-27,2000-02-28,2000-02-29');
113 eventSender
.keyDown('y');
114 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
115 shouldBeEqualToString('currentMonth()', '2001-02');
116 shouldBeEqualToString('selectedValue()', '2000-01');
117 shouldBeEqualToString('selectedDayCells()', '');
118 shouldBeEqualToString('highlightedValue()', '2001-02');
119 shouldBeEqualToString('highlightedDayCells()', '2001-02-01,2001-02-02,2001-02-03,2001-02-04,2001-02-05,2001-02-06,2001-02-07,2001-02-08,2001-02-09,2001-02-10,2001-02-11,2001-02-12,2001-02-13,2001-02-14,2001-02-15,2001-02-16,2001-02-17,2001-02-18,2001-02-19,2001-02-20,2001-02-21,2001-02-22,2001-02-23,2001-02-24,2001-02-25,2001-02-26,2001-02-27,2001-02-28');
121 debug("press shift + y");
122 eventSender
.keyDown('Y');
123 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
124 shouldBeEqualToString('currentMonth()', '2000-02');
125 shouldBeEqualToString('selectedValue()', '2000-01');
126 shouldBeEqualToString('selectedDayCells()', '2000-01-30,2000-01-31');
127 shouldBeEqualToString('highlightedValue()', '2000-02');
128 shouldBeEqualToString('highlightedDayCells()', '2000-02-01,2000-02-02,2000-02-03,2000-02-04,2000-02-05,2000-02-06,2000-02-07,2000-02-08,2000-02-09,2000-02-10,2000-02-11,2000-02-12,2000-02-13,2000-02-14,2000-02-15,2000-02-16,2000-02-17,2000-02-18,2000-02-19,2000-02-20,2000-02-21,2000-02-22,2000-02-23,2000-02-24,2000-02-25,2000-02-26,2000-02-27,2000-02-28,2000-02-29');
131 eventSender
.keyDown('d');
132 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
133 shouldBeEqualToString('currentMonth()', '2010-02');
134 shouldBeEqualToString('selectedValue()', '2000-01');
135 shouldBeEqualToString('selectedDayCells()', '');
136 shouldBeEqualToString('highlightedValue()', '2010-02');
137 shouldBeEqualToString('highlightedDayCells()', '2010-02-01,2010-02-02,2010-02-03,2010-02-04,2010-02-05,2010-02-06,2010-02-07,2010-02-08,2010-02-09,2010-02-10,2010-02-11,2010-02-12,2010-02-13,2010-02-14,2010-02-15,2010-02-16,2010-02-17,2010-02-18,2010-02-19,2010-02-20,2010-02-21,2010-02-22,2010-02-23,2010-02-24,2010-02-25,2010-02-26,2010-02-27,2010-02-28');
139 debug("press shift + d");
140 eventSender
.keyDown('D');
141 shouldBeTrue('isCalendarTableScrollingWithAnimation()');
142 shouldBeEqualToString('currentMonth()', '2000-02');
143 shouldBeEqualToString('selectedValue()', '2000-01');
144 shouldBeEqualToString('selectedDayCells()', '2000-01-30,2000-01-31');
145 shouldBeEqualToString('highlightedValue()', '2000-02');
146 shouldBeEqualToString('highlightedDayCells()', '2000-02-01,2000-02-02,2000-02-03,2000-02-04,2000-02-05,2000-02-06,2000-02-07,2000-02-08,2000-02-09,2000-02-10,2000-02-11,2000-02-12,2000-02-13,2000-02-14,2000-02-15,2000-02-16,2000-02-17,2000-02-18,2000-02-19,2000-02-20,2000-02-21,2000-02-22,2000-02-23,2000-02-24,2000-02-25,2000-02-26,2000-02-27,2000-02-28,2000-02-29');
148 debug("press enter");
149 setNoCloseOnCommit();
150 eventSender
.keyDown('\n');
151 shouldBeEqualToString('currentMonth()', '2000-02');
152 shouldBeEqualToString('selectedValue()', '2000-02');
153 shouldBeEqualToString('selectedDayCells()', '2000-02-01,2000-02-02,2000-02-03,2000-02-04,2000-02-05,2000-02-06,2000-02-07,2000-02-08,2000-02-09,2000-02-10,2000-02-11,2000-02-12,2000-02-13,2000-02-14,2000-02-15,2000-02-16,2000-02-17,2000-02-18,2000-02-19,2000-02-20,2000-02-21,2000-02-22,2000-02-23,2000-02-24,2000-02-25,2000-02-26,2000-02-27,2000-02-28,2000-02-29');
154 shouldBeEqualToString('highlightedValue()', '2000-02');
155 shouldBeEqualToString('highlightedDayCells()', '2000-02-01,2000-02-02,2000-02-03,2000-02-04,2000-02-05,2000-02-06,2000-02-07,2000-02-08,2000-02-09,2000-02-10,2000-02-11,2000-02-12,2000-02-13,2000-02-14,2000-02-15,2000-02-16,2000-02-17,2000-02-18,2000-02-19,2000-02-20,2000-02-21,2000-02-22,2000-02-23,2000-02-24,2000-02-25,2000-02-26,2000-02-27,2000-02-28,2000-02-29');
156 shouldBeEqualToString('document.getElementById("month").value', '2000-02');
158 debug('Check if tabbing works.');
159 shouldBeEqualToString('focusedElement()', '.list-view calendar-table-view');
160 eventSender
.keyDown('\t', ['shiftKey']);
161 shouldBeEqualToString('focusedElement()', '.calendar-navigation-button');
162 eventSender
.keyDown('\t', ['shiftKey']);
163 shouldBeEqualToString('focusedElement()', '.calendar-navigation-button today-button');
164 eventSender
.keyDown('\t', ['shiftKey']);
165 shouldBeEqualToString('focusedElement()', '.calendar-navigation-button');
166 eventSender
.keyDown('\t', ['shiftKey']);
167 shouldBeEqualToString('focusedElement()', '.month-popup-button');
169 debug('open the month popup');
170 eventSender
.keyDown('\n');
171 shouldBeTrue('popupWindow.global.picker.monthPopupView.isVisible');
172 shouldBeEqualToString('highlightedMonthButton()', '2000-02');
175 eventSender
.keyDown('downArrow');
176 shouldBeEqualToString('highlightedMonthButton()', '2000-06');
178 debug("press right");
179 eventSender
.keyDown('rightArrow');
180 shouldBeEqualToString('highlightedMonthButton()', '2000-07');
182 debug("press right");
183 eventSender
.keyDown('rightArrow');
184 shouldBeEqualToString('highlightedMonthButton()', '2000-08');
186 debug("press right");
187 eventSender
.keyDown('rightArrow');
188 shouldBeEqualToString('highlightedMonthButton()', '2000-09');
190 debug("press right");
191 eventSender
.keyDown('rightArrow');
192 shouldBeEqualToString('highlightedMonthButton()', '2000-10');
194 debug("press right");
195 eventSender
.keyDown('rightArrow');
196 shouldBeEqualToString('highlightedMonthButton()', '2000-11');
199 eventSender
.keyDown('leftArrow');
200 shouldBeEqualToString('highlightedMonthButton()', '2000-10');
203 eventSender
.keyDown('upArrow');
204 shouldBeEqualToString('highlightedMonthButton()', '2000-06');
206 debug("press pageDown");
207 eventSender
.keyDown('pageDown');
208 shouldBeEqualToString('highlightedMonthButton()', '2001-06');
210 debug("press pageUp");
211 eventSender
.keyDown('pageUp');
212 shouldBeEqualToString('highlightedMonthButton()', '2000-06');
214 debug('select month in the month popup');
215 eventSender
.keyDown('\n');
216 shouldBeFalse('popupWindow.global.picker.monthPopupView.isVisible');
217 shouldBeEqualToString('currentMonth()', '2000-06');
218 shouldBeEqualToString('selectedValue()', '2000-02');
219 shouldBeEqualToString('selectedDayCells()', '');
220 shouldBeEqualToString('highlightedValue()', '2000-02');
221 shouldBeEqualToString('highlightedDayCells()', '');
223 debug("focus calendar table");
224 popupWindow
.global
.picker
.calendarTableView
.element
.focus();
226 // Test twice in case midnight.
228 shouldBeTrue('testToday() || testToday()');
231 eventSender
.keyDown('escape');
232 waitUntilClosing(test2AfterClosing
);
235 function test2AfterClosing() {
236 shouldBeNull('document.getElementById("mock-page-popup")');
241 function testToday() {
242 eventSender
.keyDown('t');
243 shouldBeTrueQuiet('isCalendarTableScrollingWithAnimation()');
244 var now
= new Date();
245 var expectedMonth
= new popupWindow
.Month(now
.getFullYear(), now
.getMonth()).toString();
246 return selectedValue() === expectedMonth
&& highlightedValue() === expectedMonth
&& currentMonth() === expectedMonth
;
249 function focusedElement() {
250 var element
= popupWindow
.document
.activeElement
;
253 var identifier
= "." + element
.className
;
255 identifier
+= "[value=" + element
.value
+ "]";