Bug 1128027 - Rework Console tests that click links. r=bgrins a=lsblakk
authorJ. Ryan Stinnett <jryans@gmail.com>
Wed, 11 Mar 2015 12:07:22 -0500
changeset 250340 9fb666f03801
parent 250339 fbef1b8d36e0
child 250341 7e2e728297e6
push id4553
push userjryans@gmail.com
push date2015-03-11 17:07 +0000
treeherdermozilla-beta@7e2e728297e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins, lsblakk
bugs1128027
milestone37.0
Bug 1128027 - Rework Console tests that click links. r=bgrins a=lsblakk Console tests that click message links were allowing the events to bleed over into the next test, causing intermittent failures.
browser/devtools/webconsole/test/browser_webconsole_allow_mixedcontent_securityerrors.js
browser/devtools/webconsole/test/browser_webconsole_block_mixedcontent_securityerrors.js
browser/devtools/webconsole/test/browser_webconsole_bug_632275_getters_document_width.js
browser/devtools/webconsole/test/browser_webconsole_bug_737873_mixedcontent.js
browser/devtools/webconsole/test/browser_webconsole_bug_762593_insecure_passwords_web_console_warning.js
browser/devtools/webconsole/test/browser_webconsole_bug_846918_hsts_invalid-headers.js
browser/devtools/webconsole/test/head.js
--- a/browser/devtools/webconsole/test/browser_webconsole_allow_mixedcontent_securityerrors.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_allow_mixedcontent_securityerrors.js
@@ -34,17 +34,17 @@ let test = asyncTest(function* () {
         text: "Loading mixed (insecure) display content \"http://example.com/tests/image/test/mochitest/blue.png\" on a secure page",
         category: CATEGORY_SECURITY,
         severity: SEVERITY_WARNING,
         objects: true,
       },
     ],
   });
 
-  testClickOpenNewTab(hud, results);
+  yield testClickOpenNewTab(hud, results);
 });
 
 function pushPrefEnv()
 {
   let deferred = promise.defer();
   let options = {"set":
       [["security.mixed_content.block_active_content", false],
        ["security.mixed_content.block_display_content", false]
@@ -52,23 +52,10 @@ function pushPrefEnv()
   SpecialPowers.pushPrefEnv(options, deferred.resolve);
   return deferred.promise;
 }
 
 function testClickOpenNewTab(hud, results) {
   let warningNode = results[0].clickableElements[0];
   ok(warningNode, "link element");
   ok(warningNode.classList.contains("learn-more-link"), "link class name");
-
-  // Invoke the click event and check if a new tab would open to the correct page.
-  let linkOpened = false;
-  let oldOpenUILinkIn = window.openUILinkIn;
-  window.openUILinkIn = function(aLink) {
-    if (aLink == LEARN_MORE_URI) {
-      linkOpened = true;
-    }
-  }
-
-  EventUtils.synthesizeMouse(warningNode, 2, 2, {},
-                             warningNode.ownerDocument.defaultView);
-  ok(linkOpened, "Clicking the Learn More Warning node opens the desired page");
-  window.openUILinkIn = oldOpenUILinkIn;
+  return simulateMessageLinkClick(warningNode, LEARN_MORE_URI);
 }
--- a/browser/devtools/webconsole/test/browser_webconsole_block_mixedcontent_securityerrors.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_block_mixedcontent_securityerrors.js
@@ -38,21 +38,21 @@ let test = asyncTest(function* () {
         text: "Blocked loading mixed active content \"http://example.com/\"",
         category: CATEGORY_SECURITY,
         severity: SEVERITY_ERROR,
         objects: true,
       },
     ],
   });
 
-  testClickOpenNewTab(hud, results[0]);
+  yield testClickOpenNewTab(hud, results[0]);
 
   let results2 = yield mixedContentOverrideTest2(hud, browser);
 
-  testClickOpenNewTab(hud, results2[0]);
+  yield testClickOpenNewTab(hud, results2[0]);
 });
 
 function pushPrefEnv()
 {
   let deferred = promise.defer();
   let options = {"set": [["security.mixed_content.block_active_content", true],
                             ["security.mixed_content.block_display_content", true]]};
   SpecialPowers.pushPrefEnv(options, deferred.resolve);
@@ -113,24 +113,10 @@ function afterNotificationShown(hud, not
     ],
   }).then(msgs => deferred.resolve(msgs), Cu.reportError);
 }
 
 function testClickOpenNewTab(hud, match) {
   let warningNode = match.clickableElements[0];
   ok(warningNode, "link element");
   ok(warningNode.classList.contains("learn-more-link"), "link class name");
-
-  // Invoke the click event and check if a new tab would
-  // open to the correct page.
-  let linkOpened = false;
-  let oldOpenUILinkIn = window.openUILinkIn;
-  window.openUILinkIn = function(aLink) {
-    if (aLink == LEARN_MORE_URI) {
-      linkOpened = true;
-    }
-  }
-
-  EventUtils.synthesizeMouse(warningNode, 2, 2, {},
-                             warningNode.ownerDocument.defaultView);
-  ok(linkOpened, "Clicking the Learn More Warning node opens the desired page");
-  window.openUILinkIn = oldOpenUILinkIn;
+  return simulateMessageLinkClick(warningNode, LEARN_MORE_URI);
 }
