summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/chrome/test_bug624329.xhtml
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/content/tests/chrome/test_bug624329.xhtml
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/content/tests/chrome/test_bug624329.xhtml')
-rw-r--r--toolkit/content/tests/chrome/test_bug624329.xhtml167
1 files changed, 167 insertions, 0 deletions
diff --git a/toolkit/content/tests/chrome/test_bug624329.xhtml b/toolkit/content/tests/chrome/test_bug624329.xhtml
new file mode 100644
index 0000000000..ccbcf91584
--- /dev/null
+++ b/toolkit/content/tests/chrome/test_bug624329.xhtml
@@ -0,0 +1,167 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=624329
+-->
+<window title="Mozilla Bug 624329 context menu position"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <!-- test results are displayed in the html:body -->
+ <body xmlns="http://www.w3.org/1999/xhtml"
+ onload="beginTest()">
+ <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=624329"
+ target="_blank">Mozilla Bug 624329</a>
+ </body>
+
+ <!-- test code goes here -->
+ <script type="application/javascript">
+ <![CDATA[
+ /** Test for Bug 624329 **/
+
+SimpleTest.waitForExplicitFinish();
+
+var win;
+var timeoutID;
+var menu;
+
+const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
+
+function beginTest() {
+ if (AppConstants.platform == "macosx" && SpecialPowers.getBoolPref("widget.macos.native-context-menus", false)) {
+ // This test does not apply with native context menus.
+ ok(true, "macOS positions native menus, so we don't need to test this behaviour.");
+ SimpleTest.finish();
+ return;
+ }
+
+ openTestWindow();
+}
+
+function openTestWindow() {
+ win = window.browsingContext.topChromeWindow.openDialog("bug624329_window.xhtml", "_blank", "width=300,resizable=yes,chrome", window);
+ // Close our window if the test times out so that it doesn't interfere
+ // with later tests.
+ timeoutID = setTimeout(function () {
+ ok(false, "Test timed out.");
+ // Provide some time for a screenshot
+ setTimeout(finish, 1000);
+ }, 20000);
+}
+
+function listenOnce(event, callback) {
+ win.addEventListener(event, function listener() {
+ callback();
+ }, { once: true});
+}
+
+function childFocused() {
+ // maximizing the window is a simple way to ensure that the menu is near
+ // the right edge of the screen.
+
+ listenOnce("resize", childResized);
+ win.maximize();
+}
+
+function childResized() {
+ const isOSXMavericks = navigator.userAgent.includes("Mac OS X 10.9");
+ const isOSXYosemite = navigator.userAgent.includes("Mac OS X 10.10");
+ if (isOSXMavericks || isOSXYosemite) {
+ todo_is(win.windowState, win.STATE_MAXIMIZED,
+ "A resize before being maximized breaks this test on 10.9 and 10.10");
+ finish();
+ return;
+ }
+
+ is(win.windowState, win.STATE_MAXIMIZED,
+ "window should be maximized");
+
+ isnot(win.innerWidth, 300,
+ "window inner width should have changed");
+
+ openContextMenu();
+}
+
+function openContextMenu() {
+ var mouseX = win.innerWidth - 10;
+ var mouseY = 10;
+
+ menu = win.document.getElementById("menu");
+ var screenX = menu.screenX;
+ var screenY = menu.screenY;
+ var utils = win.windowUtils;
+
+ utils.sendMouseEvent("contextmenu", mouseX, mouseY, 2, 0, 0);
+
+ var interval = setInterval(checkMoved, 200);
+ function checkMoved() {
+ if (menu.screenX != screenX ||
+ menu.screenY != screenY) {
+ clearInterval(interval);
+ // Wait further to check that the window does not move again.
+ setTimeout(checkPosition, 1000);
+ }
+ }
+
+ function checkPosition() {
+ var rootElement = win.document.documentElement;
+ var platformIsMac = navigator.userAgent.indexOf("Mac") > -1;
+
+ var x = menu.screenX - rootElement.screenX - parseFloat(getComputedStyle(menu).marginLeft);
+ var y = menu.screenY - rootElement.screenY - parseFloat(getComputedStyle(menu).marginTop);
+
+ if (platformIsMac)
+ {
+ // This check is alterered slightly for OSX which adds padding to the top
+ // and bottom of its context menus. The menu position calculation must
+ // be changed to allow for the pointer to be outside this padding
+ // when the menu opens.
+ // (Bug 1075089)
+ ok(y + 6 >= mouseY,
+ "menu top " + (y + 6) + " should be below click point " + mouseY);
+ }
+ else
+ {
+ ok(y >= mouseY,
+ "menu top " + y + " should be below click point " + mouseY);
+ }
+
+ ok(y <= mouseY + 20,
+ "menu top " + y + " should not be too far below click point " + mouseY);
+
+ ok(x < mouseX,
+ "menu left " + x + " should be left of click point " + mouseX);
+ var right = x + menu.getBoundingClientRect().width;
+
+ if (platformIsMac) {
+ // Rather than be constrained by the right hand screen edge, OSX menus flip
+ // horizontally and appear to the left of the mouse pointer
+ ok(right < mouseX,
+ "menu right " + right + " should be left of click point " + mouseX);
+ }
+ else {
+ ok(right > mouseX,
+ "menu right " + right + " should be right of click point " + mouseX);
+ }
+
+ clearTimeout(timeoutID);
+ finish();
+ }
+
+}
+
+function finish() {
+ if (menu && navigator.platform.includes("Win")) {
+ todo(false, "Should not have to hide popup before closing its window");
+ // This avoids mochitest "Unable to restore focus" errors (bug 670053).
+ menu.hidePopup();
+ }
+ win.close();
+ SimpleTest.finish();
+}
+
+ ]]>
+ </script>
+</window>