Bug 1619157 - Test deletion of contacts from the composition sidebar. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 03 Mar 2020 11:57:13 +1300
changeset 37515 7d7596b594c302f882acb50ebe5d98d971ceb1a2
parent 37514 22c665f600c7085b3149a9246ef6b87aff7e2957
child 37516 1da9c365060718ffc88deb4d39b3930aeb02a1a7
push id2566
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:20:31 +0000
treeherdercomm-beta@a352facfa0a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1619157
Bug 1619157 - Test deletion of contacts from the composition sidebar. r=mkmelin Also create a head file that ensures no stray address books or contacts exist after a test completes.
mail/test/browser/composition/browser.ini
mail/test/browser/composition/browser_sidebarDelete.js
mail/test/browser/composition/head.js
--- a/mail/test/browser/composition/browser.ini
+++ b/mail/test/browser/composition/browser.ini
@@ -1,9 +1,10 @@
 [DEFAULT]
+head = head.js
 prefs =
   browser.tabs.remote.autostart=false
   mail.account.account1.server=server1
   mail.account.account2.identities=id1,id2
   mail.account.account2.server=server2
   mail.accountmanager.accounts=account1,account2
   mail.accountmanager.defaultaccount=account2
   mail.accountmanager.localfoldersserver=server1
@@ -69,11 +70,14 @@ reason = See bug 1413851.
 [browser_replyAddresses.js]
 skip-if = debug # Bug 1601591
 [browser_replyFormatFlowed.js]
 [browser_replyMultipartCharset.js]
 skip-if = debug # Bug 1606542
 [browser_replySignature.js]
 [browser_saveChangesOnQuit.js]
 [browser_sendButton.js]
+tags = addrbook
 [browser_sendFormat.js]
+[browser_sidebarDelete.js]
+tags = addrbook
 [browser_signatureInit.js]
 [browser_signatureUpdating.js]
new file mode 100644
--- /dev/null
+++ b/mail/test/browser/composition/browser_sidebarDelete.js
@@ -0,0 +1,77 @@
+/* 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 contacts can be deleted from the compose window sidebar.
+ */
+
+"use strict";
+
+var { create_contact, load_contacts_into_address_book } = ChromeUtils.import(
+  "resource://testing-common/mozmill/AddressBookHelpers.jsm"
+);
+var { click_tree_row } = ChromeUtils.import(
+  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
+);
+var { gMockPromptService } = ChromeUtils.import(
+  "resource://testing-common/mozmill/PromptHelpers.jsm"
+);
+var { close_compose_window, open_compose_new_mail } = ChromeUtils.import(
+  "resource://testing-common/mozmill/ComposeHelpers.jsm"
+);
+var { wait_for_frame_load } = ChromeUtils.import(
+  "resource://testing-common/mozmill/WindowHelpers.jsm"
+);
+
+/**
+ * Bug 1619157
+ * Test that a contact can be deleted from the Contacts sidebar.
+ */
+add_task(function test_sidebar_contact_delete() {
+  gMockPromptService.register();
+  gMockPromptService.returnValue = Ci.nsIPromptService.BUTTON_TITLE_OK;
+
+  // Create some contact address book card in the Personal addressbook.
+  let defaultAB = MailServices.ab.getDirectory("jsaddrbook://abook.sqlite");
+
+  let contact = create_contact("test@example.com", "Sammy Jenkis", true);
+  load_contacts_into_address_book(defaultAB, [contact]);
+
+  let cwc = open_compose_new_mail(); // compose controller
+
+  // Open Contacts sidebar.
+  cwc.window.toggleAddressPicker();
+
+  let sidebar = cwc.e("sidebar");
+  let sidebarController = wait_for_frame_load(
+    sidebar,
+    "chrome://messenger/content/addressbook/abContactsPanel.xhtml?focus"
+  );
+
+  let abTree = sidebar.contentDocument.getElementById("abResultsTree");
+
+  // The results are loaded async so wait for the population of the tree.
+  sidebarController.waitFor(
+    () => abTree.view.rowCount > 0,
+    "Addressbook cards didn't load"
+  );
+  click_tree_row(abTree, 0, cwc);
+
+  cwc.keypress(sidebarController.eid("abResultsTree"), "VK_DELETE", {});
+  Assert.notEqual(
+    null,
+    gMockPromptService.promptState,
+    "Expected a confirmEx prompt"
+  );
+
+  sidebarController.waitFor(
+    () => abTree.view.rowCount == 0,
+    "Card didn't delete"
+  );
+
+  cwc.window.toggleAddressPicker();
+  close_compose_window(cwc);
+
+  gMockPromptService.unregister();
+});
new file mode 100644
--- /dev/null
+++ b/mail/test/browser/composition/head.js
@@ -0,0 +1,39 @@
+/* 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/. */
+
+// These already exist in `window`, but hey, let's import them again to keep
+// the linter happy.
+var { fixIterator, toXPCOMArray } = ChromeUtils.import(
+  "resource:///modules/iteratorUtils.jsm"
+);
+var { MailServices } = ChromeUtils.import(
+  "resource:///modules/MailServices.jsm"
+);
+var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+registerCleanupFunction(() => {
+  for (let book of MailServices.ab.directories) {
+    if (
+      ["ldap_2.servers.history", "ldap_2.servers.pab"].includes(book.dirPrefId)
+    ) {
+      let cards = [...book.childCards];
+      if (cards.length > 0) {
+        info(`Cleaning up ${cards.length} card(s) from ${book.dirName}`);
+        for (let card of cards) {
+          if (card.isMailList) {
+            MailServices.ab.deleteAddressBook(card.mailListURI);
+          }
+        }
+        cards = cards.filter(c => !c.isMailList);
+        if (cards.length > 0) {
+          book.deleteCards(toXPCOMArray(cards, Ci.nsIMutableArray));
+        }
+      }
+      is([...book.childCards].length, 0);
+    } else {
+      Assert.report(true, undefined, undefined, "Unexpected address book!");
+      MailServices.ab.deleteAddressBook(book.URI);
+    }
+  }
+});