commit 70113e445c03b44b717039358797629fddebba51 parent 11d4b58923f03d45f7d64b85c6ef819cd40c2e08 Author: Cristina Horotan <chorotan@mozilla.com> Date: Sat, 13 Dec 2025 01:36:35 +0200 Revert "Bug 2000947 - Part 4: Avoid using event listeners for telemetry and pinning of Taskbar Tabs. r=nrishel" for causing bc failures on browser_asrouter_targeting.js DONTBUILD This reverts commit 882470344ade90bf2efd13e4105aa971fd86b470. Revert "Bug 2000947 - Part 3: Return the removed TaskbarTab from TaskbarTabsRegistry.removeTaskbarTab. r=nrishel" This reverts commit a335f2b8e44ce62b3c5d4c0a8e391ffcde7d720b. Revert "Bug 2000947 - Part 2: Have TaskbarTabsRegistry.findOrCreateTaskbarTab return additionally whether it created a Taskbar Tab or not. r=nrishel" This reverts commit c9f8c20276695e03906d9fd73cf71bdb3bb9d8d0. Revert "Bug 2000947 - Part 1: Be more careful in tests about cleaning up Taskbar Tabs and not creating them when we don't want to. r=nrishel" This reverts commit 2d48f28facb2e785bab24cca384decd0f0bfb3a0. Diffstat:
17 files changed, 92 insertions(+), 193 deletions(-)
diff --git a/browser/components/taskbartabs/TaskbarTabs.sys.mjs b/browser/components/taskbartabs/TaskbarTabs.sys.mjs @@ -45,13 +45,20 @@ export const TaskbarTabs = new (class { this.#ready = initRegistry().then(registry => { this.#registry = registry; this.#windowManager = initWindowManager(registry); + initPinManager(registry); - this.#updateMetrics(); + this.#setupTelemetry(registry); }); } - #updateMetrics() { - Glean.webApp.installedWebAppCount.set(this.#registry.countTaskbarTabs()); + #setupTelemetry(aRegistry) { + function updateMetrics() { + Glean.webApp.installedWebAppCount.set(aRegistry.countTaskbarTabs()); + } + + aRegistry.on(kTaskbarTabsRegistryEvents.created, updateMetrics); + aRegistry.on(kTaskbarTabsRegistryEvents.removed, updateMetrics); + updateMetrics(); } async waitUntilReady() { @@ -65,16 +72,7 @@ export const TaskbarTabs = new (class { async findOrCreateTaskbarTab(...args) { await this.#ready; - let result = this.#registry.findOrCreateTaskbarTab(...args); - - if (result.created) { - this.#updateMetrics(); - - // Don't wait for the pinning to complete. - TaskbarTabsPin.pinTaskbarTab(result.taskbarTab, this.#registry); - } - - return result; + return this.#registry.findOrCreateTaskbarTab(...args); } async findTaskbarTab(...args) { @@ -105,7 +103,7 @@ export const TaskbarTabs = new (class { }), ]); - let { taskbarTab } = await this.findOrCreateTaskbarTab( + let taskbarTab = await this.findOrCreateTaskbarTab( url, userContextId, // 'manifest' can be null if the site doesn't have a manifest. @@ -126,12 +124,7 @@ export const TaskbarTabs = new (class { async removeTaskbarTab(...args) { await this.#ready; - - let taskbarTab = this.#registry.removeTaskbarTab(...args); - this.#updateMetrics(); - - // Don't wait for unpinning to finish. - TaskbarTabsPin.unpinTaskbarTab(taskbarTab, this.#registry); + return this.#registry.removeTaskbarTab(...args); } async openWindow(...args) { @@ -198,3 +191,17 @@ function initWindowManager() { return wm; } + +/** + * Taskbar Tabs Pinning initialization. + * + * @param {TaskbarTabsRegistry} aRegistry - A registry to drive events to trigger pinning. + */ +function initPinManager(aRegistry) { + aRegistry.on(kTaskbarTabsRegistryEvents.created, (_, taskbarTab) => { + return TaskbarTabsPin.pinTaskbarTab(taskbarTab, aRegistry); + }); + aRegistry.on(kTaskbarTabsRegistryEvents.removed, (_, taskbarTab) => { + return TaskbarTabsPin.unpinTaskbarTab(taskbarTab, aRegistry); + }); +} diff --git a/browser/components/taskbartabs/TaskbarTabsCmd.sys.mjs b/browser/components/taskbartabs/TaskbarTabsCmd.sys.mjs @@ -92,10 +92,10 @@ async function launchTaskbarTab(aContext) { Services.scriptSecurityManager.DEFAULT_USER_CONTEXT_ID; } - ({ taskbarTab } = await lazy.TaskbarTabs.findOrCreateTaskbarTab( + taskbarTab = await lazy.TaskbarTabs.findOrCreateTaskbarTab( aContext.url, aContext.userContextId - )); + ); } await lazy.TaskbarTabs.openWindow(taskbarTab); diff --git a/browser/components/taskbartabs/TaskbarTabsRegistry.sys.mjs b/browser/components/taskbartabs/TaskbarTabsRegistry.sys.mjs @@ -236,16 +236,12 @@ export class TaskbarTabsRegistry { * created. * @param {object} aDetails.manifest - The Web app manifest that should be * associated with this Taskbar Tab. - * @returns {{taskbarTab:TaskbarTab, created:bool}} - * The matching or created Taskbar Tab, along with whether it was created. + * @returns {TaskbarTab} The matching or created Taskbar Tab. */ findOrCreateTaskbarTab(aUrl, aUserContextId, { manifest = {} } = {}) { - let existing = this.findTaskbarTab(aUrl, aUserContextId); - if (existing) { - return { - created: false, - taskbarTab: existing, - }; + let taskbarTab = this.findTaskbarTab(aUrl, aUserContextId); + if (taskbarTab) { + return taskbarTab; } let scope = { hostname: aUrl.host }; @@ -262,7 +258,7 @@ export class TaskbarTabsRegistry { } let id = Services.uuid.generateUUID().toString().slice(1, -1); - let taskbarTab = new TaskbarTab({ + taskbarTab = new TaskbarTab({ id, scopes: [scope], userContextId: aUserContextId, @@ -276,18 +272,13 @@ export class TaskbarTabsRegistry { Glean.webApp.install.record({}); this.#emitter.emit(kTaskbarTabsRegistryEvents.created, taskbarTab); - return { - created: true, - taskbarTab, - }; + return taskbarTab; } /** * Removes a Taskbar Tab. * * @param {string} aId - The ID of the TaskbarTab to remove. - * @returns {TaskbarTab?} The removed taskbar tab, or null if it wasn't - * found. */ removeTaskbarTab(aId) { let tts = this.#taskbarTabs; @@ -301,11 +292,9 @@ export class TaskbarTabsRegistry { Glean.webApp.uninstall.record({}); this.#emitter.emit(kTaskbarTabsRegistryEvents.removed, removed[0]); - return removed[0]; + } else { + lazy.logConsole.error(`Taskbar Tab ID ${aId} not found.`); } - - lazy.logConsole.error(`Taskbar Tab ID ${aId} not found.`); - return null; } /** diff --git a/browser/components/taskbartabs/test/browser/browser_taskbarTabs_cmd.js b/browser/components/taskbartabs/test/browser/browser_taskbarTabs_cmd.js @@ -23,7 +23,7 @@ let taskbarTab1; add_setup(async () => { const url1 = Services.io.newURI("https://example.com"); const userContextId1 = 0; - taskbarTab1 = await createTaskbarTab(TaskbarTabs, url1, userContextId1); + taskbarTab1 = await TaskbarTabs.findOrCreateTaskbarTab(url1, userContextId1); // Reset memory of pinning being called. sinon.resetHistory(); diff --git a/browser/components/taskbartabs/test/browser/browser_taskbarTabs_content.js b/browser/components/taskbartabs/test/browser/browser_taskbarTabs_content.js @@ -12,7 +12,7 @@ const registry = new TaskbarTabsRegistry(); const url1 = Services.io.newURI("https://example.com"); const userContextId1 = 0; -const taskbarTab1 = createTaskbarTab(registry, url1, userContextId1); +const taskbarTab1 = registry.findOrCreateTaskbarTab(url1, userContextId1); const id1 = taskbarTab1.id; const checkMedia = (aBrowser, aMode) => diff --git a/browser/components/taskbartabs/test/browser/browser_taskbarTabs_manifest.js b/browser/components/taskbartabs/test/browser/browser_taskbarTabs_manifest.js @@ -178,7 +178,7 @@ add_task(async function test_scopeDistinguishesTaskbarTabs() { ); }, "/example/another/main"); }, "/example/main"); -}).skip(); // TODO bug 2000948 +}); async function usingManifest(aCallback, aLocation = "/") { const location = httpUrl("/taskbartabs-manifest.json"); @@ -197,7 +197,7 @@ async function usingManifest(aCallback, aLocation = "/") { let result = await TaskbarTabs.moveTabIntoTaskbarTab(tab); const uri = Services.io.newURI(httpUrl(aLocation)); - const tt = await TaskbarTabs.findTaskbarTab(uri, 0); + const tt = await TaskbarTabs.findOrCreateTaskbarTab(uri, 0); is( await TaskbarTabsUtils.getTaskbarTabIdFromWindow(result.window), tt.id, diff --git a/browser/components/taskbartabs/test/browser/browser_taskbarTabs_pageAction.js b/browser/components/taskbartabs/test/browser/browser_taskbarTabs_pageAction.js @@ -179,7 +179,7 @@ add_task(async function testRightClick() { }); const uri = Services.io.newURI(BASE_URL); - const taskbarTab = await createTaskbarTab(TaskbarTabs, uri, 0); + const taskbarTab = await TaskbarTabs.findOrCreateTaskbarTab(uri, 0); is( await TaskbarTabs.getCountForId(taskbarTab.id), 0, @@ -333,12 +333,10 @@ add_task(async function testPrefIsMonitored() { }); add_task(async function test_moveTabIntoTaskbarTabCreation() { + // Ensure example.com does not have a Taskbar Tab. const uri = Services.io.newURI(BASE_URL); - Assert.equal( - await TaskbarTabs.findTaskbarTab(uri, 0), - null, - "example.com does not already have a taskbar tab" - ); + const tt = await TaskbarTabs.findOrCreateTaskbarTab(uri, 0); + await TaskbarTabs.removeTaskbarTab(tt.id); await BrowserTestUtils.withNewTab("https://example.com/", async browser => { const tab = window.gBrowser.getTabForBrowser(browser); @@ -347,14 +345,13 @@ add_task(async function test_moveTabIntoTaskbarTabCreation() { const found = TaskbarTabsUtils.getTaskbarTabIdFromWindow(move.window); is(found, move.taskbarTab.id, "Returned Taskbar Tab matches window"); await BrowserTestUtils.closeWindow(move.window); - await TaskbarTabs.removeTaskbarTab(found); }); }); add_task(async function test_moveTabIntoTaskbarTabReuse() { // Ensure example.com has a Taskbar Tab. const uri = Services.io.newURI(BASE_URL); - const tt = await createTaskbarTab(TaskbarTabs, uri, 0); + const tt = await TaskbarTabs.findOrCreateTaskbarTab(uri, 0); await BrowserTestUtils.withNewTab("https://example.com/", async browser => { const tab = window.gBrowser.getTabForBrowser(browser); @@ -363,8 +360,8 @@ add_task(async function test_moveTabIntoTaskbarTabReuse() { const found = TaskbarTabsUtils.getTaskbarTabIdFromWindow(move.window); is(found, move.taskbarTab.id, "Returned Taskbar Tab matches window"); is(tt.id, move.taskbarTab.id, "Returned Taskbar Tab existed before"); - await BrowserTestUtils.closeWindow(move.window); await TaskbarTabs.removeTaskbarTab(tt.id); + await BrowserTestUtils.closeWindow(move.window); }); }); @@ -382,7 +379,7 @@ add_task(async function test_page_action_uses_manifest() { const win = await newWinPromise; const uri = Services.io.newURI(url); - const tt = await TaskbarTabs.findTaskbarTab(uri, 0); + const tt = await TaskbarTabs.findOrCreateTaskbarTab(uri, 0); is( await TaskbarTabsUtils.getTaskbarTabIdFromWindow(win), tt.id, @@ -390,7 +387,7 @@ add_task(async function test_page_action_uses_manifest() { ); is(tt.name, "Mochitest", "Manifest name was used"); - await BrowserTestUtils.closeWindow(win); await TaskbarTabs.removeTaskbarTab(tt.id); + await BrowserTestUtils.closeWindow(win); }); }); diff --git a/browser/components/taskbartabs/test/browser/browser_taskbarTabs_telemetry.js b/browser/components/taskbartabs/test/browser/browser_taskbarTabs_telemetry.js @@ -63,7 +63,7 @@ add_task(async function testInstallAndUninstallMetric() { Services.fog.testResetFOG(); let snapshot; - const taskbarTab = createTaskbarTab(gRegistry, PARSED_URL, 0); + const taskbarTab = gRegistry.findOrCreateTaskbarTab(PARSED_URL, 0); snapshot = Glean.webApp.install.testGetValue(); is(snapshot.length, 1, "Should have recorded an 'install' event"); @@ -76,7 +76,7 @@ add_task(async function testInstallAndUninstallMetric() { async function testPinMetricCustom(aPinResult, aPinMessage = null) { let snapshot; - const taskbarTab = createTaskbarTab(gRegistry, PARSED_URL, 0); + const taskbarTab = gRegistry.findOrCreateTaskbarTab(PARSED_URL, 0); Services.fog.testResetFOG(); gShortcutPinResult = aPinResult; @@ -113,7 +113,7 @@ async function testUnpinMetricCustom( ) { let snapshot; - const taskbarTab = createTaskbarTab(gRegistry, PARSED_URL, 0); + const taskbarTab = gRegistry.findOrCreateTaskbarTab(PARSED_URL, 0); Services.fog.testResetFOG(); gShortcutPinResult = aUnpinResult; @@ -163,7 +163,7 @@ add_task(async function testPinAndUnpinMetric_DeleteInvalid() { }); add_task(async function testActivateWhenWindowOpened() { - const taskbarTab = createTaskbarTab(gRegistry, PARSED_URL, 0); + const taskbarTab = gRegistry.findOrCreateTaskbarTab(PARSED_URL, 0); Services.fog.testResetFOG(); const win1 = await gWindowManager.openWindow(taskbarTab); @@ -182,7 +182,7 @@ add_task(async function testActivateWhenWindowOpened() { add_task(async function testMoveToTaskbarLowLevelMetric() { Services.fog.testResetFOG(); - const taskbarTab = createTaskbarTab(gRegistry, PARSED_URL, 0); + const taskbarTab = gRegistry.findOrCreateTaskbarTab(PARSED_URL, 0); is( Glean.webApp.moveToTaskbar.testGetValue(), null, @@ -241,7 +241,7 @@ add_task(async function testMoveToTaskbarHighLevelMetric() { }); add_task(async function testEjectMetric() { - const taskbarTab = createTaskbarTab(gRegistry, PARSED_URL, 0); + const taskbarTab = gRegistry.findOrCreateTaskbarTab(PARSED_URL, 0); Services.fog.testResetFOG(); const win = await gWindowManager.openWindow(taskbarTab); @@ -262,7 +262,7 @@ add_task(async function testEjectMetric() { }); add_task(async function testUsageTimeMetricSingleWindow() { - const taskbarTab = createTaskbarTab(gRegistry, PARSED_URL, 0); + const taskbarTab = gRegistry.findOrCreateTaskbarTab(PARSED_URL, 0); Services.fog.testResetFOG(); const win = await gWindowManager.openWindow(taskbarTab); diff --git a/browser/components/taskbartabs/test/browser/browser_taskbarTabs_title.js b/browser/components/taskbartabs/test/browser/browser_taskbarTabs_title.js @@ -48,8 +48,7 @@ async function phaseBeforeContentTitle(aContainer, aProfileName) { return TaskbarTabs.getTaskbarTab(...args); }); - const tt = await createTaskbarTab( - TaskbarTabs, + const tt = await TaskbarTabs.findOrCreateTaskbarTab( Services.io.newURI("https://example.com/"), aContainer, { @@ -71,10 +70,7 @@ async function phaseBeforeContentTitle(aContainer, aProfileName) { // tick and hopefully that's enough. await TestUtils.waitForTick(); - return { - win, - tt, - }; + return win; } async function phaseAfterContentTitle(aWindow) { @@ -101,7 +97,7 @@ function assertHasContainerName(aPrivate, aTitle) { } async function test_defaultCase(aPrivate) { - const { tt, win } = await phaseBeforeContentTitle(0, null, aPrivate); + const win = await phaseBeforeContentTitle(0, null, aPrivate); const title = win.document.title; assertHasTaskbarTabName(aPrivate, title); ok(!title.includes(kUserContextLabel), "Doesn't include container name"); @@ -111,11 +107,10 @@ async function test_defaultCase(aPrivate) { ok(!title.includes(kUserContextLabel), "Title still has no container name"); await BrowserTestUtils.closeWindow(win); - await TaskbarTabs.removeTaskbarTab(tt.id); } async function test_container(aPrivate) { - const { tt, win } = await phaseBeforeContentTitle(1, null, aPrivate); + const win = await phaseBeforeContentTitle(1, null, aPrivate); const title = win.document.title; assertHasTaskbarTabName(aPrivate, title); assertHasContainerName(aPrivate, title); @@ -125,15 +120,10 @@ async function test_container(aPrivate) { assertHasContainerName(aPrivate, title); await BrowserTestUtils.closeWindow(win); - await TaskbarTabs.removeTaskbarTab(tt.id); } async function test_profile(aPrivate) { - const { tt, win } = await phaseBeforeContentTitle( - 0, - kGenericProfileName, - aPrivate - ); + const win = await phaseBeforeContentTitle(0, kGenericProfileName, aPrivate); const title = win.document.title; assertHasTaskbarTabName(aPrivate, title); ok(!title.includes(kUserContextLabel), "Doesn't include container name"); @@ -145,15 +135,10 @@ async function test_profile(aPrivate) { ok(title.includes(kGenericProfileName), "Does include profile name"); await BrowserTestUtils.closeWindow(win); - await TaskbarTabs.removeTaskbarTab(tt.id); } async function test_profileAndContainer(aPrivate) { - const { tt, win } = await phaseBeforeContentTitle( - 1, - kGenericProfileName, - aPrivate - ); + const win = await phaseBeforeContentTitle(1, kGenericProfileName, aPrivate); const title = win.document.title; assertHasTaskbarTabName(aPrivate, title); assertHasContainerName(aPrivate, title); @@ -165,7 +150,6 @@ async function test_profileAndContainer(aPrivate) { ok(title.includes(kGenericProfileName), "Does include profile name"); await BrowserTestUtils.closeWindow(win); - await TaskbarTabs.removeTaskbarTab(tt.id); } async function withoutExposingTitle(aTestCase) { diff --git a/browser/components/taskbartabs/test/browser/browser_taskbarTabs_windowManager.js b/browser/components/taskbartabs/test/browser/browser_taskbarTabs_windowManager.js @@ -17,12 +17,12 @@ const registry = new TaskbarTabsRegistry(); const url1 = Services.io.newURI("https://example.com"); const userContextId1 = 0; -const taskbarTab1 = createTaskbarTab(registry, url1, userContextId1); +const taskbarTab1 = registry.findOrCreateTaskbarTab(url1, userContextId1); const id1 = taskbarTab1.id; const url2 = Services.io.newURI("https://subdomain.example.com"); const userContextId2 = 1; -const taskbarTab2 = createTaskbarTab(registry, url2, userContextId2); +const taskbarTab2 = registry.findOrCreateTaskbarTab(url2, userContextId2); const id2 = taskbarTab2.id; add_task(async function test_count_for_id() { diff --git a/browser/components/taskbartabs/test/browser/head.js b/browser/components/taskbartabs/test/browser/head.js @@ -25,7 +25,7 @@ async function openTaskbarTabWindow(aTab = null) { const userContextId = 0; const registry = new TaskbarTabsRegistry(); - const taskbarTab = createTaskbarTab(registry, url, userContextId); + const taskbarTab = registry.findOrCreateTaskbarTab(url, userContextId); const windowManager = new TaskbarTabsWindowManager(); const windowPromise = BrowserTestUtils.waitForNewWindow(); @@ -38,30 +38,3 @@ async function openTaskbarTabWindow(aTab = null) { return await windowPromise; } - -/** - * Creates a new Taskbar Tab within the registry, and asserts that it does not - * already exist. - * - * (This function is also in xpcshell/head.js.) - * - * @param {TaskbarTabsRegistry|TaskbarTabs} aRegistry - * The registry to create the taskbar tab in. - * @param {...*} args - * Arguments to findOrCreateTaskbarTab. - * @returns {TaskbarTab} - * The newly-created taskbar tab. - */ -function createTaskbarTab(aRegistry, ...args) { - let result = aRegistry.findOrCreateTaskbarTab(...args); - function check({ taskbarTab, created }) { - Assert.ok(created, "Created taskbar tab did not exist before"); - return taskbarTab; - } - - if (result.then) { - return result.then(check); - } - - return check(result); -} diff --git a/browser/components/taskbartabs/test/xpcshell/head.js b/browser/components/taskbartabs/test/xpcshell/head.js @@ -1,32 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -/** - * Creates a new Taskbar Tab within the registry, and asserts that it does not - * already exist. - * - * (This function is also in xpcshell/head.js.) - * - * @param {TaskbarTabsRegistry|TaskbarTabs} aRegistry - * The registry to create the taskbar tab in. - * @param {...*} args - * Arguments to findOrCreateTaskbarTab. - * @returns {TaskbarTab} - * The newly-created taskbar tab. - */ -function createTaskbarTab(aRegistry, ...args) { - let result = aRegistry.findOrCreateTaskbarTab(...args); - function check({ taskbarTab, created }) { - Assert.ok(created, "Created taskbar tab did not exist before"); - return taskbarTab; - } - - if (result.then) { - return result.then(check); - } - - return check(result); -} diff --git a/browser/components/taskbartabs/test/xpcshell/test_TaskbarTabsRegistry.js b/browser/components/taskbartabs/test/xpcshell/test_TaskbarTabsRegistry.js @@ -35,7 +35,7 @@ add_task(async function test_create_taskbar_tab() { "Initially, no Taskbar Tab should exist for the given URL and container." ); - const taskbarTab = createTaskbarTab(registry, url, userContextId); + const taskbarTab = registry.findOrCreateTaskbarTab(url, userContextId); Assert.ok(taskbarTab, "Taskbar Tab should be created."); Assert.deepEqual( @@ -46,8 +46,7 @@ add_task(async function test_create_taskbar_tab() { const secondUrl = Services.io.newURI("https://www.another-test.com/start"); const secondUserContextId = 1; - const secondTaskbarTab = createTaskbarTab( - registry, + const secondTaskbarTab = registry.findOrCreateTaskbarTab( secondUrl, secondUserContextId ); @@ -62,17 +61,12 @@ add_task(async function test_create_taskbar_tab() { "Second Taskbar Tab created should still be present." ); - const repeated = registry.findOrCreateTaskbarTab( + const repeatTaskbarTab = registry.findOrCreateTaskbarTab( secondUrl, secondUserContextId ); - Assert.equal( - repeated.created, - false, - "The existing taskbar tab should have been found, not created" - ); Assert.deepEqual( - repeated.taskbarTab, + repeatTaskbarTab, secondTaskbarTab, "Should have found the second created Taskbar Tab instead of creating a new Taskbar Tab." ); @@ -83,7 +77,7 @@ add_task(async function test_remove_taskbar_tab() { const userContextId = 0; const registry = new TaskbarTabsRegistry(); - const taskbarTab = createTaskbarTab(registry, url, userContextId); + const taskbarTab = registry.findOrCreateTaskbarTab(url, userContextId); Assert.deepEqual( registry.findTaskbarTab(url, userContextId), @@ -91,22 +85,12 @@ add_task(async function test_remove_taskbar_tab() { "Taskbar Tab ID should match the ID returned on creation." ); - Assert.deepEqual( - registry.removeTaskbarTab(taskbarTab.id), - taskbarTab, - "The removed Taskbar Tab was removed" - ); + registry.removeTaskbarTab(taskbarTab.id); Assert.ok( !registry.findTaskbarTab(url, userContextId), "Taskbar Tab ID should be removed." ); - - Assert.strictEqual( - registry.removeTaskbarTab(taskbarTab.id), - null, - "Null was returned since no Taskbar Tab with that ID exists" - ); }); add_task(async function test_container_mismatch() { @@ -115,7 +99,7 @@ add_task(async function test_container_mismatch() { const mismatchedUserContextId = 1; const registry = new TaskbarTabsRegistry(); - const taskbarTab = createTaskbarTab(registry, url, userContextId); + const taskbarTab = registry.findOrCreateTaskbarTab(url, userContextId); Assert.ok(taskbarTab, "Taskbar Tab ID should be created."); Assert.ok( @@ -136,7 +120,7 @@ add_task(async function test_scope_navigable() { const userContextId = 0; const registry = new TaskbarTabsRegistry(); - const taskbarTab = createTaskbarTab(registry, url, userContextId); + const taskbarTab = registry.findOrCreateTaskbarTab(url, userContextId); Assert.ok( taskbarTab.isScopeNavigable(validNavigationDomain), @@ -161,7 +145,7 @@ add_task(async function test_psl_navigable() { const userContextId = 0; const registry = new TaskbarTabsRegistry(); - const taskbarTab = createTaskbarTab(registry, url, userContextId); + const taskbarTab = registry.findOrCreateTaskbarTab(url, userContextId); Assert.ok( !taskbarTab.isScopeNavigable(invalidNavigationPublicSuffixList), @@ -174,7 +158,10 @@ add_task(async function test_save_and_load_consistency() { const userContextId = 0; let saveRegistry = new TaskbarTabsRegistry(); - const saveTaskbarTab = createTaskbarTab(saveRegistry, url, userContextId); + const saveTaskbarTab = saveRegistry.findOrCreateTaskbarTab( + url, + userContextId + ); let file = testFile(); let storage = new TaskbarTabsRegistryStorage(saveRegistry, file); @@ -276,7 +263,7 @@ add_task(async function test_guards_against_non_urls() { const registry = new TaskbarTabsRegistry(); throws( - () => createTaskbarTab(registry, url, userContextId), + () => registry.findOrCreateTaskbarTab(url, userContextId), /Invalid argument, `aUrl` should be instance of `nsIURL`/, "Should reject URIs that are not URLs." ); @@ -284,8 +271,7 @@ add_task(async function test_guards_against_non_urls() { add_task(async function test_patch_becomes_visible() { const registry = new TaskbarTabsRegistry(); - const tt = createTaskbarTab( - registry, + const tt = registry.findOrCreateTaskbarTab( Services.io.newURI("https://www.test.com/start"), 0 ); @@ -313,8 +299,7 @@ add_task(async function test_patch_becomes_visible() { add_task(async function test_shortcutRelativePath_is_saved() { const registry = new TaskbarTabsRegistry(); - const tt = createTaskbarTab( - registry, + const tt = registry.findOrCreateTaskbarTab( Services.io.newURI("https://www.test.com/start"), 0 ); @@ -342,7 +327,7 @@ add_task(async function test_multiple_match_longest_prefix() { Services.io.newURI("https://example.com" + prefix); const createWithScope = uri => - createTaskbarTab(registry, uri, 0, { + registry.findOrCreateTaskbarTab(uri, 0, { manifest: { scope: uri.spec, }, @@ -368,4 +353,4 @@ add_task(async function test_multiple_match_longest_prefix() { equal(find("/abc/d/").id, ttABCD.id, "/abc/d/ matches /abc/d/"); equal(find("/abc/d/efgh").id, ttABCD.id, "/abc/d/efgh matches /abc/d/"); -}).skip(); // TODO bug 2000948 +}); diff --git a/browser/components/taskbartabs/test/xpcshell/test_taskbarTabs_existingInstalledCountMetric.js b/browser/components/taskbartabs/test/xpcshell/test_taskbarTabs_existingInstalledCountMetric.js @@ -52,14 +52,13 @@ add_task(async function test_installedCounterMetric() { equal(value(), 1, "The existing Taskbar Tab was counted"); - const { taskbarTab, created } = await TaskbarTabs.findOrCreateTaskbarTab( + const tt = await TaskbarTabs.findOrCreateTaskbarTab( Services.io.newURI("https://www.test.com"), 0 ); - equal(created, false, "No new Taskbar Tab was created"); - equal(taskbarTab.id, kId, "Correct Taskbar Tab was found"); + equal(tt.id, kId, "Correct Taskbar Tab was found"); equal(value(), 1, "Finding a Taskbar Tab does not affect the count"); - await TaskbarTabs.removeTaskbarTab(taskbarTab.id); + await TaskbarTabs.removeTaskbarTab(tt.id); equal(value(), 0, "Removing the taskbar tab was accounted for"); }); diff --git a/browser/components/taskbartabs/test/xpcshell/test_taskbarTabs_installedCountMetric.js b/browser/components/taskbartabs/test/xpcshell/test_taskbarTabs_installedCountMetric.js @@ -36,15 +36,13 @@ add_task(async function test_installedCounterMetric() { equal(value(), 0, "No taskbar tabs exist yet"); - const tt1 = await createTaskbarTab( - TaskbarTabs, + const tt1 = await TaskbarTabs.findOrCreateTaskbarTab( Services.io.newURI("https://example.com"), 0 ); equal(value(), 1, "First new taskbar tab was accounted for"); - const tt2 = await createTaskbarTab( - TaskbarTabs, + const tt2 = await TaskbarTabs.findOrCreateTaskbarTab( Services.io.newURI("https://example.edu"), 0 ); diff --git a/browser/components/taskbartabs/test/xpcshell/test_taskbarTabs_pin.js b/browser/components/taskbartabs/test/xpcshell/test_taskbarTabs_pin.js @@ -159,7 +159,7 @@ const url = Services.io.newURI("https://www.test.com"); const userContextId = 0; const registry = new TaskbarTabsRegistry(); -const taskbarTab = createTaskbarTab(registry, url, userContextId); +const taskbarTab = registry.findOrCreateTaskbarTab(url, userContextId); const patchedSpy = sinon.stub(); registry.on(TaskbarTabsRegistry.events.patched, patchedSpy); @@ -261,7 +261,7 @@ add_task(async function test_pin_location() { add_task(async function test_pin_location_dos_name() { const parsedURI = Services.io.newURI("https://aux.test"); - const invalidTaskbarTab = createTaskbarTab(registry, parsedURI, 0); + const invalidTaskbarTab = registry.findOrCreateTaskbarTab(parsedURI, 0); sinon.resetHistory(); await TaskbarTabsPin.pinTaskbarTab(invalidTaskbarTab, registry); @@ -291,7 +291,7 @@ add_task(async function test_pin_location_dos_name() { add_task(async function test_pin_location_bad_characters() { const parsedURI = Services.io.newURI("https://another.test"); - const invalidTaskbarTab = createTaskbarTab(registry, parsedURI, 0, { + const invalidTaskbarTab = registry.findOrCreateTaskbarTab(parsedURI, 0, { manifest: { name: "** :\t\r\n \\\\ >> Not a valid. filename??! << // |||: **.", }, @@ -316,7 +316,7 @@ add_task(async function test_pin_location_bad_characters() { add_task(async function test_pin_location_lnk_extension() { const parsedURI = Services.io.newURI("https://another.test"); - const invalidTaskbarTab = createTaskbarTab(registry, parsedURI, 0, { + const invalidTaskbarTab = registry.findOrCreateTaskbarTab(parsedURI, 0, { manifest: { name: "coolstartup.lnk", }, diff --git a/browser/components/taskbartabs/test/xpcshell/xpcshell.toml b/browser/components/taskbartabs/test/xpcshell/xpcshell.toml @@ -1,6 +1,5 @@ [DEFAULT] firefox-appdir = "browser" -head = "head.js" run-if = [ "os == 'win'", ]