Bug 1300647 - Part 2 - Test that the session store correctly handles the "Tab:KeepZombified" notification. r=ahunt draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 10 Sep 2016 23:01:10 +0200
changeset 413156 167366635e7fcd751acf1ed05e9a7c6532f5ad44
parent 413155 d071884dd1e78b7da470b042e244093e797dde61
child 531165 69496e30620af332ccc0939b5943468263b242be
push id29364
push usermozilla@buttercookie.de
push dateTue, 13 Sep 2016 18:47:37 +0000
reviewersahunt
bugs1300647
milestone51.0a1
Bug 1300647 - Part 2 - Test that the session store correctly handles the "Tab:KeepZombified" notification. r=ahunt MozReview-Commit-ID: 2x9V4o5iPDg
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
@@ -91,16 +91,91 @@ https://bugzilla.mozilla.org/show_bug.cg
     // 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.");
   });
 
+  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);
+    });
+
+    // 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 });
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabBlank, "Test tab is in background.");
+
+    // Zombify the backgrounded test tab
+    MemoryObserver.zombify(tabTest);
+
+    // Check that the test tab is actually zombified
+    ok(tabTest.browser.__SS_restore, "Test tab is set for delay loading.");
+    is(tabTest.browser.currentURI.spec, "about:blank", "Test tab is zombified.");
+
+    // Tell the session store that it shouldn't restore that tab on selecting
+    observerService.notifyObservers(null, "Tab:KeepZombified", tabTest.id);
+
+    // Switch back to the test tab and check that it remains zombified
+    BrowserApp.selectTab(tabTest);
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabTest, "Test tab is selected.");
+    ok(tabTest.browser.__SS_restore, "Test tab is still set for delay loading.");
+
+    // Switch to the other tab and back again
+    BrowserApp.selectTab(tabBlank);
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabBlank, "Test tab is in background.");
+    BrowserApp.selectTab(tabTest);
+
+    // "Tab:KeepZombified should be good for one TabSelect only
+    yield promiseBrowserEvent(tabTest.browser, "DOMContentLoaded");
+    is(BrowserApp.selectedTab, tabTest, "Test tab is selected.");
+
+    // Check that the test tab is no longer a zombie and has loaded the correct url
+    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.");
+
+    // Zombify the test tab again
+    BrowserApp.selectTab(tabBlank);
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabBlank, "Test tab is in background.");
+    MemoryObserver.zombify(tabTest);
+    ok(tabTest.browser.__SS_restore, "Test tab is set for delay loading.");
+    is(tabTest.browser.currentURI.spec, "about:blank", "Test tab is zombified.");
+
+    // Tell the session store that it shouldn't restore that tab on selecting
+    observerService.notifyObservers(null, "Tab:KeepZombified", tabTest.id);
+
+    // Switch back to the test tab and check that it remains zombified
+    BrowserApp.selectTab(tabTest);
+    yield promiseTabEvent(BrowserApp.deck, "TabSelect");
+    is(BrowserApp.selectedTab, tabTest, "Test tab is selected.");
+    ok(tabTest.browser.__SS_restore, "Test tab is still set for delay loading.");
+
+    // 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.");
+  });
+
   </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">
 
 </div>