From a3f0b6f2bc8a59a579f4e5b8644076d234f92ad9 Mon Sep 17 00:00:00 2001 From: Dave Camp Date: Wed, 20 Aug 2008 03:25:06 -0700 Subject: [PATCH] Backed out changeset f468ae1633d4 (bug 367052) --- .../sessionstore/src/nsSessionStore.js | 55 +++++++------- .../components/sessionstore/test/Makefile.in | 1 - .../sessionstore/test/browser/Makefile.in | 52 -------------- .../test/browser/browser_367052.js | 72 ------------------- 4 files changed, 25 insertions(+), 155 deletions(-) delete mode 100644 browser/components/sessionstore/test/browser/Makefile.in delete mode 100644 browser/components/sessionstore/test/browser/browser_367052.js diff --git a/browser/components/sessionstore/src/nsSessionStore.js b/browser/components/sessionstore/src/nsSessionStore.js index 5c523c2d210..73fa10dcdd3 100644 --- a/browser/components/sessionstore/src/nsSessionStore.js +++ b/browser/components/sessionstore/src/nsSessionStore.js @@ -572,7 +572,7 @@ SessionStoreService.prototype = { delete tabState._tab; // store closed-tab data for undo - if (tabState.entries.length > 0) { + if (tabState.entries.length > 1 || tabState.entries[0].url != "about:blank") { 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) { + if (!tabState.entries || !tabState.entries.length) { 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: [] }; + var tabData = { entries: [], index: 0 }; var browser = aTab.linkedBrowser; if (!browser || !browser.currentURI) @@ -888,8 +888,7 @@ SessionStoreService.prototype = { if (!aFullData) browser.parentNode.__SS_data = tabData; } - else if (browser.currentURI.spec != "about:blank" || - browser.contentDocument.body.hasChildNodes()) { + else { tabData.entries[0] = { url: browser.currentURI.spec }; tabData.index = 1; } @@ -1093,7 +1092,8 @@ SessionStoreService.prototype = { for (var i = 0; i < browsers.length; i++) { try { var tabData = this._windows[aWindow.__SSi].tabs[i]; - if (browsers[i].parentNode.__SS_data && browsers[i].parentNode.__SS_data._tab) + if (tabData.entries.length == 0 || + browsers[i].parentNode.__SS_data && browsers[i].parentNode.__SS_data._tab) continue; // ignore incompletely initialized tabs this._updateTextAndScrollDataForTab(aWindow, browsers[i], tabData); } @@ -1407,9 +1407,11 @@ 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 && - (!winData.tabs[0].entries || winData.tabs[0].entries.length == 0)) { - winData.tabs = []; + 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 = []; } var tabbrowser = aWindow.getBrowser(); @@ -1488,16 +1490,11 @@ 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"); @@ -1585,21 +1582,19 @@ SessionStoreService.prototype = { tab.dispatchEvent(event); var activeIndex = (tabData.index || tabData.entries.length) - 1; - if (activeIndex >= tabData.entries.length) - activeIndex = tabData.entries.length - 1; - if (activeIndex >= 0) + try { browser.webNavigation.gotoIndex(activeIndex); - - 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); } + 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); aWindow.setTimeout(function(){ _this.restoreHistory(aWindow, aTabs, aIdMap); }, 0); }, diff --git a/browser/components/sessionstore/test/Makefile.in b/browser/components/sessionstore/test/Makefile.in index 583fad065a1..4812a982e4d 100644 --- a/browser/components/sessionstore/test/Makefile.in +++ b/browser/components/sessionstore/test/Makefile.in @@ -43,7 +43,6 @@ include $(DEPTH)/config/autoconf.mk DIRS += chrome \ - browser \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/browser/components/sessionstore/test/browser/Makefile.in b/browser/components/sessionstore/test/browser/Makefile.in deleted file mode 100644 index b13bd548d1f..00000000000 --- a/browser/components/sessionstore/test/browser/Makefile.in +++ /dev/null @@ -1,52 +0,0 @@ -# ***** 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 -# -# 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) diff --git a/browser/components/sessionstore/test/browser/browser_367052.js b/browser/components/sessionstore/test/browser/browser_367052.js deleted file mode 100644 index f01f90c0125..00000000000 --- a/browser/components/sessionstore/test/browser/browser_367052.js +++ /dev/null @@ -1,72 +0,0 @@ -/* ***** 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 . - * 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); -}