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 266850 595dcfef6e65e9c3e6d305b3e0b5a0e10ae9a46a
parent 266849 dc916e35a7fcc972491a50d9bb13deda85d49023
child 266851 f66692809cc184d283205eaeae5fb837737823ff
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, test-only
bugs1120748
milestone39.0a2
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);