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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const PREF_WARN_ON_CLOSE = "browser.tabs.warnOnCloseOtherTabs";
add_task(async function setPref() {
await SpecialPowers.pushPrefEnv({
set: [[PREF_WARN_ON_CLOSE, false]],
});
});
add_task(async function replaceEmptyTabs() {
const win = await BrowserTestUtils.openNewBrowserWindow();
const tabbrowser = win.gBrowser;
ok(
tabbrowser.tabs.length == 1 && tabbrowser.tabs[0].isEmpty,
"One blank tab should be opened."
);
let blankTab = tabbrowser.tabs[0];
await BrowserTestUtils.openNewForegroundTab(
tabbrowser,
"https://example.com/1"
);
await BrowserTestUtils.openNewForegroundTab(
tabbrowser,
"https://example.com/2"
);
await BrowserTestUtils.openNewForegroundTab(
tabbrowser,
"https://example.com/3"
);
is(tabbrowser.tabs.length, 4, "There should be 4 tabs opened.");
tabbrowser.removeAllTabsBut(blankTab);
await TestUtils.waitForCondition(
() =>
SessionStore.getLastClosedTabCount(win) == 3 &&
tabbrowser.tabs.length == 1,
"wait for the tabs to close in SessionStore"
);
is(
SessionStore.getLastClosedTabCount(win),
3,
"SessionStore should know how many tabs were just closed"
);
is(tabbrowser.selectedTab, blankTab, "The blank tab should be selected.");
win.undoCloseTab();
await TestUtils.waitForCondition(
() => tabbrowser.tabs.length == 3,
"wait for the tabs to reopen"
);
is(
SessionStore.getLastClosedTabCount(win),
SessionStore.getClosedTabCountForWindow(win) ? 1 : 0,
"LastClosedTabCount should be reset"
);
ok(
!tabbrowser.tabs.includes(blankTab),
"The blank tab should have been replaced."
);
// We can't (at the time of writing) check tab order.
// Cleanup
await BrowserTestUtils.closeWindow(win);
});
|