diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/content/tests/chrome/test_menu_mouse_menuactive.xhtml | |
parent | Initial commit. (diff) | |
download | thunderbird-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 '')
-rw-r--r-- | toolkit/content/tests/chrome/test_menu_mouse_menuactive.xhtml | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/toolkit/content/tests/chrome/test_menu_mouse_menuactive.xhtml b/toolkit/content/tests/chrome/test_menu_mouse_menuactive.xhtml new file mode 100644 index 0000000000..edd7f582b5 --- /dev/null +++ b/toolkit/content/tests/chrome/test_menu_mouse_menuactive.xhtml @@ -0,0 +1,91 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> + +<window title="Menu Activation Test" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> + + <label id="label" value="label" context="contextmenu"/> + <menupopup id="contextmenu"> + <menuitem id="item1" label="Item 1"/> + <menuitem id="item2" label="Item 2"/> + </menupopup> + <script><![CDATA[ + +function waitForEvent(subject, eventName) { + return new Promise(resolve => { + subject.addEventListener(eventName, function listener(event) { + if (event.target == subject) { + subject.removeEventListener(eventName, listener); + resolve(); + } + }); + }); +} + +const menu = document.getElementById("contextmenu"); +const label = document.getElementById("label"); +const item1 = document.getElementById("item1"); +const item2 = document.getElementById("item2"); + +function openContextMenu() { + // Open the first level of the context menu + let promise = waitForEvent(menu, "popupshown"); + synthesizeMouseAtCenter(label, { + type: "contextmenu", + button: 2, + }); + return promise; +} + +function isActive(item) { + return item.hasAttribute("_moz-menuactive"); +} + +async function activateItem(item) { + info(`Activating ${item.id}`); + ok(!isActive(item), "Shouldn't be already active"); + let activated = waitForEvent(item, "DOMMenuItemActive"); + synthesizeMouse(item, 5, 5, { type: "mousemove" }); + await new Promise(r => setTimeout(r, 0)); + synthesizeMouse(item, 7, 7, { type: "mousemove" }); + await activated; +} + +add_task(async function() { + // Disable macOS native context menus, since we can't control activation of those here. + await SpecialPowers.pushPrefEnv({ set: [["widget.macos.native-context-menus", false]] }); + info(`Opening context-menu`); + await openContextMenu(); + is(menu.state, "open", "Menu should be open"); + + await activateItem(item1); + ok(isActive(item1), "item1 should be active"); + ok(!isActive(item2), "item2 should be inactive"); + + await activateItem(item2); + ok(isActive(item2), "item2 should be active"); + ok(!isActive(item1), "item1 should be inactive"); + + await activateItem(item1); + ok(isActive(item1), "item1 should be active"); + ok(!isActive(item2), "item2 should be inactive"); + + info(`Leaving context-menu`); + + let deactivated = waitForEvent(item1, "DOMMenuItemInactive"); + synthesizeMouse(label, 0, 0, { type: "mousemove" }); + + await deactivated; + ok(!isActive(item1), "item1 should be inactive"); + ok(!isActive(item2), "item2 should be inactive"); + + is(menu.state, "open", "Menu should still be open"); + menu.hidePopup(); +}); + + ]]></script> +</window> |