tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit c943c5eecf75d89279b9f53b0a86d86913e12c72
parent cb7d6e60469b7f2f43610132a19453b5a86dc8c7
Author: Rob Wu <rob@robwu.nl>
Date:   Thu,  9 Oct 2025 01:59:34 +0000

Bug 1814871 - Move extension button/panel tests relating involving no extensions to its own file r=rpl

head_unified_extensions.js contains two tests that verify the behavior
when there are no extensions. In preparation for changing these
behaviors, this patch moves the tests to its own file.

Moreover, this patch changes the way that the empty panels is simulated.
Rather than starting each test with stubbing out the
gUnifiedExtensions.getActivePolicies() implementation to suppress the
unwanted test extensions, we now hide the test extensions explicitly.
Besides being more realistically matching what non-test users see, this
also ensures that the mock is applied to all browser windows, instead of
just the browser window that was opened in the test.

Differential Revision: https://phabricator.services.mozilla.com/D265131

Diffstat:
Mbrowser/components/extensions/test/browser/browser.toml | 2++
Mbrowser/components/extensions/test/browser/browser_unified_extensions.js | 106-------------------------------------------------------------------------------
Abrowser/components/extensions/test/browser/browser_unified_extensions_empty_panel.js | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 128 insertions(+), 106 deletions(-)

