diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini index b8c8f34ad00a..6012e1710cfd 100644 --- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini +++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini @@ -172,6 +172,7 @@ skip-if = true # Bug 1437807 skip-if = true # Bug 1437843 [browser_console_consolejsm_output.js] skip-if = true # Bug 1437844 +[browser_console_context_menu_entries.js] [browser_console_dead_objects.js] skip-if = true # Bug 1437845 [browser_console_error_source_click.js] diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/browser_console_context_menu_entries.js b/devtools/client/webconsole/new-console-output/test/mochitest/browser_console_context_menu_entries.js new file mode 100644 index 000000000000..3d62cad76b7a --- /dev/null +++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_console_context_menu_entries.js @@ -0,0 +1,69 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Check that we display the expected context menu entries. + +const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" + + "new-console-output/test/mochitest/test-console.html"; + +add_task(async function () { + // Enable net messages in the console for this test. + await pushPref("devtools.browserconsole.filter.net", true); + + await addTab(TEST_URI); + const hud = await HUDService.toggleBrowserConsole(); + + info("Reload the content window to produce a network log"); + const onNetworkMessage = waitForMessage(hud, "test-console.html"); + ContentTask.spawn(gBrowser.selectedBrowser, null, () => { + content.wrappedJSObject.location.reload(); + }); + const networkMessage = await onNetworkMessage; + + info("Open and check the context menu for the network message"); + let menuPopup = await openContextMenu(hud, networkMessage.node); + ok(menuPopup, "The context menu is displayed on a network message"); + + let expectedContextMenu = [ + "#console-menu-copy-url (a)", + "#console-menu-open-url (T)", + "#console-menu-store (S) [disabled]", + "#console-menu-copy (C)", + "#console-menu-copy-object (o) [disabled]", + "#console-menu-select (A)" + ]; + is(getSimplifiedContextMenu(menuPopup).join("\n"), expectedContextMenu.join("\n"), + "The context menu has the expected entries for a network message"); + + info("Logging a text message in the content window"); + const onLogMessage = waitForMessage(hud, "simple text message"); + ContentTask.spawn(gBrowser.selectedBrowser, null, () => { + content.wrappedJSObject.console.log("simple text message"); + }); + + const logMessage = await onLogMessage; + menuPopup = await openContextMenu(hud, logMessage.node); + ok(menuPopup, "The context menu is displayed on a log message"); + + expectedContextMenu = [ + "#console-menu-store (S) [disabled]", + "#console-menu-copy (C)", + "#console-menu-copy-object (o) [disabled]", + "#console-menu-select (A)" + ]; + is(getSimplifiedContextMenu(menuPopup).join("\n"), expectedContextMenu.join("\n"), + "The context menu has the expected entries for a simple log message"); + + await hideContextMenu(hud); +}); + +function getSimplifiedContextMenu(popupElement) { + return [...popupElement.querySelectorAll("menuitem")] + .map(entry => { + const key = entry.getAttribute("accesskey"); + const disabled = entry.hasAttribute("disabled"); + return `#${entry.id} (${key})${disabled ? " [disabled]": ""}` + }); +} diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/head.js b/devtools/client/webconsole/new-console-output/test/mochitest/head.js index 7642b78205dc..362a565970eb 100644 --- a/devtools/client/webconsole/new-console-output/test/mochitest/head.js +++ b/devtools/client/webconsole/new-console-output/test/mochitest/head.js @@ -242,7 +242,8 @@ async function openContextMenu(hud, element) { let onConsoleMenuOpened = hud.ui.newConsoleOutput.once("menu-open"); synthesizeContextMenuEvent(element); await onConsoleMenuOpened; - return hud.ui.newConsoleOutput.toolbox.doc.getElementById("webconsole-menu"); + const doc = hud.ui.newConsoleOutput.owner.chromeWindow.document; + return doc.getElementById("webconsole-menu"); } /** @@ -254,7 +255,8 @@ async function openContextMenu(hud, element) { * @return promise */ function hideContextMenu(hud) { - let popup = hud.ui.newConsoleOutput.toolbox.doc.getElementById("webconsole-menu"); + const doc = hud.ui.newConsoleOutput.owner.chromeWindow.document; + let popup = doc.getElementById("webconsole-menu"); if (!popup) { return Promise.resolve(); } diff --git a/devtools/client/webconsole/new-console-output/utils/context-menu.js b/devtools/client/webconsole/new-console-output/utils/context-menu.js index c088e2c67e2d..cdf625925f93 100644 --- a/devtools/client/webconsole/new-console-output/utils/context-menu.js +++ b/devtools/client/webconsole/new-console-output/utils/context-menu.js @@ -69,17 +69,15 @@ function createContextMenu(jsterm, parentNode, { })); // Open Network message in the Network panel. - menu.append(new MenuItem({ - id: "console-menu-open-in-network-panel", - label: l10n.getStr("webconsole.menu.openInNetworkPanel.label"), - accesskey: l10n.getStr("webconsole.menu.openInNetworkPanel.accesskey"), - visible: source === MESSAGE_SOURCE.NETWORK, - click: () => { - if (request && serviceContainer.openNetworkPanel) { - serviceContainer.openNetworkPanel(message.messageId); - } - }, - })); + if (serviceContainer.openNetworkPanel && request) { + menu.append(new MenuItem({ + id: "console-menu-open-in-network-panel", + label: l10n.getStr("webconsole.menu.openInNetworkPanel.label"), + accesskey: l10n.getStr("webconsole.menu.openInNetworkPanel.accesskey"), + visible: source === MESSAGE_SOURCE.NETWORK, + click: () => serviceContainer.openNetworkPanel(message.messageId) + })); + } // Open URL in a new tab for a network request. menu.append(new MenuItem({