diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index ff8bea2b0..84ca8d09d 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..7674939b31ba0bd444659e0f1e8cc7265c687356 100644 +index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..89ae48f816bee85b2870f383723b520bd2b354b8 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -127,6 +127,8 @@ const TAB_EVENTS = [ @@ -172,7 +172,7 @@ index 2c2f43bf743ef458b378e85e9ed44a971711e1d9..7674939b31ba0bd444659e0f1e8cc726 ); + aWindow.gZenFolders?.restoreDataFromSessionStore(winData.folders); + aWindow.gZenViewSplitter?.restoreDataFromSessionStore(winData.splitViewData); -+ aWindow.gZenWorkspaces?.activeWorkspace = winData.activeZenSpace || null; ++ aWindow.gZenWorkspaces.activeWorkspace = winData.activeZenSpace || null; this._log.debug( `restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs` ); diff --git a/src/zen/sessionstore/ZenWindowSync.sys.mjs b/src/zen/sessionstore/ZenWindowSync.sys.mjs index cbd1687d9..e724de6d9 100644 --- a/src/zen/sessionstore/ZenWindowSync.sys.mjs +++ b/src/zen/sessionstore/ZenWindowSync.sys.mjs @@ -106,9 +106,6 @@ class nsZenWindowSync { for (let topic of OBSERVING) { Services.obs.addObserver(this, topic); } - lazy.SessionStore.promiseAllWindowsRestored.then(() => { - this.#onSessionStoreInitialized(); - }); } uninit() { @@ -172,27 +169,6 @@ class nsZenWindowSync { return `${Date.now()}-${Math.round(Math.random() * 100)}`; } - /** - * Called when the session store has finished initializing for a window. - * - * @param {Window} aWindow - The browser window that has initialized session store. - */ - #onSessionStoreInitialized() { - // For every tab we have in where there's no sync ID, we need to - // assign one and sync it to other windows. - // This should only happen really when updating from an older version - // that didn't have this feature. - this.#runOnAllWindows(null, (aWindow) => { - const { gBrowser } = aWindow; - for (let tab of gBrowser.tabs) { - if (!tab.id) { - tab.id = this.#newTabSyncId; - lazy.TabStateFlusher.flush(tab.linkedBrowser); - } - } - }); - } - /** * Runs a callback function on all browser windows except the specified one. * @@ -872,7 +848,12 @@ class nsZenWindowSync { on_TabPinned(aEvent) { const tab = aEvent.target; - this.setPinnedTabState(tab); + // There are cases where the pinned state is changed but we don't + // wan't to override the initial state we stored when the tab was created. + // For example, when session restore pins a tab again. + if (!tab._zenPinnedInitialState) { + this.setPinnedTabState(tab); + } return this.on_TabMove(aEvent); } diff --git a/src/zen/tabs/ZenPinnedTabManager.mjs b/src/zen/tabs/ZenPinnedTabManager.mjs index 6cebde5fb..c39c439d4 100644 --- a/src/zen/tabs/ZenPinnedTabManager.mjs +++ b/src/zen/tabs/ZenPinnedTabManager.mjs @@ -611,7 +611,7 @@ class nsZenPinnedTabManager extends nsZenDOMOperatedFeature { } } - async onLocationChange(browser) { + onLocationChange(browser) { const tab = gBrowser.getTabForBrowser(browser); if ( !tab || diff --git a/src/zen/tests/folders/browser_folder_owner_tabs.js b/src/zen/tests/folders/browser_folder_owner_tabs.js index 00de0f44a..7af7c963a 100644 --- a/src/zen/tests/folders/browser_folder_owner_tabs.js +++ b/src/zen/tests/folders/browser_folder_owner_tabs.js @@ -31,9 +31,6 @@ add_task(async function test_Duplicate_Tab_Inside_Folder() { for (const t of folder.tabs) { ok(t.pinned, 'All tabs in the folder should be pinned'); - if (!t.hasAttribute('zen-empty-tab')) { - ok(t.hasAttribute('zen-pin-id'), 'All non-empty tabs should have a zen-pinned-id attribute'); - } } gBrowser.selectedTab = selectedTab; diff --git a/src/zen/tests/pinned/browser.toml b/src/zen/tests/pinned/browser.toml index b26d96f32..22082e1f5 100644 --- a/src/zen/tests/pinned/browser.toml +++ b/src/zen/tests/pinned/browser.toml @@ -13,14 +13,9 @@ prefs = ["zen.workspaces.separate-essentials=false"] ["browser_pinned_close.js"] ["browser_pinned_changed.js"] ["browser_pinned_created.js"] -["browser_pinned_edit_label.js"] -["browser_pinned_removed.js"] -["browser_pinned_reorder_changed_label.js"] -["browser_pinned_reordered.js"] ["browser_pinned_to_essential.js"] ["browser_private_mode_no_essentials.js"] ["browser_private_mode_no_ctx_menu.js"] -["browser_issue_7654.js"] ["browser_issue_8726.js"] diff --git a/src/zen/tests/pinned/browser_issue_7654.js b/src/zen/tests/pinned/browser_issue_7654.js deleted file mode 100644 index d982a910f..000000000 --- a/src/zen/tests/pinned/browser_issue_7654.js +++ /dev/null @@ -1,65 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - https://creativecommons.org/publicdomain/zero/1.0/ */ - -'use strict'; - -ChromeUtils.defineESModuleGetters(this, { - UrlbarTestUtils: 'resource://testing-common/UrlbarTestUtils.sys.mjs', -}); - -add_task(async function test_Search_Pinned_Title() { - let resolvePromise; - const promise = new Promise((resolve) => { - resolvePromise = resolve; - }); - - const customLabel = 'ZEN ROCKS'; - - await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/1' }, async (browser) => { - const tab = gBrowser.getTabForBrowser(browser); - tab.addEventListener( - 'ZenPinnedTabCreated', - async function () { - const pinTabID = tab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - await gZenPinnedTabManager.updatePinTitle(tab, customLabel, true); - - const pinnedTabs = await ZenPinnedTabsStorage.getPins(); - const pinObject = pinnedTabs.find((pin) => pin.uuid === pinTabID); - Assert.equal(pinObject.title, customLabel, 'The pin object should have the correct title'); - - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/2', true); - - await UrlbarTestUtils.promiseAutocompleteResultPopup({ - window, - value: customLabel, - waitForFocus: SimpleTest.waitForFocus, - }); - - const total = UrlbarTestUtils.getResultCount(window); - info(`Found ${total} matches`); - - const result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1); - - const url = result?.url; - Assert.equal( - url, - 'https://example.com/1', - `Should have the found result '${url}' in the expected list of entries` - ); - Assert.equal( - result?.title, - customLabel, - `Should have the found result '${result?.title}' in the expected list of entries` - ); - - BrowserTestUtils.removeTab(gBrowser.selectedTab); - resolvePromise(); - }, - { once: true } - ); - gBrowser.pinTab(tab); - await promise; - }); -}); diff --git a/src/zen/tests/pinned/browser_pinned_changed.js b/src/zen/tests/pinned/browser_pinned_changed.js index 576c16946..f2ffb466f 100644 --- a/src/zen/tests/pinned/browser_pinned_changed.js +++ b/src/zen/tests/pinned/browser_pinned_changed.js @@ -11,27 +11,20 @@ add_task(async function test_Changed_Pinned() { await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/1' }, async (browser) => { const tab = gBrowser.getTabForBrowser(browser); - tab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(tab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - - const pinTabID = tab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); - await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); - setTimeout(() => { - ok( - tab.hasAttribute('zen-pinned-changed'), - 'The tab should have a zen-pinned-changed attribute after being pinned' - ); - resolvePromise(); - }, 0); - }, - { once: true } - ); gBrowser.pinTab(tab); + + ok(tab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); + + BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); + await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); + setTimeout(() => { + ok( + tab.hasAttribute('zen-pinned-changed'), + 'The tab should have a zen-pinned-changed attribute after being pinned' + ); + resolvePromise(); + }, 0); + await promise; }); }); diff --git a/src/zen/tests/pinned/browser_pinned_close.js b/src/zen/tests/pinned/browser_pinned_close.js index c3c009ae2..b283a8c10 100644 --- a/src/zen/tests/pinned/browser_pinned_close.js +++ b/src/zen/tests/pinned/browser_pinned_close.js @@ -15,20 +15,13 @@ add_task(async function test_Unload_NoReset_Pinned() { await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/1' }, async (browser) => { const tab = gBrowser.getTabForBrowser(browser); - tab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - const pinTabID = tab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - document.getElementById('cmd_close').doCommand(); - setTimeout(() => { - ok(tab.closing, 'The tab should be closing after being closed'); - resolvePromise(); - }, 100); - }, - { once: true } - ); gBrowser.pinTab(tab); + + document.getElementById('cmd_close').doCommand(); + setTimeout(() => { + ok(tab.closing, 'The tab should be closing after being closed'); + resolvePromise(); + }, 100); await promise; }); }); diff --git a/src/zen/tests/pinned/browser_pinned_created.js b/src/zen/tests/pinned/browser_pinned_created.js index 6a8070aa1..bc7658fcb 100644 --- a/src/zen/tests/pinned/browser_pinned_created.js +++ b/src/zen/tests/pinned/browser_pinned_created.js @@ -12,38 +12,24 @@ add_task(async function test_Create_Pinned() { await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); const newTab = gBrowser.selectedTab; - newTab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - - const pinTabID = newTab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - try { - const pins = await ZenPinnedTabsStorage.getPins(); - const pinObject = pins.find((pin) => pin.uuid === pinTabID); - ok(pinObject, 'The pin object should exist in the ZenPinnedTabsStorage'); - Assert.equal( - pinObject.url, - 'https://example.com/', - 'The pin object should have the correct URL' - ); - Assert.equal( - pinObject.workspaceUuid, - gZenWorkspaces.activeWorkspace, - 'The pin object should have the correct workspace UUID' - ); - } catch (error) { - ok(false, 'Error while checking the pin object in ZenPinnedTabsStorage: ' + error); - } - - resolvePromise(); - }, - { once: true } - ); gBrowser.pinTab(newTab); + ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); + + try { + const pinObject = newTab.__zenPinnedInitialState; + ok(pinObject, 'The pin object should exist in the ZenPinnedTabsStorage'); + Assert.equal( + pinObject.entry.url, + 'https://example.com/', + 'The pin object should have the correct URL' + ); + } catch (error) { + ok(false, 'Error while checking the pin object in ZenPinnedTabsStorage: ' + error); + } + + resolvePromise(); + await promise; await BrowserTestUtils.removeTab(newTab); }); diff --git a/src/zen/tests/pinned/browser_pinned_edit_label.js b/src/zen/tests/pinned/browser_pinned_edit_label.js deleted file mode 100644 index e03cb7cb8..000000000 --- a/src/zen/tests/pinned/browser_pinned_edit_label.js +++ /dev/null @@ -1,42 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - https://creativecommons.org/publicdomain/zero/1.0/ */ - -'use strict'; - -add_task(async function test_Create_Pinned() { - let resolvePromise; - const promise = new Promise((resolve) => { - resolvePromise = resolve; - }); - - const customLabel = 'Test Label'; - - await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/' }, async (browser) => { - const tab = gBrowser.getTabForBrowser(browser); - tab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(tab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - - const pinTabID = tab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - await gZenPinnedTabManager.updatePinTitle(tab, customLabel, true); - - const pinnedTabs = await ZenPinnedTabsStorage.getPins(); - const pinObject = pinnedTabs.find((pin) => pin.uuid === pinTabID); - Assert.equal(pinObject.title, customLabel, 'The pin object should have the correct title'); - Assert.equal( - pinObject.url, - 'https://example.com/', - 'The pin object should have the correct URL' - ); - - resolvePromise(); - }, - { once: true } - ); - gBrowser.pinTab(tab); - await promise; - }); -}); diff --git a/src/zen/tests/pinned/browser_pinned_nounload_reset.js b/src/zen/tests/pinned/browser_pinned_nounload_reset.js index 9930b0268..8effbee1f 100644 --- a/src/zen/tests/pinned/browser_pinned_nounload_reset.js +++ b/src/zen/tests/pinned/browser_pinned_nounload_reset.js @@ -15,37 +15,26 @@ add_task(async function test_NoUnload_Changed_Pinned() { await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/1' }, async (browser) => { const tab = gBrowser.getTabForBrowser(browser); - tab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - const pinTabID = tab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); - await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); - setTimeout(() => { - ok( - tab.hasAttribute('zen-pinned-changed'), - 'The tab should have a zen-pinned-changed attribute after being pinned' - ); - document.getElementById('cmd_close').doCommand(); - setTimeout(() => { - ok( - !tab.hasAttribute('zen-pinned-changed'), - 'The tab should not have a zen-pinned-changed attribute after being closed' - ); - ok( - !tab.hasAttribute('discarded'), - 'The tab should not be discarded after being closed' - ); - ok(tab != gBrowser.selectedTab, 'The tab should not be selected after being closed'); - resolvePromise(); - }, 100); - }, 0); - }, - { once: true } - ); gBrowser.pinTab(tab); + + BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); + await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); + setTimeout(() => { + ok( + tab.hasAttribute('zen-pinned-changed'), + 'The tab should have a zen-pinned-changed attribute after being pinned' + ); + document.getElementById('cmd_close').doCommand(); + setTimeout(() => { + ok( + !tab.hasAttribute('zen-pinned-changed'), + 'The tab should not have a zen-pinned-changed attribute after being closed' + ); + ok(!tab.hasAttribute('discarded'), 'The tab should not be discarded after being closed'); + ok(tab != gBrowser.selectedTab, 'The tab should not be selected after being closed'); + resolvePromise(); + }, 100); + }, 0); await promise; }); }); diff --git a/src/zen/tests/pinned/browser_pinned_removed.js b/src/zen/tests/pinned/browser_pinned_removed.js deleted file mode 100644 index 4e4bc7959..000000000 --- a/src/zen/tests/pinned/browser_pinned_removed.js +++ /dev/null @@ -1,52 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - https://creativecommons.org/publicdomain/zero/1.0/ */ - -'use strict'; - -add_task(async function test_Remove_Pinned() { - let resolvePromise; - const promise = new Promise((resolve) => { - resolvePromise = resolve; - }); - - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); - - const newTab = gBrowser.selectedTab; - newTab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - - const pinTabID = newTab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - const pins = await ZenPinnedTabsStorage.getPins(); - const pinObject = pins.find((pin) => pin.uuid === pinTabID); - ok(pinObject, 'The pin object should exist in the ZenPinnedTabsStorage'); - newTab.addEventListener( - 'ZenPinnedTabRemoved', - async function (event) { - const pins = await ZenPinnedTabsStorage.getPins(); - const pinObject = pins.find((pin) => pin.uuid === pinTabID); - ok( - !pinObject, - 'The pin object should not exist in the ZenPinnedTabsStorage after removal' - ); - ok( - !newTab.hasAttribute('zen-pin-id'), - 'The tab should not have a zen-pin-id attribute after removal' - ); - ok(!newTab.pinned, 'The tab should not be pinned after removal'); - resolvePromise(); - }, - { once: true } - ); - gBrowser.unpinTab(newTab); - }, - { once: true } - ); - gBrowser.pinTab(newTab); - - await promise; - await BrowserTestUtils.removeTab(newTab); -}); diff --git a/src/zen/tests/pinned/browser_pinned_reorder_changed_label.js b/src/zen/tests/pinned/browser_pinned_reorder_changed_label.js deleted file mode 100644 index 10908c565..000000000 --- a/src/zen/tests/pinned/browser_pinned_reorder_changed_label.js +++ /dev/null @@ -1,126 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - https://creativecommons.org/publicdomain/zero/1.0/ */ - -'use strict'; - -add_task(async function test_Pinned_Reorder_Changed_Label() { - let resolvePromise; - const promise = new Promise((resolve) => { - resolvePromise = resolve; - }); - - const tabsToRemove = []; - for (let i = 0; i < 3; i++) { - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); - gBrowser.pinTab(gBrowser.selectedTab); - tabsToRemove.push(gBrowser.selectedTab); - } - - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); - tabsToRemove.push(gBrowser.selectedTab); - - const customLabel = 'Test Label'; - - const newTab = gBrowser.selectedTab; - newTab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - - const pinTabID = newTab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - await gZenPinnedTabManager.updatePinTitle(newTab, customLabel, true); - - const pins = await ZenPinnedTabsStorage.getPins(); - const pinObject = pins.find((pin) => pin.uuid === pinTabID); - - newTab.addEventListener( - 'ZenPinnedTabMoved', - async function (event) { - const pins = await ZenPinnedTabsStorage.getPins(); - const pinObject = pins.find((pin) => pin.uuid === pinTabID); - Assert.equal( - pinObject.title, - customLabel, - 'The pin object should have the correct title' - ); - Assert.equal( - pinObject.position, - 2, - 'The pin object should have the correct position after moving' - ); - resolvePromise(); - }, - { once: true } - ); - gBrowser.moveTabTo(newTab, { tabIndex: 2 }); - }, - { once: true } - ); - gBrowser.pinTab(newTab); - - await promise; - for (const tab of tabsToRemove) { - await BrowserTestUtils.removeTab(tab); - } -}); - -add_task(async function test_Pinned_Reorder_Changed_Label() { - let resolvePromise; - const promise = new Promise((resolve) => { - resolvePromise = resolve; - }); - - const tabsToRemove = []; - for (let i = 0; i < 3; i++) { - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); - gBrowser.pinTab(gBrowser.selectedTab); - tabsToRemove.push(gBrowser.selectedTab); - } - - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); - tabsToRemove.push(gBrowser.selectedTab); - - const customLabel = 'Test Label'; - - const newTab = gBrowser.selectedTab; - newTab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - - const pinTabID = newTab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - newTab.addEventListener( - 'ZenPinnedTabMoved', - async function (event) { - await gZenPinnedTabManager.updatePinTitle(newTab, customLabel, true); - const pins = await ZenPinnedTabsStorage.getPins(); - const pinObject = pins.find((pin) => pin.uuid === pinTabID); - Assert.equal( - pinObject.title, - customLabel, - 'The pin object should have the correct title' - ); - Assert.equal( - pinObject.position, - 1, - 'The pin object should have the correct position after moving' - ); - resolvePromise(); - }, - { once: true } - ); - gBrowser.moveTabTo(newTab, { tabIndex: 1 }); - }, - { once: true } - ); - gBrowser.pinTab(newTab); - - await promise; - for (const tab of tabsToRemove) { - await BrowserTestUtils.removeTab(tab); - } -}); diff --git a/src/zen/tests/pinned/browser_pinned_reordered.js b/src/zen/tests/pinned/browser_pinned_reordered.js deleted file mode 100644 index 6fc523b8b..000000000 --- a/src/zen/tests/pinned/browser_pinned_reordered.js +++ /dev/null @@ -1,97 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - https://creativecommons.org/publicdomain/zero/1.0/ */ - -'use strict'; - -add_task(async function test_Create_Pinned() { - let resolvePromise; - const promise = new Promise((resolve) => { - resolvePromise = resolve; - }); - - const tabsToRemove = []; - for (let i = 0; i < 3; i++) { - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); - gBrowser.pinTab(gBrowser.selectedTab); - tabsToRemove.push(gBrowser.selectedTab); - } - - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); - tabsToRemove.push(gBrowser.selectedTab); - - const newTab = gBrowser.selectedTab; - newTab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - - const pinTabID = newTab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - const pins = await ZenPinnedTabsStorage.getPins(); - const pinObject = pins.find((pin) => pin.uuid === pinTabID); - const startIndex = pinObject.position; - Assert.greater(startIndex, 0, 'The pin object should have the correct start index'); - - resolvePromise(); - }, - { once: true } - ); - gBrowser.pinTab(newTab); - - await promise; - for (const tab of tabsToRemove) { - await BrowserTestUtils.removeTab(tab); - } -}); - -add_task(async function test_Create_Pinned() { - let resolvePromise; - const promise = new Promise((resolve) => { - resolvePromise = resolve; - }); - - const tabsToRemove = []; - for (let i = 0; i < 3; i++) { - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); - gBrowser.pinTab(gBrowser.selectedTab); - tabsToRemove.push(gBrowser.selectedTab); - } - - await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); - tabsToRemove.push(gBrowser.selectedTab); - - const newTab = gBrowser.selectedTab; - newTab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - - const pinTabID = newTab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - newTab.addEventListener( - 'ZenPinnedTabMoved', - async function (event) { - const pins = await ZenPinnedTabsStorage.getPins(); - const pinObject = pins.find((pin) => pin.uuid === pinTabID); - Assert.equal( - pinObject.position, - 0, - 'The pin object should have the correct position after moving' - ); - resolvePromise(); - }, - { once: true } - ); - gBrowser.moveTabTo(newTab, { tabIndex: 0 }); - }, - { once: true } - ); - gBrowser.pinTab(newTab); - - await promise; - for (const tab of tabsToRemove) { - await BrowserTestUtils.removeTab(tab); - } -}); diff --git a/src/zen/tests/pinned/browser_pinned_reset_noswitch.js b/src/zen/tests/pinned/browser_pinned_reset_noswitch.js index 969e68f31..458e62af9 100644 --- a/src/zen/tests/pinned/browser_pinned_reset_noswitch.js +++ b/src/zen/tests/pinned/browser_pinned_reset_noswitch.js @@ -15,37 +15,26 @@ add_task(async function test_Unload_NoReset_Pinned() { await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/1' }, async (browser) => { const tab = gBrowser.getTabForBrowser(browser); - tab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - const pinTabID = tab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); - await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); - setTimeout(() => { - ok( - tab.hasAttribute('zen-pinned-changed'), - 'The tab should have a zen-pinned-changed attribute after being pinned' - ); - document.getElementById('cmd_close').doCommand(); - setTimeout(() => { - ok( - !tab.hasAttribute('zen-pinned-changed'), - 'The tab should not have a zen-pinned-changed attribute after being closed' - ); - ok( - !tab.hasAttribute('discarded'), - 'The tab should not be discarded after being closed' - ); - ok(tab === gBrowser.selectedTab, 'The tab should not be selected after being closed'); - resolvePromise(); - }, 100); - }, 0); - }, - { once: true } - ); gBrowser.pinTab(tab); + + BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); + await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); + setTimeout(() => { + ok( + tab.hasAttribute('zen-pinned-changed'), + 'The tab should have a zen-pinned-changed attribute after being pinned' + ); + document.getElementById('cmd_close').doCommand(); + setTimeout(() => { + ok( + !tab.hasAttribute('zen-pinned-changed'), + 'The tab should not have a zen-pinned-changed attribute after being closed' + ); + ok(!tab.hasAttribute('discarded'), 'The tab should not be discarded after being closed'); + ok(tab === gBrowser.selectedTab, 'The tab should not be selected after being closed'); + resolvePromise(); + }, 100); + }, 0); await promise; }); }); diff --git a/src/zen/tests/pinned/browser_pinned_switch.js b/src/zen/tests/pinned/browser_pinned_switch.js index d0a2caa56..8d62e5fc4 100644 --- a/src/zen/tests/pinned/browser_pinned_switch.js +++ b/src/zen/tests/pinned/browser_pinned_switch.js @@ -15,37 +15,26 @@ add_task(async function test_Unload_NoReset_Pinned() { await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/1' }, async (browser) => { const tab = gBrowser.getTabForBrowser(browser); - tab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - const pinTabID = tab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); - await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); - setTimeout(() => { - ok( - tab.hasAttribute('zen-pinned-changed'), - 'The tab should have a zen-pinned-changed attribute after being pinned' - ); - document.getElementById('cmd_close').doCommand(); - setTimeout(() => { - ok( - tab.hasAttribute('zen-pinned-changed'), - 'The tab should not have a zen-pinned-changed attribute after being closed' - ); - ok( - !tab.hasAttribute('discarded'), - 'The tab should not be discarded after being closed' - ); - ok(tab != gBrowser.selectedTab, 'The tab should not be selected after being closed'); - resolvePromise(); - }, 100); - }, 0); - }, - { once: true } - ); gBrowser.pinTab(tab); + + BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); + await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); + setTimeout(() => { + ok( + tab.hasAttribute('zen-pinned-changed'), + 'The tab should have a zen-pinned-changed attribute after being pinned' + ); + document.getElementById('cmd_close').doCommand(); + setTimeout(() => { + ok( + tab.hasAttribute('zen-pinned-changed'), + 'The tab should not have a zen-pinned-changed attribute after being closed' + ); + ok(!tab.hasAttribute('discarded'), 'The tab should not be discarded after being closed'); + ok(tab != gBrowser.selectedTab, 'The tab should not be selected after being closed'); + resolvePromise(); + }, 100); + }, 0); await promise; }); }); diff --git a/src/zen/tests/pinned/browser_pinned_to_essential.js b/src/zen/tests/pinned/browser_pinned_to_essential.js index 51315384d..2a605c1be 100644 --- a/src/zen/tests/pinned/browser_pinned_to_essential.js +++ b/src/zen/tests/pinned/browser_pinned_to_essential.js @@ -12,26 +12,18 @@ add_task(async function test_Pinned_To_Essential() { await BrowserTestUtils.openNewForegroundTab(window.gBrowser, 'https://example.com/', true); const newTab = gBrowser.selectedTab; - newTab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - - const pinTabID = newTab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - gZenPinnedTabManager.addToEssentials(newTab); - ok( - newTab.hasAttribute('zen-essential') && newTab.parentNode.getAttribute('container') == '0', - 'New tab should be marked as essential.' - ); - - resolvePromise(); - }, - { once: true } - ); gBrowser.pinTab(newTab); + ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); + + gZenPinnedTabManager.addToEssentials(newTab); + ok( + newTab.hasAttribute('zen-essential') && newTab.parentNode.getAttribute('container') == '0', + 'New tab should be marked as essential.' + ); + + resolvePromise(); + await promise; await BrowserTestUtils.removeTab(newTab); }); diff --git a/src/zen/tests/pinned/browser_pinned_unload_changed.js b/src/zen/tests/pinned/browser_pinned_unload_changed.js index 5d7bc6f53..ca4d77cf4 100644 --- a/src/zen/tests/pinned/browser_pinned_unload_changed.js +++ b/src/zen/tests/pinned/browser_pinned_unload_changed.js @@ -15,35 +15,27 @@ add_task(async function test_Unload_Changed_Pinned() { await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/1' }, async (browser) => { const tab = gBrowser.getTabForBrowser(browser); - tab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - const pinTabID = tab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); - await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); - setTimeout(() => { - ok( - tab.hasAttribute('zen-pinned-changed'), - 'The tab should have a zen-pinned-changed attribute after being pinned' - ); - document.getElementById('cmd_close').doCommand(); - setTimeout(() => { - ok( - !tab.hasAttribute('zen-pinned-changed'), - 'The tab should not have a zen-pinned-changed attribute after being closed' - ); - - ok(tab.hasAttribute('discarded'), 'The tab should not be discarded after being closed'); - ok(tab != gBrowser.selectedTab, 'The tab should not be selected after being closed'); - resolvePromise(); - }, 100); - }, 0); - }, - { once: true } - ); gBrowser.pinTab(tab); + + BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); + await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); + setTimeout(() => { + ok( + tab.hasAttribute('zen-pinned-changed'), + 'The tab should have a zen-pinned-changed attribute after being pinned' + ); + document.getElementById('cmd_close').doCommand(); + setTimeout(() => { + ok( + !tab.hasAttribute('zen-pinned-changed'), + 'The tab should not have a zen-pinned-changed attribute after being closed' + ); + + ok(tab.hasAttribute('discarded'), 'The tab should not be discarded after being closed'); + ok(tab != gBrowser.selectedTab, 'The tab should not be selected after being closed'); + resolvePromise(); + }, 100); + }, 0); await promise; }); }); diff --git a/src/zen/tests/pinned/browser_pinned_unload_noreset.js b/src/zen/tests/pinned/browser_pinned_unload_noreset.js index 538c84bac..0163a5a73 100644 --- a/src/zen/tests/pinned/browser_pinned_unload_noreset.js +++ b/src/zen/tests/pinned/browser_pinned_unload_noreset.js @@ -15,34 +15,26 @@ add_task(async function test_Unload_NoReset_Pinned() { await BrowserTestUtils.withNewTab({ gBrowser, url: 'https://example.com/1' }, async (browser) => { const tab = gBrowser.getTabForBrowser(browser); - tab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - const pinTabID = tab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); - - BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); - await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); - setTimeout(() => { - ok( - tab.hasAttribute('zen-pinned-changed'), - 'The tab should have a zen-pinned-changed attribute after being pinned' - ); - document.getElementById('cmd_close').doCommand(); - setTimeout(() => { - ok( - tab.hasAttribute('zen-pinned-changed'), - 'The tab should not have a zen-pinned-changed attribute after being closed' - ); - ok(tab.hasAttribute('discarded'), 'The tab should not be discarded after being closed'); - ok(tab != gBrowser.selectedTab, 'The tab should not be selected after being closed'); - resolvePromise(); - }, 100); - }, 0); - }, - { once: true } - ); gBrowser.pinTab(tab); + + BrowserTestUtils.startLoadingURIString(browser, 'https://example.com/2'); + await BrowserTestUtils.browserLoaded(browser, false, 'https://example.com/2'); + setTimeout(() => { + ok( + tab.hasAttribute('zen-pinned-changed'), + 'The tab should have a zen-pinned-changed attribute after being pinned' + ); + document.getElementById('cmd_close').doCommand(); + setTimeout(() => { + ok( + tab.hasAttribute('zen-pinned-changed'), + 'The tab should not have a zen-pinned-changed attribute after being closed' + ); + ok(tab.hasAttribute('discarded'), 'The tab should not be discarded after being closed'); + ok(tab != gBrowser.selectedTab, 'The tab should not be selected after being closed'); + resolvePromise(); + }, 100); + }, 0); await promise; }); }); diff --git a/src/zen/tests/pinned/browser_private_mode_no_essentials.js b/src/zen/tests/pinned/browser_private_mode_no_essentials.js index 06b178289..8de324771 100644 --- a/src/zen/tests/pinned/browser_private_mode_no_essentials.js +++ b/src/zen/tests/pinned/browser_private_mode_no_essentials.js @@ -11,36 +11,29 @@ add_task(async function test_Private_Mode_No_Essentials() { }); const newTab = gBrowser.selectedTab; - newTab.addEventListener( - 'ZenPinnedTabCreated', - async function (event) { - ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); + gBrowser.pinTab(newTab); - const pinTabID = newTab.getAttribute('zen-pin-id'); - ok(pinTabID, 'The tab should have a zen-pin-id attribute after being pinned'); + ok(newTab.pinned, 'The tab should be pinned after calling gBrowser.pinTab()'); - try { - const pins = await ZenPinnedTabsStorage.getPins(); - const pinObject = pins.find((pin) => pin.uuid === pinTabID); - ok(pinObject, 'The pin object should exist in the ZenPinnedTabsStorage'); + try { + const pins = await ZenPinnedTabsStorage.getPins(); + const pinObject = pins.find((pin) => pin.uuid === pinTabID); + ok(pinObject, 'The pin object should exist in the ZenPinnedTabsStorage'); - let privateWindow = await BrowserTestUtils.openNewBrowserWindow({ - private: true, - }); - await privateWindow.gZenWorkspaces.promiseInitialized; - ok( - !privateWindow.gBrowser.tabs.some((tab) => tab.pinned), - 'Private window should not have any pinned tabs initially' - ); + let privateWindow = await BrowserTestUtils.openNewBrowserWindow({ + private: true, + }); + await privateWindow.gZenWorkspaces.promiseInitialized; + ok( + !privateWindow.gBrowser.tabs.some((tab) => tab.pinned), + 'Private window should not have any pinned tabs initially' + ); - await BrowserTestUtils.closeWindow(privateWindow); - } catch (error) { - ok(false, 'Error while checking the pin object in ZenPinnedTabsStorage: ' + error); - } - resolvePromise(); - }, - { once: true } - ); + await BrowserTestUtils.closeWindow(privateWindow); + } catch (error) { + ok(false, 'Error while checking the pin object in ZenPinnedTabsStorage: ' + error); + } + resolvePromise(); gZenPinnedTabManager.addToEssentials(newTab); await promise; diff --git a/src/zen/tests/welcome/browser_welcome.js b/src/zen/tests/welcome/browser_welcome.js index d780ce9f1..3b95fab20 100644 --- a/src/zen/tests/welcome/browser_welcome.js +++ b/src/zen/tests/welcome/browser_welcome.js @@ -162,7 +162,6 @@ add_task(async function test_Welcome_Steps() { ); Assert.equal(tab.group, group, 'Pinned tabs should belong to the first tab group'); } - ok(tab.hasAttribute('zen-pin-id'), 'Pinned tabs should have a zen-pin-id attribute'); } } group.delete();