Bug 1241085 - fix issues with about:newtab and other initial pages whose URIs now persist after session restore, r?mconley
MozReview-Commit-ID: BbzOSwFucf6
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -773,17 +773,23 @@ var SessionStoreInternal = {
case "SessionStore:restoreHistoryComplete":
// Notify the tabbrowser that the tab chrome has been restored.
let tabData = TabState.collect(tab);
// wall-paper fix for bug 439675: make sure that the URL to be loaded
// is always visible in the address bar if no other value is present
let activePageData = tabData.entries[tabData.index - 1] || null;
let uri = activePageData ? activePageData.url || null : null;
- if (!browser.userTypedValue) {
+ // NB: we won't set initial URIs (about:home, about:newtab, etc.) here
+ // because their load will not normally trigger a location bar clearing
+ // when they finish loading (to avoid race conditions where we then
+ // clear user input instead), so we shouldn't set them here either.
+ // They also don't fall under the issues in bug 439675 where user input
+ // needs to be preserved if the load doesn't succeed.
+ if (!browser.userTypedValue && uri && !win.gInitialPages.includes(uri)) {
browser.userTypedValue = uri;
}
// If the page has a title, set it.
if (activePageData) {
if (activePageData.title) {
tab.label = activePageData.title;
tab.crop = "end";
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -216,10 +216,11 @@ skip-if = true
skip-if = os == "mac"
[browser_911547.js]
[browser_send_async_message_oom.js]
[browser_multiple_navigateAndRestore.js]
run-if = e10s
[browser_async_window_flushing.js]
[browser_forget_async_closings.js]
+[browser_newtab_userTypedValue.js]
[browser_sessionStoreContainer.js]
[browser_1234021.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_newtab_userTypedValue.js
@@ -0,0 +1,55 @@
+"use strict";
+
+add_task(function* () {
+ let win = yield BrowserTestUtils.openNewBrowserWindow();
+ yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:logo");
+ let tabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(win.gBrowser, () => {});
+ win.BrowserOpenTab();
+ let tab = yield tabOpenedAndSwitchedTo;
+ is(win.gURLBar.value, "", "URL bar should be empty");
+ is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
+ let state = JSON.parse(SessionStore.getTabState(tab));
+ ok(!state.userTypedValue, "userTypedValue should be undefined on the tab's state");
+ tab = null;
+
+ yield BrowserTestUtils.closeWindow(win);
+
+ ok(SessionStore.getClosedWindowCount(), "Should have a closed window");
+
+ win = SessionStore.undoCloseWindow(0);
+ yield TestUtils.topicObserved("sessionstore-single-window-restored",
+ subject => subject == win);
+ yield BrowserTestUtils.waitForMessage(win.gBrowser.selectedBrowser.messageManager, "SessionStore:update");
+
+ is(win.gURLBar.value, "", "URL bar should be empty");
+ tab = win.gBrowser.selectedTab;
+ is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
+ state = JSON.parse(SessionStore.getTabState(tab));
+ ok(!state.userTypedValue, "userTypedValue should be undefined on the tab's state");
+
+ yield BrowserTestUtils.removeTab(tab);
+
+ for (let url of gInitialPages) {
+ if (url == BROWSER_NEW_TAB_URL) {
+ continue; // We tested this above.
+ }
+ yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, url);
+ yield BrowserTestUtils.closeWindow(win);
+
+ ok(SessionStore.getClosedWindowCount(), "Should have a closed window");
+
+ win = SessionStore.undoCloseWindow(0);
+ yield TestUtils.topicObserved("sessionstore-single-window-restored",
+ subject => subject == win);
+ yield BrowserTestUtils.waitForMessage(win.gBrowser.selectedBrowser.messageManager, "SessionStore:update");
+
+ is(win.gURLBar.value, "", "URL bar should be empty");
+ tab = win.gBrowser.selectedTab;
+ is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
+ state = JSON.parse(SessionStore.getTabState(tab));
+ ok(!state.userTypedValue, "userTypedValue should be undefined on the tab's state");
+
+ yield BrowserTestUtils.removeTab(tab);
+ }
+ yield BrowserTestUtils.closeWindow(win);
+});