Bug 1320987 - Stop leaking tabs during test_session_zombification. r=gbrown draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 30 Nov 2016 21:53:33 +0100
changeset 446052 5e870acba4c8ee05557f1ac0175bda12606b4e28
parent 445506 bb43b9d6d37485a8215557c39e75fd7814cc2d8d
child 538693 0e3cf84351ee6a5617033e78a864774b8785dc88
push id37687
push usermozilla@buttercookie.de
push dateWed, 30 Nov 2016 21:23:19 +0000
reviewersgbrown
bugs1320987
milestone53.0a1
Bug 1320987 - Stop leaking tabs during test_session_zombification. r=gbrown A subtest's cleanup function only runs at the very end, after *all* subtests have finished. This means that we cannot use it to close the test tabs if we want to reuse the tab variables during following subtests. If we did, we'd be leaking those previous tabs, meaning they remain open at the end of the test and cause possible problems for following tests as well as lots of "Unable to restore focus" messages in the log. MozReview-Commit-ID: H87JQ5gcIAg
mobile/android/tests/browser/chrome/test_session_zombification.html
--- a/mobile/android/tests/browser/chrome/test_session_zombification.html
+++ b/mobile/android/tests/browser/chrome/test_session_zombification.html
@@ -28,32 +28,41 @@ https://bugzilla.mozilla.org/show_bug.cg
   Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
   XPCOMUtils.defineLazyGetter(this, "MemoryObserver", function() {
     let sandbox = {};
     Services.scriptloader.loadSubScript("chrome://browser/content/MemoryObserver.js", sandbox);
     return sandbox["MemoryObserver"];
   });
 
   // The chrome window
-  let chromeWin;
+  let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+  let BrowserApp = chromeWin.BrowserApp;
 
   // Track the tabs where the tests are happening
   let tabBlank;
   let tabTest;
 
+  function cleanupTabs() {
+    if (tabBlank) {
+      BrowserApp.closeTab(tabBlank);
+      tabBlank = null;
+    }
+
+    if (tabTest) {
+      BrowserApp.closeTab(tabTest);
+      tabTest = null;
+    }
+  }
+
   const url1 = "data:text/html;charset=utf-8,It%20was%20a%20dark%20and%20stormy%20night.";
   const url2 = "data:text/html;charset=utf-8,Suddenly%2C%20a%20tab%20was%20zombified.";
 
   add_task(function* test_sessionStoreZombify() {
-    chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
-    let BrowserApp = chromeWin.BrowserApp;
-
     SimpleTest.registerCleanupFunction(function() {
-      BrowserApp.closeTab(tabBlank);
-      BrowserApp.closeTab(tabTest);
+      cleanupTabs();
     });
 
     // Add a new tab with some content
     tabTest = BrowserApp.addTab(url1 , { selected: true, parentId: BrowserApp.selectedTab.id });
     yield promiseBrowserEvent(tabTest.browser, "DOMContentLoaded");
 
     // Add a new tab with a blank page
     tabBlank = BrowserApp.addTab("about:blank", { selected: true, parentId: BrowserApp.selectedTab.id });
@@ -89,26 +98,25 @@ https://bugzilla.mozilla.org/show_bug.cg
     ok(tabTest.browser.__SS_restore, "Test tab is set for delay loading.");
 
     // Switch back to the test tab and wait for it to reload
     BrowserApp.selectTab(tabTest);
     yield promiseBrowserEvent(tabTest.browser, "DOMContentLoaded");
 
     // Check that the test tab has loaded the correct url
     is(tabTest.browser.currentURI.spec, url2, "Test tab is showing the second URL.");
+
+    cleanupTabs();
   });
 
   add_task(function* test_sessionStoreKeepAsZombie() {
-    chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
-    let BrowserApp = chromeWin.BrowserApp;
     let observerService = Services.obs;
 
     SimpleTest.registerCleanupFunction(function() {
-      BrowserApp.closeTab(tabBlank);
-      BrowserApp.closeTab(tabTest);
+      cleanupTabs();
     });
 
     // Add a new tab with some content
     tabTest = BrowserApp.addTab(url1 , { selected: true, parentId: BrowserApp.selectedTab.id });
     yield promiseBrowserEvent(tabTest.browser, "DOMContentLoaded");
 
     // Add a new tab with a blank page
     tabBlank = BrowserApp.addTab("about:blank", { selected: true, parentId: BrowserApp.selectedTab.id });
@@ -164,16 +172,18 @@ https://bugzilla.mozilla.org/show_bug.cg
 
     // Fake an "application-foreground" notification
     observerService.notifyObservers(null, "application-foreground", null);
 
     // The test tab should now start reloading
     yield promiseBrowserEvent(tabTest.browser, "DOMContentLoaded");
     ok(!tabTest.browser.__SS_restore, "Test tab is no longer set for delay loading.");
     is(tabTest.browser.currentURI.spec, url1, "Test tab is showing the test URL.");
+
+    cleanupTabs();
   });
 
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1044556">Mozilla Bug 1044556</a>
 <p id="display"></p>
 <div id="content" style="display: none">