diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /browser/base/content/test/contextMenu/browser_contextmenu_childprocess.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/test/contextMenu/browser_contextmenu_childprocess.js')
-rw-r--r-- | browser/base/content/test/contextMenu/browser_contextmenu_childprocess.js | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/browser/base/content/test/contextMenu/browser_contextmenu_childprocess.js b/browser/base/content/test/contextMenu/browser_contextmenu_childprocess.js new file mode 100644 index 0000000000..af85d0a62c --- /dev/null +++ b/browser/base/content/test/contextMenu/browser_contextmenu_childprocess.js @@ -0,0 +1,129 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const gBaseURL = + "https://example.com/browser/browser/base/content/test/contextMenu/"; + +add_task(async function() { + await SpecialPowers.pushPrefEnv({ + set: [["dom.menuitem.enabled", true]], + }); + + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + gBaseURL + "subtst_contextmenu.html" + ); + + let contextMenu = document.getElementById("contentAreaContextMenu"); + + // Get the point of the element with the page menu (test-pagemenu) and + // synthesize a right mouse click there. + let popupShownPromise = BrowserTestUtils.waitForEvent( + contextMenu, + "popupshown" + ); + await BrowserTestUtils.synthesizeMouse( + "#test-pagemenu", + 5, + 5, + { type: "contextmenu", button: 2 }, + tab.linkedBrowser + ); + await popupShownPromise; + + checkMenu(contextMenu); + + let popupHiddenPromise = BrowserTestUtils.waitForEvent( + contextMenu, + "popuphidden" + ); + contextMenu.hidePopup(); + await popupHiddenPromise; + + BrowserTestUtils.removeTab(tab); +}); + +function checkItems(menuitem, arr) { + for (let i = 0; i < arr.length; i += 2) { + let str = arr[i]; + let details = arr[i + 1]; + if (str == "---") { + is(menuitem.localName, "menuseparator", "menuseparator"); + } else if ("children" in details) { + is(menuitem.localName, "menu", "submenu"); + is(menuitem.getAttribute("label"), str, str + " label"); + checkItems(menuitem.menupopup.firstElementChild, details.children); + } else { + is(menuitem.localName, "menuitem", str + " menuitem"); + + is(menuitem.getAttribute("label"), str, str + " label"); + is(menuitem.getAttribute("type"), details.type, str + " type"); + is( + menuitem.getAttribute("image"), + details.icon ? gBaseURL + details.icon : "", + str + " icon" + ); + + if (details.checked) { + is(menuitem.getAttribute("checked"), "true", str + " checked"); + } else { + ok(!menuitem.hasAttribute("checked"), str + " checked"); + } + + if (details.disabled) { + is(menuitem.getAttribute("disabled"), "true", str + " disabled"); + } else { + ok(!menuitem.hasAttribute("disabled"), str + " disabled"); + } + } + + menuitem = menuitem.nextElementSibling; + } +} + +function checkMenu(contextMenu) { + let items = [ + "Plain item", + { type: "", icon: "", checked: false, disabled: false }, + "Disabled item", + { type: "", icon: "", checked: false, disabled: true }, + "Item w/ textContent", + { type: "", icon: "", checked: false, disabled: false }, + "---", + null, + "Checkbox", + { type: "checkbox", icon: "", checked: true, disabled: false }, + "---", + null, + "Radio1", + { type: "checkbox", icon: "", checked: true, disabled: false }, + "Radio2", + { type: "checkbox", icon: "", checked: false, disabled: false }, + "Radio3", + { type: "checkbox", icon: "", checked: false, disabled: false }, + "---", + null, + "Item w/ icon", + { type: "", icon: "favicon.ico", checked: false, disabled: false }, + "Item w/ bad icon", + { type: "", icon: "", checked: false, disabled: false }, + "---", + null, + "Submenu", + { + children: [ + "Radio1", + { type: "checkbox", icon: "", checked: false, disabled: false }, + "Radio2", + { type: "checkbox", icon: "", checked: true, disabled: false }, + "Radio3", + { type: "checkbox", icon: "", checked: false, disabled: false }, + "---", + null, + "Checkbox", + { type: "checkbox", icon: "", checked: false, disabled: false }, + ], + }, + ]; + checkItems(contextMenu.children[2], items); +} |