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
|
const PREF_WARN_ON_CLOSE = "browser.tabs.warnOnCloseOtherTabs";
async function openTabMenuFor(tab) {
let tabMenu = tab.ownerDocument.getElementById("tabContextMenu");
let tabMenuShown = BrowserTestUtils.waitForEvent(tabMenu, "popupshown");
EventUtils.synthesizeMouseAtCenter(
tab,
{ type: "contextmenu" },
tab.ownerGlobal
);
await tabMenuShown;
return tabMenu;
}
add_task(async function setPref() {
await SpecialPowers.pushPrefEnv({
set: [[PREF_WARN_ON_CLOSE, false]],
});
});
add_task(async function usingTabCloseButton() {
let tab1 = await addTab();
let tab2 = await addTab();
let tab3 = await addTab();
let tab4 = await addTab();
is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
await BrowserTestUtils.switchTab(gBrowser, tab1);
await triggerClickOn(tab2, { ctrlKey: true });
ok(tab1.multiselected, "Tab1 is multiselected");
ok(tab2.multiselected, "Tab2 is multiselected");
ok(!tab3.multiselected, "Tab3 is not multiselected");
ok(!tab4.multiselected, "Tab4 is not multiselected");
is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
is(gBrowser.selectedTab, tab1, "Tab1 is active");
// Closing a tab which is not multiselected
let tab4CloseBtn = tab4.closeButton;
let tab4Closing = BrowserTestUtils.waitForTabClosing(tab4);
tab4.mOverCloseButton = true;
ok(tab4.mOverCloseButton, "Mouse over tab4 close button");
tab4CloseBtn.click();
await tab4Closing;
is(gBrowser.selectedTab, tab1, "Tab1 is active");
ok(tab1.multiselected, "Tab1 is multiselected");
ok(!tab1.closing, "Tab1 is not closing");
ok(tab2.multiselected, "Tab2 is multiselected");
ok(!tab2.closing, "Tab2 is not closing");
ok(!tab3.multiselected, "Tab3 is not multiselected");
ok(!tab3.closing, "Tab3 is not closing");
ok(tab4.closing, "Tab4 is closing");
is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
// Closing a selected tab
let tab2CloseBtn = tab2.closeButton;
tab2.mOverCloseButton = true;
let tab1Closing = BrowserTestUtils.waitForTabClosing(tab1);
let tab2Closing = BrowserTestUtils.waitForTabClosing(tab2);
tab2CloseBtn.click();
await tab1Closing;
await tab2Closing;
ok(tab1.closing, "Tab1 is closing");
ok(tab2.closing, "Tab2 is closing");
ok(!tab3.closing, "Tab3 is not closing");
is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
BrowserTestUtils.removeTab(tab3);
});
add_task(async function usingTabContextMenu() {
let tab1 = await addTab();
let tab2 = await addTab();
let tab3 = await addTab();
let tab4 = await addTab();
let menuItemCloseTab = document.getElementById("context_closeTab");
is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
await BrowserTestUtils.switchTab(gBrowser, tab1);
await triggerClickOn(tab2, { ctrlKey: true });
ok(tab1.multiselected, "Tab1 is multiselected");
ok(tab2.multiselected, "Tab2 is multiselected");
ok(!tab3.multiselected, "Tab3 is not multiselected");
ok(!tab4.multiselected, "Tab4 is not multiselected");
is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
// Check the context menu with a non-multiselected tab
updateTabContextMenu(tab4);
let { args } = document.l10n.getAttributes(menuItemCloseTab);
is(args.tabCount, 1, "Close Tab item lists a single tab");
// Check the context menu with a multiselected tab. We have to actually open
// it (not just call `updateTabContextMenu`) in order for
// `TabContextMenu.contextTab` to stay non-null when we click an item.
let menu = await openTabMenuFor(tab2);
({ args } = document.l10n.getAttributes(menuItemCloseTab));
is(args.tabCount, 2, "Close Tab item lists more than one tab");
let tab1Closing = BrowserTestUtils.waitForTabClosing(tab1);
let tab2Closing = BrowserTestUtils.waitForTabClosing(tab2);
menuItemCloseTab.click();
menu.hidePopup();
await tab1Closing;
await tab2Closing;
ok(tab1.closing, "Tab1 is closing");
ok(tab2.closing, "Tab2 is closing");
ok(!tab3.closing, "Tab3 is not closing");
ok(!tab4.closing, "Tab4 is not closing");
is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
BrowserTestUtils.removeTab(tab3);
BrowserTestUtils.removeTab(tab4);
});
|