diff --git a/browser/components/extensions/test/browser/browser.toml b/browser/components/extensions/test/browser/browser.toml @@ -751,6 +751,8 @@ support-files = ["!/toolkit/mozapps/extensions/test/xpinstall/amosigned.xpi"] ["browser_unified_extensions_doorhangers_postinstall.js"] +["browser_unified_extensions_empty_panel.js"] + ["browser_unified_extensions_item_messagebar.js"] ["browser_unified_extensions_messages.js"] diff --git a/browser/components/extensions/test/browser/browser_unified_extensions.js b/browser/components/extensions/test/browser/browser_unified_extensions.js @@ -401,112 +401,6 @@ add_task(async function test_list_active_extensions_only() { await Promise.all(extensions.map(extension => extension.unload())); }); -add_task(async function test_button_opens_discopane_when_no_extension() { - // The test harness registers regular extensions so we need to mock the - // `getActivePolicies` extension to simulate zero extensions installed. - const origGetActivePolicies = gUnifiedExtensions.getActivePolicies; - gUnifiedExtensions.getActivePolicies = () => []; - - await BrowserTestUtils.withNewTab( - { gBrowser, url: "about:robots" }, - async () => { - const { button } = gUnifiedExtensions; - ok(button, "expected button"); - - // Primary click should open about:addons. - const tabPromise = BrowserTestUtils.waitForNewTab( - gBrowser, - "about:addons", - true - ); - - button.click(); - - const tab = await tabPromise; - is( - gBrowser.currentURI.spec, - "about:addons", - "expected about:addons to be open" - ); - is( - gBrowser.selectedBrowser.contentWindow.gViewController.currentViewId, - "addons://discover/", - "expected about:addons to show the recommendations" - ); - BrowserTestUtils.removeTab(tab); - - // "Right-click" should open the context menu only. - const contextMenu = document.getElementById("toolbar-context-menu"); - const popupShownPromise = BrowserTestUtils.waitForEvent( - contextMenu, - "popupshown" - ); - EventUtils.synthesizeMouseAtCenter(button, { - type: "contextmenu", - button: 2, - }); - await popupShownPromise; - await closeChromeContextMenu(contextMenu.id, null); - } - ); - - gUnifiedExtensions.getActivePolicies = origGetActivePolicies; -}); - -add_task( - async function test_button_opens_extlist_when_no_extension_and_pane_disabled() { - // If extensions.getAddons.showPane is set to false, there is no "Recommended" tab, - // so we need to make sure we don't navigate to it. - - // The test harness registers regular extensions so we need to mock the - // `getActivePolicies` extension to simulate zero extensions installed. - const origGetActivePolicies = gUnifiedExtensions.getActivePolicies; - gUnifiedExtensions.getActivePolicies = () => []; - - await SpecialPowers.pushPrefEnv({ - set: [ - // Set this to another value to make sure not to "accidentally" land on the right page - ["extensions.ui.lastCategory", "addons://list/theme"], - ["extensions.getAddons.showPane", false], - ], - }); - - await BrowserTestUtils.withNewTab( - { gBrowser, url: "about:robots" }, - async () => { - const { button } = gUnifiedExtensions; - ok(button, "expected button"); - - // Primary click should open about:addons. - const tabPromise = BrowserTestUtils.waitForNewTab( - gBrowser, - "about:addons", - true - ); - - button.click(); - - const tab = await tabPromise; - is( - gBrowser.currentURI.spec, - "about:addons", - "expected about:addons to be open" - ); - is( - gBrowser.selectedBrowser.contentWindow.gViewController.currentViewId, - "addons://list/extension", - "expected about:addons to show the extension list" - ); - BrowserTestUtils.removeTab(tab); - } - ); - - await SpecialPowers.popPrefEnv(); - - gUnifiedExtensions.getActivePolicies = origGetActivePolicies; - } -); - add_task( async function test_unified_extensions_panel_not_open_in_customization_mode() { const listView = getListView(); diff --git a/browser/components/extensions/test/browser/browser_unified_extensions_empty_panel.js b/browser/components/extensions/test/browser/browser_unified_extensions_empty_panel.js @@ -0,0 +1,126 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { sinon } = ChromeUtils.importESModule( + "resource://testing-common/Sinon.sys.mjs" +); + +loadTestSubscript("head_unified_extensions.js"); + +add_setup(async function () { + // Make sure extension buttons added to the navbar will not overflow in the + // panel, which could happen when a previous test file resizes the current + // window. + await ensureMaximizedWindow(window); + + const sandbox = sinon.createSandbox(); + registerCleanupFunction(() => sandbox.restore()); + + // The test harness registers test extensions which affects the rendered + // button and panel. This matters especially for tests that want to verify + // the behavior when there are no extensions to render in the list. + // Temporarily fake-hide these extensions to ensure that we start with zero + // extensions from the test's POV. + function fakeHideExtension(extensionId) { + const { extension } = WebExtensionPolicy.getByID(extensionId); + // This shadows ExtensionData.isHidden of the Extension subclass, causing + // gUnifiedExtensions.getActivePolicies() to ignore the extension. + sandbox.stub(extension, "isHidden").get(() => true); + } + fakeHideExtension("mochikit@mozilla.org"); + fakeHideExtension("special-powers@mozilla.org"); +}); + +add_task(async function test_button_opens_discopane_when_no_extension() { + await BrowserTestUtils.withNewTab( + { gBrowser, url: "about:robots" }, + async () => { + const { button } = gUnifiedExtensions; + ok(button, "expected button"); + + // Primary click should open about:addons. + const tabPromise = BrowserTestUtils.waitForNewTab( + gBrowser, + "about:addons", + true + ); + + button.click(); + + const tab = await tabPromise; + is( + gBrowser.currentURI.spec, + "about:addons", + "expected about:addons to be open" + ); + is( + gBrowser.selectedBrowser.contentWindow.gViewController.currentViewId, + "addons://discover/", + "expected about:addons to show the recommendations" + ); + BrowserTestUtils.removeTab(tab); + + // "Right-click" should open the context menu only. + const contextMenu = document.getElementById("toolbar-context-menu"); + const popupShownPromise = BrowserTestUtils.waitForEvent( + contextMenu, + "popupshown" + ); + EventUtils.synthesizeMouseAtCenter(button, { + type: "contextmenu", + button: 2, + }); + await popupShownPromise; + await closeChromeContextMenu(contextMenu.id, null); + } + ); +}); + +add_task( + async function test_button_opens_extlist_when_no_extension_and_pane_disabled() { + // If extensions.getAddons.showPane is set to false, there is no "Recommended" tab, + // so we need to make sure we don't navigate to it. + + await SpecialPowers.pushPrefEnv({ + set: [ + // Set this to another value to make sure not to "accidentally" land on the right page + ["extensions.ui.lastCategory", "addons://list/theme"], + ["extensions.getAddons.showPane", false], + ], + }); + + await BrowserTestUtils.withNewTab( + { gBrowser, url: "about:robots" }, + async () => { + const { button } = gUnifiedExtensions; + ok(button, "expected button"); + + // Primary click should open about:addons. + const tabPromise = BrowserTestUtils.waitForNewTab( + gBrowser, + "about:addons", + true + ); + + button.click(); + + const tab = await tabPromise; + is( + gBrowser.currentURI.spec, + "about:addons", + "expected about:addons to be open" + ); + is( + gBrowser.selectedBrowser.contentWindow.gViewController.currentViewId, + "addons://list/extension", + "expected about:addons to show the extension list" + ); + BrowserTestUtils.removeTab(tab); + } + ); + + await SpecialPowers.popPrefEnv(); + } +);