Bug 367052 - "[SessionStore] about:blank shows up in back arrow history of restored blank tabs" [r=dietrich]

This commit is contained in:
Simon Bünzli 2008-08-20 01:33:30 -05:00
parent 62fcdc68d4
commit c668011f2c
4 changed files with 155 additions and 25 deletions

View File

@ -572,7 +572,7 @@ SessionStoreService.prototype = {
delete tabState._tab;
// store closed-tab data for undo
if (tabState.entries.length > 1 || tabState.entries[0].url != "about:blank") {
if (tabState.entries.length > 0) {
this._windows[aWindow.__SSi]._closedTabs.unshift({
state: tabState,
title: aTab.getAttribute("label"),
@ -688,7 +688,7 @@ SessionStoreService.prototype = {
setTabState: function sss_setTabState(aTab, aState) {
var tabState = this._safeEval("(" + aState + ")");
if (!tabState.entries || !tabState.entries.length) {
if (!tabState.entries) {
Components.returnCode = Cr.NS_ERROR_INVALID_ARG;
return;
}
@ -857,7 +857,7 @@ SessionStoreService.prototype = {
* @returns object
*/
_collectTabData: function sss_collectTabData(aTab, aFullData) {
var tabData = { entries: [], index: 0 };
var tabData = { entries: [] };
var browser = aTab.linkedBrowser;
if (!browser || !browser.currentURI)
@ -888,7 +888,8 @@ SessionStoreService.prototype = {
if (!aFullData)
browser.parentNode.__SS_data = tabData;
}
else {
else if (browser.currentURI.spec != "about:blank" ||
browser.contentDocument.body.hasChildNodes()) {
tabData.entries[0] = { url: browser.currentURI.spec };
tabData.index = 1;
}
@ -1092,8 +1093,7 @@ SessionStoreService.prototype = {
for (var i = 0; i < browsers.length; i++) {
try {
var tabData = this._windows[aWindow.__SSi].tabs[i];
if (tabData.entries.length == 0 ||
browsers[i].parentNode.__SS_data && browsers[i].parentNode.__SS_data._tab)
if (browsers[i].parentNode.__SS_data && browsers[i].parentNode.__SS_data._tab)
continue; // ignore incompletely initialized tabs
this._updateTextAndScrollDataForTab(aWindow, browsers[i], tabData);
}
@ -1407,11 +1407,9 @@ SessionStoreService.prototype = {
}
// don't restore a single blank tab when we've had an external
// URL passed in for loading at startup (cf. bug 357419)
else if (root._firstTabs && !aOverwriteTabs && winData.tabs.length == 1) {
let tabEntries = winData.tabs[0].entries || [];
if (tabEntries.length == 0 ||
tabEntries.length == 1 && tabEntries[0].url == "about:blank")
winData.tabs = [];
else if (root._firstTabs && !aOverwriteTabs && winData.tabs.length == 1 &&
(!winData.tabs[0].entries || winData.tabs[0].entries.length == 0)) {
winData.tabs = [];
}
var tabbrowser = aWindow.getBrowser();
@ -1490,11 +1488,16 @@ SessionStoreService.prototype = {
// mark the tabs as loading
for (t = 0; t < aTabs.length; t++) {
if (!aTabs[t].entries || !aTabs[t].entries[0])
continue; // there won't be anything to load
var tab = aTabs[t]._tab;
var browser = tabbrowser.getBrowserForTab(tab);
if (!aTabs[t].entries || aTabs[t].entries.length == 0) {
// make sure to blank out this tab's content
// (just purging the tab's history won't be enough)
browser.contentDocument.location = "about:blank";
continue;
}
browser.stop(); // in case about:blank isn't done yet
tab.setAttribute("busy", "true");
@ -1582,19 +1585,21 @@ SessionStoreService.prototype = {
tab.dispatchEvent(event);
var activeIndex = (tabData.index || tabData.entries.length) - 1;
try {
if (activeIndex >= tabData.entries.length)
activeIndex = tabData.entries.length - 1;
if (activeIndex >= 0)
browser.webNavigation.gotoIndex(activeIndex);
}
catch (ex) { } // ignore an invalid tabData.index
// restore those aspects of the currently active documents
// which are not preserved in the plain history entries
// (mainly scroll state and text data)
browser.__SS_restore_data = tabData.entries[activeIndex] || {};
browser.__SS_restore_text = tabData.text || "";
browser.__SS_restore_tab = tab;
browser.__SS_restore = this.restoreDocument_proxy;
browser.addEventListener("load", browser.__SS_restore, true);
if (tabData.entries.length > 0) {
// restore those aspects of the currently active documents
// which are not preserved in the plain history entries
// (mainly scroll state and text data)
browser.__SS_restore_data = tabData.entries[activeIndex] || {};
browser.__SS_restore_text = tabData.text || "";
browser.__SS_restore_tab = tab;
browser.__SS_restore = this.restoreDocument_proxy;
browser.addEventListener("load", browser.__SS_restore, true);
}
aWindow.setTimeout(function(){ _this.restoreHistory(aWindow, aTabs, aIdMap); }, 0);
},

View File

@ -43,6 +43,7 @@ include $(DEPTH)/config/autoconf.mk
DIRS += chrome \
browser \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,52 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is sessionstore test code.
#
# The Initial Developer of the Original Code is
# Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Simon Bünzli <zeniko@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = browser/components/sessionstore/test/browser
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_BROWSER_TEST_FILES = \
browser_367052.js \
$(NULL)
libs:: $(_BROWSER_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)

View File

@ -0,0 +1,72 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is sessionstore test code.
*
* The Initial Developer of the Original Code is
* Simon Bünzli <zeniko@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
function test() {
/** Test for Bug 367052 **/
// test setup
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
let tabbrowser = getBrowser();
waitForExplicitFinish();
// make sure that the next closed tab will increase getClosedTabCount
let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo");
gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
let closedTabCount = ss.getClosedTabCount(window);
// restore a blank tab
let tab = tabbrowser.addTab("about:");
tab.linkedBrowser.addEventListener("load", function(aEvent) {
this.removeEventListener("load", arguments.callee, true);
let browser = tabbrowser.getBrowserForTab(tab);
let history = browser.webNavigation.sessionHistory;
ok(history.count >= 1, "the new tab does have at least one history entry");
ss.setTabState(tab, "{ entries: [] }");
tab.linkedBrowser.addEventListener("load", function(aEvent) {
ok(history.count == 0, "the tab was restored without any history whatsoever");
tabbrowser.removeTab(tab);
ok(ss.getClosedTabCount(window) == closedTabCount,
"The closed blank tab wasn't added to Recently Closed Tabs");
// clean up
gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo);
finish();
}, true);
}, true);
}