Bug 1759590 - Add tests for repeat and non-repeat cancellations. r=#thunderbird-reviewers,darktrojan

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

--HG--
extra : histedit_source : d8fd40e5ad22be32e0c8cd4672f1dec025e646e8
This commit is contained in:
Lasana Murray 2022-07-11 21:57:19 +00:00
Родитель e9355a36db
Коммит 50f934d610
6 изменённых файлов: 513 добавлений и 0 удалений

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

@ -18,10 +18,12 @@ support-files = data/**
skip-if = os == 'win'
[browser_identityPrompt.js]
[browser_imipBar.js]
[browser_imipBarCancel.js]
[browser_imipBarEmail.js]
[browser_imipBarExceptionOnly.js]
[browser_imipBarExceptions.js]
[browser_imipBarRepeat.js]
[browser_imipBarRepeatCancel.js]
[browser_imipBarRepeatUpdates.js]
[browser_imipBarUpdates.js]
[browser_unsupportedFreq.js]

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

@ -0,0 +1,130 @@
/* 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 via the imip-bar.
*/
"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"
);
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 accepting a cancellation to an already accepted event.
*/
add_task(async function testCancelAccepted() {
transport.reset();
let invite = new FileUtils.File(getTestFilePath("data/single-event.eml"));
let win = await openImipMessage(invite);
await clickAction(win, "imipAcceptButton");
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
transport,
calendar,
event,
});
});
/**
* Tests accepting a cancellation to tentatively accepted event.
*/
add_task(async function testCancelTentative() {
transport.reset();
let invite = new FileUtils.File(getTestFilePath("data/single-event.eml"));
let win = await openImipMessage(invite);
await clickAction(win, "imipTentativeButton");
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
transport,
calendar,
event,
});
});
/**
* Tests accepting a cancellation to an already declined event.
*/
add_task(async function testCancelDeclined() {
transport.reset();
let invite = new FileUtils.File(getTestFilePath("data/single-event.eml"));
let win = await openImipMessage(invite);
await clickAction(win, "imipDeclineButton");
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
transport,
calendar,
event,
});
});
/**
* Tests the handling of a cancellation when the event was not processed
* previously.
*/
add_task(async function testUnprocessedCancel() {
transport.reset();
let invite = new FileUtils.File(getTestFilePath("data/cancel-single-event.eml"));
let win = await openImipMessage(invite);
// There should be no buttons present because there is no action to take.
// Note: the imip-bar message "This message contains an event that has already been processed" is
// misleading.
for (let button of [...win.document.querySelectorAll("#imip-view-toolbar > toolbarbutton")]) {
Assert.ok(button.hidden, `${button.id} is hidden`);
}
await BrowserTestUtils.closeWindow(win);
});

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

@ -0,0 +1,187 @@
/* 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 invitations via the imip-bar.
*/
"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"
);
let identity;
let calendar;
let transport;
/**
* Initialize account, identity and calendar.
*/
add_setup(async function() {
requestLongerTimeout(5);
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 accepting a cancellation to an already accepted recurring event.
*/
add_task(async function testCancelAcceptedRecurring() {
let win = await openImipMessage(new FileUtils.File(getTestFilePath("data/repeat-event.eml")));
await clickAction(win, "imipAcceptRecurrencesButton");
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
calendar,
event,
transport,
isRecurring: true,
});
});
/**
* Tests accepting a cancellation to an already tentatively accepted event.
*/
add_task(async function testCancelTentativeRecurring() {
let win = await openImipMessage(new FileUtils.File(getTestFilePath("data/repeat-event.eml")));
await clickAction(win, "imipTentativeRecurrencesButton");
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
calendar,
event,
transport,
identity,
isRecurring: true,
});
});
/**
* Tests accepting a cancellation to an already declined recurring event.
*/
add_task(async function testCancelDeclinedRecurring() {
let win = await openImipMessage(new FileUtils.File(getTestFilePath("data/repeat-event.eml")));
await clickAction(win, "imipDeclineRecurrencesButton");
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
calendar,
event,
transport,
identity,
isRecurring: true,
});
});
/**
* Tests accepting a cancellation to a single occurrence of an already accepted
* recurring event.
*/
add_task(async function testCancelAcceptedOccurrence() {
let win = await openImipMessage(new FileUtils.File(getTestFilePath("data/repeat-event.eml")));
await clickAction(win, "imipAcceptRecurrencesButton");
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
calendar,
event,
transport,
isRecurring: true,
recurrenceId: "20220317T110000Z",
});
await calendar.deleteItem(event.parentItem);
});
/**
* Tests accepting a cancellation to a single occurrence of an already tentatively
* accepted event.
*/
add_task(async function testCancelTentativeOccurrence() {
let win = await openImipMessage(new FileUtils.File(getTestFilePath("data/repeat-event.eml")));
await clickAction(win, "imipTentativeRecurrencesButton");
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
calendar,
event,
transport,
identity,
isRecurring: true,
recurrenceId: "20220317T110000Z",
});
await calendar.deleteItem(event.parentItem);
});
/**
* Tests accepting a cancellation to a single occurrence of an already declined
* recurring event.
*/
add_task(async function testCancelDeclinedOccurrence() {
let win = await openImipMessage(new FileUtils.File(getTestFilePath("data/repeat-event.eml")));
await clickAction(win, "imipDeclineRecurrencesButton");
let event = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
await BrowserTestUtils.closeWindow(win);
await doCancelTest({
calendar,
event,
transport,
identity,
isRecurring: true,
recurrenceId: "20220317T110000Z",
});
await calendar.deleteItem(event.parentItem);
});
/**
* Tests the handling of a cancellation when the event was not processed
* previously.
*/
add_task(async function testUnprocessedCancel() {
transport.reset();
let invite = new FileUtils.File(getTestFilePath("data/cancel-repeat-event.eml"));
let win = await openImipMessage(invite);
for (let button of [...win.document.querySelectorAll("#imip-view-toolbar > toolbarbutton")]) {
Assert.ok(button.hidden, `${button.id} is hidden`);
}
await BrowserTestUtils.closeWindow(win);
});

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

