diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/base/content/test/popups/browser_popup_inner_outer_size.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/popups/browser_popup_inner_outer_size.js | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/browser/base/content/test/popups/browser_popup_inner_outer_size.js b/browser/base/content/test/popups/browser_popup_inner_outer_size.js new file mode 100644 index 0000000000..7e2e0e43fe --- /dev/null +++ b/browser/base/content/test/popups/browser_popup_inner_outer_size.js @@ -0,0 +1,120 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +async function checkForDeltaMismatch(aMsg) { + let getDelta = () => { + return { + width: this.content.outerWidth - this.content.innerWidth, + height: this.content.outerHeight - this.content.innerHeight, + }; + }; + + let initialDelta = getDelta(); + let latestDelta = initialDelta; + + this.content.testerPromise = new Promise(resolve => { + // Called from stopCheck + this.content.resolveFunc = resolve; + info(`[${aMsg}] Starting interval tester.`); + this.content.intervalID = this.content.setInterval(() => { + let currentDelta = getDelta(); + if ( + latestDelta.width != currentDelta.width || + latestDelta.height != currentDelta.height + ) { + latestDelta = currentDelta; + + let { innerWidth: iW, outerWidth: oW } = this.content; + let { innerHeight: iH, outerHeight: oH } = this.content; + info(`[${aMsg}] Delta changed. (inner ${iW}x${iH}, outer ${oW}x${oH})`); + + let { width: w, height: h } = currentDelta; + is(w, initialDelta.width, `[${aMsg}] Inner to outer width delta.`); + is(h, initialDelta.height, `[${aMsg}] Inner to outer height delta.`); + } + }, 0); + }).then(() => { + let { width: w, height: h } = latestDelta; + is(w, initialDelta.width, `[${aMsg}] Final inner to outer width delta.`); + is(h, initialDelta.height, `[${aMsg}] Final Inner to outer height delta.`); + }); +} + +async function stopCheck(aMsg) { + info(`[${aMsg}] Stopping interval tester.`); + this.content.clearInterval(this.content.intervalID); + info(`[${aMsg}] Resolving interval tester.`); + this.content.resolveFunc(); + await this.content.testerPromise; +} + +add_task(async function test_innerToOuterDelta() { + let tab = await BrowserTestUtils.openNewForegroundTab( + window.gBrowser, + "https://example.net" + ); + let popupBrowsingContext = await SpecialPowers.spawn( + tab.linkedBrowser, + [], + async () => { + info("Opening popup."); + let popup = this.content.open( + "https://example.net", + "", + "width=200,height=200" + ); + info("Waiting for load event."); + await ContentTaskUtils.waitForEvent(popup, "load"); + return popup.browsingContext; + } + ); + + await SpecialPowers.spawn( + popupBrowsingContext, + ["Content"], + checkForDeltaMismatch + ); + let popupChrome = popupBrowsingContext.topChromeWindow; + await SpecialPowers.spawn(popupChrome, ["Chrome"], checkForDeltaMismatch); + + let numResizes = 3; + let resizeStep = 5; + let { outerWidth: width, outerHeight: height } = popupChrome; + let finalWidth = width + numResizes * resizeStep; + let finalHeight = height + numResizes * resizeStep; + + info(`Starting ${numResizes} resizes.`); + await new Promise(resolve => { + let resizeListener = () => { + if ( + popupChrome.outerWidth == finalWidth && + popupChrome.outerHeight == finalHeight + ) { + popupChrome.removeEventListener("resize", resizeListener); + resolve(); + } + }; + popupChrome.addEventListener("resize", resizeListener); + + let resizeNext = () => { + width += resizeStep; + height += resizeStep; + info(`Resizing to ${width}x${height}`); + popupChrome.resizeTo(width, height); + numResizes--; + if (numResizes > 0) { + info(`${numResizes} resizes remaining.`); + popupChrome.requestAnimationFrame(resizeNext); + } + }; + resizeNext(); + }); + + await SpecialPowers.spawn(popupBrowsingContext, ["Content"], stopCheck); + await SpecialPowers.spawn(popupChrome, ["Chrome"], stopCheck); + + await SpecialPowers.spawn(popupBrowsingContext, [], () => { + this.content.close(); + }); + await BrowserTestUtils.removeTab(tab); +}); |