tor-browser

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

commit ee39d4dc9f95f1e654958c17db1aba0079c8130d
parent fc3c63758b5d8a951a89e7b00f8b7b22e839e467
Author: Nikki Sharpley <nsharpley@mozilla.com>
Date:   Wed, 29 Oct 2025 15:34:38 +0000

Bug 1983325 - Green up the browser/base/content/test/general tests when enabling sidebar.revamp by default r=kcochrane

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

Diffstat:
Mbrowser/base/content/test/general/browser.toml | 2+-
Dbrowser/base/content/test/general/browser_backButtonFitts.js | 43-------------------------------------------
Abrowser/base/content/test/general/browser_backOrSidebarButtonFitts.js | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 44 deletions(-)

diff --git a/browser/base/content/test/general/browser.toml b/browser/base/content/test/general/browser.toml @@ -44,7 +44,7 @@ support-files = [ ["browser_addCertException.js"] # DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD. -["browser_backButtonFitts.js"] +["browser_backOrSidebarButtonFitts.js"] https_first_disabled = true # DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD. diff --git a/browser/base/content/test/general/browser_backButtonFitts.js b/browser/base/content/test/general/browser_backButtonFitts.js @@ -1,43 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -add_task(async function () { - let firstLocation = - // eslint-disable-next-line @microsoft/sdl/no-insecure-url - "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; - await BrowserTestUtils.openNewForegroundTab(gBrowser, firstLocation); - - await ContentTask.spawn(gBrowser.selectedBrowser, {}, async function () { - // Mark the first entry as having been interacted with. - content.document.notifyUserGestureActivation(); - - // Push the state before maximizing the window and clicking below. - content.history.pushState("page2", "page2", "page2"); - }); - - window.maximize(); - - // Find where the nav-bar is vertically. - var navBar = document.getElementById("nav-bar"); - var boundingRect = navBar.getBoundingClientRect(); - var yPixel = boundingRect.top + Math.floor(boundingRect.height / 2); - var xPixel = 0; // Use the first pixel of the screen since it is maximized. - - let popStatePromise = BrowserTestUtils.waitForContentEvent( - gBrowser.selectedBrowser, - "popstate", - true - ); - EventUtils.synthesizeMouseAtPoint(xPixel, yPixel, {}, window); - await popStatePromise; - - is( - gBrowser.selectedBrowser.currentURI.spec, - firstLocation, - "Clicking the first pixel should have navigated back." - ); - window.restore(); - - gBrowser.removeCurrentTab(); -}); diff --git a/browser/base/content/test/general/browser_backOrSidebarButtonFitts.js b/browser/base/content/test/general/browser_backOrSidebarButtonFitts.js @@ -0,0 +1,77 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +async function test_back_button(x, y) { + // If the first button is the back button, set up history. + let firstLocation = + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; + await BrowserTestUtils.openNewForegroundTab(gBrowser, firstLocation); + await ContentTask.spawn(gBrowser.selectedBrowser, {}, async function () { + // Mark the first entry as having been interacted with. + content.document.notifyUserGestureActivation(); + content.history.pushState("page2", "page2", "page2"); + }); + + let popStatePromise = BrowserTestUtils.waitForContentEvent( + gBrowser.selectedBrowser, + "popstate", + true + ); + EventUtils.synthesizeMouseAtPoint(x, y, {}, window); + await popStatePromise; + is( + gBrowser.selectedBrowser.currentURI.spec, + firstLocation, + "Clicking the first pixel should have navigated back." + ); + gBrowser.removeCurrentTab(); +} + +async function test_sidebar_button(x, y) { + // If the first button is the sidebar, check initial sidebar state + let sidebarMain = document.getElementById("sidebar-main"); + let initialSidebarHiddenState = sidebarMain.hidden; + + EventUtils.synthesizeMouseAtPoint(x, y, {}, window); + is( + sidebarMain.hidden, + !initialSidebarHiddenState, + "Clicking the first pixel should toggle the sidebar" + ); + + // Ensure sidebar is put back into original state for following tests + EventUtils.synthesizeMouseAtPoint(x, y, {}, window); + is( + sidebarMain.hidden, + initialSidebarHiddenState, + "Clicking the first pixel should toggle the sidebar" + ); + Services.prefs.clearUserPref("browser.engagement.sidebar-button.has-used"); +} + +add_task(async function () { + let navBarCustomizationTarget = document.getElementById( + "nav-bar-customization-target" + ); + // The first button in the nav bar could be either the back or sidebar button, depending + // on whether sidebar.revamp is true and what OS we are using. + let firstNavBarButton = navBarCustomizationTarget.childNodes[0].id; + + window.maximize(); + + // Find where the nav-bar is vertically. + var navBar = document.getElementById("nav-bar"); + var boundingRect = navBar.getBoundingClientRect(); + var yPixel = boundingRect.top + Math.floor(boundingRect.height / 2); + var xPixel = 0; // Use the first pixel of the screen since it is maximized. + + if (firstNavBarButton == "back-button") { + await test_back_button(xPixel, yPixel); + } else if (firstNavBarButton == "sidebar-button") { + await test_sidebar_button(xPixel, yPixel); + } + + window.restore(); +});