browser_navigation.js (2647B)
1 "use strict"; 2 3 const REQUEST_URL = 4 "http://httpsfirst.com/browser/dom/security/test/https-first/"; 5 6 async function promiseGetHistoryIndex(browser) { 7 if (!SpecialPowers.Services.appinfo.sessionHistoryInParent) { 8 return SpecialPowers.spawn(browser, [], function () { 9 let shistory = 10 docShell.browsingContext.childSessionHistory.legacySHistory; 11 return shistory.index; 12 }); 13 } 14 15 let shistory = browser.browsingContext.sessionHistory; 16 return shistory.index; 17 } 18 19 async function testNavigations() { 20 // Load initial site 21 22 let url1 = REQUEST_URL + "file_navigation.html?foo1"; 23 let url2 = REQUEST_URL + "file_navigation.html?foo2"; 24 let url3 = REQUEST_URL + "file_navigation.html?foo3"; 25 26 let loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 27 BrowserTestUtils.startLoadingURIString(gBrowser, url1); 28 await loaded; 29 30 // Load another site 31 loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 32 await SpecialPowers.spawn( 33 gBrowser.selectedBrowser, 34 [url2], 35 async url => (content.location.href = url) 36 ); 37 await loaded; 38 39 // Load another site 40 loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 41 await SpecialPowers.spawn( 42 gBrowser.selectedBrowser, 43 [url3], 44 async url => (content.location.href = url) 45 ); 46 await loaded; 47 is( 48 await promiseGetHistoryIndex(gBrowser.selectedBrowser), 49 2, 50 "correct session history index after load 3" 51 ); 52 53 // Go back one site by clicking the back button 54 info("Clicking back button"); 55 loaded = BrowserTestUtils.waitForLocationChange(gBrowser, url2); 56 let backButton = document.getElementById("back-button"); 57 backButton.click(); 58 await loaded; 59 is( 60 await promiseGetHistoryIndex(gBrowser.selectedBrowser), 61 1, 62 "correct session history index after going back for the first time" 63 ); 64 65 // Go back again 66 info("Clicking back button again"); 67 loaded = BrowserTestUtils.waitForLocationChange(gBrowser, url1); 68 backButton.click(); 69 await loaded; 70 is( 71 await promiseGetHistoryIndex(gBrowser.selectedBrowser), 72 0, 73 "correct session history index after going back for the second time" 74 ); 75 } 76 77 add_task(async function () { 78 waitForExplicitFinish(); 79 80 await SpecialPowers.pushPrefEnv({ 81 set: [["dom.security.https_first", true]], 82 }); 83 84 await testNavigations(); 85 86 // If fission is enabled we also want to test the navigations with the bfcache 87 // in the parent. 88 if (SpecialPowers.getBoolPref("fission.autostart")) { 89 await SpecialPowers.pushPrefEnv({ 90 set: [["fission.bfcacheInParent", true]], 91 }); 92 93 await testNavigations(); 94 } 95 96 finish(); 97 });