|
| 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