Bug 1784019 - Keep window open when restoring if Firefox View is selected. r=dao
Differential Revision: https://phabricator.services.mozilla.com/D154395
This commit is contained in:
@@ -3975,6 +3975,16 @@ var SessionStoreInternal = {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
tabbrowser.selectedTab.hidden &&
|
||||
tabbrowser.visibleTabs.length === removableTabs.length
|
||||
) {
|
||||
// If all the visible tabs are also removable and the selected tab is hidden, we will later remove the
|
||||
// visible tabs causing the browser to automatically close because the only tab left is hidden.
|
||||
// To prevent the browser from automatically closing, we will leave one other tab open.
|
||||
removableTabs.shift();
|
||||
}
|
||||
|
||||
if (tabbrowser.tabs.length == removableTabs.length) {
|
||||
canOverwriteTabs = true;
|
||||
} else {
|
||||
|
||||
@@ -115,6 +115,7 @@ skip-if =
|
||||
[browser_dying_cache.js]
|
||||
skip-if = (os == 'win') # bug 1331853
|
||||
[browser_dynamic_frames.js]
|
||||
[browser_firefoxView_selected_restore.js]
|
||||
[browser_formdata.js]
|
||||
skip-if =
|
||||
verify && debug
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const { _LastSession } = ChromeUtils.import(
|
||||
"resource:///modules/sessionstore/SessionStore.jsm"
|
||||
);
|
||||
const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
|
||||
|
||||
const state = {
|
||||
windows: [
|
||||
{
|
||||
tabs: [
|
||||
{
|
||||
entries: [
|
||||
{
|
||||
url: "http://example.org/",
|
||||
triggeringPrincipal_base64,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
selected: 2,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/**
|
||||
* This is regrettable, but when `promiseBrowserState` resolves, we're still
|
||||
* midway through loading the tabs. To avoid race conditions in URLs for tabs
|
||||
* being available, wait for all the loads to finish:
|
||||
*/
|
||||
function promiseSessionStoreLoads(numberOfLoads) {
|
||||
let loadsSeen = 0;
|
||||
return new Promise(resolve => {
|
||||
Services.obs.addObserver(function obs(browser) {
|
||||
loadsSeen++;
|
||||
if (loadsSeen == numberOfLoads) {
|
||||
resolve();
|
||||
}
|
||||
// The typeof check is here to avoid one test messing with everything else by
|
||||
// keeping the observer indefinitely.
|
||||
if (typeof info == "undefined" || loadsSeen >= numberOfLoads) {
|
||||
Services.obs.removeObserver(obs, "sessionstore-debug-tab-restored");
|
||||
}
|
||||
info("Saw load for " + browser.currentURI.spec);
|
||||
}, "sessionstore-debug-tab-restored");
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test() {
|
||||
let fxViewBtn = document.getElementById("firefox-view-button");
|
||||
ok(fxViewBtn, "Got the Firefox View button");
|
||||
fxViewBtn.click();
|
||||
|
||||
await BrowserTestUtils.browserLoaded(
|
||||
window.FirefoxViewHandler.tab.linkedBrowser
|
||||
);
|
||||
|
||||
let allTabsRestored = promiseSessionStoreLoads(1);
|
||||
|
||||
_LastSession.setState(state);
|
||||
|
||||
is(gBrowser.tabs.length, 2, "Number of tabs is 2");
|
||||
|
||||
ss.restoreLastSession();
|
||||
|
||||
await allTabsRestored;
|
||||
|
||||
ok(
|
||||
window.FirefoxViewHandler.tab.selected,
|
||||
"The Firefox View tab is selected and the browser window did not close"
|
||||
);
|
||||
is(gBrowser.tabs.length, 3, "Number of tabs is 3");
|
||||
|
||||
gBrowser.removeTab(window.FirefoxViewHandler.tab);
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
});
|
||||
Reference in New Issue
Block a user