Bug 1100687 - part 1: fix browser_addCertException.js, r=jaws
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 26 Feb 2016 14:50:03 +0000
changeset 322342 083380e8d36f1ad68ddd565eeee3231ac9196282
parent 322341 8033efa33b55d559f6d8735f4d404435b3fbf57e
child 322343 2fa086d51b6a8d94566493b34cbce00a37af5024
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1100687
milestone47.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 1100687 - part 1: fix browser_addCertException.js, r=jaws MozReview-Commit-ID: ZHUpRLAkxV
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_addCertException.js
browser/base/content/test/general/head.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -513,17 +513,16 @@ skip-if = e10s # Bug 1094240 - has findb
 [browser_registerProtocolHandler_notification.js]
 [browser_no_mcb_on_http_site.js]
 tags = mcb
 [browser_bug1104165-switchtab-decodeuri.js]
 [browser_bug1003461-switchtab-override.js]
 [browser_bug1024133-switchtab-override-keynav.js]
 [browser_bug1025195_switchToTabHavingURI_aOpenParams.js]
 [browser_addCertException.js]
-skip-if = e10s # Bug 1100687 - test directly manipulates content (content.document.getElementById)
 [browser_bug1045809.js]
 tags = mcb
 [browser_bug1225194-remotetab.js]
 [browser_e10s_switchbrowser.js]
 [browser_e10s_about_process.js]
 [browser_e10s_chrome_process.js]
 [browser_e10s_javascript.js]
 [browser_blockHPKP.js]
--- a/browser/base/content/test/general/browser_addCertException.js
+++ b/browser/base/content/test/general/browser_addCertException.js
@@ -11,83 +11,60 @@
 // the site, including showing the right identity box and control center icons.
 function test() {
   waitForExplicitFinish();
   whenNewTabLoaded(window, loadBadCertPage);
 }
 
 // Attempt to load https://expired.example.com (which has an expired cert).
 function loadBadCertPage() {
-  gBrowser.addProgressListener(certErrorProgressListener);
-  gBrowser.selectedBrowser.loadURI("https://expired.example.com");
+  Services.obs.addObserver(certExceptionDialogObserver,
+                           "cert-exception-ui-ready", false);
+  let startedLoad = BrowserTestUtils.loadURI(gBrowser.selectedBrowser,
+                                             "https://expired.example.com");
+  startedLoad.then(() => promiseErrorPageLoaded(gBrowser.selectedBrowser)).then(function() {
+    ContentTask.spawn(gBrowser.selectedBrowser, null, function*() {
+      content.document.getElementById("exceptionDialogButton").click();
+    });
+  });
 }
 
-// The browser should load about:certerror. When This happens, click the
-// button to open the certificate exception dialog.
-var certErrorProgressListener = {
-  buttonClicked: false,
-
-  onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
-    if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
-      let self = this;
-      // Can't directly call button.click() in onStateChange
-      executeSoon(function() {
-        let button = content.document.getElementById("exceptionDialogButton");
-        // If about:certerror hasn't fully loaded, the button won't be present.
-        // It will eventually be there, however.
-        if (button && !self.buttonClicked) {
-          gBrowser.removeProgressListener(self);
-          Services.obs.addObserver(certExceptionDialogObserver,
-                                   "cert-exception-ui-ready", false);
-          button.click();
-        }
-      });
-    }
-  }
-};
-
 // When the certificate exception dialog has opened, click the button to add
 // an exception.
 const EXCEPTION_DIALOG_URI = "chrome://pippki/content/exceptionDialog.xul";
 var certExceptionDialogObserver = {
   observe: function(aSubject, aTopic, aData) {
     if (aTopic == "cert-exception-ui-ready") {
       Services.obs.removeObserver(this, "cert-exception-ui-ready");
       let certExceptionDialog = getDialog(EXCEPTION_DIALOG_URI);
       ok(certExceptionDialog, "found exception dialog");
       executeSoon(function() {
-        gBrowser.selectedBrowser.addEventListener("load",
-                                                  successfulLoadListener,
-                                                  true);
+        BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(realPageLoaded);
         certExceptionDialog.documentElement.getButton("extra1").click();
       });
     }
   }
 };
 
 // Finally, we should successfully load https://expired.example.com.
-var successfulLoadListener = {
-  handleEvent: function() {
-    gBrowser.selectedBrowser.removeEventListener("load", this, true);
-    checkControlPanelIcons();
-    let certOverrideService = Cc["@mozilla.org/security/certoverride;1"]
-                                .getService(Ci.nsICertOverrideService);
-    certOverrideService.clearValidityOverride("expired.example.com", -1);
-    gBrowser.removeTab(gBrowser.selectedTab);
-    finish();
-  }
+function realPageLoaded() {
+  checkControlPanelIcons();
+  let certOverrideService = Cc["@mozilla.org/security/certoverride;1"]
+                              .getService(Ci.nsICertOverrideService);
+  certOverrideService.clearValidityOverride("expired.example.com", -1);
+  BrowserTestUtils.removeTab(gBrowser.selectedTab).then(finish);
 };
 
 // Check for the correct icons in the identity box and control center.
 function checkControlPanelIcons() {
   let { gIdentityHandler } = gBrowser.ownerGlobal;
   gIdentityHandler._identityBox.click();
   document.getElementById("identity-popup-security-expander").click();
 
-  is_element_visible(document.getElementById("connection-icon"));
+  is_element_visible(document.getElementById("connection-icon"), "Should see connection icon");
   let connectionIconImage = gBrowser.ownerGlobal
         .getComputedStyle(document.getElementById("connection-icon"), "")
         .getPropertyValue("list-style-image");
   let securityViewBG = gBrowser.ownerGlobal
         .getComputedStyle(document.getElementById("identity-popup-securityView"), "")
         .getPropertyValue("background-image");
   let securityContentBG = gBrowser.ownerGlobal
         .getComputedStyle(document.getElementById("identity-popup-security-content"), "")
--- a/browser/base/content/test/general/head.js
+++ b/browser/base/content/test/general/head.js
@@ -953,22 +953,22 @@ function is_visible(element) {
   if (element.parentNode != element.ownerDocument)
     return is_visible(element.parentNode);
 
   return true;
 }
 
 function is_element_visible(element, msg) {
   isnot(element, null, "Element should not be null, when checking visibility");
-  ok(is_visible(element), msg);
+  ok(is_visible(element), msg || "Element should be visible");
 }
 
 function is_element_hidden(element, msg) {
   isnot(element, null, "Element should not be null, when checking visibility");
-  ok(is_hidden(element), msg);
+  ok(is_hidden(element), msg || "Element should be hidden");
 }
 
 function promisePopupEvent(popup, eventSuffix) {
   let endState = {shown: "open", hidden: "closed"}[eventSuffix];
 
   if (popup.state == endState)
     return Promise.resolve();
 
@@ -1210,8 +1210,17 @@ function promiseCrashReport(expectedExtr
         } else {
           is(value, expectedExtra[key],
              `Crash report had the right extra value for ${key}`);
         }
       }
     }
   });
 }
+
+function promiseErrorPageLoaded(browser) {
+  return new Promise(resolve => {
+    browser.addEventListener("DOMContentLoaded", function onLoad() {
+      browser.removeEventListener("DOMContentLoaded", onLoad, false, true);
+      resolve();
+    }, false, true);
+  });
+}