michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: /** Test for Bug 447951 **/ michael@0: michael@0: waitForExplicitFinish(); michael@0: const baseURL = "http://mochi.test:8888/browser/" + michael@0: "browser/components/sessionstore/test/browser_447951_sample.html#"; michael@0: michael@0: // Make sure the functionality added in bug 943339 doesn't affect the results michael@0: gPrefService.setIntPref("browser.sessionstore.max_serialize_back", -1); michael@0: gPrefService.setIntPref("browser.sessionstore.max_serialize_forward", -1); michael@0: registerCleanupFunction(function () { michael@0: gPrefService.clearUserPref("browser.sessionstore.max_serialize_back"); michael@0: gPrefService.clearUserPref("browser.sessionstore.max_serialize_forward"); michael@0: }); michael@0: michael@0: let tab = gBrowser.addTab(); michael@0: whenBrowserLoaded(tab.linkedBrowser, function() { michael@0: let tabState = { entries: [] }; michael@0: let max_entries = gPrefService.getIntPref("browser.sessionhistory.max_entries"); michael@0: for (let i = 0; i < max_entries; i++) michael@0: tabState.entries.push({ url: baseURL + i }); michael@0: michael@0: ss.setTabState(tab, JSON.stringify(tabState)); michael@0: whenTabRestored(tab, function() { michael@0: SyncHandlers.get(tab.linkedBrowser).flush(); michael@0: tabState = JSON.parse(ss.getTabState(tab)); michael@0: is(tabState.entries.length, max_entries, "session history filled to the limit"); michael@0: is(tabState.entries[0].url, baseURL + 0, "... but not more"); michael@0: michael@0: // visit yet another anchor (appending it to session history) michael@0: tab.linkedBrowser.contentDocument.querySelector("a").click(); michael@0: michael@0: function check() { michael@0: SyncHandlers.get(tab.linkedBrowser).flush(); michael@0: tabState = JSON.parse(ss.getTabState(tab)); michael@0: if (tabState.entries[tabState.entries.length - 1].url != baseURL + "end") { michael@0: // It may take a few passes through the event loop before we michael@0: // get the right URL. michael@0: executeSoon(check); michael@0: return; michael@0: } michael@0: michael@0: is(tab.linkedBrowser.currentURI.spec, baseURL + "end", michael@0: "the new anchor was loaded"); michael@0: is(tabState.entries[tabState.entries.length - 1].url, baseURL + "end", michael@0: "... and ignored"); michael@0: is(tabState.entries[0].url, baseURL + 1, michael@0: "... and the first item was removed"); michael@0: michael@0: // clean up michael@0: gBrowser.removeTab(tab); michael@0: finish(); michael@0: } michael@0: michael@0: check(); michael@0: }); michael@0: }); michael@0: }