Bug 701377 - setTabState() always unhides the tab; r=zpao

This commit is contained in:
Tim Taubert 2012-03-28 09:25:42 +02:00
parent 4dba960240
commit 5d779dc649
3 changed files with 64 additions and 6 deletions

View File

@ -2735,6 +2735,8 @@ SessionStoreService.prototype = {
if (aOverwriteTabs && tabbrowser.selectedTab._tPos >= newTabCount) if (aOverwriteTabs && tabbrowser.selectedTab._tPos >= newTabCount)
tabbrowser.moveTabTo(tabbrowser.selectedTab, newTabCount - 1); tabbrowser.moveTabTo(tabbrowser.selectedTab, newTabCount - 1);
let numVisibleTabs = 0;
for (var t = 0; t < newTabCount; t++) { for (var t = 0; t < newTabCount; t++) {
tabs.push(t < openTabCount ? tabs.push(t < openTabCount ?
tabbrowser.tabs[t] : tabbrowser.tabs[t] :
@ -2747,10 +2749,19 @@ SessionStoreService.prototype = {
if (winData.tabs[t].pinned) if (winData.tabs[t].pinned)
tabbrowser.pinTab(tabs[t]); tabbrowser.pinTab(tabs[t]);
if (winData.tabs[t].hidden) if (winData.tabs[t].hidden) {
tabbrowser.hideTab(tabs[t]); tabbrowser.hideTab(tabs[t]);
else }
else {
tabbrowser.showTab(tabs[t]); tabbrowser.showTab(tabs[t]);
numVisibleTabs++;
}
}
// if all tabs to be restored are hidden, make the first one visible
if (!numVisibleTabs && winData.tabs.length) {
winData.tabs[0].hidden = false;
tabbrowser.showTab(tabs[0]);
} }
// If overwriting tabs, we want to reset each tab's "restoring" state. Since // If overwriting tabs, we want to reset each tab's "restoring" state. Since
@ -2880,10 +2891,7 @@ SessionStoreService.prototype = {
let unhiddenTabs = aTabData.filter(function (aData) !aData.hidden).length; let unhiddenTabs = aTabData.filter(function (aData) !aData.hidden).length;
// if all tabs to be restored are hidden, make the first one visible if (unhiddenTabs && aTabs.length > 1) {
if (unhiddenTabs == 0) {
aTabData[0].hidden = false;
} else if (aTabs.length > 1) {
// Load hidden tabs last, by pushing them to the end of the list // Load hidden tabs last, by pushing them to the end of the list
for (let t = 0, tabsToReorder = aTabs.length - unhiddenTabs; tabsToReorder > 0; ) { for (let t = 0, tabsToReorder = aTabs.length - unhiddenTabs; tabsToReorder > 0; ) {
if (aTabData[t].hidden) { if (aTabData[t].hidden) {

View File

@ -159,6 +159,7 @@ _BROWSER_TEST_FILES = \
browser_687710.js \ browser_687710.js \
browser_687710_2.js \ browser_687710_2.js \
browser_694378.js \ browser_694378.js \
browser_701377.js \
browser_705597.js \ browser_705597.js \
browser_707862.js \ browser_707862.js \
browser_739805.js \ browser_739805.js \

View File

@ -0,0 +1,49 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
let state = {windows:[{tabs:[
{entries:[{url:"http://example.com#1"}]},
{entries:[{url:"http://example.com#2"}], hidden: true}
]}]};
function test() {
waitForExplicitFinish();
newWindowWithState(state, function (aWindow) {
let tab = aWindow.gBrowser.tabs[1];
ok(tab.hidden, "the second tab is hidden");
let tabShown = false;
let tabShowCallback = function () tabShown = true;
tab.addEventListener("TabShow", tabShowCallback, false);
let tabState = ss.getTabState(tab);
ss.setTabState(tab, tabState);
tab.removeEventListener("TabShow", tabShowCallback, false);
ok(tab.hidden && !tabShown, "tab remains hidden");
finish();
});
}
// ----------
function whenWindowLoaded(aWindow, aCallback) {
aWindow.addEventListener("load", function onLoad() {
aWindow.removeEventListener("load", onLoad, false);
executeSoon(aCallback);
}, false);
}
// ----------
function newWindowWithState(aState, aCallback) {
let opts = "chrome,all,dialog=no,height=800,width=800";
let win = window.openDialog(getBrowserURL(), "_blank", opts);
registerCleanupFunction(function () win.close());
whenWindowLoaded(win, function () {
ss.setWindowState(win, JSON.stringify(aState), true);
executeSoon(function () aCallback(win));
});
}