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
|
add_task(async function test() {
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, tab2);
await triggerClickOn(tab1, { ctrlKey: true });
await triggerClickOn(tab3, { ctrlKey: true });
ok(tab1.multiselected, "Tab1 is multiselected");
ok(tab2.multiselected, "Tab2 is multiselected");
ok(tab3.multiselected, "Tab3 is multiselected");
ok(!tab4.multiselected, "Tab4 is not multiselected");
is(gBrowser.multiSelectedTabsCount, 3, "Three multiselected tabs");
let newWindow = gBrowser.replaceTabsWithWindow(tab1);
// waiting for tab2 to close ensure that the newWindow is created,
// thus newWindow.gBrowser used in the second waitForCondition
// will not be undefined.
await TestUtils.waitForCondition(
() => tab2.closing,
"Wait for tab2 to close"
);
await TestUtils.waitForCondition(
() => newWindow.gBrowser.visibleTabs.length == 3,
"Wait for all three tabs to get moved to the new window"
);
let gBrowser2 = newWindow.gBrowser;
is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
is(gBrowser.visibleTabs.length, 2, "Two tabs now in the old window");
is(gBrowser2.visibleTabs.length, 3, "Three tabs in the new window");
is(
gBrowser2.visibleTabs.indexOf(gBrowser2.selectedTab),
1,
"Previously active tab is still the active tab in the new window"
);
BrowserTestUtils.closeWindow(newWindow);
BrowserTestUtils.removeTab(tab4);
});
add_task(async function testLazyTabs() {
let params = { createLazyBrowser: true };
let oldTabs = [];
let numTabs = 4;
for (let i = 0; i < numTabs; ++i) {
oldTabs.push(
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
BrowserTestUtils.addTab(gBrowser, `http://example.com/?${i}`, params)
);
}
await BrowserTestUtils.switchTab(gBrowser, oldTabs[0]);
for (let i = 1; i < numTabs; ++i) {
await triggerClickOn(oldTabs[i], { ctrlKey: true });
}
isnot(oldTabs[0].linkedPanel, "", `Old tab 0 shouldn't be lazy`);
for (let i = 1; i < numTabs; ++i) {
is(oldTabs[i].linkedPanel, "", `Old tab ${i} should be lazy`);
}
is(gBrowser.multiSelectedTabsCount, numTabs, `${numTabs} multiselected tabs`);
for (let i = 0; i < numTabs; ++i) {
ok(oldTabs[i].multiselected, `Old tab ${i} should be multiselected`);
}
let tabsMoved = new Promise(resolve => {
let numTabsMoved = 0;
window.addEventListener("TabClose", async function listener(event) {
let oldTab = event.target;
let i = oldTabs.indexOf(oldTab);
if (i == 0) {
isnot(
oldTab.linkedPanel,
"",
`Old tab ${i} should continue not being lazy`
);
} else if (i > 0) {
is(oldTab.linkedPanel, "", `Old tab ${i} should continue being lazy`);
} else {
return;
}
let newTab = event.detail.adoptedBy;
await TestUtils.waitForCondition(() => {
return newTab.linkedBrowser.currentURI.spec != "about:blank";
}, `Wait for the new tab to finish the adoption of the old tab`);
if (++numTabsMoved == numTabs) {
window.removeEventListener("TabClose", listener);
resolve();
}
});
});
let newWindow = gBrowser.replaceTabsWithWindow(oldTabs[0]);
await tabsMoved;
let newTabs = newWindow.gBrowser.tabs;
isnot(newTabs[0].linkedPanel, "", `New tab 0 should continue not being lazy`);
for (let i = 1; i < numTabs; ++i) {
is(newTabs[i].linkedPanel, "", `New tab ${i} should continue being lazy`);
}
is(
newTabs[0].linkedBrowser.currentURI.spec,
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
`http://example.com/?0`,
`New tab 0 should have the right URL`
);
for (let i = 1; i < numTabs; ++i) {
is(
SessionStore.getLazyTabValue(newTabs[i], "url"),
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
`http://example.com/?${i}`,
`New tab ${i} should have the right lazy URL`
);
}
for (let i = 0; i < numTabs; ++i) {
ok(newTabs[i].multiselected, `New tab ${i} should be multiselected`);
}
BrowserTestUtils.closeWindow(newWindow);
});
|