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/browser_webextension_dropdown.js | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 devtools/client/framework/test/browser_webextension_dropdown.js (limited to 'devtools/client/framework/test/browser_webextension_dropdown.js') diff --git a/devtools/client/framework/test/browser_webextension_dropdown.js b/devtools/client/framework/test/browser_webextension_dropdown.js new file mode 100644 index 0000000000..b291ac7a9e --- /dev/null +++ b/devtools/client/framework/test/browser_webextension_dropdown.js @@ -0,0 +1,135 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/* globals browser */ + +const URL = + "data:text/html;charset=utf8,test for drop down menu in devtools extension"; + +add_task(async function runTest() { + const extension = await startupExtension(); + + const tab = await addTab(URL); + const toolbox = await gDevTools.showToolboxForTab(tab, { + toolId: "webconsole", + }); + const { + Toolbox, + } = require("resource://devtools/client/framework/toolbox.js"); + await toolbox.switchHost(Toolbox.HostType.WINDOW); + + await extension.awaitMessage("devtools_page_loaded"); + + const toolboxAdditionalTools = toolbox.getAdditionalTools(); + is( + toolboxAdditionalTools.length, + 1, + "Got the expected number of toolbox specific panel registered." + ); + + const panelId = toolboxAdditionalTools[0].id; + + await gDevTools.showToolboxForTab(tab, { toolId: panelId }); + + await extension.awaitMessage("devtools_panel_loaded"); + + const panel = findExtensionPanel(); + ok(panel, "found extension panel"); + + const iframe = panel.firstChild; + const popupShownPromise = BrowserTestUtils.waitForSelectPopupShown( + toolbox.win.browsingContext.topChromeWindow + ); + + const browser = iframe.contentDocument.getElementById( + "webext-panels-browser" + ); + ok(browser, "found extension panel browser"); + + info("Waiting for menu"); + await ContentTask.spawn(browser, null, async function () { + const menu = content.document.getElementById("menu"); + const event = new content.MouseEvent("mousedown"); + menu.dispatchEvent(event); + }); + + const popup = await popupShownPromise; + info("popup is shown"); + + popup.hidePopup(); + + await toolbox.destroy(); + + gBrowser.removeCurrentTab(); + + await extension.unload(); +}); + +async function startupExtension() { + async function devtools_page() { + await browser.devtools.panels.create( + "drop", + "/icon.png", + "/devtools_panel.html" + ); + browser.test.sendMessage("devtools_page_loaded"); + } + + async function devtools_panel() { + browser.test.sendMessage("devtools_panel_loaded"); + } + + const extension = ExtensionTestUtils.loadExtension({ + manifest: { + devtools_page: "devtools_page.html", + }, + files: { + "devtools_page.html": ` + + + + + + + + `, + "devtools_page.js": devtools_page, + "icon.png": "", + "devtools_panel.html": ` + + + + + + + + + `, + "devtools_panel.js": devtools_panel, + }, + }); + + await extension.startup(); + + return extension; +} + +function findExtensionPanel() { + const win = Services.wm.getMostRecentWindow("devtools:toolbox"); + ok(win, "toolbox separate window exists"); + + const iframe = win.document.querySelector(".devtools-toolbox-window-iframe"); + const deck = iframe.contentDocument.getElementById("toolbox-deck"); + for (const box of deck.childNodes) { + if (box.id && box.id.startsWith("toolbox-panel-webext-devtools-panel")) { + return box; + } + } + return null; +} -- cgit v1.2.3