Files
sousa-gecko/toolkit/modules/tests/browser/browser_toTopLevelWidgetRect.js
T
Gregory Pappas 677fcfdeaa Bug 2024649 - Remove LayoutUtils.sys.mjs r=emilio,geckoview-reviewers,Sasha,jonalmeida
After bug 1691346, LayoutUtils is a thin wrapper over a few methods on
windowUtils. I think we can get rid of it and just call these methods
directly now.

Differential Revision: https://phabricator.services.mozilla.com/D288661
2026-06-06 04:55:03 +00:00

54 lines
1.5 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
add_task(async function () {
await SpecialPowers.pushPrefEnv({
set: [["test.wait300msAfterTabSwitch", true]],
});
});
add_task(async function test_toTopLevelWidgetRect() {
const tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"data:text/html;charset=utf-8,test"
);
// Convert (12, 34) in a content document coordinates into this browser window
// coordinates.
const positionInBrowser = await SpecialPowers.spawn(
tab.linkedBrowser,
[],
() => {
return content.window.windowUtils.toTopLevelWidgetRect(12, 34, 0, 0);
}
);
// Dispatch a mousedown event on the browser window coordinates position to
// see whether it's fired on the correct position in the content document.
const mouseDownPromise = BrowserTestUtils.waitForContentEvent(
tab.linkedBrowser,
"mousedown",
false,
event => {
dump(`mousedown on (${event.clientX}, ${event.clientY})`);
return event.clientX == 12 && event.clientY == 34;
}
);
// A workaround for bug 1743857.
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
await Promise.resolve();
});
EventUtils.synthesizeMouseAtPoint(
positionInBrowser.x / window.devicePixelRatio,
positionInBrowser.y / window.devicePixelRatio,
{ type: "mousedown", button: 1 }
);
await mouseDownPromise;
Assert.ok(true, "windowUtils.toTopLevelWidgetRect() works as expected");
BrowserTestUtils.removeTab(tab);
});