Bug 1288606 - Fix intermittent orange by making sure a weakly held nsISHistoryListener doesn't get GC'd before the browser_bug670318.js completes. r?Gijs draft
authorMike Conley <mconley@mozilla.com>
Tue, 11 Oct 2016 09:43:57 -0400
changeset 423648 d7f9990e9ee74b2b694da88a5bb4eb228857f3fe
parent 423325 f143da9b49b249a809c208ad81df1d4517be6c49
child 533498 4833fe02a1719892343af5902e150762ed75462c
push id31957
push usermconley@mozilla.com
push dateTue, 11 Oct 2016 13:44:29 +0000
reviewersGijs
bugs1288606, 670318
milestone52.0a1
Bug 1288606 - Fix intermittent orange by making sure a weakly held nsISHistoryListener doesn't get GC'd before the browser_bug670318.js completes. r?Gijs MozReview-Commit-ID: AWvpK6OpmmI
docshell/test/browser/browser_bug670318.js
--- a/docshell/test/browser/browser_bug670318.js
+++ b/docshell/test/browser/browser_bug670318.js
@@ -26,16 +26,17 @@ add_task(function* test() {
             addEventListener("load", function onLoad() {
               removeEventListener("load", onLoad, true);
 
               Assert.ok(history.index < history.count, "history.index is valid");
               testDone.resolve();
             }, true);
 
             history.removeSHistoryListener(listener);
+            delete content._testListener;
             content.setTimeout(() => { content.location.reload(); }, 0);
           }
 
           return true;
         },
 
         OnHistoryReload: () => true,
         OnHistoryGoBack: () => true,
@@ -50,13 +51,20 @@ add_task(function* test() {
           return true;
         },
 
         QueryInterface: XPCOMUtils.generateQI([Ci.nsISHistoryListener,
                                                Ci.nsISupportsWeakReference])
       };
 
       history.addSHistoryListener(listener);
+      // Since listener implements nsISupportsWeakReference, we are
+      // responsible for keeping it alive so that the GC doesn't clear
+      // it before the test completes. We do this by anchoring the listener
+      // to the content global window, and clearing it just before the test
+      // completes.
+      content._testListener = listener;
       content.location = URL;
+
       yield testDone.promise;
     });
   });
 });