Bug 1617535 - Attempt to fix timing issues in address book tests. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 25 Feb 2020 10:43:48 +0200
changeset 28842 56ae836a9049cc48094e3270560f98b0cc819225
parent 28841 50299b137825efbbab45527059b6570df842cd4d
child 28843 f34fd430a920b192011a843926cc975366c9df9d
push id17068
push usermkmelin@iki.fi
push dateTue, 25 Feb 2020 08:58:52 +0000
treeherdercomm-central@3e7f62e8f741 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1617535
Bug 1617535 - Attempt to fix timing issues in address book tests. r=mkmelin
mail/components/addrbook/test/browser/browser_ldap_search.js
mail/components/addrbook/test/browser/browser_mailing_lists.js
mail/components/addrbook/test/browser/head.js
--- a/mail/components/addrbook/test/browser/browser_ldap_search.js
+++ b/mail/components/addrbook/test/browser/browser_ldap_search.js
@@ -22,19 +22,21 @@ add_task(async () => {
     `ldap://localhost:${LDAPServer.port}/`,
     0
   );
   let book = MailServices.ab.getDirectoryFromId(bookPref);
 
   let abWindow = await openAddressBookWindow();
   let abDocument = abWindow.document;
 
-  registerCleanupFunction(() => {
+  registerCleanupFunction(async () => {
     abWindow.close();
+    let deletePromise = promiseDirectoryRemoved();
     MailServices.ab.deleteAddressBook(book.URI);
+    await deletePromise;
     LDAPServer.close();
   });
 
   let dirTree = abDocument.getElementById("dirTree");
   is(dirTree.view.getCellText(2, dirTree.columns[0]), "Mochitest");
   mailTestUtils.treeClick(EventUtils, abWindow, dirTree, 2, 0, {});
 
   let resultsTree = abDocument.getElementById("abResultsTree");
--- a/mail/components/addrbook/test/browser/browser_mailing_lists.js
+++ b/mail/components/addrbook/test/browser/browser_mailing_lists.js
@@ -25,20 +25,27 @@ const inputs = {
 const getDisplayedAddress = address => `${address} <${address}>`;
 
 let global = {};
 
 /**
  * Set up: create a new address book to hold the mailing list.
  */
 add_task(async () => {
+  let bookPrefName = MailServices.ab.newAddressBook(inputs.abName, null, 101);
+  let addressBook = MailServices.ab.getDirectoryFromId(bookPrefName);
+
   let abWindow = await openAddressBookWindow();
-  let addressBook = await createNewAddressBook(abWindow, inputs.abName);
 
   let dirTree = abWindow.document.getElementById("dirTree");
+  is(
+    dirTree.view.getCellText(2, dirTree.columns[0]),
+    inputs.abName,
+    `address book ("${inputs.abName}") is displayed in the address book list`
+  );
 
   /**
    * Click a row in the address book list (tree).
    *
    * @param {number} row - The tree row to click.
    * @param {number} clickCount - Number of clicks to synthesize.
    */
   let dirTreeClick = (row, clickCount) => {
@@ -113,22 +120,16 @@ add_task(async () => {
       // both of them there.
       EventUtils.sendKey("TAB", mlWindow);
       EventUtils.sendString(inputs.addresses.slice(0, 2).join(", "), mlWindow);
 
       mlDocElement.getButton("accept").click();
     }
   );
 
-  is(
-    global.dirTree.view.getCellText(2, global.dirTree.columns[0]),
-    inputs.abName,
-    `address book ("${inputs.abName}") is displayed in the address book list`
-  );
-
   // Select the address book.
   global.dirTreeClick(2, 1);
 
   // Open the new mailing list dialog, the callback above interacts with it.
   EventUtils.synthesizeMouseAtCenter(
     global.abWindow.document.getElementById("button-newlist"),
     { clickCount: 1 },
     global.abWindow
@@ -456,27 +457,28 @@ add_task(async () => {
 /**
  * Tear down: delete the address book and close the address book window.
  */
 add_task(async () => {
   let mailingListWindowPromise = BrowserTestUtils.promiseAlertDialog(
     "accept",
     "chrome://global/content/commonDialog.xhtml"
   );
+  let deletePromise = promiseDirectoryRemoved();
 
   is(
     global.dirTree.view.getCellText(2, global.dirTree.columns[0]),
     inputs.abName,
     `address book ("${inputs.abName}") is displayed in the address book list`
   );
 
   global.dirTreeClick(2, 1);
   EventUtils.sendKey("DELETE", global.abWindow);
 
-  await mailingListWindowPromise;
+  await Promise.all([mailingListWindowPromise, deletePromise]);
 
   let addressBook = [...MailServices.ab.directories].find(
     directory => directory.dirName == inputs.abName
   );
 
   ok(!addressBook, "address book was deleted");
 
   global.abWindow.close();
--- a/mail/components/addrbook/test/browser/head.js
+++ b/mail/components/addrbook/test/browser/head.js
@@ -51,8 +51,23 @@ async function createNewAddressBook(abWi
   let addressBook = [...MailServices.ab.directories].find(
     directory => directory.dirName == abName
   );
 
   ok(addressBook, "a new address book was created");
 
   return addressBook;
 }
+
+function promiseDirectoryRemoved() {
+  return new Promise(resolve => {
+    let observer = {
+      onItemRemoved() {
+        MailServices.ab.removeAddressBookListener(this);
+        resolve();
+      },
+    };
+    MailServices.ab.addAddressBookListener(
+      observer,
+      Ci.nsIAbListener.directoryRemoved
+    );
+  });
+}