diff --git a/src/zen/spaces/ZenSpaceManager.mjs b/src/zen/spaces/ZenSpaceManager.mjs index d5c118b11..d1f6a609d 100644 --- a/src/zen/spaces/ZenSpaceManager.mjs +++ b/src/zen/spaces/ZenSpaceManager.mjs @@ -1551,7 +1551,7 @@ class nsZenWorkspaces { !tab.hasAttribute("pending") ); - await gBrowser.explicitUnloadTabs(tabsToUnload); // TODO: unit test this + await gBrowser.explicitUnloadTabs(tabsToUnload); } moveTabToWorkspace(tab, workspaceID) { diff --git a/src/zen/tests/spaces/browser.toml b/src/zen/tests/spaces/browser.toml index ac77baa44..deacec1f7 100644 --- a/src/zen/tests/spaces/browser.toml +++ b/src/zen/tests/spaces/browser.toml @@ -24,4 +24,6 @@ support-files = [ ["browser_private_mode_startup.js"] +["browser_unload_all_other_spaces.js"] + ["browser_workspace_bookmarks.js"] diff --git a/src/zen/tests/spaces/browser_unload_all_other_spaces.js b/src/zen/tests/spaces/browser_unload_all_other_spaces.js new file mode 100644 index 000000000..0280519c1 --- /dev/null +++ b/src/zen/tests/spaces/browser_unload_all_other_spaces.js @@ -0,0 +1,162 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_setup(async function () {}); + +// verify that with only one workspace, regular tabs should remain loaded +add_task(async function test_UnloadAllOtherWorkspace_oneWorkspace() { + const workspace = + await gZenWorkspaces.createAndSaveWorkspace("Test Workspace"); + const workspaceId = workspace.uuid; + await gZenWorkspaces.changeWorkspace(workspace); + + const tabs = []; + for (let i = 0; i < 3; i++) { + const tab = await BrowserTestUtils.openNewForegroundTab( + window.gBrowser, + `data:text/html,Hi! I am regular tab ${i}`, + true, + { skipAnimation: true } + ); + tabs.push(tab); + } + + for (const tab of tabs) { + ok(!tab.hasAttribute("pending"), "Tab should not be pending before unload"); + ok(tab.linkedPanel, "Tab should have linked panel before unload"); + } + + await gZenWorkspaces.unloadAllOtherWorkspaces(); + + for (const tab of tabs) { + ok(!tab.hasAttribute("pending"), "Tab should not be pending after unload"); + ok(tab.linkedPanel, "Tab should have linked panel after unload"); + } + + await gZenWorkspaces.removeWorkspace(workspaceId); +}); + +// with multiple workspaces, only regular tabs in other workspaces should be unloaded +add_task(async function test_UnloadAllOtherWorkspace_multipleWorkspaces() { + const inactiveWorkspace = + await gZenWorkspaces.createAndSaveWorkspace("Inactive Workspace"); + const activeWorkspace = + await gZenWorkspaces.createAndSaveWorkspace("Active Workspace"); + + const inactiveWorkspaceId = inactiveWorkspace.uuid; + const activeWorkspaceId = activeWorkspace.uuid; + + const inactiveWorkspaceTabs = []; + for (let i = 0; i < 2; i++) { + const tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + `data:text/html,Regular Tab ${i} in Inactive`, + true, + { skipAnimation: true } + ); + tab.setAttribute("zen-workspace-id", inactiveWorkspaceId); + inactiveWorkspaceTabs.push(tab); + } + + const activeWorkspaceTabs = []; + for (let i = 0; i < 2; i++) { + const tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + `data:text/html,Regular Tab ${i} in Active`, + true, + { skipAnimation: true } + ); + tab.setAttribute("zen-workspace-id", activeWorkspaceId); + activeWorkspaceTabs.push(tab); + } + + await gZenWorkspaces.unloadAllOtherWorkspaces(); + + for (const tab of activeWorkspaceTabs) { + ok( + !tab.hasAttribute("pending"), + "Tab in active workspace should not be unloaded" + ); + ok(tab.linkedPanel, "Tab in active workspace should have linked panel"); + } + + for (const tab of inactiveWorkspaceTabs) { + ok( + tab.hasAttribute("pending"), + "Tab in inactive workspace should be unloaded" + ); + ok( + !tab.linkedPanel, + "Tab in inactive workspace should not have linked panel" + ); + } + await gZenWorkspaces.removeWorkspace(inactiveWorkspaceId); + await gZenWorkspaces.removeWorkspace(activeWorkspaceId); +}); + +// essentials in any workspace are not unloaded +add_task(async function test_UnloadAllOtherWorkspace_essentials() { + const activeWorkspace = + await gZenWorkspaces.createAndSaveWorkspace("Active Workspace"); + const inactiveWorkspace = + await gZenWorkspaces.createAndSaveWorkspace("Inactive Workspace"); + + const activeWorkspaceId = activeWorkspace.uuid; + const inactiveWorkspaceId = inactiveWorkspace.uuid; + + const activeWorkspaceTabs = []; + for (let i = 0; i < 2; i++) { + const tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + `data:text/html,Essential Tab ${i} in Active`, + true, + { skipAnimation: true } + ); + tab.setAttribute("zen-workspace-id", activeWorkspaceId); + tab.setAttribute("zen-essential", "true"); + activeWorkspaceTabs.push(tab); + } + + const inactiveWorkspaceTabs = []; + for (let i = 0; i < 2; i++) { + const tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + `data:text/html,Essential Tab ${i} in Inactive`, + true, + { skipAnimation: true } + ); + gZenPinnedTabManager.addToEssentials(tab); + inactiveWorkspaceTabs.push(tab); + } + + await gZenWorkspaces.unloadAllOtherWorkspaces(); + + for (const tab of activeWorkspaceTabs) { + ok( + !tab.hasAttribute("pending"), + "Essential Tab in active workspace should not be unloaded" + ); + ok( + tab.linkedPanel, + "Essential Tab in active workspace should have linked panel" + ); + } + + for (const tab of inactiveWorkspaceTabs) { + ok( + !tab.hasAttribute("pending"), + "Essential Tab in inactive workspace should not be unloaded" + ); + ok( + tab.linkedPanel, + "Essential Tab in inactive workspace should have linked panel" + ); + } + for (const tab of inactiveWorkspaceTabs) { + gBrowser.removeTab(tab); + } + await gZenWorkspaces.removeWorkspace(inactiveWorkspaceId); + await gZenWorkspaces.removeWorkspace(activeWorkspaceId); +});