Bug 1358314 - Fix 'Open Link in New Tab' context menu item after tab navigated in non-e10s mode. r=kmag
authorLuca Greco <lgreco@mozilla.com>
Mon, 24 Apr 2017 16:22:31 +0200
changeset 356585 fea9c89ca6a5c59569bd0acf09ebe8a0b3dd4401
parent 356584 9ec331cdc006aabba75f140834c5373fc4cbe3a9
child 356586 3446cf5d9cce69d516ea4e51cde35c80105a341d
push id31767
push usercbook@mozilla.com
push dateFri, 05 May 2017 13:15:58 +0000
treeherdermozilla-central@8872ad4d52b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1358314
milestone55.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 1358314 - Fix 'Open Link in New Tab' context menu item after tab navigated in non-e10s mode. r=kmag MozReview-Commit-ID: KIG3QTx4J6b
browser/base/content/nsContextMenu.js
browser/base/content/test/tabs/browser.ini
browser/base/content/test/tabs/browser_contextmenu_openlink_after_tabnavigated.js
browser/base/content/test/tabs/test_bug1358314.html
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -1045,18 +1045,21 @@ nsContextMenu.prototype = {
                    referrerPolicy: gContextMenuContentData.referrerPolicy,
                    frameOuterWindowID: gContextMenuContentData.frameOuterWindowID,
                    noReferrer: this.linkHasNoReferrer };
     for (let p in extra) {
       params[p] = extra[p];
     }
 
     if (!this.isRemote) {
-      params.frameOuterWindowID = WebNavigationFrames.getFrameId(this.target.ownerGlobal);
+      // Propagate the frameOuterWindowID value saved when
+      // the context menu has been opened.
+      params.frameOuterWindowID = this.frameOuterWindowID;
     }
+
     // If we want to change userContextId, we must be sure that we don't
     // propagate the referrer.
     if ("userContextId" in params &&
         params.userContextId != gContextMenuContentData.userContextId) {
       params.noReferrer = true;
     }
 
     return params;
--- a/browser/base/content/test/tabs/browser.ini
+++ b/browser/base/content/test/tabs/browser.ini
@@ -1,14 +1,16 @@
 [DEFAULT]
 support-files =
   dummy_page.html
+  test_bug1358314.html
 
 [browser_abandonment_telemetry.js]
 [browser_allow_process_switches_despite_related_browser.js]
+[browser_contextmenu_openlink_after_tabnavigated.js]
 [browser_tabCloseProbes.js]
 [browser_tabSpinnerProbe.js]
 skip-if = !e10s # Tab spinner is e10s only.
 [browser_tabSpinnerTypeProbe.js]
 skip-if = !e10s # Tab spinner is e10s only.
 [browser_tabSwitchPrintPreview.js]
 skip-if = os == 'mac'
 [browser_navigatePinnedTab.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabs/browser_contextmenu_openlink_after_tabnavigated.js
@@ -0,0 +1,43 @@
+"use strict";
+
+const example_base = "http://example.com/browser/browser/base/content/test/tabs/";
+
+add_task(function* test_contextmenu_openlink_after_tabnavigated() {
+  let url = example_base + "test_bug1358314.html";
+
+  const tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
+
+  const contextMenu = document.getElementById("contentAreaContextMenu");
+  let awaitPopupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
+  yield BrowserTestUtils.synthesizeMouse("a", 0, 0, {
+    type: "contextmenu",
+    button: 2,
+  }, gBrowser.selectedBrowser);
+  yield awaitPopupShown;
+  info("Popup Shown");
+
+  info("Navigate the tab with the opened context menu");
+  gBrowser.selectedBrowser.loadURI("about:blank");
+  yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
+
+  let awaitNewTabOpen = BrowserTestUtils.waitForNewTab(gBrowser, "http://example.com/");
+
+  info("Click the 'open link in new tab' menu item");
+  let openLinkMenuItem = contextMenu.querySelector("#context-openlinkintab");
+  openLinkMenuItem.click();
+
+  info("Wait for the new tab to be opened");
+  const newTab = yield awaitNewTabOpen;
+
+  // Close the contextMenu popup if it has not been closed yet.
+  contextMenu.hidePopup();
+
+  yield BrowserTestUtils.browserLoaded(newTab.linkedBrowser);
+  const newTabURL = yield ContentTask.spawn(newTab.linkedBrowser, null, function* () {
+    return content.location.href;
+  });
+  is(newTabURL, "http://example.com/", "Got the expected URL loaded in the new tab");
+
+  yield BrowserTestUtils.removeTab(newTab);
+  yield BrowserTestUtils.removeTab(tab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabs/test_bug1358314.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+  </head>
+  <body>
+    <p>Test page</p>
+    <a href="/">Link</a>
+  </body>
+</html>