summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_async_flushes.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /browser/components/sessionstore/test/browser_async_flushes.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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 'browser/components/sessionstore/test/browser_async_flushes.js')
-rw-r--r--browser/components/sessionstore/test/browser_async_flushes.js113
1 files changed, 113 insertions, 0 deletions
diff --git a/browser/components/sessionstore/test/browser_async_flushes.js b/browser/components/sessionstore/test/browser_async_flushes.js
new file mode 100644
index 000000000..a4cbbfbc7
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_async_flushes.js
@@ -0,0 +1,113 @@
+"use strict";
+
+const URL = "data:text/html;charset=utf-8,<a href=%23>clickme</a>";
+
+add_task(function* test_flush() {
+ // Create new tab.
+ let tab = gBrowser.addTab(URL);
+ let browser = tab.linkedBrowser;
+ yield promiseBrowserLoaded(browser);
+
+ // Flush to empty any queued update messages.
+ yield TabStateFlusher.flush(browser);
+
+ // There should be one history entry.
+ let {entries} = JSON.parse(ss.getTabState(tab));
+ is(entries.length, 1, "there is a single history entry");
+
+ // Click the link to navigate, this will add second shistory entry.
+ yield ContentTask.spawn(browser, null, function* () {
+ return new Promise(resolve => {
+ addEventListener("hashchange", function onHashChange() {
+ removeEventListener("hashchange", onHashChange);
+ resolve();
+ });
+
+ // Click the link.
+ content.document.querySelector("a").click();
+ });
+ });
+
+ // Flush to empty any queued update messages.
+ yield TabStateFlusher.flush(browser);
+
+ // There should be two history entries now.
+ ({entries} = JSON.parse(ss.getTabState(tab)));
+ is(entries.length, 2, "there are two shistory entries");
+
+ // Cleanup.
+ gBrowser.removeTab(tab);
+});
+
+add_task(function* test_crash() {
+ // Create new tab.
+ let tab = gBrowser.addTab(URL);
+ gBrowser.selectedTab = tab;
+ let browser = tab.linkedBrowser;
+ yield promiseBrowserLoaded(browser);
+
+ // Flush to empty any queued update messages.
+ yield TabStateFlusher.flush(browser);
+
+ // There should be one history entry.
+ let {entries} = JSON.parse(ss.getTabState(tab));
+ is(entries.length, 1, "there is a single history entry");
+
+ // Click the link to navigate.
+ yield ContentTask.spawn(browser, null, function* () {
+ return new Promise(resolve => {
+ addEventListener("hashchange", function onHashChange() {
+ removeEventListener("hashchange", onHashChange);
+ resolve();
+ });
+
+ // Click the link.
+ content.document.querySelector("a").click();
+ });
+ });
+
+ // Crash the browser and flush. Both messages are async and will be sent to
+ // the content process. The "crash" message makes it first so that we don't
+ // get a chance to process the flush. The TabStateFlusher however should be
+ // notified so that the flush still completes.
+ let promise1 = BrowserTestUtils.crashBrowser(browser);
+ let promise2 = TabStateFlusher.flush(browser);
+ yield Promise.all([promise1, promise2]);
+
+ // The pending update should be lost.
+ ({entries} = JSON.parse(ss.getTabState(tab)));
+ is(entries.length, 1, "still only one history entry");
+
+ // Cleanup.
+ gBrowser.removeTab(tab);
+});
+
+add_task(function* test_remove() {
+ // Create new tab.
+ let tab = gBrowser.addTab(URL);
+ let browser = tab.linkedBrowser;
+ yield promiseBrowserLoaded(browser);
+
+ // Flush to empty any queued update messages.
+ yield TabStateFlusher.flush(browser);
+
+ // There should be one history entry.
+ let {entries} = JSON.parse(ss.getTabState(tab));
+ is(entries.length, 1, "there is a single history entry");
+
+ // Click the link to navigate.
+ yield ContentTask.spawn(browser, null, function* () {
+ return new Promise(resolve => {
+ addEventListener("hashchange", function onHashChange() {
+ removeEventListener("hashchange", onHashChange);
+ resolve();
+ });
+
+ // Click the link.
+ content.document.querySelector("a").click();
+ });
+ });
+
+ // Request a flush and remove the tab. The flush should still complete.
+ yield Promise.all([TabStateFlusher.flush(browser), promiseRemoveTab(tab)]);
+})