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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
/* 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/. */
/* import-globals-from ../../base/content/calendar-views-utils.js */
/* globals openOptionsDialog, openAddonsMgr */
const { CalendarTestUtils } = ChromeUtils.import(
"resource://testing-common/calendar/CalendarTestUtils.jsm"
);
async function openTasksTab() {
let tabmail = document.getElementById("tabmail");
let tasksMode = tabmail.tabModes.tasks;
if (tasksMode.tabs.length == 1) {
tabmail.selectedTab = tasksMode.tabs[0];
} else {
let tasksTabButton = document.getElementById("tasksButton");
EventUtils.synthesizeMouseAtCenter(tasksTabButton, { clickCount: 1 });
}
is(tasksMode.tabs.length, 1, "tasks tab is open");
is(tabmail.selectedTab, tasksMode.tabs[0], "tasks tab is selected");
await new Promise(resolve => setTimeout(resolve));
}
async function closeTasksTab() {
let tabmail = document.getElementById("tabmail");
let tasksMode = tabmail.tabModes.tasks;
if (tasksMode.tabs.length == 1) {
tabmail.closeTab(tasksMode.tabs[0]);
}
is(tasksMode.tabs.length, 0, "tasks tab is not open");
await new Promise(resolve => setTimeout(resolve));
}
/**
* Currently there's always a folder tab open, hence "select" not "open".
*/
async function selectFolderTab() {
const tabmail = document.getElementById("tabmail");
const folderMode = tabmail.tabModes.mail3PaneTab;
tabmail.selectedTab = folderMode.tabs[0];
is(folderMode.tabs.length > 0, true, "at least one folder tab is open");
is(tabmail.selectedTab, folderMode.tabs[0], "a folder tab is selected");
await new Promise(resolve => setTimeout(resolve));
}
async function openChatTab() {
let tabmail = document.getElementById("tabmail");
let chatMode = tabmail.tabModes.chat;
if (chatMode.tabs.length == 1) {
tabmail.selectedTab = chatMode.tabs[0];
} else {
window.showChatTab();
}
is(chatMode.tabs.length, 1, "chat tab is open");
is(tabmail.selectedTab, chatMode.tabs[0], "chat tab is selected");
await new Promise(resolve => setTimeout(resolve));
}
async function closeChatTab() {
let tabmail = document.getElementById("tabmail");
let chatMode = tabmail.tabModes.chat;
if (chatMode.tabs.length == 1) {
tabmail.closeTab(chatMode.tabs[0]);
}
is(chatMode.tabs.length, 0, "chat tab is not open");
await new Promise(resolve => setTimeout(resolve));
}
/**
* Opens a new calendar event or task tab.
*
* @param {string} tabMode - Mode of the new tab, either `calendarEvent` or `calendarTask`.
* @returns {string} - The id of the new tab's panel element.
*/
async function _openNewCalendarItemTab(tabMode) {
let tabmail = document.getElementById("tabmail");
let itemTabs = tabmail.tabModes[tabMode].tabs;
let previousTabCount = itemTabs.length;
Services.prefs.setBoolPref("calendar.item.editInTab", true);
let buttonId = "sidePanelNewEvent";
if (tabMode == "calendarTask") {
await openTasksTab();
buttonId = "sidePanelNewTask";
} else {
await CalendarTestUtils.openCalendarTab(window);
}
let newItemButton = document.getElementById(buttonId);
EventUtils.synthesizeMouseAtCenter(newItemButton, { clickCount: 1 });
let newTab = itemTabs[itemTabs.length - 1];
is(itemTabs.length, previousTabCount + 1, `new ${tabMode} tab is open`);
is(tabmail.selectedTab, newTab, `new ${tabMode} tab is selected`);
await BrowserTestUtils.browserLoaded(newTab.iframe);
await new Promise(resolve => setTimeout(resolve));
return newTab.panel.id;
}
let openNewCalendarEventTab = _openNewCalendarItemTab.bind(null, "calendarEvent");
let openNewCalendarTaskTab = _openNewCalendarItemTab.bind(null, "calendarTask");
/**
* Selects an existing (open) calendar event or task tab.
*
* @param {string} tabMode - The tab mode, either `calendarEvent` or `calendarTask`.
* @param {string} panelId - The id of the tab's panel element.
*/
async function _selectCalendarItemTab(tabMode, panelId) {
let tabmail = document.getElementById("tabmail");
let itemTabs = tabmail.tabModes[tabMode].tabs;
let tabToSelect = itemTabs.find(tab => tab.panel.id == panelId);
ok(tabToSelect, `${tabMode} tab is open`);
tabmail.selectedTab = tabToSelect;
is(tabmail.selectedTab, tabToSelect, `${tabMode} tab is selected`);
await new Promise(resolve => setTimeout(resolve));
}
let selectCalendarEventTab = _selectCalendarItemTab.bind(null, "calendarEvent");
let selectCalendarTaskTab = _selectCalendarItemTab.bind(null, "calendarTask");
/**
* Closes a calendar event or task tab.
*
* @param {string} tabMode - The tab mode, either `calendarEvent` or `calendarTask`.
* @param {string} panelId - The id of the panel of the tab to close.
*/
async function _closeCalendarItemTab(tabMode, panelId) {
let tabmail = document.getElementById("tabmail");
let itemTabs = tabmail.tabModes[tabMode].tabs;
let previousTabCount = itemTabs.length;
let itemTab = itemTabs.find(tab => tab.panel.id == panelId);
if (itemTab) {
// Tab does not immediately close, so wait for it.
let tabClosedPromise = new Promise(resolve => {
itemTab.tabNode.addEventListener("TabClose", resolve, { once: true });
});
tabmail.closeTab(itemTab);
await tabClosedPromise;
}
is(itemTabs.length, previousTabCount - 1, `${tabMode} tab was closed`);
await new Promise(resolve => setTimeout(resolve));
}
let closeCalendarEventTab = _closeCalendarItemTab.bind(null, "calendarEvent");
let closeCalendarTaskTab = _closeCalendarItemTab.bind(null, "calendarTask");
async function openPreferencesTab() {
const tabmail = document.getElementById("tabmail");
const prefsMode = tabmail.tabModes.preferencesTab;
if (prefsMode.tabs.length == 1) {
tabmail.selectedTab = prefsMode.tabs[0];
} else {
openOptionsDialog();
}
is(prefsMode.tabs.length, 1, "preferences tab is open");
is(tabmail.selectedTab, prefsMode.tabs[0], "preferences tab is selected");
await new Promise(resolve => setTimeout(resolve));
}
async function closeAddressBookTab() {
let tabmail = document.getElementById("tabmail");
let abMode = tabmail.tabModes.addressBookTab;
if (abMode.tabs.length == 1) {
tabmail.closeTab(abMode.tabs[0]);
}
is(abMode.tabs.length, 0, "address book tab is not open");
await new Promise(resolve => setTimeout(resolve));
}
async function closePreferencesTab() {
let tabmail = document.getElementById("tabmail");
let prefsMode = tabmail.tabModes.preferencesTab;
if (prefsMode.tabs.length == 1) {
tabmail.closeTab(prefsMode.tabs[0]);
}
is(prefsMode.tabs.length, 0, "preferences tab is not open");
await new Promise(resolve => setTimeout(resolve));
}
async function openAddonsTab() {
const tabmail = document.getElementById("tabmail");
const contentMode = tabmail.tabModes.contentTab;
if (contentMode.tabs.length == 1) {
tabmail.selectedTab = contentMode.tabs[0];
} else {
openAddonsMgr("addons://list/extension");
}
is(contentMode.tabs.length, 1, "addons tab is open");
is(tabmail.selectedTab, contentMode.tabs[0], "addons tab is selected");
await new Promise(resolve => setTimeout(resolve));
}
async function closeAddonsTab() {
let tabmail = document.getElementById("tabmail");
let contentMode = tabmail.tabModes.contentTab;
if (contentMode.tabs.length == 1) {
tabmail.closeTab(contentMode.tabs[0]);
}
is(contentMode.tabs.length, 0, "addons tab is not open");
await new Promise(resolve => setTimeout(resolve));
}
/**
* Create a calendar using the "Create New Calendar" dialog.
*
* @param {string} name - Name for the new calendar.
* @param {object} [data] - Data to enter into the dialog.
* @param {boolean} [data.showReminders] - False to disable reminders.
* @param {string} [data.email] - An email address.
* @param {object} [data.network] - Data for network calendars.
* @param {string} [data.network.location] - A URI (leave undefined for local ICS file).
* @param {boolean} [data.network.offline] - False to disable the cache.
*/
async function createCalendarUsingDialog(name, data = {}) {
/**
* Callback function to interact with the dialog.
*
* @param {nsIDOMWindow} win - The dialog window.
*/
async function useDialog(win) {
let doc = win.document;
let dialogElement = doc.querySelector("dialog");
let acceptButton = dialogElement.getButton("accept");
if (data.network) {
// Choose network calendar type.
doc.querySelector("#calendar-type [value='network']").click();
acceptButton.click();
// Enter a location.
if (data.network.location == undefined) {
let calendarFile = Services.dirsvc.get("TmpD", Ci.nsIFile);
calendarFile.append(name + ".ics");
let fileURI = Services.io.newFileURI(calendarFile);
data.network.location = fileURI.prePath + fileURI.pathQueryRef;
}
EventUtils.synthesizeMouseAtCenter(doc.querySelector("#network-location-input"), {}, win);
EventUtils.sendString(data.network.location, win);
// Choose offline support.
if (data.network.offline == undefined) {
data.network.offline = true;
}
let offlineCheckbox = doc.querySelector("#network-cache-checkbox");
if (!offlineCheckbox.checked) {
EventUtils.synthesizeMouseAtCenter(offlineCheckbox, {}, win);
}
acceptButton.click();
// Set up an observer to wait for calendar(s) to be found, before
// clicking the accept button to subscribe to the calendar(s).
let observer = new MutationObserver(mutationList => {
mutationList.forEach(async mutation => {
if (mutation.type === "childList") {
acceptButton.click();
}
});
});
observer.observe(doc.querySelector("#network-calendar-list"), { childList: true });
} else {
// Choose local calendar type.
doc.querySelector("#calendar-type [value='local']").click();
acceptButton.click();
// Set calendar name.
// Setting the value does not activate the accept button on all platforms,
// so we need to type something in case the field is empty.
let nameInput = doc.querySelector("#local-calendar-name-input");
if (nameInput.value == "") {
EventUtils.synthesizeMouseAtCenter(nameInput, {}, win);
EventUtils.sendString(name, win);
}
// Set reminder option.
if (data.showReminders == undefined) {
data.showReminders = true;
}
let localFireAlarmsCheckbox = doc.querySelector("#local-fire-alarms-checkbox");
if (localFireAlarmsCheckbox.checked != data.showReminders) {
EventUtils.synthesizeMouseAtCenter(localFireAlarmsCheckbox, {}, win);
}
// Set email account.
if (data.email == undefined) {
data.email = "none";
}
let emailIdentityMenulist = doc.querySelector("#email-identity-menulist");
EventUtils.synthesizeMouseAtCenter(emailIdentityMenulist, {}, win);
emailIdentityMenulist.querySelector("menuitem[value='none']").click();
// Create the calendar.
acceptButton.click();
}
}
let dialogWindowPromise = BrowserTestUtils.promiseAlertDialog(
null,
"chrome://calendar/content/calendar-creation.xhtml",
{ callback: useDialog }
);
// Open the "create new calendar" dialog.
CalendarTestUtils.openCalendarTab(window);
// This double-click must be inside the calendar list but below the list items.
EventUtils.synthesizeMouseAtCenter(document.querySelector("#calendar-list"), { clickCount: 2 });
return dialogWindowPromise;
}
const calendarViewsInitialState = CalendarTestUtils.saveCalendarViewsState(window);
registerCleanupFunction(async () => {
await CalendarTestUtils.restoreCalendarViewsState(window, calendarViewsInitialState);
await closeTasksTab();
await closeChatTab();
await closeAddressBookTab();
await closePreferencesTab();
await closeAddonsTab();
// Close any event or task tabs that are open.
let tabmail = document.getElementById("tabmail");
let eventTabPanelIds = tabmail.tabModes.calendarEvent.tabs.map(tab => tab.panel.id);
let taskTabPanelIds = tabmail.tabModes.calendarTask.tabs.map(tab => tab.panel.id);
for (let id of eventTabPanelIds) {
await closeCalendarEventTab(id);
}
for (let id of taskTabPanelIds) {
await closeCalendarTaskTab(id);
}
Services.prefs.setBoolPref("calendar.item.editInTab", false);
Assert.equal(tabmail.tabInfo.length, 1, "all tabs closed");
});
|