Bug 1120748 - Ensure the progress listener created by createNetworkErrorMessagePromise() isn't GCed too early. r=felipe, a=test-only
authorTim Taubert <ttaubert@mozilla.com>
Thu, 02 Apr 2015 12:04:40 +0200
changeset 258234 9c755cdc241c
parent 258233 b9d2266daf60
child 258235 ffb13ef5ff0a
push id4623
push userryanvm@gmail.com
push date2015-04-03 01:49 +0000
treeherdermozilla-beta@9c755cdc241c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, test-only
bugs1120748
milestone38.0
Bug 1120748 - Ensure the progress listener created by createNetworkErrorMessagePromise() isn't GCed too early. r=felipe, 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,21 +15,22 @@ 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) {
-  return new Promise(function(resolve, reject) {
+  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;
 
-    let progressListener = {
+    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");
         }
       },
 
       onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
@@ -60,18 +61,27 @@ function createNetworkErrorMessagePromis
       QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
                           Ci.nsISupportsWeakReference])
     };
 
     aBrowser.addProgressListener(progressListener,
             Ci.nsIWebProgress.NOTIFY_LOCATION |
             Ci.nsIWebProgress.NOTIFY_STATE_REQUEST);
   });
+
+  // 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);