Bug 1752389 - Use CalendarTestUtils.createCalendar to create calendars in tests. r=darktrojan

Differential Revision: https://phabricator.services.mozilla.com/D137188
This commit is contained in:
Lasana Murray 2022-01-27 23:26:34 +00:00
Родитель ba930a418c
Коммит 84bc229a28
8 изменённых файлов: 29 добавлений и 55 удалений

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

@ -119,11 +119,8 @@ add_task(async () => {
await dialogPromise; await dialogPromise;
// Add some new calendars, check their properties. // Add some new calendars, check their properties.
let uri = Services.io.newURI("moz-memory-calendar://");
for (let i = 1; i <= 3; i++) { for (let i = 1; i <= 3; i++) {
calendars[i] = manager.createCalendar("memory", uri); calendars[i] = CalendarTestUtils.createCalendar(`Mochitest ${i}`, "memory");
calendars[i].name = `Mochitest ${i}`;
manager.registerCalendar(calendars[i]);
} }
Assert.equal(manager.getCalendars().length, 4); Assert.equal(manager.getCalendars().length, 4);
@ -312,7 +309,7 @@ add_task(async () => {
// Test deleting calendars. // Test deleting calendars.
// Delete a calendar by unregistering it. // Delete a calendar by unregistering it.
manager.unregisterCalendar(calendars[3]); CalendarTestUtils.removeCalendar(calendars[3]);
Assert.equal(manager.getCalendars().length, 3); Assert.equal(manager.getCalendars().length, 3);
Assert.equal(calendarList.rowCount, 3); Assert.equal(calendarList.rowCount, 3);
checkSortOrder(0, 1, 2); checkSortOrder(0, 1, 2);

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

@ -15,16 +15,12 @@ let { TelemetryTestUtils } = ChromeUtils.import("resource://testing-common/Telem
add_task(async function test_calendar_count() { add_task(async function test_calendar_count() {
Services.telemetry.clearScalars(); Services.telemetry.clearScalars();
let manager = cal.getCalendarManager(); let calendars = cal.getCalendarManager().getCalendars();
let uri = Services.io.newURI("moz-memory-calendar://");
let calendars = manager.getCalendars();
for (let i = 1; i <= 3; i++) { for (let i = 1; i <= 3; i++) {
calendars[i] = manager.createCalendar("memory", uri); calendars[i] = CalendarTestUtils.createCalendar(`Mochitest ${i}`, "memory");
calendars[i].name = `Mochitest ${i}`;
if (i === 1 || i === 3) { if (i === 1 || i === 3) {
calendars[i].readOnly = true; calendars[i].readOnly = true;
} }
manager.registerCalendar(calendars[i]);
} }
reportCalendars(); reportCalendars();
@ -43,6 +39,6 @@ add_task(async function test_calendar_count() {
// Clean up. // Clean up.
for (let i = 1; i <= 3; i++) { for (let i = 1; i <= 3; i++) {
manager.removeCalendar(calendars[i]); CalendarTestUtils.removeCalendar(calendars[i]);
} }
}); });

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

@ -4,11 +4,9 @@ var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
var { MailServices } = ChromeUtils.import("resource:///modules/MailServices.jsm"); var { MailServices } = ChromeUtils.import("resource:///modules/MailServices.jsm");
add_task(async () => { add_task(async () => {
let manager = cal.getCalendarManager(); let calendar = CalendarTestUtils.createCalendar("Mochitest", "memory");
let calendar = manager.createCalendar("memory", Services.io.newURI("moz-memory-calendar://"));
calendar.name = "Mochitest"; calendar.name = "Mochitest";
calendar.setProperty("organizerId", "mailto:mochitest@invalid"); calendar.setProperty("organizerId", "mailto:mochitest@invalid");
manager.registerCalendar(calendar);
let freeBusyService = cal.getFreeBusyService(); let freeBusyService = cal.getFreeBusyService();
freeBusyService.addProvider(freeBusyProvider); freeBusyService.addProvider(freeBusyProvider);
@ -51,7 +49,7 @@ add_task(async () => {
}; };
registerCleanupFunction(async () => { registerCleanupFunction(async () => {
manager.unregisterCalendar(calendar); CalendarTestUtils.removeCalendar(calendar);
freeBusyService.removeProvider(freeBusyProvider); freeBusyService.removeProvider(freeBusyProvider);
MailServices.ab.deleteAddressBook(book.URI); MailServices.ab.deleteAddressBook(book.URI);
}); });
@ -260,14 +258,11 @@ add_task(async () => {
}); });
add_task(async () => { add_task(async () => {
let manager = cal.getCalendarManager(); let calendar = CalendarTestUtils.createCalendar("Mochitest", "memory");
let calendar = manager.createCalendar("memory", Services.io.newURI("moz-memory-calendar://"));
calendar.name = "Mochitest";
calendar.setProperty("organizerId", "mailto:mochitest@invalid"); calendar.setProperty("organizerId", "mailto:mochitest@invalid");
manager.registerCalendar(calendar);
registerCleanupFunction(async () => { registerCleanupFunction(async () => {
manager.unregisterCalendar(calendar); CalendarTestUtils.removeCalendar(calendar);
}); });
let defaults = { let defaults = {

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

@ -10,17 +10,17 @@ var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
var { PluralForm } = ChromeUtils.import("resource://gre/modules/PluralForm.jsm"); var { PluralForm } = ChromeUtils.import("resource://gre/modules/PluralForm.jsm");
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var { CalendarTestUtils } = ChromeUtils.import(
"resource://testing-common/calendar/CalendarTestUtils.jsm"
);
const DEFVALUE = 43; const DEFVALUE = 43;
add_task(async function testDefaultAlarms() { add_task(async function testDefaultAlarms() {
let manager = cal.getCalendarManager(); let calendar = CalendarTestUtils.createCalendar("Mochitest", "memory");
let calendar = manager.createCalendar("memory", Services.io.newURI("moz-memory-calendar://"));
calendar.name = "Mochitest";
calendar.setProperty("calendar-main-default", true); calendar.setProperty("calendar-main-default", true);
manager.registerCalendar(calendar);
registerCleanupFunction(async () => { registerCleanupFunction(async () => {
manager.unregisterCalendar(calendar); CalendarTestUtils.removeCalendar(calendar);
}); });
let localeUnitString = cal.l10n.getCalString("unitDays"); let localeUnitString = cal.l10n.getCalString("unitDays");

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

@ -4,14 +4,15 @@
var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm"); var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
var { CalendarTestUtils } = ChromeUtils.import(
"resource://testing-common/calendar/CalendarTestUtils.jsm"
);
add_task(async function testCategoryColors() { add_task(async function testCategoryColors() {
let manager = cal.getCalendarManager(); let calendar = CalendarTestUtils.createCalendar("Mochitest", "memory");
let calendar = manager.createCalendar("memory", Services.io.newURI("moz-memory-calendar://"));
calendar.name = "Mochitest";
manager.registerCalendar(calendar);
registerCleanupFunction(async () => { registerCleanupFunction(async () => {
manager.unregisterCalendar(calendar); CalendarTestUtils.removeCalendar(calendar);
}); });
let { prefsWindow, prefsDocument } = await openNewPrefsTab("paneCalendar", "categorieslist"); let { prefsWindow, prefsDocument } = await openNewPrefsTab("paneCalendar", "categorieslist");

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

@ -9,13 +9,10 @@
const { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm"); const { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
const manager = cal.getCalendarManager(); const calendar = CalendarTestUtils.createCalendar("Minimonths", "memory");
const calendar = manager.createCalendar("memory", Services.io.newURI("moz-memory-calendar://"));
calendar.name = "Minimonths";
manager.registerCalendar(calendar);
registerCleanupFunction(() => { registerCleanupFunction(() => {
manager.unregisterCalendar(calendar); CalendarTestUtils.removeCalendar(calendar);
}); });
requestLongerTimeout(2); requestLongerTimeout(2);

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

@ -7,23 +7,15 @@
const { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm"); const { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
const { CalEvent } = ChromeUtils.import("resource:///modules/CalEvent.jsm"); const { CalEvent } = ChromeUtils.import("resource:///modules/CalEvent.jsm");
let manager = cal.getCalendarManager();
let composite = cal.view.getCompositeCalendar(window); let composite = cal.view.getCompositeCalendar(window);
// This is the calendar we're going to change the properties of. // This is the calendar we're going to change the properties of.
let thisCalendar = manager.createCalendar("memory", Services.io.newURI("moz-memory-calendar://")); let thisCalendar = CalendarTestUtils.createCalendar("This Calendar", "memory");
thisCalendar.name = `This Calendar`;
thisCalendar.setProperty("color", "#ffee22"); thisCalendar.setProperty("color", "#ffee22");
manager.registerCalendar(thisCalendar);
// This calendar isn't going to change, and we'll check it doesn't. // This calendar isn't going to change, and we'll check it doesn't.
let notThisCalendar = manager.createCalendar( let notThisCalendar = CalendarTestUtils.createCalendar("Not This Calendar", "memory");
"memory",
Services.io.newURI("moz-memory-calendar://")
);
notThisCalendar.name = `Not This Calendar`;
notThisCalendar.setProperty("color", "#dd3333"); notThisCalendar.setProperty("color", "#dd3333");
manager.registerCalendar(notThisCalendar);
add_task(async function setUp() { add_task(async function setUp() {
let { dedent } = CalendarTestUtils; let { dedent } = CalendarTestUtils;
@ -260,6 +252,6 @@ add_task(async function testDayView() {
}); });
registerCleanupFunction(async () => { registerCleanupFunction(async () => {
manager.unregisterCalendar(thisCalendar); CalendarTestUtils.removeCalendar(thisCalendar);
manager.unregisterCalendar(notThisCalendar); CalendarTestUtils.removeCalendar(notThisCalendar);
}); });

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

@ -42,20 +42,16 @@ class TestCalFilter extends CalFilterMixin(class {}) {
} }
} }
let manager, calendar, testWidget; let calendar, testWidget;
let testItems = {}; let testItems = {};
let addedTestItems = {}; let addedTestItems = {};
add_task(async function setUp() { add_task(async function setUp() {
await new Promise(resolve => do_calendar_startup(resolve)); await new Promise(resolve => do_calendar_startup(resolve));
manager = cal.getCalendarManager(); calendar = CalendarTestUtils.createCalendar("test", "storage");
calendar = manager.createCalendar("storage", Services.io.newURI(`moz-storage-calendar://`));
calendar.name = "test";
calendar.setProperty("calendar-main-in-composite", true); calendar.setProperty("calendar-main-in-composite", true);
Assert.ok(!calendar.getProperty("disabled")); Assert.ok(!calendar.getProperty("disabled"));
manager.registerCalendar(calendar);
testWidget = new TestCalFilter(); testWidget = new TestCalFilter();
testWidget.startDate = cal.createDateTime("20210801"); testWidget.startDate = cal.createDateTime("20210801");