Files
firefox/mobile/android/tests/browser/chrome/test_session_zombification.html
T

188 lines
7.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1044556
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1044556</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="head.js"></script>
<script type="application/javascript">
/** Test for Bug 1044556 **/
"use strict";
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Messaging.jsm");
Cu.import("resource://gre/modules/Task.jsm");
// The chrome window
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() {
SimpleTest.registerCleanupFunction(function() {
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 });
is(BrowserApp.selectedTab, tabBlank, "Test tab is in background.");
// Zombify the backgrounded test tab
tabTest.zombify();
// Check that the test tab is actually zombified
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, url1, "Test tab is showing the first URL.");
// Navigate to some other content
BrowserApp.loadURI(url2, tabTest.browser);
yield promiseBrowserEvent(tabTest.browser, "DOMContentLoaded");
is(tabTest.browser.currentURI.spec, url2, "Test tab is showing the second URL.");
// Switch to the other tab
BrowserApp.selectTab(tabBlank);
yield promiseTabEvent(BrowserApp.deck, "TabSelect");
is(BrowserApp.selectedTab, tabBlank, "Test tab is in background.");
// Zombify the backgrounded test tab again
tabTest.zombify();
// Check that the test tab is actually zombified
ok(tabTest.browser.__SS_restore, "Test tab is set for delay loading.");
// Test that the tab's own function for unzombifying works as well
tabTest.unzombify();
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() {
let observerService = Services.obs;
SimpleTest.registerCleanupFunction(function() {
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 });
yield promiseTabEvent(BrowserApp.deck, "TabSelect");
is(BrowserApp.selectedTab, tabBlank, "Test tab is in background.");
// Zombify the backgrounded test tab
tabTest.zombify();
// 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
EventDispatcher.instance.dispatch("Tab:KeepZombified", {nextSelectedTabId: 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.");
tabTest.zombify();
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
EventDispatcher.instance.dispatch("Tab:KeepZombified", {nextSelectedTabId: 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");
// 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">
</div>
<pre id="test">
</pre>
</body>
</html>