From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- ...test_autoscrolling_in_extension_popup_window.js | 189 +++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 gfx/layers/apz/test/mochitest/browser_test_autoscrolling_in_extension_popup_window.js (limited to 'gfx/layers/apz/test/mochitest/browser_test_autoscrolling_in_extension_popup_window.js') diff --git a/gfx/layers/apz/test/mochitest/browser_test_autoscrolling_in_extension_popup_window.js b/gfx/layers/apz/test/mochitest/browser_test_autoscrolling_in_extension_popup_window.js new file mode 100644 index 0000000000..911af7548d --- /dev/null +++ b/gfx/layers/apz/test/mochitest/browser_test_autoscrolling_in_extension_popup_window.js @@ -0,0 +1,189 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +Services.scriptloader.loadSubScript( + "chrome://mochitests/content/browser/browser/components/extensions/test/browser/head.js", + this +); +Services.scriptloader.loadSubScript( + "chrome://mochitests/content/browser/browser/components/extensions/test/browser/head_browserAction.js", + this +); + +Services.scriptloader.loadSubScript( + "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_utils.js", + this +); + +Services.scriptloader.loadSubScript( + "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js", + this +); + +add_task(async () => { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + browser_action: { + default_popup: "popup.html", + browser_style: true, + }, + }, + + files: { + "popup.html": ` + + + + + + + + + + `, + "popup.js": function () { + window.addEventListener( + "mousemove", + () => { + dump("Got a mousemove event in the popup content document\n"); + browser.test.sendMessage("received-mousemove"); + }, + { once: true } + ); + window.addEventListener( + "scroll", + () => { + dump("Got a scroll event in the popup content document\n"); + browser.test.sendMessage("received-scroll"); + }, + { once: true } + ); + }, + }, + }); + + await extension.startup(); + + await SpecialPowers.pushPrefEnv({ set: [["apz.popups.enabled", true]] }); + + // Open the popup window of the extension. + const browserForPopup = await openBrowserActionPanel( + extension, + undefined, + true + ); + + if (!browserForPopup.isRemoteBrowser) { + await closeBrowserAction(extension); + await extension.unload(); + ok( + true, + "Skipping this test since the popup window doesn't have remote contents" + ); + return; + } + + // Flush APZ repaints and waits for MozAfterPaint to make sure APZ state is + // stable. + await promiseApzFlushedRepaintsInPopup(browserForPopup); + + const { screenX, screenY, viewId, presShellId } = await SpecialPowers.spawn( + browserForPopup, + [], + () => { + const winUtils = SpecialPowers.getDOMWindowUtils(content.window); + return { + screenX: content.window.mozInnerScreenX * content.devicePixelRatio, + screenY: content.window.mozInnerScreenY * content.devicePixelRatio, + viewId: winUtils.getViewId(content.document.documentElement), + presShellId: winUtils.getPresShellId(), + }; + } + ); + + // Before starting autoscroll we need to make sure a mousemove event has been + // processed in the popup content so that subsequent mousemoves for autoscroll + // will be properly processed in autoscroll animation. + const mousemoveEventPromise = extension.awaitMessage("received-mousemove"); + + const nativeMouseEventPromise = promiseNativeMouseEventWithAPZ({ + type: "mousemove", + target: browserForPopup, + offsetX: 100, + offsetY: 50, + }); + + await Promise.all([nativeMouseEventPromise, mousemoveEventPromise]); + + const scrollEventPromise = extension.awaitMessage("received-scroll"); + + // Start autoscrolling. + ok( + browserForPopup.browsingContext.startApzAutoscroll( + screenX + 100, + screenY + 50, + viewId, + presShellId + ) + ); + + // Send sequential mousemove events to cause autoscrolling. + for (let i = 0; i < 10; i++) { + await promiseNativeMouseEventWithAPZ({ + type: "mousemove", + target: browserForPopup, + offsetX: 100, + offsetY: 50 + i * 10, + }); + } + + // Flush APZ repaints and waits for MozAfterPaint to make sure the scroll has + // been reflected on the main thread. + const apzPromise = promiseApzFlushedRepaintsInPopup(browserForPopup); + + await Promise.all([apzPromise, scrollEventPromise]); + + const scrollY = await SpecialPowers.spawn(browserForPopup, [], () => { + return content.window.scrollY; + }); + ok(scrollY > 0, "Autoscrolling works in the popup window"); + + browserForPopup.browsingContext.stopApzAutoscroll(viewId, presShellId); + + await closeBrowserAction(extension); + + await extension.unload(); +}); -- cgit v1.2.3