browser_bug724239.js (2003B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const { TabStateFlusher } = ChromeUtils.importESModule( 5 "resource:///modules/sessionstore/TabStateFlusher.sys.mjs" 6 ); 7 8 add_task(async function test_blank() { 9 await BrowserTestUtils.withNewTab( 10 { gBrowser, url: "about:blank" }, 11 async function (browser) { 12 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 13 BrowserTestUtils.startLoadingURIString(browser, "http://example.com"); 14 await BrowserTestUtils.browserLoaded(browser); 15 ok(!gBrowser.canGoBack, "about:blank wasn't added to session history"); 16 } 17 ); 18 }); 19 20 add_task(async function test_newtab() { 21 await BrowserTestUtils.withNewTab( 22 { gBrowser, url: "about:blank" }, 23 async function (browser) { 24 // Can't load it directly because that'll use a preloaded tab if present. 25 let stopped = BrowserTestUtils.browserStopped(browser, "about:newtab"); 26 BrowserTestUtils.startLoadingURIString(browser, "about:newtab"); 27 await stopped; 28 29 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 30 stopped = BrowserTestUtils.browserStopped(browser, "http://example.com/"); 31 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 32 BrowserTestUtils.startLoadingURIString(browser, "http://example.com/"); 33 await stopped; 34 35 // This makes sure the parent process has the most up-to-date notion 36 // of the tab's session history. 37 await TabStateFlusher.flush(browser); 38 39 let tab = gBrowser.getTabForBrowser(browser); 40 let tabState = JSON.parse(SessionStore.getTabState(tab)); 41 Assert.equal( 42 tabState.entries.length, 43 2, 44 "We should have 2 entries in the session history." 45 ); 46 47 Assert.equal( 48 tabState.entries[0].url, 49 "about:newtab", 50 "about:newtab should be the first entry." 51 ); 52 53 Assert.ok(gBrowser.canGoBack, "Should be able to browse back."); 54 } 55 ); 56 });