summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/addrbook/test/browser/browser_open_actions.js
blob: cb6f681ec808a82cd026ea518f0b5cbfc16f9c79 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* 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/. */

let tabmail = document.getElementById("tabmail");
let writableBook, writableCard, readOnlyBook, readOnlyCard;

add_setup(function () {
  writableBook = createAddressBook("writable book");
  writableCard = writableBook.addCard(createContact("writable", "card"));

  readOnlyBook = createAddressBook("read-only book");
  readOnlyCard = readOnlyBook.addCard(createContact("read-only", "card"));
  readOnlyBook.setBoolValue("readOnly", true);

  registerCleanupFunction(async function () {
    await promiseDirectoryRemoved(writableBook.URI);
    await promiseDirectoryRemoved(readOnlyBook.URI);
  });
});

async function inEditingMode() {
  let abWindow = getAddressBookWindow();
  await TestUtils.waitForCondition(
    () => abWindow.detailsPane.isEditing,
    "entering editing mode"
  );
}

async function notInEditingMode() {
  let abWindow = getAddressBookWindow();
  await TestUtils.waitForCondition(
    () => !abWindow.detailsPane.isEditing,
    "leaving editing mode"
  );
}

/**
 * Tests than a `toAddressBook` call with no argument opens the Address Book.
 * Then call it again with the tab open and check that it doesn't reload.
 */
add_task(async function testNoAction() {
  let abWindow1 = await window.toAddressBook();
  Assert.equal(tabmail.tabInfo.length, 2);
  Assert.equal(tabmail.currentTabInfo.mode.name, "addressBookTab");
  await notInEditingMode();

  let abWindow2 = await window.toAddressBook();
  Assert.equal(tabmail.tabInfo.length, 2);
  Assert.equal(tabmail.currentTabInfo.mode.name, "addressBookTab");
  Assert.equal(
    abWindow2.browsingContext.currentWindowGlobal.innerWindowId,
    abWindow1.browsingContext.currentWindowGlobal.innerWindowId,
    "address book page did not reload"
  );
  await notInEditingMode();

  tabmail.selectTabByIndex(undefined, 1);
  let abWindow3 = await window.toAddressBook();
  Assert.equal(tabmail.tabInfo.length, 2);
  Assert.equal(tabmail.currentTabInfo.mode.name, "addressBookTab");
  Assert.equal(
    abWindow3.browsingContext.currentWindowGlobal.innerWindowId,
    abWindow1.browsingContext.currentWindowGlobal.innerWindowId,
    "address book page did not reload"
  );
  await notInEditingMode();

  await closeAddressBookWindow();
  Assert.equal(tabmail.tabInfo.length, 1);
});

/**
 * Tests than a call to toAddressBook with only a create action opens the
 * Address Book. A new blank card should open in edit mode.
 */
add_task(async function testCreateBlank() {
  await window.toAddressBook({ action: "create" });
  await inEditingMode();
  // TODO check blank
  await closeAddressBookWindow();
});

/**
 * Tests than a call to toAddressBook with a create action and an email
 * address opens the Address Book. A new card with the email address should
 * open in edit mode.
 */
add_task(async function testCreateWithAddress() {
  await window.toAddressBook({ action: "create", address: "test@invalid" });
  await inEditingMode();
  // TODO check address matches
  await closeAddressBookWindow();
});

/**
 * Tests than a call to toAddressBook with a create action and a vCard opens
 * the Address Book. A new card should open in edit mode.
 */
add_task(async function testCreateWithVCard() {
  await window.toAddressBook({
    action: "create",
    vCard:
      "BEGIN:VCARD\r\nFN:a test person\r\nN:person;test;;a;\r\nEND:VCARD\r\n",
  });
  await inEditingMode();
  // TODO check card matches
  await closeAddressBookWindow();
});

/**
 * Tests than a call to toAddressBook with a display action opens the Address
 * Book. The card should be displayed.
 */
add_task(async function testDisplayCard() {
  await window.toAddressBook({ action: "display", card: writableCard });
  checkDirectoryDisplayed(writableBook);
  await notInEditingMode();

  // let abWindow = getAddressBookWindow();
  // let h1 = abWindow.document.querySelector("h1");
  // Assert.equal(h1.textContent, "writable contact");

  await closeAddressBookWindow();
});

/**
 * Tests than a call to toAddressBook with an edit action and a writable card
 * opens the Address Book. The card should open in edit mode.
 */
add_task(async function testEditCardWritable() {
  await window.toAddressBook({ action: "edit", card: writableCard });
  checkDirectoryDisplayed(writableBook);
  await inEditingMode();

  // let abWindow = getAddressBookWindow();
  // let h1 = abWindow.document.querySelector("h1");
  // Assert.equal(h1.textContent, "writable contact");

  await closeAddressBookWindow();
});

/**
 * Tests than a call to toAddressBook with an edit action and a read-only card
 * opens the Address Book. The card should open in display mode.
 */
add_task(async function testEditCardReadOnly() {
  await window.toAddressBook({ action: "edit", card: readOnlyCard });
  checkDirectoryDisplayed(readOnlyBook);
  await notInEditingMode();

  // let abWindow = getAddressBookWindow();
  // let h1 = abWindow.document.querySelector("h1");
  // Assert.equal(h1.textContent, "read-only contact");

  await closeAddressBookWindow();
});