--- a/browser/devtools/webconsole/test/browser_webconsole_bug_632275_getters_document_width.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_bug_632275_getters_document_width.js
@@ -1,18 +1,11 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-///////////////////
-//
-// Whitelisting this test.
-// As part of bug 1077403, the leaking uncaught rejection should be fixed. 
-//
-thisTestLeaksUncaughtRejectionsAndShouldBeFixed("Error: Connection closed");
-
 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-bug-632275-getters.html";
 
 let getterValue = null;
 
 function test() {
   loadTab(TEST_URI).then(() => {
     openConsole().then(consoleOpened);
   });
--- a/browser/devtools/webconsole/test/browser_webconsole_bug_737873_mixedcontent.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_bug_737873_mixedcontent.js
@@ -7,65 +7,54 @@
  *  Tanvi Vyas <tanvi@mozilla.com>
  *
  * ***** END LICENSE BLOCK ***** */
 
 // Tests that the Web Console Mixed Content messages are displayed
 
 const TEST_URI = "data:text/html;charset=utf8,Web Console mixed content test";
 const TEST_HTTPS_URI = "https://example.com/browser/browser/devtools/webconsole/test/test-bug-737873-mixedcontent.html";
+const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Security/MixedContent";
 
 let test = asyncTest(function* () {
   Services.prefs.setBoolPref("security.mixed_content.block_display_content", false);
   Services.prefs.setBoolPref("security.mixed_content.block_active_content", false);
 
   yield loadTab(TEST_URI);
 
   let hud = yield openConsole();
 
   yield testMixedContent(hud);
 
   Services.prefs.clearUserPref("security.mixed_content.block_display_content");
   Services.prefs.clearUserPref("security.mixed_content.block_active_content");
 });
 
-function testMixedContent(hud) {
+let testMixedContent = Task.async(function*(hud) {
   content.location = TEST_HTTPS_URI;
 
-  return waitForMessages({
+  let results = yield waitForMessages({
     webconsole: hud,
     messages: [{
       text: "example.com",
       category: CATEGORY_NETWORK,
       severity: SEVERITY_WARNING,
     }],
-  }).then((results) => {
-    let msg = [...results[0].matched][0];
-    ok(msg, "page load logged");
-    ok(msg.classList.contains("mixed-content"), ".mixed-content element");
+  });
 
-    let link = msg.querySelector(".learn-more-link");
-    ok(link, "mixed content link element");
-    is(link.textContent, "[Mixed Content]", "link text is accurate");
+  let msg = [...results[0].matched][0];
+  ok(msg, "page load logged");
+  ok(msg.classList.contains("mixed-content"), ".mixed-content element");
+
+  let link = msg.querySelector(".learn-more-link");
+  ok(link, "mixed content link element");
+  is(link.textContent, "[Mixed Content]", "link text is accurate");
 
-    let oldOpenLink = hud.openLink;
-    let linkOpened = false;
-    hud.openLink = (url) => {
-      is(url, "https://developer.mozilla.org/docs/Security/MixedContent",
-         "url opened");
-      linkOpened = true;
-    };
+  yield simulateMessageLinkClick(link, LEARN_MORE_URI);
 
-    EventUtils.synthesizeMouse(link, 2, 2, {}, link.ownerDocument.defaultView);
-
-    ok(linkOpened, "clicking the Mixed Content link opened a page");
+  ok(!msg.classList.contains("filtered-by-type"), "message is not filtered");
 
-    hud.openLink = oldOpenLink;
-
-    ok(!msg.classList.contains("filtered-by-type"), "message is not filtered");
-
-    hud.setFilterState("netwarn", false);
+  hud.setFilterState("netwarn", false);
 
-    ok(msg.classList.contains("filtered-by-type"), "message is filtered");
+  ok(msg.classList.contains("filtered-by-type"), "message is filtered");
 
-    hud.setFilterState("netwarn", true);
-  });
-}
+  hud.setFilterState("netwarn", true);
+});
--- a/browser/devtools/webconsole/test/browser_webconsole_bug_762593_insecure_passwords_web_console_warning.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_bug_762593_insecure_passwords_web_console_warning.js
@@ -35,31 +35,17 @@ let test = asyncTest(function* () {
         name: "Insecure form action error displayed successfully",
         text: INSECURE_FORM_ACTION_MSG,
         category: CATEGORY_SECURITY,
         severity: SEVERITY_WARNING
       },
     ],
   });
 
