mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1077738: Retain whether history entries are set to persist in session history and restore that. r=smacleod
This commit is contained in:
parent
8a33314cf9
commit
c8f85a9dc7
@ -67,7 +67,7 @@ let SessionHistoryInternal = {
|
||||
let data = {entries: []};
|
||||
let isPinned = docShell.isAppTab;
|
||||
let webNavigation = docShell.QueryInterface(Ci.nsIWebNavigation);
|
||||
let history = webNavigation.sessionHistory;
|
||||
let history = webNavigation.sessionHistory.QueryInterface(Ci.nsISHistoryInternal);
|
||||
|
||||
if (history && history.count > 0) {
|
||||
let oldest;
|
||||
@ -88,17 +88,28 @@ let SessionHistoryInternal = {
|
||||
newest = history.count - 1;
|
||||
}
|
||||
|
||||
try {
|
||||
for (let i = oldest; i <= newest; i++) {
|
||||
let shEntry = history.getEntryAtIndex(i, false);
|
||||
let entry = this.serializeEntry(shEntry, isPinned);
|
||||
data.entries.push(entry);
|
||||
}
|
||||
} catch (ex) {
|
||||
// In some cases, getEntryAtIndex will throw. This seems to be due to
|
||||
// history.count being higher than it should be. By doing this in a
|
||||
// try-catch, we'll update history to where it breaks, print an error
|
||||
// message, and still save sessionstore.js.
|
||||
// Loop over the transaction linked list directly so we can get the
|
||||
// persist property for each transaction.
|
||||
let txn = history.rootTransaction;
|
||||
let i = 0;
|
||||
while (txn && i < oldest) {
|
||||
txn = txn.next;
|
||||
i++;
|
||||
}
|
||||
|
||||
while (txn && i <= newest) {
|
||||
let shEntry = txn.sHEntry;
|
||||
let entry = this.serializeEntry(shEntry, isPinned);
|
||||
entry.persist = txn.persist;
|
||||
data.entries.push(entry);
|
||||
txn = txn.next;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i <= newest) {
|
||||
// In some cases, there don't seem to be as many history entries as
|
||||
// history.count claims. we'll save whatever history we can, print an
|
||||
// error message, and still save sessionstore.js.
|
||||
debug("SessionStore failed gathering complete history " +
|
||||
"for the focused window/tab. See bug 669196.");
|
||||
}
|
||||
@ -297,11 +308,12 @@ let SessionHistoryInternal = {
|
||||
let idMap = { used: {} };
|
||||
let docIdentMap = {};
|
||||
for (let i = 0; i < tabData.entries.length; i++) {
|
||||
let entry = tabData.entries[i];
|
||||
//XXXzpao Wallpaper patch for bug 514751
|
||||
if (!tabData.entries[i].url)
|
||||
if (!entry.url)
|
||||
continue;
|
||||
history.addEntry(this.deserializeEntry(tabData.entries[i],
|
||||
idMap, docIdentMap), true);
|
||||
let persist = "persist" in entry ? entry.persist : true;
|
||||
history.addEntry(this.deserializeEntry(entry, idMap, docIdentMap), persist);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -76,6 +76,7 @@ skip-if = buildapp == 'mulet'
|
||||
[browser_frame_history.js]
|
||||
[browser_global_store.js]
|
||||
[browser_history_cap.js]
|
||||
[browser_history_persist.js]
|
||||
[browser_label_and_icon.js]
|
||||
[browser_merge_closed_tabs.js]
|
||||
[browser_pageStyle.js]
|
||||
|
@ -0,0 +1,79 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Ensure that history entries that should not be persisted are restored in the
|
||||
* same state.
|
||||
*/
|
||||
add_task(function check_history_not_persisted() {
|
||||
// Create an about:blank tab
|
||||
let tab = gBrowser.addTab("about:blank");
|
||||
let browser = tab.linkedBrowser;
|
||||
yield promiseBrowserLoaded(browser);
|
||||
|
||||
// Retrieve the tab state.
|
||||
TabState.flush(browser);
|
||||
let state = JSON.parse(ss.getTabState(tab));
|
||||
ok(!state.entries[0].persist, "Should have collected the persistence state");
|
||||
gBrowser.removeTab(tab);
|
||||
browser = null;
|
||||
|
||||
// Open a new tab to restore into.
|
||||
tab = gBrowser.addTab("about:blank");
|
||||
browser = tab.linkedBrowser;
|
||||
yield promiseTabState(tab, state);
|
||||
let sessionHistory = browser.sessionHistory;
|
||||
|
||||
is(sessionHistory.count, 1, "Should be a single history entry");
|
||||
is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:blank", "Should be the right URL");
|
||||
|
||||
// Load a new URL into the tab, it should replace the about:blank history entry
|
||||
browser.loadURI("about:robots");
|
||||
yield promiseBrowserLoaded(browser);
|
||||
sessionHistory = browser.sessionHistory;
|
||||
is(sessionHistory.count, 1, "Should be a single history entry");
|
||||
is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:robots", "Should be the right URL");
|
||||
|
||||
// Cleanup.
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
/**
|
||||
* Check that entries default to being persisted when the attribute doesn't
|
||||
* exist
|
||||
*/
|
||||
add_task(function check_history_default_persisted() {
|
||||
// Create an about:blank tab
|
||||
let tab = gBrowser.addTab("about:blank");
|
||||
let browser = tab.linkedBrowser;
|
||||
yield promiseBrowserLoaded(browser);
|
||||
|
||||
// Retrieve the tab state.
|
||||
TabState.flush(browser);
|
||||
let state = JSON.parse(ss.getTabState(tab));
|
||||
delete state.entries[0].persist;
|
||||
gBrowser.removeTab(tab);
|
||||
browser = null;
|
||||
|
||||
// Open a new tab to restore into.
|
||||
tab = gBrowser.addTab("about:blank");
|
||||
browser = tab.linkedBrowser;
|
||||
yield promiseTabState(tab, state);
|
||||
let sessionHistory = browser.sessionHistory;
|
||||
|
||||
is(sessionHistory.count, 1, "Should be a single history entry");
|
||||
is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:blank", "Should be the right URL");
|
||||
|
||||
// Load a new URL into the tab, it should replace the about:blank history entry
|
||||
browser.loadURI("about:robots");
|
||||
yield promiseBrowserLoaded(browser);
|
||||
sessionHistory = browser.sessionHistory;
|
||||
is(sessionHistory.count, 2, "Should be two history entries");
|
||||
is(sessionHistory.getEntryAtIndex(0, false).URI.spec, "about:blank", "Should be the right URL");
|
||||
is(sessionHistory.getEntryAtIndex(1, false).URI.spec, "about:robots", "Should be the right URL");
|
||||
|
||||
// Cleanup.
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
@ -193,6 +193,10 @@ function waitForTabState(aTab, aState, aCallback) {
|
||||
ss.setTabState(aTab, JSON.stringify(aState));
|
||||
}
|
||||
|
||||
function promiseTabState(tab, state) {
|
||||
return new Promise(resolve => waitForTabState(tab, state, resolve));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for a content -> chrome message.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user