summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/composition/head.js
blob: 7b37c05ca03b64b371ed648be30672ab66a728ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* 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/. */

var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);
var utils = ChromeUtils.import("resource://testing-common/mozmill/utils.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(cards);
        }
      }
      is(book.childCards.length, 0);
    } else {
      Assert.report(true, undefined, undefined, "Unexpected address book!");
      MailServices.ab.deleteAddressBook(book.URI);
    }
  }

  Services.focus.focusedWindow = window;
  let mailButton = document.getElementById("mailButton");
  mailButton.focus();
  mailButton.blur();
});

/**
 * Get the body part of an MIME message.
 *
 * @param {string} content - The message content.
 * @returns {string}
 */
function getMessageBody(content) {
  let separatorIndex = content.indexOf("\r\n\r\n");
  Assert.equal(content.slice(-2), "\r\n", "Should end with a line break.");
  return content.slice(separatorIndex + 4, -2);
}

async function chooseIdentity(win, identityKey) {
  let popup = win.document.getElementById("msgIdentityPopup");
  let shownPromise = BrowserTestUtils.waitForEvent(popup, "popupshown");
  EventUtils.synthesizeMouseAtCenter(
    win.document.getElementById("msgIdentity"),
    {},
    win
  );
  await shownPromise;
  let hiddenPromise = BrowserTestUtils.waitForEvent(popup, "popuphidden");
  popup.activateItem(popup.querySelector(`[identitykey="${identityKey}"]`));
  await hiddenPromise;
}