Backed out changeset 7f034002d8a0 (bug 1766669) for causing failures related to TestSessionStoreEnabledAllWindows.test_close_tabs. CLOSED TREE

This commit is contained in:
criss 2022-07-14 23:47:32 +03:00
parent b77dc7a479
commit b7c8c91ce6
8 changed files with 53 additions and 145 deletions

View File

@ -382,10 +382,7 @@ var SessionStartup = {
this.willRestore() &&
this._initialState &&
this._initialState.windows &&
(!this.willRestoreAsCrashed()
? this._initialState.windows.filter(w => !w._maybeDontRestoreTabs)
: this._initialState.windows
).some(w => w.tabs.some(t => !t.pinned))
this._initialState.windows.some(w => w.tabs.some(t => !t.pinned))
);
});
});

View File

@ -390,8 +390,8 @@ var SessionStore = {
return SessionStoreInternal.getClosedWindowData();
},
maybeDontRestoreTabs(aWindow) {
SessionStoreInternal.maybeDontRestoreTabs(aWindow);
maybeDontSaveTabs(aWindow) {
SessionStoreInternal.maybeDontSaveTabs(aWindow);
},
undoCloseWindow: function ss_undoCloseWindow(aIndex) {
@ -908,8 +908,6 @@ var SessionStoreInternal = {
"autorestore",
1
);
this._removeExplicitlyClosedTabs(state);
}
// Update the session start time using the restored session state.
@ -930,10 +928,6 @@ var SessionStoreInternal = {
delete aWindow.__lastSessionWindowID;
});
}
// clear _maybeDontRestoreTabs because we have restored (or not)
// windows and so they don't matter
state.windows.forEach(win => delete win._maybeDontRestoreTabs);
state._closedWindows.forEach(win => delete win._maybeDontRestoreTabs);
} catch (ex) {
this._log.error("The session file is invalid: " + ex);
}
@ -952,64 +946,6 @@ var SessionStoreInternal = {
return state;
},
/**
* When initializing session, if we are restoring the last session at startup,
* close open tabs or close windows marked _maybeDontRestoreTabs (if they were closed
* by closing remaining tabs).
* See bug 490136
*/
_removeExplicitlyClosedTabs(state) {
// Don't restore tabs that has been explicitly closed
for (let i = 0; i < state.windows.length; ) {
const winData = state.windows[i];
if (winData._maybeDontRestoreTabs) {
if (state.windows.length == 1) {
// it's the last window, we just want to close tabs
let j = 0;
// reset close group (we don't want to append tabs to existing group close).
winData._lastClosedTabGroupCount = -1;
while (winData.tabs.length) {
const tabState = winData.tabs.pop();
// Ensure the index is in bounds.
let activeIndex = (tabState.index || tabState.entries.length) - 1;
activeIndex = Math.min(activeIndex, tabState.entries.length - 1);
activeIndex = Math.max(activeIndex, 0);
let title = "";
if (activeIndex in tabState.entries) {
title =
tabState.entries[activeIndex].title ||
tabState.entries[activeIndex].url;
}
const tabData = {
state: tabState,
title,
image: tabState.image,
pos: j++,
closedAt: Date.now(),
closedInGroup: true,
};
if (this._shouldSaveTabState(tabState)) {
this.saveClosedTabData(winData, winData._closedTabs, tabData);
}
}
} else {
// We can remove the window since it doesn't have any
// tabs that we should restore and it's not the only window
if (winData.tabs.some(this._shouldSaveTabState)) {
winData.closedAt = Date.now();
state._closedWindows.unshift(winData);
}
state.windows.splice(i, 1);
continue; // we don't want to increment the index
}
}
i++;
}
},
_initPrefs() {
this._prefBranch = Services.prefs.getBranch("browser.");
@ -1936,6 +1872,16 @@ var SessionStoreInternal = {
for (let [tab, tabData] of tabMap) {
let permanentKey = tab.linkedBrowser.permanentKey;
this._closedWindowTabs.set(permanentKey, tabData);
if (aWindow._dontSaveTabs && !tabData.isPrivate) {
// Close remaining tabs.
tab._closedInGroup = true;
this.maybeSaveClosedTab(aWindow, tab, tabData);
}
}
if (aWindow._dontSaveTabs) {
winData.tabs.splice(0, winData.tabs.length);
winData.selected = -1;
}
if (isFullyLoaded) {
@ -3404,9 +3350,10 @@ var SessionStoreInternal = {
return Cu.cloneInto(this._closedWindows, {});
},
maybeDontRestoreTabs(aWindow) {
// Don't restore the tabs if we restore the session at startup
this._windows[aWindow.__SSi]._maybeDontRestoreTabs = true;
maybeDontSaveTabs(aWindow) {
if (this.willAutoRestore && this.isLastRestorableWindow()) {
aWindow._dontSaveTabs = true;
}
},
isLastRestorableWindow() {

View File

@ -280,6 +280,7 @@ skip-if = (verify && debug && (os == 'mac' || os == 'win'))
[browser_819510_perwindowpb.js]
skip-if = true # Bug 1284312, Bug 1341980, bug 1381451
[browser_not_collect_when_idle.js]
[browser_close_last_nonprivate_tab.js]
# Disabled for frequent intermittent failures
[browser_464620_a.js]

View File

@ -0,0 +1,34 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* With session restore enabled and quit on last tab close enabled
* When closing the last tab while having another private window,
* it shouldn't be restored at the next startup of Firefox.
* See bug 1732366 for more information.
*/
add_task(async function test_bug_1730021() {
await SpecialPowers.pushPrefEnv({
set: [["browser.sessionstore.resume_session_once", true]],
});
ok(SessionStore.willAutoRestore, "the session will be restored if we quit");
SessionStore.maybeDontSaveTabs(window);
ok(window._dontSaveTabs, "the tabs should be closed at quit");
delete window._dontSaveTabs;
ok(!window._dontSaveTabs, "the flag should be reset");
let newWin = await BrowserTestUtils.openNewBrowserWindow({ private: true });
SessionStore.maybeDontSaveTabs(window);
ok(
window._dontSaveTabs,
"the tabs should be closed at quit even if a private window is open"
);
delete window._dontSaveTabs;
ok(!window._dontSaveTabs, "the flag should be reset");
await BrowserTestUtils.closeWindow(newWin);
});

View File

@ -6,4 +6,3 @@ tags = local
skip-if =
os != "win"
win10_2004 # Bug 1727691
[test_restore_windows_after_close_last_tabs.py]

View File

@ -206,16 +206,6 @@ class SessionStoreTestCase(WindowManagerMixin, MarionetteTestCase):
return opened_windows
def _close_tab_shortcut(self):
self.marionette.actions.sequence("key", "keyboard_id").key_down(
self.accelKey
).key_down("w").key_up("w").key_up(self.accelKey).perform()
def close_all_tabs_and_restart(self):
self.close_all_tabs()
self.marionette.quit(in_app=True, callback=self._close_tab_shortcut)
self.marionette.start_session()
def simulate_os_shutdown(self):
"""Simulate an OS shutdown.

View File

@ -1,60 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# add this directory to the path
from __future__ import absolute_import
import sys
import os
sys.path.append(os.path.dirname(__file__))
from session_store_test_case import SessionStoreTestCase
class TestSessionStoreEnabledAllWindows(SessionStoreTestCase):
def setUp(self, include_private=True):
"""Setup for the test, enabling session restore.
:param include_private: Whether to open private windows.
"""
super(TestSessionStoreEnabledAllWindows, self).setUp(
include_private=include_private, startup_page=3
)
def test_with_variety(self):
"""Test opening and restoring both standard and private windows.
Opens a set of windows, both standard and private, with
some number of tabs in them. Once the tabs have loaded, restarts
the browser, and then ensures that the standard tabs have been
restored, and that the private ones have not.
"""
self.wait_for_windows(
self.all_windows, "Not all requested windows have been opened"
)
self.marionette.quit(in_app=True)
self.marionette.start_session()
self.wait_for_windows(
self.test_windows, "Non private browsing windows should have been restored"
)
def test_close_tabs(self):
self.wait_for_windows(
self.all_windows, "Not all requested windows have been opened"
)
self.close_all_tabs_and_restart()
self.assertEqual(
len(self.marionette.chrome_window_handles),
1,
msg="Windows from last session shouldn`t have been restored.",
)
self.assertEqual(
len(self.marionette.window_handles),
1,
msg="Tabs from last session shouldn`t have been restored.",
)

View File

@ -33,7 +33,7 @@ function closeWindow(aClose, aPromptFunction, aSource) {
// If the user explicitly closes the last tabs in the window close remaining tabs. Bug 490136
if (aClose) {
window.SessionStore?.maybeDontRestoreTabs(window);
window.SessionStore?.maybeDontSaveTabs(window);
}
} else if (
typeof aPromptFunction == "function" &&