diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /mobile/android/tests/browser/chrome/test_session_zombification.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/tests/browser/chrome/test_session_zombification.html')
-rw-r--r-- | mobile/android/tests/browser/chrome/test_session_zombification.html | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/mobile/android/tests/browser/chrome/test_session_zombification.html b/mobile/android/tests/browser/chrome/test_session_zombification.html new file mode 100644 index 000000000..eba255ff6 --- /dev/null +++ b/mobile/android/tests/browser/chrome/test_session_zombification.html @@ -0,0 +1,185 @@ +<!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"); + + // Import the MemoryObserver + 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; + + // Track the tabs where the tests are happening + let tabBlank; + let tabTest; + + 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); + }); + + // 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 + MemoryObserver.zombify(tabTest); + + // 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 + MemoryObserver.zombify(tabTest); + + // 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, 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> +<pre id="test"> +</pre> +</body> +</html> |