@ -0,0 +1,49 @@
MIME-Version: 1.0
Date: Mon, 28 Mar 2022 17:49:35 +0000
Subject: Invitation: Repeat Event @ Daily from 2pm to 3pm 3 times (AST) (receiver@example.com)
From: sender@example.com
To: receiver@example.com
Content-Type: multipart/mixed; boundary="00000000000080f3db05db4aef5b"
--00000000000080f3db05db4aef5b
Content-Type: multipart/alternative; boundary="00000000000080f3da05db4aef59"
--00000000000080f3da05db4aef59
Content-Type: text/calendar; charset="UTF-8"; method=CANCEL
Content-Transfer-Encoding: 7bit
BEGIN:VCALENDAR
METHOD:CANCEL
BEGIN:VEVENT
DTSTART:20220316T110000Z
DTEND:20220316T113000Z
RRULE:FREQ=DAILY;WKST=SU;COUNT=3;INTERVAL=1
DTSTAMP:20220316T191602Z
UID:02e79b96
ORGANIZER;CN=Sender;
EMAIL=sender@example.com:mailto:sender@example.com
ATTENDEE;CN=Sender;
EMAIL=sender@example.com;CUTYPE=INDIVIDUAL;
PARTSTAT=ACCEPTED:mailto:sender@example.com
ATTENDEE;CN=Receiver;EMAIL=receiver@example.com;CUTYPE=INDIVIDUAL;
PARTSTAT=NEEDS-ACTION:mailto:receiver@example.com
ATTENDEE;CN=Other;EMAIL=other@example.com;CUTYPE=INDIVIDUAL;
PARTSTAT=NEEDS-ACTION:mailto:other@example.com
CREATED:20220328T174934Z
LAST-MODIFIED:20220328T174934Z
LOCATION:Somewhere
SEQUENCE:1
STATUS:CANCELLED
SUMMARY:Repeat Event
DESCRIPTION:An event invitation.
TRANSP:OPAQUE
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER:-P1D
DESCRIPTION:This is an event reminder
END:VALARM
END:VEVENT
END:VCALENDAR
--00000000000080f3da05db4aef59--
--00000000000080f3db05db4aef5b--

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

