/* 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 CalDAV sync without sync tokens. This test is the same as * browser_caldavCalendar_cached.js, but exercises different code paths. */ var { CalDAVServer } = ChromeUtils.importESModule( "resource://testing-common/calendar/CalDAVServer.sys.mjs" ); CalDAVServer.open("bob", "bob"); CalDAVServer.canDoSyncCollection = false; let calendar; add_setup(async function () { const logins = await Services.logins.searchLoginsAsync({ origin: CalDAVServer.origin, httpRealm: "test", }); if (!logins.length) { // Save a username and password to the login manager. const loginInfo = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo); loginInfo.init(CalDAVServer.origin, null, "test", "bob", "bob", "", ""); await Services.logins.addLoginAsync(loginInfo); } calendarObserver._onLoadPromise = Promise.withResolvers(); calendar = createCalendar("caldav", `${CalDAVServer.origin}/calendars/bob/test/`, true); await calendarObserver._onLoadPromise.promise; info("calendar set-up complete"); registerCleanupFunction(async () => { // This test has issues cleaning up, and it breaks all the subsequent tests. await new Promise(r => setTimeout(r, 1000)); // eslint-disable-line mozilla/no-arbitrary-setTimeout await CalDAVServer.close(); CalDAVServer.canDoSyncCollection = true; await Services.logins.removeAllLoginsAsync(); removeCalendar(calendar); }); }); async function promiseIdle() { await TestUtils.waitForCondition(() => !calendar.wrappedJSObject.mPendingSync); } add_task(async function testAlarms() { calendarObserver._batchRequired = true; await runTestAlarms(calendar); // Be sure the calendar has finished deleting the event. await promiseIdle(); }); add_task(async function testSyncChanges() { await syncChangesTest.setUp(); await CalDAVServer.putItemInternal( "/calendars/bob/test/ad0850e5-8020-4599-86a4-86c90af4e2cd.ics", syncChangesTest.part1Item ); await syncChangesTest.runPart1(); await CalDAVServer.putItemInternal( "/calendars/bob/test/ad0850e5-8020-4599-86a4-86c90af4e2cd.ics", syncChangesTest.part2Item ); await syncChangesTest.runPart2(); CalDAVServer.deleteItemInternal("/calendars/bob/test/ad0850e5-8020-4599-86a4-86c90af4e2cd.ics"); await syncChangesTest.runPart3(); // Be sure the calendar has finished all requests. await promiseIdle(); });