Bug 1430507 - pass something that's always serializable for SVG elements and the context menu, r?nhnt11 draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 15 Jan 2018 09:45:50 +0000
changeset 720956 1f87368a838de5768e7808aafa6df33b9ac15271
parent 720848 e4107773cffb1baefd5446666fce22c4d6eb0517
child 746206 fdc9b66127e143ea1022df7d0bda71b2cb5445a3
push id95702
push usergijskruitbosch@gmail.com
push dateTue, 16 Jan 2018 16:10:58 +0000
reviewersnhnt11
bugs1430507
milestone59.0a1
Bug 1430507 - pass something that's always serializable for SVG elements and the context menu, r?nhnt11 MozReview-Commit-ID: KUDsCdzAM4D
browser/base/content/test/contextMenu/browser.ini
browser/base/content/test/contextMenu/browser_contextmenu_linkopen.js
browser/base/content/test/contextMenu/test_contextmenu_links.html
browser/modules/ContextMenu.jsm
--- a/browser/base/content/test/contextMenu/browser.ini
+++ b/browser/base/content/test/contextMenu/browser.ini
@@ -1,7 +1,9 @@
 [DEFAULT]
 support-files =
   !/browser/base/content/test/general/contextmenu_common.js
   subtst_contextmenu_webext.html
+  test_contextmenu_links.html
 
 [browser_contextmenu_touch.js]
 skip-if = !(os == 'win' && os_version == '10.0')
+[browser_contextmenu_linkopen.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/contextMenu/browser_contextmenu_linkopen.js
@@ -0,0 +1,69 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const TEST_LINK = "https://example.com/";
+const RESOURCE_LINK = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com") + "test_contextmenu_links.html";
+
+async function activateContextAndWaitFor(selector, where) {
+  let contextMenuItem = "openlink";
+  let openPromise;
+  let closeMethod;
+  switch (where) {
+    case "tab":
+      contextMenuItem += "intab";
+      openPromise = BrowserTestUtils.waitForNewTab(gBrowser, TEST_LINK, false);
+      closeMethod = async (tab) => BrowserTestUtils.removeTab(tab);
+      break;
+    case "privatewindow":
+      contextMenuItem += "private";
+      openPromise = BrowserTestUtils.waitForNewWindow(TEST_LINK).then(win => {
+        ok(PrivateBrowsingUtils.isWindowPrivate(win), "Should have opened a private window.");
+        return win;
+      });
+      closeMethod = async (win) => BrowserTestUtils.closeWindow(win);
+      break;
+    case "window":
+      // No contextMenuItem suffix for normal new windows;
+      openPromise = BrowserTestUtils.waitForNewWindow(TEST_LINK).then(win => {
+        ok(!PrivateBrowsingUtils.isWindowPrivate(win), "Should have opened a normal window.");
+        return win;
+      });
+      closeMethod = async (win) => BrowserTestUtils.closeWindow(win);
+      break;
+  }
+  let contextMenu = document.getElementById("contentAreaContextMenu");
+  is(contextMenu.state, "closed", "checking if popup is closed");
+  let awaitPopupShown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
+  await BrowserTestUtils.synthesizeMouse(selector, 0, 0, {
+      type: "contextmenu",
+      button: 2,
+      centered: true,
+    },
+    gBrowser.selectedBrowser);
+  await awaitPopupShown;
+  info("Popup Shown");
+  let awaitPopupHidden = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
+  let domItem = contextMenu.querySelector("#context-" + contextMenuItem);
+  info("Going to click item " + domItem.id);
+  let bounds = domItem.getBoundingClientRect();
+  ok(bounds.height && bounds.width, "DOM context menu item " + where + " should be visible");
+  ok(!domItem.disabled, "DOM context menu item " + where + " shouldn't be disabled");
+  domItem.click();
+  contextMenu.hidePopup();
+  await awaitPopupHidden;
+
+  let openedThing = await openPromise;
+  await closeMethod(openedThing);
+}
+
+add_task(async function test_select_text_link() {
+  let testTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, RESOURCE_LINK);
+  for (let elementID of ["test-link", "test-image-link", "svg-with-link", "svg-with-relative-link"]) {
+    for (let where of ["tab", "window", "privatewindow"]) {
+      await activateContextAndWaitFor("#" + elementID, where);
+    }
+  }
+  await BrowserTestUtils.removeTab(testTab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/contextMenu/test_contextmenu_links.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Subtest for browser context menu links</title>
+</head>
+<body>
+Browser context menu link subtest.
+
+<a id="test-link" href="https://example.com">Click the monkey!</a>
+<a id="test-image-link" href="/"><img src="ctxmenu-image.png"></a>
+<svg id="svg-with-link" width=10 height=10><a xlink:href="https://example.com/"><circle cx="50%" cy="50%" r="50%" fill="blue"/></a></svg>
+<svg id="svg-with-relative-link" width=10 height=10><a xlink:href="/"><circle cx="50%" cy="50%" r="50%" fill="blue"/></a></svg>
+</body>
+</html>
--- a/browser/modules/ContextMenu.jsm
+++ b/browser/modules/ContextMenu.jsm
@@ -687,17 +687,17 @@ class ContextMenu {
           HAVE_CURRENT_DATA: context.target.HAVE_CURRENT_DATA,
         });
       }
     }
 
     context.target = cleanTarget;
 
     if (context.link) {
-      context.link = { href: context.link.href };
+      context.link = { href: context.linkURL };
     }
 
     delete context.linkURI;
   }
 
   _setContext(aEvent) {
     this.context = Object.create(null);
     const context = this.context;