browser_replace_load.js (1847B)
1 "use strict"; 2 3 const STATE = { 4 entries: [{ url: "about:robots" }, { url: "about:mozilla" }], 5 selected: 2, 6 }; 7 8 /** 9 * Bug 1100223. Calling browser.loadURI() while a tab is loading causes 10 * sessionstore to override the desired target URL. This test ensures that 11 * calling loadURI() on a pending tab causes the tab to no longer be marked 12 * as pending and correctly finish the instructed load while keeping the 13 * restored history around. 14 */ 15 add_task(async function () { 16 await testSwitchToTab("about:mozilla#fooobar", { 17 ignoreFragment: "whenComparingAndReplace", 18 }); 19 await testSwitchToTab("about:mozilla?foo=bar", { replaceQueryString: true }); 20 }); 21 22 var testSwitchToTab = async function (url, options) { 23 // Create a background tab. 24 let tab = BrowserTestUtils.addTab(gBrowser, "about:blank"); 25 let browser = tab.linkedBrowser; 26 await promiseBrowserLoaded(browser); 27 28 // The tab shouldn't be restored right away. 29 Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); 30 31 // Prepare the tab state. 32 let promise = promiseTabRestoring(tab); 33 ss.setTabState(tab, JSON.stringify(STATE)); 34 ok(tab.hasAttribute("pending"), "tab is pending"); 35 await promise; 36 37 options.triggeringPrincipal = 38 Services.scriptSecurityManager.getSystemPrincipal(); 39 40 // Switch-to-tab with a similar URI. 41 switchToTabHavingURI(url, false, options); 42 43 // Tab should now restore 44 await promiseTabRestored(tab); 45 is(browser.currentURI.spec, url, "correct URL loaded"); 46 47 // Check that we didn't lose any history entries. 48 await SpecialPowers.spawn(browser, [], async function () { 49 let webNavigation = docShell.QueryInterface(Ci.nsIWebNavigation); 50 let history = webNavigation.sessionHistory; 51 Assert.equal(history && history.count, 3, "three history entries"); 52 }); 53 54 // Cleanup. 55 gBrowser.removeTab(tab); 56 };