Bug 1759590 - Add tests for cancelling recurring event exceptions. r=#thunderbird-reviewers,darktrojan

Differential Revision: https://phabricator.services.mozilla.com/D150415

Depends on D150294

--HG--
extra : histedit_source : 6ad4d91e7e163623f1ea4eaf4837dbca3de515a1
This commit is contained in:
Lasana Murray 2022-07-11 21:57:23 +00:00
Родитель 50f934d610
Коммит 734c818805
3 изменённых файлов: 174 добавлений и 3 удалений

Просмотреть файл

@ -20,6 +20,7 @@ skip-if = os == 'win'
[browser_imipBar.js]
[browser_imipBarCancel.js]
[browser_imipBarEmail.js]
[browser_imipBarExceptionCancel.js]
[browser_imipBarExceptionOnly.js]
[browser_imipBarExceptions.js]
[browser_imipBarRepeat.js]

Просмотреть файл

@ -0,0 +1,136 @@
/* 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/. */
/**
* Tests for processing cancellations to recurring event exceptions.
*/
"use strict";
var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
var { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
var { MailServices } = ChromeUtils.import("resource:///modules/MailServices.jsm");
var { CalendarTestUtils } = ChromeUtils.import(
"resource://testing-common/calendar/CalendarTestUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
CalEvent: "resource:///modules/CalEvent.jsm",
});
let identity;
let calendar;
let transport;
/**
* Initialize account, identity and calendar.
*/
add_setup(async function() {
let account = MailServices.accounts.createAccount();
account.incomingServer = MailServices.accounts.createIncomingServer(
"receiver",
"example.com",
"imap"
);
identity = MailServices.accounts.createIdentity();
identity.email = "receiver@example.com";
account.addIdentity(identity);
await CalendarTestUtils.setCalendarView(window, "month");
window.goToDate(cal.createDateTime("20220316T191602Z"));
calendar = CalendarTestUtils.createCalendar("Test");
transport = new EmailTransport(account, identity);
let getImipTransport = cal.itip.getImipTransport;
cal.itip.getImipTransport = () => transport;
let deleteMgr = Cc["@mozilla.org/calendar/deleted-items-manager;1"].getService(
Ci.calIDeletedItems
).wrappedJSObject;
let markDeleted = deleteMgr.markDeleted;
deleteMgr.markDeleted = () => {};
registerCleanupFunction(() => {
MailServices.accounts.removeAccount(account, true);
cal.itip.getImipTransport = getImipTransport;
deleteMgr.markDeleted = markDeleted;
CalendarTestUtils.removeCalendar(calendar);
});
});
/**
* Tests cancelling an exception works.
*/
add_task(async function testCancelException() {
for (let partStat of ["ACCEPTED", "TENTATIVE", "DECLINED"]) {
await doCancelExceptionTest({
calendar,
transport,
identity,
partStat,
recurrenceId: "20220317T110000Z",
isRecurring: true,
});
}
});
/**
* Tests cancelling an event with only an exception processed works.
*/
add_task(async function testCancelExceptionOnly() {
for (let partStat of ["ACCEPTED", "TENTATIVE", "DECLINED"]) {
let win = await openImipMessage(
new FileUtils.File(getTestFilePath("data/exception-major.eml"))
);
await clickAction(win, actionIds.single.button[partStat]);
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 5, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
calendar,
event,
transport,
identity,
});
}
});
/**
* Tests processing a cancellation for a recurring event works when only an
* exception was processed previously.
*/
add_task(async function testCancelSeriesWithExceptionOnly() {
for (let partStat of ["ACCEPTED", "TENTATIVE", "DECLINED"]) {
let win = await openImipMessage(
new FileUtils.File(getTestFilePath("data/exception-major.eml"))
);
await clickMenuAction(
win,
actionIds.single.button[partStat],
actionIds.single.noReply[partStat]
);
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 5, 1)).item;
await BrowserTestUtils.closeWindow(win);
let cancel = new FileUtils.File(getTestFilePath("data/cancel-repeat-event.eml"));
let cancelWin = await openImipMessage(cancel);
let deleteButton = cancelWin.document.getElementById("imipDeleteButton");
Assert.ok(!deleteButton.hidden, `#${deleteButton.id} button shown`);
EventUtils.synthesizeMouseAtCenter(deleteButton, {}, cancelWin);
await BrowserTestUtils.closeWindow(cancelWin);
await CalendarTestUtils.monthView.waitForNoItemAt(window, 3, 5, 1);
Assert.ok(!(await calendar.getItem(event.id)), "event was deleted");
Assert.equal(
transport.sentItems.length,
0,
"itip subsystem did not attempt to send a response"
);
Assert.equal(transport.sentMsgs.length, 0, "no call was made into the mail subsystem");
}
});

