Bug 1241085 - fix issues with about:newtab and other initial pages whose URIs now persist after session restore, r?mconley draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 06 May 2016 09:11:33 +0100
changeset 364226 0e0d011dffe82ef87ee50fd0ebb1b64373e58521
parent 364225 5ad003c9cd1d61092f653eb345d9658ed120a78c
child 520212 382435d6310e05e896ed9c609624d870f3f7b31d
push id17388
push usergijskruitbosch@gmail.com
push dateFri, 06 May 2016 08:12:53 +0000
reviewersmconley
bugs1241085
milestone49.0a1
Bug 1241085 - fix issues with about:newtab and other initial pages whose URIs now persist after session restore, r?mconley MozReview-Commit-ID: BbzOSwFucf6
browser/components/sessionstore/SessionStore.jsm
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_newtab_userTypedValue.js
--- 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);
+});