Bug 1457109 - Open links in the next tab, in background if Ctrl/Cmd is pressed; r=yulia.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Tue, 05 Mar 2019 14:10:19 +0000
changeset 520426 fb3cbe9457a98eddda6488517d6a70ce3ab64a16
parent 520425 d9bc0e4940579d50952ea8db78fb3f69dfc2b443
child 520427 295288a5868385e81cc0e96f2acc7ead3039ff7a
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1457109
milestone67.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 1457109 - Open links in the next tab, in background if Ctrl/Cmd is pressed; r=yulia. This patch passes the relevant options to the `openDocLink` function, which means now links: - will open right next to the current tab - will open in background if Ctrl/Cmd is pressed. A test case is added to ensures this works as expected. Differential Revision: https://phabricator.services.mozilla.com/D22075
devtools/client/webconsole/test/mochitest/browser_webconsole_clickable_urls.js
devtools/client/webconsole/webconsole.js
--- a/devtools/client/webconsole/test/mochitest/browser_webconsole_clickable_urls.js
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_clickable_urls.js
@@ -7,28 +7,48 @@
 // as the output is already tested in Reps (in Github).
 
 "use strict";
 
 const TEST_URI = "data:text/html;charset=utf8,Clickable URLS";
 
 add_task(async function() {
   const hud = await openNewTabAndConsole(TEST_URI);
+  const currentTab = gBrowser.selectedTab;
 
-  const url = "http://example.com/";
-  await ContentTask.spawn(gBrowser.selectedBrowser, url, function(uri) {
-    content.wrappedJSObject.console.log(uri);
+  const firstURL = "http://example.com/";
+  const secondURL = "http://example.com/?id=secondURL";
+  ContentTask.spawn(gBrowser.selectedBrowser, [firstURL, secondURL], (urls) => {
+    content.wrappedJSObject.console.log("Visit ", urls[0], " and ", urls[1]);
   });
 
-  const node = await waitFor(() => findMessage(hud, url));
-  const link = node.querySelector("a.url");
+  const node = await waitFor(() => findMessage(hud, firstURL));
+  const [urlEl1, urlEl2] = Array.from(node.querySelectorAll("a.url"));
 
-  const onTabLoaded = BrowserTestUtils.waitForNewTab(gBrowser, url, true);
+  let onTabLoaded = BrowserTestUtils.waitForNewTab(gBrowser, firstURL, true);
 
-  info("Clicking on the link");
-  link.click();
+  info("Clicking on the first link");
+  urlEl1.click();
 
-  const newTab = await onTabLoaded;
+  let newTab = await onTabLoaded;
   // We only need to check that newTab is truthy since
   // BrowserTestUtils.waitForNewTab checks the URL.
   ok(newTab, "The expected tab was opened.");
-  BrowserTestUtils.removeTab(newTab);
+
+  info("Select the first tab again");
+  gBrowser.selectedTab = currentTab;
+
+  info("Ctrl/Cmd + Click on the second link");
+  onTabLoaded = BrowserTestUtils.waitForNewTab(gBrowser, secondURL, true);
+
+  const isMacOS = Services.appinfo.OS === "Darwin";
+  EventUtils.sendMouseEvent({
+    type: "click",
+    [isMacOS ? "metaKey" : "ctrlKey"]: true,
+  }, urlEl2, hud.ui.window);
+
+  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");
 });
--- a/devtools/client/webconsole/webconsole.js
+++ b/devtools/client/webconsole/webconsole.js
@@ -7,16 +7,17 @@
 var Services = require("Services");
 loader.lazyRequireGetter(this, "Utils", "devtools/client/webconsole/utils", true);
 loader.lazyRequireGetter(this, "WebConsoleUI", "devtools/client/webconsole/webconsole-ui", true);
 loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
 loader.lazyRequireGetter(this, "viewSource", "devtools/client/shared/view-source");
 loader.lazyRequireGetter(this, "openDocLink", "devtools/client/shared/link", true);
 
 var gHudId = 0;
+const isMacOS = Services.appinfo.OS === "Darwin";
 
 /**
  * A WebConsole instance is an interactive console initialized *per target*
  * that displays console log data as well as provides an interactive terminal to
  * manipulate the target's document content.
  *
  * This object only wraps the iframe that holds the Web Console UI. This is
  * meant to be an integration point between the Firefox UI and the Web Console
@@ -143,18 +144,21 @@ class WebConsole {
   }
 
   /**
    * Open a link in a new tab.
    *
    * @param string link
    *        The URL you want to open in a new tab.
    */
-  openLink(link, e) {
-    openDocLink(link);
+  openLink(link, e = {}) {
+    openDocLink(link, {
+      relatedToCurrent: true,
+      inBackground: isMacOS ? e.metaKey : e.ctrlKey,
+    });
   }
 
   /**
    * Open a link in Firefox's view source.
    *
    * @param string sourceURL
    *        The URL of the file.
    * @param integer sourceLine