1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var { handleDeleteOccurrencePrompt } = ChromeUtils.import(
"resource://testing-common/calendar/CalendarUtils.jsm"
);
var { formatDate, menulistSelect, saveAndCloseItemDialog, setData } = ChromeUtils.import(
"resource://testing-common/calendar/ItemEditingHelpers.jsm"
);
var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
var { dayView, weekView, multiweekView, monthView } = CalendarTestUtils;
const ENDDATE = cal.createDateTime("20090126T000000Z"); // Last Monday in month.
const HOUR = 8;
add_task(async function testWeeklyUntilRecurrence() {
let calendar = CalendarTestUtils.createCalendar();
registerCleanupFunction(() => {
CalendarTestUtils.removeCalendar(calendar);
});
await CalendarTestUtils.setCalendarView(window, "day");
await CalendarTestUtils.goToDate(window, 2009, 1, 5); // Monday
// Create weekly recurring event.
let eventBox = dayView.getHourBoxAt(window, HOUR);
let { dialogWindow, iframeWindow } = await CalendarTestUtils.editNewEvent(window, eventBox);
await setData(dialogWindow, iframeWindow, { title: "Event", repeat: setRecurrence });
await saveAndCloseItemDialog(dialogWindow);
// Check day view.
for (let week = 0; week < 3; week++) {
// Monday
await dayView.waitForEventBoxAt(window, 1);
await CalendarTestUtils.calendarViewForward(window, 2);
// Wednesday
await dayView.waitForEventBoxAt(window, 1);
await CalendarTestUtils.calendarViewForward(window, 2);
// Friday
await dayView.waitForEventBoxAt(window, 1);
await CalendarTestUtils.calendarViewForward(window, 3);
}
// Monday, last occurrence
await dayView.waitForEventBoxAt(window, 1);
await CalendarTestUtils.calendarViewForward(window, 2);
// Wednesday
await dayView.waitForNoEventBoxAt(window, 1);
// Check week view.
await CalendarTestUtils.setCalendarView(window, "week");
await CalendarTestUtils.goToDate(window, 2009, 1, 5);
for (let week = 0; week < 3; week++) {
// Monday
await weekView.waitForEventBoxAt(window, 2, 1);
// Wednesday
await weekView.waitForEventBoxAt(window, 4, 1);
// Friday
await weekView.waitForEventBoxAt(window, 6, 1);
await CalendarTestUtils.calendarViewForward(window, 1);
}
// Monday, last occurrence
await weekView.waitForEventBoxAt(window, 2, 1);
// Wednesday
await weekView.waitForNoEventBoxAt(window, 4, 1);
// Check multiweek view.
await CalendarTestUtils.setCalendarView(window, "multiweek");
await CalendarTestUtils.goToDate(window, 2009, 1, 5);
for (let week = 1; week < 4; week++) {
// Monday
await multiweekView.waitForItemAt(window, week, 2, 1);
// Wednesday
await multiweekView.waitForItemAt(window, week, 4, 1);
// Friday
await multiweekView.waitForItemAt(window, week, 6, 1);
}
// Monday, last occurrence
await multiweekView.waitForItemAt(window, 4, 2, 1);
// Wednesday
await multiweekView.waitForNoItemAt(window, 4, 4, 1);
// Check month view.
await CalendarTestUtils.setCalendarView(window, "month");
await CalendarTestUtils.goToDate(window, 2009, 1, 5);
// starts on week 2 in month-view
for (let week = 2; week < 5; week++) {
// Monday
await monthView.waitForItemAt(window, week, 2, 1);
// Wednesday
await monthView.waitForItemAt(window, week, 4, 1);
// Friday
await monthView.waitForItemAt(window, week, 6, 1);
}
// Monday, last occurrence
await monthView.waitForItemAt(window, 5, 2, 1);
// Wednesday
await monthView.waitForNoItemAt(window, 5, 4, 1);
// Delete event.
let box = monthView.getItemAt(window, 2, 2, 1);
EventUtils.synthesizeMouseAtCenter(box, {}, window);
await handleDeleteOccurrencePrompt(window, box, true);
await monthView.waitForNoItemAt(window, 2, 2, 1);
Assert.ok(true, "Test ran to completion");
});
async function setRecurrence(recurrenceWindow) {
let recurrenceDocument = recurrenceWindow.document;
// weekly
await menulistSelect(recurrenceDocument.getElementById("period-list"), "1");
let mon = cal.l10n.getDateFmtString("day.2.Mmm");
let wed = cal.l10n.getDateFmtString("day.4.Mmm");
let fri = cal.l10n.getDateFmtString("day.6.Mmm");
let dayPicker = recurrenceDocument.getElementById("daypicker-weekday");
// Starting from Monday so it should be checked.
Assert.ok(dayPicker.querySelector(`[label="${mon}"]`).checked, "mon checked");
// Check Wednesday and Friday too.
EventUtils.synthesizeMouseAtCenter(
dayPicker.querySelector(`[label="${wed}"]`),
{},
recurrenceWindow
);
EventUtils.synthesizeMouseAtCenter(
dayPicker.querySelector(`[label="${fri}"]`),
{},
recurrenceWindow
);
// Set until date.
EventUtils.synthesizeMouseAtCenter(
recurrenceDocument.getElementById("recurrence-range-until"),
{},
recurrenceWindow
);
// Delete previous date.
let untilInput = recurrenceDocument.getElementById("repeat-until-date");
untilInput.focus();
EventUtils.synthesizeKey("a", { accelKey: true }, recurrenceWindow);
untilInput.focus();
EventUtils.synthesizeKey("VK_DELETE", {}, recurrenceWindow);
let endDateString = formatDate(ENDDATE);
EventUtils.sendString(endDateString, recurrenceWindow);
// Move focus to ensure the date is selected.
untilInput.focus();
EventUtils.synthesizeKey("VK_TAB", {}, recurrenceWindow);
let button = recurrenceDocument.querySelector("dialog").getButton("accept");
button.scrollIntoView();
// Close dialog.
EventUtils.synthesizeMouseAtCenter(button, {}, recurrenceWindow);
}
|