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
|
/* 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/. */
"use strict";
var utils = ChromeUtils.import("resource://testing-common/mozmill/utils.jsm");
var { assert_tab_mode_name, mc } = ChromeUtils.import(
"resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);
/**
* Create a new chat tab, making that tab the current tab. We block until the
* message finishes loading. (Inspired by open_selected_message_in_new_tab)
*/
async function open_chat_tab() {
// Get the current tab count so we can make sure the tab actually opened.
let preCount =
mc.window.document.getElementById("tabmail").tabContainer.allTabs.length;
mc.window.document.getElementById("tabmail").openTab("chat", {});
await wait_for_chat_tab_to_open(mc);
if (
mc.window.document.getElementById("tabmail").tabContainer.allTabs.length !=
preCount + 1
) {
throw new Error("The tab never actually got opened!");
}
let newTab = mc.window.document.getElementById("tabmail").tabInfo[preCount];
return newTab;
}
async function wait_for_chat_tab_to_open(aController) {
if (aController == null) {
aController = mc;
}
utils.waitFor(
function () {
let chatTabFound = false;
for (let tab of mc.window.document.getElementById("tabmail").tabInfo) {
if (tab.mode.type == "chat") {
chatTabFound = true;
break;
}
}
return chatTabFound;
},
"Timeout waiting for chat tab to open",
1000,
50
);
// The above may return immediately, meaning the event queue might not get a
// chance. Give it a chance now.
await new Promise(resolve => setTimeout(resolve));
}
/**
* This tests that the chat tab is restored properly after tabs are
* serialized. As for folder tabs, we can't test a restart (can we ?), so we
* just test the persist/restore cycle.
*/
add_task(async function test_chat_tab_restore() {
// Close everything but the first tab.
let closeTabs = function () {
while (mc.window.document.getElementById("tabmail").tabInfo.length > 1) {
mc.window.document.getElementById("tabmail").closeTab(1);
}
};
await open_chat_tab();
let state = mc.window.document.getElementById("tabmail").persistTabs();
closeTabs();
mc.window.document.getElementById("tabmail").restoreTabs(state);
if (
mc.window.document.getElementById("tabmail").tabContainer.allTabs.length < 2
) {
throw new Error("The tab is not restored!");
}
let tabTypes = ["mail3PaneTab", "chat"];
for (let i in tabTypes) {
assert_tab_mode_name(
mc.window.document.getElementById("tabmail").tabInfo[i],
tabTypes[i]
);
}
closeTabs();
Assert.report(
false,
undefined,
undefined,
"Test ran to completion successfully"
);
});
|