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
|
/* 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 for attached vcards.
*/
"use strict";
var { get_cards_in_all_address_books_for_email } = ChromeUtils.import(
"resource://testing-common/mozmill/AddressBookHelpers.jsm"
);
var { close_window, plan_for_modal_dialog, wait_for_modal_dialog } =
ChromeUtils.import("resource://testing-common/mozmill/WindowHelpers.jsm");
async function openMessageFromFile(file) {
let fileURL = Services.io
.newFileURI(file)
.mutate()
.setQuery("type=application/x-message-display")
.finalize();
let winPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
window.openDialog(
"chrome://messenger/content/messageWindow.xhtml",
"_blank",
"all,chrome,dialog=no,status,toolbar",
fileURL
);
let win = await winPromise;
await BrowserTestUtils.waitForEvent(win, "MsgLoaded");
if (win.content.document.readyState != "complete") {
await BrowserTestUtils.waitForEvent(win.content, "load", true);
}
await TestUtils.waitForCondition(() => Services.focus.activeWindow == win);
return win;
}
/**
* Bug 1374779
* Check if clicking attached vCard image opens the Address Book and adds a contact.
*/
add_task(async function test_check_vcard_icon() {
// Force full screen to avoid UI issues before the AB gets fully responsive.
window.fullScreen = true;
let newcards = get_cards_in_all_address_books_for_email(
"meister@example.com"
);
Assert.equal(newcards.length, 0, "card does not exist at the start");
let tabPromise = BrowserTestUtils.waitForEvent(window, "TabOpen");
let file = new FileUtils.File(getTestFilePath("data/test-vcard-icon.eml"));
let messageWindow = await openMessageFromFile(file);
// Click icon on the vcard block.
let vcard = messageWindow.content.document.querySelector(".moz-vcard-badge");
EventUtils.synthesizeMouseAtCenter(vcard, {}, vcard.ownerGlobal);
await tabPromise;
await TestUtils.waitForCondition(
() => Services.focus.activeWindow == window,
"the main window was focused"
);
let tabmail = document.getElementById("tabmail");
Assert.equal(
tabmail.currentTabInfo.mode.name,
"addressBookTab",
"the Address Book tab opened"
);
let abWindow = tabmail.currentTabInfo.browser.contentWindow;
let saveEditButton = await TestUtils.waitForCondition(
() => abWindow.document.getElementById("saveEditButton"),
"Address Book page properly loaded"
);
await TestUtils.waitForCondition(
() => BrowserTestUtils.is_visible(saveEditButton),
"entered edit mode"
);
saveEditButton.scrollIntoView();
EventUtils.synthesizeMouseAtCenter(saveEditButton, {}, abWindow);
// Check new card was created from the vcard.
newcards = get_cards_in_all_address_books_for_email("meister@example.com");
Assert.equal(newcards.length, 1, "exactly one card created");
Assert.equal(newcards[0].displayName, "Meister", "display name saved");
Assert.ok(
newcards[0].photoURL.startsWith(
"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/"
),
"PHOTO correctly saved"
);
tabmail.closeTab(tabmail.currentTabInfo);
// Reset the window size.
window.fullScreen = false;
await BrowserTestUtils.closeWindow(messageWindow);
});
|