tor-browser

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

commit 092473b3a40cac386cda52db7369439b2276f38a
parent 18b66ea8b7e4bda797bf8af8f32808125c3a2a95
Author: Dharma Ong <dharmaong00@gmail.com>
Date:   Thu, 27 Nov 2025 17:04:15 +0000

Bug 1961688 - Compute values for breakout perf test instead of using magic numbers. r=jteow

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

Diffstat:
Mbrowser/base/content/test/performance/head.js | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 60 insertions(+), 8 deletions(-)

diff --git a/browser/base/content/test/performance/head.js b/browser/base/content/test/performance/head.js @@ -770,6 +770,10 @@ async function runUrlbarTest( URLBar.focus(); URLBar.value = SEARCH_TERM; + + let SHADOW_OVERFLOW_LEFT, SHADOW_OVERFLOW_RIGHT, SHADOW_OVERFLOW_TOP; + let INLINE_MARGIN, VERTICAL_OFFSET; + let testFn = async function () { let popup = URLBar.view; let oldOnQueryResults = popup.onQueryResults.bind(popup); @@ -820,22 +824,69 @@ async function runUrlbarTest( await waitExtra(); } + let shadowElem = win.document.querySelector("#urlbar > .urlbar-background"); + let shadow = getComputedStyle(shadowElem).boxShadow; + + let inlineElem = win.document.querySelector("#urlbar"); + let inlineMargin = getComputedStyle(inlineElem).marginInlineStart; + + let offsetElem = win.document.querySelector("#urlbar-container"); + let verticalOffset = getComputedStyle(offsetElem).paddingTop; + + function extractPixelValue(value) { + if (value) { + return parseInt(value.replace("px", ""), 10); + } + return 0; + } + + function calculateShadowOverflow(boxShadow) { + const regex = /-?\d+px/g; + const matches = boxShadow.match(regex); + + if (matches && matches.length >= 2) { + // Parse shadow values, defaulting missing values to 0. + const [offsetX, offsetY, blurRadius = 0, spreadRadius = 0] = + matches.map(value => parseInt(value.replace("px", ""), 10)); + + const left = Math.max(0, -offsetX + blurRadius + spreadRadius); + const right = Math.max(0, offsetX + blurRadius + spreadRadius); + const top = Math.max(0, -offsetY + blurRadius + spreadRadius); + const bottom = Math.max(0, offsetY + blurRadius + spreadRadius); + + return { left, right, top, bottom }; + } + + return { left: 0, right: 0, top: 0, bottom: 0 }; + } + + let overflow = calculateShadowOverflow(shadow); + const FUZZ_FACTOR = 4; + // The blur/spread/offset of the box shadow, plus fudge factors depending on platform. + SHADOW_OVERFLOW_LEFT = overflow.left + FUZZ_FACTOR; + SHADOW_OVERFLOW_RIGHT = overflow.right + FUZZ_FACTOR; + SHADOW_OVERFLOW_TOP = overflow.top + FUZZ_FACTOR; + + // Margin applied to the breakout-extend urlbar + INLINE_MARGIN = -extractPixelValue(inlineMargin); // Flip symbol since this CSS value is negative. + // The popover positioning requires this offset + VERTICAL_OFFSET = -extractPixelValue(verticalOffset); // Flip symbol since this CSS value is positive. + await UrlbarTestUtils.promisePopupClose(win); + URLBar.value = ""; }; let urlbarRect = URLBar.getBoundingClientRect(); - // To isolate unexpected repaints, we need to filter out the rectangle of - // pixels changed by showing the urlbar popover - const SHADOW_SIZE = 17; // The blur/spread of the box shadow, plus 1px fudge factor - const INLINE_MARGIN = 5; // Margin applied to the breakout-extend urlbar - const VERTICAL_OFFSET = -4; // The popover positioning requires this offset + await testFn(); let expectedRects = { filter: rects => { const referenceRect = { - x1: Math.floor(urlbarRect.left) - INLINE_MARGIN - SHADOW_SIZE, - x2: Math.ceil(urlbarRect.right) + INLINE_MARGIN + SHADOW_SIZE, - y1: Math.floor(urlbarRect.top) + VERTICAL_OFFSET - SHADOW_SIZE, + x1: Math.floor(urlbarRect.left) - INLINE_MARGIN - SHADOW_OVERFLOW_LEFT, + x2: + Math.floor(urlbarRect.right) + INLINE_MARGIN + SHADOW_OVERFLOW_RIGHT, + y1: Math.floor(urlbarRect.top) + VERTICAL_OFFSET - SHADOW_OVERFLOW_TOP, }; + // We put text into the urlbar so expect its textbox to change. // We expect many changes in the results view. // So we just allow changes anywhere in the urlbar. We don't check the @@ -871,6 +922,7 @@ async function runUrlbarTest( } await BrowserTestUtils.closeWindow(win); + await TestUtils.waitForTick(); } /**