Bug 1374741 - Within devtools/ tests make openUILinkIn() provide the correct triggeringPrincipal. r?jryans draft
authorJonathan Kingston <jkt@mozilla.com>
Wed, 21 Feb 2018 23:21:03 +0000
changeset 779509 3edbda51e8503059c4d44d2eb0d660aefceb7632
parent 779508 bc5dc3794db72456af7ccfad5d750f0afadc417b
push id105784
push userbmo:jkt@mozilla.com
push dateTue, 10 Apr 2018 00:20:01 +0000
reviewersjryans
bugs1374741
milestone61.0a1
Bug 1374741 - Within devtools/ tests make openUILinkIn() provide the correct triggeringPrincipal. r?jryans MozReview-Commit-ID: GNEe8H0sc4L
devtools/client/aboutdebugging/test/browser_page_not_found.js
devtools/client/webconsole/new-console-output/test/mochitest/head.js
devtools/client/webconsole/test/browser_webconsole_open-links-without-callback.js
devtools/client/webconsole/test/head.js
--- a/devtools/client/aboutdebugging/test/browser_page_not_found.js
+++ b/devtools/client/aboutdebugging/test/browser_page_not_found.js
@@ -15,17 +15,17 @@ add_task(async function() {
   document.querySelector("[aria-controls='addons-panel']").click();
   await waitUntilElement("#addons-panel", document);
 
   await waitForInitialAddonList(document);
   element = document.querySelector(".header-name");
   is(element.textContent, "Add-ons", "Show Addons");
 
   info("Opening about:debugging#invalid-hash");
-  window.openUILinkIn("about:debugging#invalid-hash", "current");
+  window.openTrustedLinkIn("about:debugging#invalid-hash", "current");
   await waitUntilElement(".error-page", document);
 
   element = document.querySelector(".header-name");
   is(element.textContent, "Page not found", "Show error page");
 
   gBrowser.goBack();
   await waitUntilElement("#addons-panel", document);
   await waitForInitialAddonList(document);
--- a/devtools/client/webconsole/new-console-output/test/mochitest/head.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/head.js
@@ -492,39 +492,42 @@ async function closeConsole(tab = gBrows
  *          A Promise that is resolved when the link click simulation occured or
  *          when the click is not dispatched.
  *          The promise resolves with an object that holds the following properties
  *          - link: url of the link or null(if event not fired)
  *          - where: "tab" if tab is active or "tabshifted" if tab is inactive
  *            or null(if event not fired)
  */
 function simulateLinkClick(element, clickEventProps) {
-  // Override openUILinkIn to prevent navigating.
-  let oldOpenUILinkIn = window.openUILinkIn;
+  // Override LinkIn methods to prevent navigating.
+  let oldOpenTrustedLinkIn = window.openTrustedLinkIn;
+  let oldOpenWebLinkIn = window.openWebLinkIn;
 
   const onOpenLink = new Promise((resolve) => {
-    window.openUILinkIn = function(link, where) {
-      window.openUILinkIn = oldOpenUILinkIn;
+    window.openWebLinkIn = window.openTrustedLinkIn = function(link, where) {
+      window.openTrustedLinkIn = oldOpenTrustedLinkIn;
+      window.openWebLinkIn = oldOpenWebLinkIn;
       resolve({link: link, where});
     };
-
     if (clickEventProps) {
       // Click on the link using the event properties.
       element.dispatchEvent(clickEventProps);
     } else {
       // Click on the link.
       element.click();
     }
   });
 
-  // Declare a timeout Promise that we can use to make sure openUILinkIn was not called.
+  // Declare a timeout Promise that we can use to make sure openTrustedLinkIn or
+  // openWebLinkIn was not called.
   let timeoutId;
   const onTimeout = new Promise(function(resolve) {
     timeoutId = setTimeout(() => {
-      window.openUILinkIn = oldOpenUILinkIn;
+      window.openTrustedLinkIn = oldOpenTrustedLinkIn;
+      window.openWebLinkIn = oldOpenWebLinkIn;
       timeoutId = null;
       resolve({link: null, where: null});
     }, 1000);
   });
 
   onOpenLink.then(() => {
     if (timeoutId) {
       clearTimeout(timeoutId);
--- a/devtools/client/webconsole/test/browser_webconsole_open-links-without-callback.js
+++ b/devtools/client/webconsole/test/browser_webconsole_open-links-without-callback.js
@@ -32,23 +32,23 @@ function test() {
     let messageNode = messages[0].matched.values().next().value;
 
     // The correct anchor is second in the message node; the first anchor has
     // class .cm-variable. Ignore the first one by not matching anchors that
     // have the class .cm-variable.
     let urlNode = messageNode.querySelector("a:not(.cm-variable)");
 
     let linkOpened = false;
-    let oldOpenUILinkIn = window.openUILinkIn;
-    window.openUILinkIn = function (aLink) {
+    let oldOpenWebLinkIn = window.openWebLinkIn;
+    window.openWebLinkIn = function (aLink) {
       if (aLink == TEST_PAGE_URI) {
         linkOpened = true;
       }
     };
 
     EventUtils.synthesizeMouseAtCenter(urlNode, {}, hud.iframeWindow);
 
     ok(linkOpened, "Clicking the URL opens the desired page");
-    window.openUILinkIn = oldOpenUILinkIn;
+    window.openWebLinkIn = oldOpenWebLinkIn;
   }
 
   Task.spawn(runner).then(finishTest);
 }
--- a/devtools/client/webconsole/test/head.js
+++ b/devtools/client/webconsole/test/head.js
@@ -1799,21 +1799,23 @@ function getSourceActor(sources, URL) {
  * Verify that clicking on a link from a popup notification message tries to
  * open the expected URL.
  */
 function simulateMessageLinkClick(element, expectedLink) {
   let deferred = defer();
 
   // Invoke the click event and check if a new tab would
   // open to the correct page.
-  let oldOpenUILinkIn = window.openUILinkIn;
-  window.openUILinkIn = function (link) {
+  let oldOpenWebLinkIn = window.openWebLinkIn;
+  let oldOpenTrustedLinkIn = window.openTrustedLinkIn;
+  window.openTrustedLinkIn = window.openWebLinkIn = function (link) {
     if (link == expectedLink) {
       ok(true, "Clicking the message link opens the desired page");
-      window.openUILinkIn = oldOpenUILinkIn;
+      window.openWebLinkIn = oldOpenWebLinkIn;
+      window.openTrustedLinkIn = oldOpenTrustedLinkIn;
       deferred.resolve();
     }
   };
 
   let event = new MouseEvent("click", {
     detail: 1,
     button: 0,
     bubbles: true,