test: Fixed tests for the pinned tabs manager, b=no-bug, c=tabs, folders, tests, welcome

This commit is contained in:
mr. m
2025-12-14 11:16:29 +01:00
parent f094b6239d
commit cc7780e078
21 changed files with 169 additions and 671 deletions

View File

@@ -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`
);

View File

@@ -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);
}

View File

@@ -611,7 +611,7 @@ class nsZenPinnedTabManager extends nsZenDOMOperatedFeature {
}
}
async onLocationChange(browser) {
onLocationChange(browser) {
const tab = gBrowser.getTabForBrowser(browser);
if (
!tab ||

View File

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

View File

@@ -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"]

View File

@@ -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;
});
});

View File

@@ -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;
});
});

View File

@@ -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;
});
});

View File

@@ -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);
});

View File

@@ -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;
});
});

View File

@@ -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;
});
});

View File

@@ -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);
});

View File

@@ -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);
}
});

View File

@@ -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);
}
});

View File

@@ -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;
});
});

View File

@@ -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;
});
});

View File

@@ -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);
});

View File

@@ -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;
});
});

View File

@@ -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;
});
});

View File

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

View File

@@ -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();