Просмотреть файл

@ -815,6 +815,7 @@ async function doCancelTest({ transport, calendar, isRecurring, event, recurrenc
if (recurrenceId) {
let srcTxt = await IOUtils.readUTF8(cancelMsgFile.path);
srcTxt = srcTxt.replaceAll(/RRULE:.+/g, `RECURRENCE-ID:${recurrenceId}`);
srcTxt = srcTxt.replaceAll(/SEQUENCE:.+/g, "SEQUENCE:3");
cancelMsgFile = FileTestUtils.getTempFile("cancel-occurrence.eml");
await IOUtils.writeUTF8(cancelMsgFile.path, srcTxt);
}
@ -823,7 +824,6 @@ async function doCancelTest({ transport, calendar, isRecurring, event, recurrenc
let deleteButton = win.document.getElementById("imipDeleteButton");
Assert.ok(!deleteButton.hidden, `#${deleteButton.id} button shown`);
EventUtils.synthesizeMouseAtCenter(deleteButton, {}, win);
await BrowserTestUtils.closeWindow(win);
if (isRecurring && recurrenceId) {
// Expects a single occurrence to be cancelled.
@ -837,7 +837,7 @@ async function doCancelTest({ transport, calendar, isRecurring, event, recurrenc
Infinity
);
return occurrences.length == 2;
});
}, "occurrence was deleted");
Assert.ok(
occurrences.every(occ => occ.recurrenceId && occ.recurrenceId != recurrenceId),
@ -852,9 +852,43 @@ async function doCancelTest({ transport, calendar, isRecurring, event, recurrenc
await CalendarTestUtils.monthView.waitForNoItemAt(window, 3, 6, 1);
}
Assert.ok(!(await calendar.getItem(eventId)), "event was deleted");
await TestUtils.waitForCondition(async () => {
let result = await calendar.getItem(eventId);
return !result;
}, "event was deleted");
}
await BrowserTestUtils.closeWindow(win);
Assert.equal(transport.sentItems.length, 0, "itip subsystem did not attempt to send a response");
Assert.equal(transport.sentMsgs.length, 0, "no call was made into the mail subsystem");
}
/**
* Tests processing of cancellations to exceptions to recurring events.
*
* @param {ImipBarActionTestConf} conf
*/
async function doCancelExceptionTest(conf) {
let { partStat, recurrenceId, calendar } = conf;
let invite = new FileUtils.File(getTestFilePath("data/repeat-event.eml"));
let win = await openImipMessage(invite);
await clickAction(win, actionIds.recurring.button[partStat]);
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item.parentItem;
await BrowserTestUtils.closeWindow(win);
let update = new FileUtils.File(getTestFilePath("data/exception-major.eml"));
let updateWin = await openImipMessage(update);
await clickAction(updateWin, actionIds.single.button[partStat]);
let exception;
await TestUtils.waitForCondition(async () => {
event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item.parentItem;
exception = event.recurrenceInfo.getExceptionFor(cal.createDateTime(recurrenceId));
return !!exception;
}, "exception applied");
await BrowserTestUtils.closeWindow(updateWin);
await doCancelTest({ ...conf, event });
await calendar.deleteItem(event);
}