Bug 1214556 - Add open url MenuItem for links in Web Console. r=nchevobbe
authorRaymond Liu <raymond.liu.dev@gmail.com>
Tue, 26 Nov 2019 09:04:29 +0000
changeset 503824 26e47abeac8aa4eac2c5860b29bbc2bda59d1b5b
parent 503823 72344e4b773765014d99730188c7bcc0cd1b7cde
child 503825 2607f7ba81ba8cdabe59a59de4417bae91daf7c0
push id101567
push usernchevobbe@mozilla.com
push dateTue, 26 Nov 2019 10:25:55 +0000
treeherderautoland@26e47abeac8a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1214556
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1214556 - Add open url MenuItem for links in Web Console. r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D54418
devtools/client/webconsole/test/browser/browser_webconsole_context_menu_open_url.js
devtools/client/webconsole/utils/context-menu.js
--- a/devtools/client/webconsole/test/browser/browser_webconsole_context_menu_open_url.js
+++ b/devtools/client/webconsole/test/browser/browser_webconsole_context_menu_open_url.js
@@ -1,19 +1,20 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-// Test that the Open URL in new Tab menu item is displayed for network logs and works as
-// expected.
+// Test that the Open URL in new Tab menu item is displayed for links in text messages
+// and network logs and that they work as expected.
 
 "use strict";
 
 const TEST_URI =
   "http://example.com/browser/devtools/client/webconsole/" +
   "test/browser/test-console.html";
+const TEST_URI2 = "http://example.com/";
 
 add_task(async function() {
   // Enable net messages in the console for this test.
   await pushPref("devtools.webconsole.filter.net", true);
 
   const hud = await openNewTabAndConsole(TEST_URI);
   await clearOutput(hud);
 
@@ -27,38 +28,64 @@ add_task(async function() {
   ok(message, "Text log found in the console");
 
   info("Open and check the context menu for the logged text message");
   let menuPopup = await openContextMenu(hud, message);
   let openUrlItem = menuPopup.querySelector("#console-menu-open-url");
   ok(!openUrlItem, "Open URL menu item is not available");
 
   await hideContextMenu(hud);
+
+  info("Test Open URL menu item for a text message containing a link");
+  await ContentTask.spawn(gBrowser.selectedBrowser, TEST_URI2, url => {
+    content.wrappedJSObject.console.log("Visit", url);
+  });
+
+  info("Open context menu for the link");
+  message = await waitFor(() => findMessage(hud, "Visit"));
+  const urlNode = message.querySelector("a.url");
+  menuPopup = await openContextMenu(hud, urlNode);
+  openUrlItem = menuPopup.querySelector("#console-menu-open-url");
+  ok(openUrlItem, "Open URL menu item is available");
+
+  info("Click on Open URL menu item and wait for new tab to open");
+  let currentTab = gBrowser.selectedTab;
+  const onTabLoaded = BrowserTestUtils.waitForNewTab(gBrowser, TEST_URI2, true);
+  openUrlItem.click();
+  let newTab = await onTabLoaded;
+  ok(newTab, "The expected tab was opened.");
+  is(
+    newTab._tPos,
+    currentTab._tPos + 1,
+    "The new tab was opened in the position to the right of the current tab"
+  );
+  is(gBrowser.selectedTab, currentTab, "The tab was opened in the background");
+
   await clearOutput(hud);
 
   info("Test Open URL menu item for network log");
 
   info("Reload the content window to produce a network log");
   await ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
     content.wrappedJSObject.location.reload();
   });
   message = await waitFor(() => findMessage(hud, "test-console.html"));
   ok(message, "Network log found in the console");
 
   info("Open and check the context menu for the logged network message");
   menuPopup = await openContextMenu(hud, message);
   openUrlItem = menuPopup.querySelector("#console-menu-open-url");
   ok(openUrlItem, "Open URL menu item is available");
 
-  const currentTab = gBrowser.selectedTab;
+  currentTab = gBrowser.selectedTab;
   const tabLoaded = listenToTabLoad();
   info("Click on Open URL menu item and wait for new tab to open");
   openUrlItem.click();
   await hideContextMenu(hud);
-  const newTab = await tabLoaded;
+  newTab = await tabLoaded;
   const newTabHref = newTab.linkedBrowser.currentURI.spec;
   is(newTabHref, TEST_URI, "Tab was opened with the expected URL");
 
   info("Remove the new tab and select the previous tab back");
   gBrowser.removeTab(newTab);
   gBrowser.selectedTab = currentTab;
 });
 
--- a/devtools/client/webconsole/utils/context-menu.js
+++ b/devtools/client/webconsole/utils/context-menu.js
@@ -266,16 +266,28 @@ function createContextMenu(event, messag
         click: () => dispatch(actions.jumpToExecutionPoint(executionPoint)),
       })
     );
   }
 
   if (url) {
     menu.append(
       new MenuItem({
+        id: "console-menu-open-url",
+        label: l10n.getStr("webconsole.menu.openURL.label"),
+        accesskey: l10n.getStr("webconsole.menu.openURL.accesskey"),
+        click: () =>
+          openContentLink(url, {
+            inBackground: true,
+            relatedToCurrent: true,
+          }),
+      })
+    );
+    menu.append(
+      new MenuItem({
         id: "console-menu-copy-url",
         label: l10n.getStr("webconsole.menu.copyURL.label"),
         accesskey: l10n.getStr("webconsole.menu.copyURL.accesskey"),
         click: () => clipboardHelper.copyString(url),
       })
     );
   }