Bug 1374741 - Within devtools/ tests make openUILinkIn() provide the correct triggeringPrincipal. r?pbro draft
authorJonathan Kingston <jkt@mozilla.com>
Wed, 21 Feb 2018 23:21:03 +0000
changeset 759756 9381663777dacbc2b84faaf607760026a4cfbb3a
parent 759755 9e74f48c2a0842d7c53050d8ed886ef1e645f992
push id100453
push userbmo:jkt@mozilla.com
push dateMon, 26 Feb 2018 15:22:58 +0000
reviewerspbro
bugs1374741
milestone60.0a1
Bug 1374741 - Within devtools/ tests make openUILinkIn() provide the correct triggeringPrincipal. r?pbro 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(function* () {
   document.querySelector("[aria-controls='addons-panel']").click();
   yield waitUntilElement("#addons-panel", document);
 
   yield 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");
   yield waitUntilElement(".error-page", document);
 
   element = document.querySelector(".header-name");
   is(element.textContent, "Page not found", "Show error page");
 
   gBrowser.goBack();
   yield waitUntilElement("#addons-panel", document);
   yield waitForInitialAddonList(document);
--- a/devtools/client/webconsole/new-console-output/test/mochitest/head.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/head.js
@@ -477,38 +477,44 @@ async function closeConsole(tab = gBrows
  * @returns Promise
  *          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;
+  let oldOpenTrustedLinkIn = window.openTrustedLinkIn;
+  let oldOpenWebLinkIn = window.openWebLinkIn;
 
   const onOpenLink = new Promise((resolve) => {
-    window.openUILinkIn = function (link, where) {
-      window.openUILinkIn = oldOpenUILinkIn;
+    window.openTrustedLinkIn = function (link, where) {
+      window.openTrustedLinkIn = oldOpenTrustedLinkIn;
+      resolve({link: link, where});
+    };
+    window.openWebLinkIn = function (link, where) {
+      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 was not called.
   let timeoutId;
   const onTimeout = new Promise(function(resolve, reject) {
     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
@@ -1774,21 +1774,29 @@ 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.openUILinkIn;
+  window.openWebLinkIn = function (link) {
     if (link == expectedLink) {
       ok(true, "Clicking the message link opens the desired page");
-      window.openUILinkIn = oldOpenUILinkIn;
+      window.openWebLinkIn = oldOpenWebLinkIn;
+      deferred.resolve();
+    }
+  };
+  let oldOpenTrustedLinkIn = window.openUILinkIn;
+  window.openTrustedLinkIn = function (link) {
+    if (link == expectedLink) {
+      ok(true, "Clicking the message link opens the desired page");
+      window.openTrustedLinkIn = oldOpenTrustedLinkIn;
       deferred.resolve();
     }
   };
 
   let event = new MouseEvent("click", {
     detail: 1,
     button: 0,
     bubbles: true,