Skip to content

Commit 8b9f449

Browse files
authored
no-bug: added tests for unloading all other workspaces (gh-13100)
1 parent 9433b8a commit 8b9f449

3 files changed

Lines changed: 165 additions & 1 deletion

File tree

src/zen/spaces/ZenSpaceManager.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ class nsZenWorkspaces {
15511551
!tab.hasAttribute("pending")
15521552
);
15531553

1554-
await gBrowser.explicitUnloadTabs(tabsToUnload); // TODO: unit test this
1554+
await gBrowser.explicitUnloadTabs(tabsToUnload);
15551555
}
15561556

15571557
moveTabToWorkspace(tab, workspaceID) {

src/zen/tests/spaces/browser.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ support-files = [
2424

2525
["browser_private_mode_startup.js"]
2626

27+
["browser_unload_all_other_spaces.js"]
28+
2729
["browser_workspace_bookmarks.js"]
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
https://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
"use strict";
5+
6+
add_setup(async function () {});
7+
8+
// verify that with only one workspace, regular tabs should remain loaded
9+
add_task(async function test_UnloadAllOtherWorkspace_oneWorkspace() {
10+
const workspace =
11+
await gZenWorkspaces.createAndSaveWorkspace("Test Workspace");
12+
const workspaceId = workspace.uuid;
13+
await gZenWorkspaces.changeWorkspace(workspace);
14+
15+
const tabs = [];
16+
for (let i = 0; i < 3; i++) {
17+
const tab = await BrowserTestUtils.openNewForegroundTab(
18+
window.gBrowser,
19+
`data:text/html,<title>Hi! I am regular tab ${i}</title>`,
20+
true,
21+
{ skipAnimation: true }
22+
);
23+
tabs.push(tab);
24+
}
25+
26+
for (const tab of tabs) {
27+
ok(!tab.hasAttribute("pending"), "Tab should not be pending before unload");
28+
ok(tab.linkedPanel, "Tab should have linked panel before unload");
29+
}
30+
31+
await gZenWorkspaces.unloadAllOtherWorkspaces();
32+
33+
for (const tab of tabs) {
34+
ok(!tab.hasAttribute("pending"), "Tab should not be pending after unload");
35+
ok(tab.linkedPanel, "Tab should have linked panel after unload");
36+
}
37+
38+
await gZenWorkspaces.removeWorkspace(workspaceId);
39+
});
40+
41+
// with multiple workspaces, only regular tabs in other workspaces should be unloaded
42+
add_task(async function test_UnloadAllOtherWorkspace_multipleWorkspaces() {
43+
const inactiveWorkspace =
44+
await gZenWorkspaces.createAndSaveWorkspace("Inactive Workspace");
45+
const activeWorkspace =
46+
await gZenWorkspaces.createAndSaveWorkspace("Active Workspace");
47+
48+
const inactiveWorkspaceId = inactiveWorkspace.uuid;
49+
const activeWorkspaceId = activeWorkspace.uuid;
50+
51+
const inactiveWorkspaceTabs = [];
52+
for (let i = 0; i < 2; i++) {
53+
const tab = await BrowserTestUtils.openNewForegroundTab(
54+
gBrowser,
55+
`data:text/html,<title>Regular Tab ${i} in Inactive</title>`,
56+
true,
57+
{ skipAnimation: true }
58+
);
59+
tab.setAttribute("zen-workspace-id", inactiveWorkspaceId);
60+
inactiveWorkspaceTabs.push(tab);
61+
}
62+
63+
const activeWorkspaceTabs = [];
64+
for (let i = 0; i < 2; i++) {
65+
const tab = await BrowserTestUtils.openNewForegroundTab(
66+
gBrowser,
67+
`data:text/html,<title>Regular Tab ${i} in Active</title>`,
68+
true,
69+
{ skipAnimation: true }
70+
);
71+
tab.setAttribute("zen-workspace-id", activeWorkspaceId);
72+
activeWorkspaceTabs.push(tab);
73+
}
74+
75+
await gZenWorkspaces.unloadAllOtherWorkspaces();
76+
77+
for (const tab of activeWorkspaceTabs) {
78+
ok(
79+
!tab.hasAttribute("pending"),
80+
"Tab in active workspace should not be unloaded"
81+
);
82+
ok(tab.linkedPanel, "Tab in active workspace should have linked panel");
83+
}
84+
85+
for (const tab of inactiveWorkspaceTabs) {
86+
ok(
87+
tab.hasAttribute("pending"),
88+
"Tab in inactive workspace should be unloaded"
89+
);
90+
ok(
91+
!tab.linkedPanel,
92+
"Tab in inactive workspace should not have linked panel"
93+
);
94+
}
95+
await gZenWorkspaces.removeWorkspace(inactiveWorkspaceId);
96+
await gZenWorkspaces.removeWorkspace(activeWorkspaceId);
97+
});
98+
99+
// essentials in any workspace are not unloaded
100+
add_task(async function test_UnloadAllOtherWorkspace_essentials() {
101+
const activeWorkspace =
102+
await gZenWorkspaces.createAndSaveWorkspace("Active Workspace");
103+
const inactiveWorkspace =
104+
await gZenWorkspaces.createAndSaveWorkspace("Inactive Workspace");
105+
106+
const activeWorkspaceId = activeWorkspace.uuid;
107+
const inactiveWorkspaceId = inactiveWorkspace.uuid;
108+
109+
const activeWorkspaceTabs = [];
110+
for (let i = 0; i < 2; i++) {
111+
const tab = await BrowserTestUtils.openNewForegroundTab(
112+
gBrowser,
113+
`data:text/html,<title>Essential Tab ${i} in Active</title>`,
114+
true,
115+
{ skipAnimation: true }
116+
);
117+
tab.setAttribute("zen-workspace-id", activeWorkspaceId);
118+
tab.setAttribute("zen-essential", "true");
119+
activeWorkspaceTabs.push(tab);
120+
}
121+
122+
const inactiveWorkspaceTabs = [];
123+
for (let i = 0; i < 2; i++) {
124+
const tab = await BrowserTestUtils.openNewForegroundTab(
125+
gBrowser,
126+
`data:text/html,<title>Essential Tab ${i} in Inactive</title>`,
127+
true,
128+
{ skipAnimation: true }
129+
);
130+
gZenPinnedTabManager.addToEssentials(tab);
131+
inactiveWorkspaceTabs.push(tab);
132+
}
133+
134+
await gZenWorkspaces.unloadAllOtherWorkspaces();
135+
136+
for (const tab of activeWorkspaceTabs) {
137+
ok(
138+
!tab.hasAttribute("pending"),
139+
"Essential Tab in active workspace should not be unloaded"
140+
);
141+
ok(
142+
tab.linkedPanel,
143+
"Essential Tab in active workspace should have linked panel"
144+
);
145+
}
146+
147+
for (const tab of inactiveWorkspaceTabs) {
148+
ok(
149+
!tab.hasAttribute("pending"),
150+
"Essential Tab in inactive workspace should not be unloaded"
151+
);
152+
ok(
153+
tab.linkedPanel,
154+
"Essential Tab in inactive workspace should have linked panel"
155+
);
156+
}
157+
for (const tab of inactiveWorkspaceTabs) {
158+
gBrowser.removeTab(tab);
159+
}
160+
await gZenWorkspaces.removeWorkspace(inactiveWorkspaceId);
161+
await gZenWorkspaces.removeWorkspace(activeWorkspaceId);
162+
});

0 commit comments

Comments
 (0)