Bug 1120748 - Resolve intermittent failure of browser_ssl_error_reports.js. r=ttaubert, a=test-only
authorMark Goodwin <mgoodwin@mozilla.com>
Wed, 15 Apr 2015 15:49:51 +0100
changeset 258502 22eb12ac64e9
parent 258501 34331bbc9575
child 258503 348cc6be3ba0
push id4682
push userryanvm@gmail.com
push date2015-04-16 18:48 +0000
treeherdermozilla-beta@45a5eaa7813b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert, test-only
bugs1120748
milestone38.0
Bug 1120748 - Resolve intermittent failure of browser_ssl_error_reports.js. r=ttaubert, a=test-only
browser/base/content/test/general/browser_ssl_error_reports.js
--- a/browser/base/content/test/general/browser_ssl_error_reports.js
+++ b/browser/base/content/test/general/browser_ssl_error_reports.js
@@ -15,73 +15,42 @@ add_task(function* test_send_report_manu
 });
 
 add_task(function* test_send_report_manual_nocert() {
   yield testSendReportManual(noCertURL, "nocert");
 });
 
 // creates a promise of the message in an error page
 function createNetworkErrorMessagePromise(aBrowser) {
-  let progressListener;
   let promise = new Promise(function(resolve, reject) {
-    // Error pages do not fire "load" events, so use a progressListener.
     let originalDocumentURI = aBrowser.contentDocument.documentURI;
 
-    progressListener = {
-      onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {
-        // Make sure nothing other than an error page is loaded.
-        if (!(aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_ERROR_PAGE)) {
-          reject("location change was not to an error page");
-        }
-      },
+    let loadedListener = function() {
+      let doc = aBrowser.contentDocument;
 
-      onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
-        let doc = aBrowser.contentDocument;
-
-        if (doc && doc.getElementById("reportCertificateError")) {
-          // Wait until the documentURI changes (from about:blank) this should
-          // be the error page URI.
-          let documentURI = doc.documentURI;
-          if (documentURI == originalDocumentURI) {
-            return;
-          }
+      if (doc && doc.getElementById("reportCertificateError")) {
+        let documentURI = doc.documentURI;
 
-          aWebProgress.removeProgressListener(progressListener,
-            Ci.nsIWebProgress.NOTIFY_LOCATION |
-            Ci.nsIWebProgress.NOTIFY_STATE_REQUEST);
-          let matchArray = /about:neterror\?.*&d=([^&]*)/.exec(documentURI);
-          if (!matchArray) {
-            reject("no network error message found in URI")
+        aBrowser.removeEventListener("DOMContentLoaded", loadedListener, true);
+        let matchArray = /about:neterror\?.*&d=([^&]*)/.exec(documentURI);
+        if (!matchArray) {
+          reject("no network error message found in URI");
           return;
-          }
-
-          let errorMsg = matchArray[1];
-          resolve(decodeURIComponent(errorMsg));
         }
-      },
 
-      QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
-                          Ci.nsISupportsWeakReference])
+        let errorMsg = matchArray[1];
+        resolve(decodeURIComponent(errorMsg));
+      }
     };
-
-    aBrowser.addProgressListener(progressListener,
-            Ci.nsIWebProgress.NOTIFY_LOCATION |
-            Ci.nsIWebProgress.NOTIFY_STATE_REQUEST);
+    aBrowser.addEventListener("DOMContentLoaded", loadedListener, true);
   });
 
-  // Ensure the weak progress listener is kept alive as long as the promise.
-  createNetworkErrorMessagePromise.listeners.set(promise, progressListener);
-
   return promise;
 }
 
-// Keep a map of promises to their progress listeners so
-// the weak progress listeners aren't GCed too early.
-createNetworkErrorMessagePromise.listeners = new WeakMap();
-
 // check we can set the 'automatically send' pref
 add_task(function* test_set_automatic() {
   setup();
   let tab = gBrowser.addTab(badChainURL, {skipAnimation: true});
   let browser = tab.linkedBrowser;
   let mm = browser.messageManager;
   mm.loadFrameScript(ROOT + "browser_ssl_error_reports_content.js", true);