@ -0,0 +1,78 @@
MIME-Version: 1.0
Content-Transfer-Encoding: binary
Content-Type: multipart/mixed; boundary="_----------=_1647458162153312762582"
Date: Wed, 16 Mar 2022 15:16:02 -0400
To: receiver@example.com
Subject: Cancellation: Single Event @ Wed, Mar 16 2022 11:00 AST
From: Sender <sender@example.com>
This is a multi-part message in MIME format.
--_----------=_1647458162153312762582
MIME-Version: 1.0
Content-Transfer-Encoding: binary
Content-Type: multipart/alternative; boundary="_----------=_1647458162153312762583"
Date: Wed, 16 Mar 2022 15:16:02 -0400
This is a multi-part message in MIME format.
--_----------=_1647458162153312762583
MIME-Version: 1.0
Content-Disposition: inline
Content-Length: 227
Content-Transfer-Encoding: binary
Content-Type: text/plain; charset="utf-8"
Date: Wed, 16 Mar 2022 15:16:02 -0400
Single Event
When:
Wed, Mar 16 2022
11:00 - 12:00 AST
Where:
Somewhere
--_----------=_1647458162153312762583
MIME-Version: 1.0
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Content-Type: text/calendar; charset="utf-8"; method=CANCEL
Date: Wed, 16 Mar 2022 15:16:02 -0400
BEGIN:VCALENDAR
VERSION:2.0
METHOD:CANCEL
CALSCALE:GREGORIAN
BEGIN:VEVENT
UID:02e79b96
SEQUENCE:1
DTSTAMP:20220317T191602Z
CREATED:20220316T191532Z
DTSTART:20220316T110000Z
DTEND:20220316T113000Z
DURATION:PT1H
PRIORITY:0
SUMMARY:Single Event
DESCRIPTION:An event invitation.
LOCATION:Somewhere
STATUS:CANCELLED
TRANSP:OPAQUE
CLASS:PUBLIC
ORGANIZER;CN=3DSender;
EMAIL=3Dsender@example.com:mailto:sender@example.com
ATTENDEE;CN=3DSender;
EMAIL=3Dsender@example.com;CUTYPE=3DINDIVIDUAL;
PARTSTAT=3DACCEPTED:mailto:sender@example.com
ATTENDEE;CN=Receiver;EMAIL=3Dreceiver@example.com;CUTYPE=3DINDIVIDUAL;
PARTSTAT=3DNEEDS-ACTION:mailto:receiver@example.com
ATTENDEE;CN=Other;EMAIL=other@example.com;CUTYPE=3DINDIVIDUAL;
PARTSTAT=3DNEEDS-ACTION:mailto:other@example.com
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER:-P1D
DESCRIPTION:This is an event reminder
END:VALARM
END:VEVENT
END:VCALENDAR
--_----------=_1647458162153312762583--

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

@ -791,3 +791,70 @@ async function doExceptionOnlyTest(conf) {
}
await calendar.deleteItem(event.parentItem);
}
/**
* Tests the recognition and application of a cancellation to an existing event.
*
* @param {ImipBarActionTestConf} conf
*/
async function doCancelTest({ transport, calendar, isRecurring, event, recurrenceId }) {
transport.reset();
let eventId = event.id;
if (isRecurring) {
// wait for the other occurrences to appear.
await CalendarTestUtils.monthView.waitForItemAt(window, 3, 5, 1);
await CalendarTestUtils.monthView.waitForItemAt(window, 3, 6, 1);
}
let cancellationPath = isRecurring
? "data/cancel-repeat-event.eml"
: "data/cancel-single-event.eml";
let cancelMsgFile = new FileUtils.File(getTestFilePath(cancellationPath));
if (recurrenceId) {
let srcTxt = await IOUtils.readUTF8(cancelMsgFile.path);
srcTxt = srcTxt.replaceAll(/RRULE:.+/g, `RECURRENCE-ID:${recurrenceId}`);
cancelMsgFile = FileTestUtils.getTempFile("cancel-occurrence.eml");
await IOUtils.writeUTF8(cancelMsgFile.path, srcTxt);
}
let win = await openImipMessage(cancelMsgFile);
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.
let occurrences;
await TestUtils.waitForCondition(async () => {
let { parentItem } = (await CalendarTestUtils.monthView.waitForItemAt(window, 3, 4, 1)).item;
occurrences = parentItem.recurrenceInfo.getOccurrences(
cal.createDateTime("19700101"),
cal.createDateTime("30000101"),
Infinity
);
return occurrences.length == 2;
});
Assert.ok(
occurrences.every(occ => occ.recurrenceId && occ.recurrenceId != recurrenceId),
`occurrence "${recurrenceId}" removed`
);
Assert.ok(!!(await calendar.getItem(eventId)), "event was not deleted");
} else {
await CalendarTestUtils.monthView.waitForNoItemAt(window, 3, 4, 1);
if (isRecurring) {
await CalendarTestUtils.monthView.waitForNoItemAt(window, 3, 5, 1);
await CalendarTestUtils.monthView.waitForNoItemAt(window, 3, 6, 1);
}
Assert.ok(!(await calendar.getItem(eventId)), "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");
}