Bug 1692279 - Refactor the promiseDirectoryRemoved function for tests. r=mkmelin

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Geoff Lankow 2021-02-25 04:25:15 +00:00
Родитель 30dd928780
Коммит b322b81e5f
14 изменённых файлов: 26 добавлений и 69 удалений

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

@ -287,7 +287,5 @@ add_task(async function testEveryThingOK() {
await closeAddressBookWindow();
await CardDAVServer.close();
let removePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(directory.URI);
await removePromise;
await promiseDirectoryRemoved(directory.URI);
});

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

@ -31,9 +31,7 @@ add_task(async () => {
let directory = MailServices.ab.getDirectoryFromId(dirPrefId);
let davDirectory = CardDAVDirectory.forFile(directory.fileName);
registerCleanupFunction(async () => {
let removePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(directory.URI);
await removePromise;
await promiseDirectoryRemoved(directory.URI);
Assert.equal(davDirectory._syncTimer, null, "sync timer cleaned up");
});

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

@ -42,9 +42,7 @@ add_task(async () => {
let directory = MailServices.ab.getDirectoryFromId(dirPrefId);
let davDirectory = CardDAVDirectory.forFile(directory.fileName);
registerCleanupFunction(async () => {
let removePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(directory.URI);
await removePromise;
await promiseDirectoryRemoved(directory.URI);
Assert.equal(davDirectory._syncTimer, null, "sync timer cleaned up");
});

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

@ -260,9 +260,7 @@ add_task(async function test_insertion_order() {
);
await closeAddressBookWindow();
let deletePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(bookA.URI);
await deletePromise;
await promiseDirectoryRemoved(bookA.URI);
});
/**
@ -425,7 +423,5 @@ add_task(async function test_name_column() {
await closeAddressBookWindow();
let deletePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(book.URI);
await deletePromise;
await promiseDirectoryRemoved(book.URI);
});

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

@ -215,9 +215,7 @@ add_task(async () => {
// Delete the displayed book, and check that we return to "All Address Books".
let directoryRemoved = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(newBook2.URI);
await directoryRemoved;
await promiseDirectoryRemoved(newBook2.URI);
checkDirectoryDisplayed(null);
checkBooksOrder(
{ level: 1, directory: personalBook },
@ -230,9 +228,7 @@ add_task(async () => {
// Remove the first book.
directoryRemoved = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(newBook1.URI);
await directoryRemoved;
await promiseDirectoryRemoved(newBook1.URI);
checkDirectoryDisplayed(null);
checkBooksOrder(
{ level: 1, directory: personalBook },

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

@ -57,9 +57,7 @@ add_task(async () => {
registerCleanupFunction(async () => {
abWindow.close();
personalBook.deleteCards(cardsToRemove);
let deletePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(book.URI);
await deletePromise;
await promiseDirectoryRemoved(book.URI);
LDAPServer.close();
});

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

@ -506,7 +506,7 @@ add_task(async () => {
"accept",
"chrome://global/content/commonDialog.xhtml"
);
let deletePromise = promiseDirectoryRemoved();
let deletePromise = TestUtils.topicObserved("addrbook-directory-deleted");
Assert.equal(
global.dirTree.view.getCellText(2, global.dirTree.columns[0]),

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

@ -222,14 +222,8 @@ function checkNamesListed(...expectedNames) {
}
}
function promiseDirectoryRemoved() {
return new Promise(resolve => {
let observer = {
observe() {
Services.obs.removeObserver(observer, "addrbook-directory-deleted");
resolve();
},
};
Services.obs.addObserver(observer, "addrbook-directory-deleted");
});
function promiseDirectoryRemoved(uri) {
let removePromise = TestUtils.topicObserved("addrbook-directory-deleted");
MailServices.ab.deleteAddressBook(uri);
return removePromise;
}

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

@ -2,6 +2,9 @@ var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var { MailServices } = ChromeUtils.import(
"resource:///modules/MailServices.jsm"
);
var { TestUtils } = ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"
);
var { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
@ -17,16 +20,10 @@ registerCleanupFunction(function() {
load("../../../resources/mailShutdown.js");
});
function promiseDirectoryRemoved() {
return new Promise(resolve => {
let observer = {
observe() {
Services.obs.removeObserver(observer, "addrbook-directory-deleted");
resolve();
},
};
Services.obs.addObserver(observer, "addrbook-directory-deleted");
});
function promiseDirectoryRemoved(uri) {
let removePromise = TestUtils.topicObserved("addrbook-directory-deleted");
MailServices.ab.deleteAddressBook(uri);
return removePromise;
}
function acObserver() {}

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

@ -37,8 +37,7 @@ add_task(async function clearPref() {
]);
Services.prefs.setStringPref("mail.collect_addressbook", book.URI);
MailServices.ab.deleteAddressBook(book.URI);
await promiseDirectoryRemoved();
await promiseDirectoryRemoved(book.URI);
Assert.deepEqual(getExistingDirectories(), [
"ldap_2.servers.pab",

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

@ -389,9 +389,7 @@ add_task(async function createContactWithUID() {
});
add_task(async function deleteAddressBook() {
let deletePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(book.URI);
await deletePromise;
await promiseDirectoryRemoved(book.URI);
observer.checkEvents(["addrbook-directory-deleted", book, null]);
ok(!Services.prefs.prefHasUserValue("ldap_2.servers.newbook.dirType"));

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

@ -33,13 +33,6 @@ function addDirectory(dirName) {
return MailServices.ab.getDirectoryFromId(dirPrefId);
}
async function removeDirectory(directory) {
// Remove the directory
let deletePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(directory.URI);
await deletePromise;
}
async function run_test() {
var expectedABs = [kPABData.URI, kCABData.URI];
@ -71,7 +64,7 @@ async function run_test() {
expectedABs.splice(pos, 1);
await removeDirectory(newDirectory1);
await promiseDirectoryRemoved(newDirectory1.URI);
newDirectory1 = null;
// Test - Check new directory list
@ -80,7 +73,7 @@ async function run_test() {
// Test - Repeat the removal
await removeDirectory(newDirectory2);
await promiseDirectoryRemoved(newDirectory2.URI);
newDirectory2 = null;
expectedABs.pop();

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

@ -15,12 +15,6 @@ function renameDirectory(directory, newName) {
directory.dirName = newName;
}
async function removeDirectory(directory) {
let deletePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(directory.URI);
await deletePromise;
}
/**
* Create 4 addressbooks (directories). Rename the second one and delete
* the third one. Check if their names are still correct. (bug 745664)
@ -38,7 +32,7 @@ async function run_test() {
for (let dir in dirNames) {
Assert.equal(dirNames[dir], directories[dir].dirName);
}
await removeDirectory(directories[2]);
await promiseDirectoryRemoved(directories[2].URI);
dirNames.splice(2, 1);
directories.splice(2, 1);

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

@ -37,9 +37,7 @@ add_task(async function createAddressBook() {
Assert.notEqual(newFromUID, pabFromUID);
Assert.notEqual(newFromUID, historyFromUID);
let deletePromise = promiseDirectoryRemoved();
MailServices.ab.deleteAddressBook(newFromId.URI);
await deletePromise;
await promiseDirectoryRemoved(newFromId.URI);
Assert.ok(!MailServices.ab.getDirectoryFromUID(newFromId.UID));
});