diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /browser/components/sessionstore/test/browser_async_flushes.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/sessionstore/test/browser_async_flushes.js')
-rw-r--r-- | browser/components/sessionstore/test/browser_async_flushes.js | 123 |
1 files changed, 123 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 0000000000..ad3b27ed4e --- /dev/null +++ b/browser/components/sessionstore/test/browser_async_flushes.js @@ -0,0 +1,123 @@ +"use strict"; + +const PATH = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content/", + "http://example.com/" +); +const URL = PATH + "file_async_flushes.html"; + +add_task(async function test_flush() { + // Create new tab. + let tab = BrowserTestUtils.addTab(gBrowser, URL); + let browser = tab.linkedBrowser; + await promiseBrowserLoaded(browser); + + // Flush to empty any queued update messages. + await 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. + await SpecialPowers.spawn(browser, [], async function() { + return new Promise(resolve => { + docShell.chromeEventHandler.addEventListener( + "hashchange", + () => resolve(), + { once: true, capture: true } + ); + + // Click the link. + content.document.querySelector("a").click(); + }); + }); + + // Flush to empty any queued update messages. + await 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(async function test_crash() { + // Create new tab. + let tab = BrowserTestUtils.addTab(gBrowser, URL); + gBrowser.selectedTab = tab; + let browser = tab.linkedBrowser; + await promiseBrowserLoaded(browser); + + // Flush to empty any queued update messages. + await 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. + await SpecialPowers.spawn(browser, [], async function() { + return new Promise(resolve => { + docShell.chromeEventHandler.addEventListener( + "hashchange", + () => resolve(), + { once: true, capture: true } + ); + + // 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.crashFrame(browser); + let promise2 = TabStateFlusher.flush(browser); + await 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(async function test_remove() { + // Create new tab. + let tab = BrowserTestUtils.addTab(gBrowser, URL); + let browser = tab.linkedBrowser; + await promiseBrowserLoaded(browser); + + // Flush to empty any queued update messages. + await 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. + await SpecialPowers.spawn(browser, [], async function() { + return new Promise(resolve => { + docShell.chromeEventHandler.addEventListener( + "hashchange", + () => resolve(), + { once: true, capture: true } + ); + + // Click the link. + content.document.querySelector("a").click(); + }); + }); + + // Request a flush and remove the tab. The flush should still complete. + await Promise.all([ + TabStateFlusher.flush(browser), + promiseRemoveTabAndSessionState(tab), + ]); +}); |