-  testClickOpenNewTab(hud, result);
+  yield testClickOpenNewTab(hud, result);
 });
 
 function testClickOpenNewTab(hud, [result]) {
   let msg = [...result.matched][0];
   let warningNode = msg.querySelector(".learn-more-link");
   ok(warningNode, "learn more link");
-
-  // Invoke the click event and check if a new tab would open to the correct
-  // page
-  let linkOpened = false;
-  let oldOpenUILinkIn = window.openUILinkIn;
-  window.openUILinkIn = function(aLink) {
-    if (aLink == INSECURE_PASSWORDS_URI) {
-      linkOpened = true;
-    }
-  }
-
-  EventUtils.synthesizeMouse(warningNode, 2, 2, {},
-                             warningNode.ownerDocument.defaultView);
-  ok(linkOpened, "Clicking the Insecure Passwords Warning node opens the desired page");
-  window.openUILinkIn = oldOpenUILinkIn;
+  return simulateMessageLinkClick(warningNode, INSECURE_PASSWORDS_URI);
 }
--- a/browser/devtools/webconsole/test/browser_webconsole_bug_846918_hsts_invalid-headers.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_bug_846918_hsts_invalid-headers.js
@@ -1,50 +1,35 @@
  /* Any copyright is dedicated to the Public Domain.
   * http://creativecommons.org/publicdomain/zero/1.0/ */
 /* Tests that errors about invalid HSTS security headers are logged
  *  to the web console */
 const TEST_URI = "https://example.com/browser/browser/devtools/webconsole/test/test-bug-846918-hsts-invalid-headers.html";
 const HSTS_INVALID_HEADER_MSG = "The site specified an invalid Strict-Transport-Security header.";
 const LEARN_MORE_URI = "https://developer.mozilla.org/docs/Security/HTTP_Strict_Transport_Security";
 
-function test()
-{
-  loadTab(TEST_URI).then(() => {
-    openConsole().then((hud) => {
-      waitForMessages({
-        webconsole: hud,
-        messages: [
-          {
-            name: "Invalid HSTS header error displayed successfully",
-            text: HSTS_INVALID_HEADER_MSG,
-            category: CATEGORY_SECURITY,
-            severity: SEVERITY_WARNING,
-            objects: true,
-          },
-        ],
-      }).then((results) => testClickOpenNewTab(hud, results));
-    })
+let test = asyncTest(function* () {
+  yield loadTab(TEST_URI);
+
+  let hud = yield openConsole();
+
+  let results = yield waitForMessages({
+    webconsole: hud,
+    messages: [
+      {
+        name: "Invalid HSTS header error displayed successfully",
+        text: HSTS_INVALID_HEADER_MSG,
+        category: CATEGORY_SECURITY,
+        severity: SEVERITY_WARNING,
+        objects: true,
+      },
+    ],
   });
-}
+
+  yield testClickOpenNewTab(hud, results);
+});
 
 function testClickOpenNewTab(hud, results) {
   let warningNode = results[0].clickableElements[0];
   ok(warningNode, "link element");
   ok(warningNode.classList.contains("learn-more-link"), "link class name");
-
-  // Invoke the click event and check if a new tab would
-  // open to the correct page.
-  let linkOpened = false;
-  let oldOpenUILinkIn = window.openUILinkIn;
-  window.openUILinkIn = function(aLink) {
-    if (aLink == LEARN_MORE_URI) {
-      linkOpened = true;
-    }
-  }
-
-  EventUtils.synthesizeMouse(warningNode, 2, 2, {},
-                             warningNode.ownerDocument.defaultView);
-  ok(linkOpened, "Clicking the Learn More Warning node opens the desired page");
-  window.openUILinkIn = oldOpenUILinkIn;
-
-  finishTest();
+  return simulateMessageLinkClick(warningNode, LEARN_MORE_URI);
 }
--- a/browser/devtools/webconsole/test/head.js
+++ b/browser/devtools/webconsole/test/head.js
@@ -1625,8 +1625,37 @@ function once(target, eventName, useCapt
 
   return deferred.promise;
 }
 
 function getSourceActor(aSources, aURL) {
   let item = aSources.getItemForAttachment(a => a.source.url === aURL);
   return item && item.value;
 }
+
+/**
+ * Verify that clicking on a link from a popup notification message tries to
+ * open the expected URL.
+ */
+function simulateMessageLinkClick(element, expectedLink) {
+  let deferred = promise.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) {
+    if (link == expectedLink) {
+      ok(true, "Clicking the message link opens the desired page");
+      window.openUILinkIn = oldOpenUILinkIn;
+      deferred.resolve();
+    }
+  };
+
+  let event = new MouseEvent("click", {
+    detail: 1,
+    button: 0,
+    bubbles: true,
+    cancelable: true
+  });
+  element.dispatchEvent(event);
+
+  return deferred.promise;
+}