Bug 739805 - Calling getTabState() on a not-yet-restored tab wipes out text and scroll data; r=zpao

This commit is contained in:
Tim Taubert 2012-03-28 09:13:48 +02:00
parent c50a5992a2
commit 7ae3f10617
3 changed files with 61 additions and 3 deletions

View File

@ -2090,9 +2090,6 @@ SessionStoreService.prototype = {
_updateTextAndScrollData: function sss_updateTextAndScrollData(aWindow) { _updateTextAndScrollData: function sss_updateTextAndScrollData(aWindow) {
var browsers = aWindow.gBrowser.browsers; var browsers = aWindow.gBrowser.browsers;
this._windows[aWindow.__SSi].tabs.forEach(function (tabData, i) { this._windows[aWindow.__SSi].tabs.forEach(function (tabData, i) {
if (browsers[i].__SS_data &&
browsers[i].__SS_tabStillLoading)
return; // ignore incompletely initialized tabs
try { try {
this._updateTextAndScrollDataForTab(aWindow, browsers[i], tabData); this._updateTextAndScrollDataForTab(aWindow, browsers[i], tabData);
} }
@ -2114,6 +2111,10 @@ SessionStoreService.prototype = {
*/ */
_updateTextAndScrollDataForTab: _updateTextAndScrollDataForTab:
function sss_updateTextAndScrollDataForTab(aWindow, aBrowser, aTabData, aFullData) { function sss_updateTextAndScrollDataForTab(aWindow, aBrowser, aTabData, aFullData) {
// we shouldn't update data for incompletely initialized tabs
if (aBrowser.__SS_data && aBrowser.__SS_tabStillLoading)
return;
var tabIndex = (aTabData.index || aTabData.entries.length) - 1; var tabIndex = (aTabData.index || aTabData.entries.length) - 1;
// entry data needn't exist for tabs just initialized with an incomplete session state // entry data needn't exist for tabs just initialized with an incomplete session state
if (!aTabData.entries[tabIndex]) if (!aTabData.entries[tabIndex])

View File

@ -161,6 +161,7 @@ _BROWSER_TEST_FILES = \
browser_694378.js \ browser_694378.js \
browser_705597.js \ browser_705597.js \
browser_707862.js \ browser_707862.js \
browser_739805.js \
$(NULL) $(NULL)
ifneq ($(OS_ARCH),Darwin) ifneq ($(OS_ARCH),Darwin)

View File

@ -0,0 +1,56 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_STATE_NEEDS_RESTORE = 1;
let tabState = {
entries: [{url: "data:text/html,<input%20id='foo'>", formdata: {"#foo": "bar"}}]
};
function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
registerCleanupFunction(function () {
if (gBrowser.tabs.length > 1)
gBrowser.removeTab(gBrowser.tabs[1]);
Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
});
let tab = gBrowser.addTab("about:blank");
let browser = tab.linkedBrowser;
whenBrowserLoaded(browser, function () {
isnot(gBrowser.selectedTab, tab, "newly created tab is not selected");
ss.setTabState(tab, JSON.stringify(tabState));
is(browser.__SS_restoreState, TAB_STATE_NEEDS_RESTORE, "tab needs restoring");
let state = JSON.parse(ss.getTabState(tab));
let formdata = state.entries[0].formdata;
is(formdata && formdata["#foo"], "bar", "tab state's formdata is valid");
whenTabRestored(tab, function () {
let input = browser.contentDocument.getElementById("foo");
is(input.value, "bar", "formdata has been restored correctly");
finish();
});
// Restore the tab by selecting it.
gBrowser.selectedTab = tab;
});
}
function whenBrowserLoaded(aBrowser, aCallback) {
aBrowser.addEventListener("load", function onLoad() {
aBrowser.removeEventListener("load", onLoad, true);
executeSoon(aCallback);
}, true);
}
function whenTabRestored(aTab, aCallback) {
aTab.addEventListener("SSTabRestored", function onRestored() {
aTab.removeEventListener("SSTabRestored", onRestored);
executeSoon(aCallback);
});
}