Bug 1847617 - Add about:home to the list of URLs we filter out when deciding if a closing window has state that should be saved. r=dao,sessionstore-reviewers

* And fix the urlbar test that breaks now that about:home tabs with no history aren't saved when closed.

Differential Revision: https://phabricator.services.mozilla.com/D185605
This commit is contained in:
Sam Foster
2023-08-11 19:14:51 +00:00
parent 5844ef9404
commit 8115a9c131
4 changed files with 174 additions and 1 deletions

View File

@@ -6149,6 +6149,7 @@ var SessionStoreInternal = {
!(
aTabState.entries.length == 1 &&
(entryUrl == "about:blank" ||
entryUrl == "about:home" ||
entryUrl == "about:newtab" ||
entryUrl == "about:privatebrowsing") &&
!aTabState.userTypedValue

View File

@@ -365,6 +365,7 @@ skip-if =
os == "win" && os_version == "6.1" # Skip on Azure - frequent failure
[browser_sessionStorage_size.js]
[browser_sessionStoreContainer.js]
[browser_should_restore_tab.js]
[browser_sizemodeBeforeMinimized.js]
[browser_speculative_connect.js]
[browser_swapDocShells.js]

View File

@@ -0,0 +1,139 @@
const NOTIFY_CLOSED_OBJECTS_CHANGED = "sessionstore-closed-objects-changed";
add_setup(async () => {
registerCleanupFunction(async () => {
Services.obs.notifyObservers(null, "browser:purge-session-history");
});
});
async function check_tab_close_notification(openedTab, expectNotification) {
let tabUrl = openedTab.linkedBrowser.currentURI.spec;
let win = openedTab.ownerGlobal;
let initialTabCount = SessionStore.getClosedTabCountForWindow(win);
let tabClosed = BrowserTestUtils.waitForTabClosing(openedTab);
let notified = false;
function topicObserver(_, topic) {
notified = true;
}
Services.obs.addObserver(topicObserver, NOTIFY_CLOSED_OBJECTS_CHANGED);
BrowserTestUtils.removeTab(openedTab);
await tabClosed;
// SessionStore does a setTimeout(notify, 0) to notifyObservers when it handles TabClose
// We need to wait long enough to be confident the observer would have been notified
// if it was going to be.
let ticks = 0;
await TestUtils.waitForCondition(() => {
return ++ticks > 1;
});
Services.obs.removeObserver(topicObserver, NOTIFY_CLOSED_OBJECTS_CHANGED);
if (expectNotification) {
Assert.ok(
notified,
`Expected ${NOTIFY_CLOSED_OBJECTS_CHANGED} when the ${tabUrl} tab closed`
);
Assert.equal(
SessionStore.getClosedTabCountForWindow(win),
initialTabCount + 1,
"Expected closed tab count to have incremented"
);
} else {
Assert.ok(
!notified,
`Expected no ${NOTIFY_CLOSED_OBJECTS_CHANGED} when the ${tabUrl} tab closed`
);
Assert.equal(
SessionStore.getClosedTabCountForWindow(win),
initialTabCount,
"Expected closed tab count to have not changed"
);
}
}
add_task(async function test_control_case() {
let win = window;
let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(
win.gBrowser,
() => {}
);
let tab = await BrowserTestUtils.openNewForegroundTab(
win.gBrowser,
"https://example.com/"
);
await tabOpenedAndSwitchedTo;
await check_tab_close_notification(tab, true);
});
add_task(async function test_about_new_tab() {
let win = window;
let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(
win.gBrowser,
() => {}
);
// This opens about:newtab:
win.BrowserOpenTab();
let tab = await tabOpenedAndSwitchedTo;
await check_tab_close_notification(tab, false);
});
add_task(async function test_about_home() {
let win = window;
let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(
win.gBrowser,
() => {}
);
let tab = await BrowserTestUtils.openNewForegroundTab(
win.gBrowser,
"about:home"
);
await tabOpenedAndSwitchedTo;
await check_tab_close_notification(tab, false);
});
add_task(async function test_navigated_about_home() {
let win = window;
let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(
win.gBrowser,
() => {}
);
let tab = await BrowserTestUtils.openNewForegroundTab(
win.gBrowser,
"https://example.com/"
);
await tabOpenedAndSwitchedTo;
BrowserTestUtils.loadURIString(tab.linkedBrowser, "about:home");
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
// even if we end up on an ignorable URL,
// if there's meaningful history, we should save this tab
await check_tab_close_notification(tab, true);
});
add_task(async function test_about_blank() {
let win = window;
let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(
win.gBrowser,
() => {}
);
let tab = await BrowserTestUtils.openNewForegroundTab(
win.gBrowser,
"about:blank"
);
await tabOpenedAndSwitchedTo;
await check_tab_close_notification(tab, false);
});
add_task(async function test_about_privatebrowsing() {
let win = window;
let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(
win.gBrowser,
() => {}
);
let tab = await BrowserTestUtils.openNewForegroundTab(
win.gBrowser,
"about:privatebrowsing"
);
await tabOpenedAndSwitchedTo;
await check_tab_close_notification(tab, false);
});