|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 function test() { |
|
6 /** Test for Bug 447951 **/ |
|
7 |
|
8 waitForExplicitFinish(); |
|
9 const baseURL = "http://mochi.test:8888/browser/" + |
|
10 "browser/components/sessionstore/test/browser_447951_sample.html#"; |
|
11 |
|
12 // Make sure the functionality added in bug 943339 doesn't affect the results |
|
13 gPrefService.setIntPref("browser.sessionstore.max_serialize_back", -1); |
|
14 gPrefService.setIntPref("browser.sessionstore.max_serialize_forward", -1); |
|
15 registerCleanupFunction(function () { |
|
16 gPrefService.clearUserPref("browser.sessionstore.max_serialize_back"); |
|
17 gPrefService.clearUserPref("browser.sessionstore.max_serialize_forward"); |
|
18 }); |
|
19 |
|
20 let tab = gBrowser.addTab(); |
|
21 whenBrowserLoaded(tab.linkedBrowser, function() { |
|
22 let tabState = { entries: [] }; |
|
23 let max_entries = gPrefService.getIntPref("browser.sessionhistory.max_entries"); |
|
24 for (let i = 0; i < max_entries; i++) |
|
25 tabState.entries.push({ url: baseURL + i }); |
|
26 |
|
27 ss.setTabState(tab, JSON.stringify(tabState)); |
|
28 whenTabRestored(tab, function() { |
|
29 SyncHandlers.get(tab.linkedBrowser).flush(); |
|
30 tabState = JSON.parse(ss.getTabState(tab)); |
|
31 is(tabState.entries.length, max_entries, "session history filled to the limit"); |
|
32 is(tabState.entries[0].url, baseURL + 0, "... but not more"); |
|
33 |
|
34 // visit yet another anchor (appending it to session history) |
|
35 tab.linkedBrowser.contentDocument.querySelector("a").click(); |
|
36 |
|
37 function check() { |
|
38 SyncHandlers.get(tab.linkedBrowser).flush(); |
|
39 tabState = JSON.parse(ss.getTabState(tab)); |
|
40 if (tabState.entries[tabState.entries.length - 1].url != baseURL + "end") { |
|
41 // It may take a few passes through the event loop before we |
|
42 // get the right URL. |
|
43 executeSoon(check); |
|
44 return; |
|
45 } |
|
46 |
|
47 is(tab.linkedBrowser.currentURI.spec, baseURL + "end", |
|
48 "the new anchor was loaded"); |
|
49 is(tabState.entries[tabState.entries.length - 1].url, baseURL + "end", |
|
50 "... and ignored"); |
|
51 is(tabState.entries[0].url, baseURL + 1, |
|
52 "... and the first item was removed"); |
|
53 |
|
54 // clean up |
|
55 gBrowser.removeTab(tab); |
|
56 finish(); |
|
57 } |
|
58 |
|
59 check(); |
|
60 }); |
|
61 }); |
|
62 } |