Bug 1410591 - Focus the content area when restoring the selected tab. r=mikedeboer
authorDão Gottwald <dao@mozilla.com>
Mon, 23 Apr 2018 19:13:58 +0200
changeset 415154 a5dad10abab907953d379a0a2a6c3b198a4255d6
parent 415153 05476b05d16802c6032b7d3f6984e89150fceba8
child 415155 a5dcdb37129d7ee74288c8a6c99a37924357fb3f
push id33889
push useraciure@mozilla.com
push dateTue, 24 Apr 2018 01:14:50 +0000
treeherdermozilla-central@b35a1f66c452 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1410591
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1410591 - Focus the content area when restoring the selected tab. r=mikedeboer
browser/components/sessionstore/SessionStore.jsm
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_focus_after_restore.js
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -2500,19 +2500,16 @@ var SessionStoreInternal = {
     let tab = tabbrowser.selectedTab = tabbrowser.addTab(null, state);
 
     // restore tab content
     this.restoreTab(tab, state);
 
     // restore the tab's position
     tabbrowser.moveTabTo(tab, pos);
 
-    // focus the tab's content area (bug 342432)
-    tab.linkedBrowser.focus();
-
     // Notify of changes to closed objects.
     this._notifyOfClosedObjectsChange();
 
     return tab;
   },
 
   forgetClosedTab: function ssi_forgetClosedTab(aWindow, aIndex) {
     if (!aWindow.__SSi) {
@@ -4014,16 +4011,21 @@ var SessionStoreInternal = {
       new ViewSourceBrowser(browser);
     }
 
     browser.messageManager.sendAsyncMessage("SessionStore:restoreTabContent",
       {loadArguments, isRemotenessUpdate,
        reason: aOptions.restoreContentReason ||
                RESTORE_TAB_CONTENT_REASON.SET_STATE,
        requestTime: Services.telemetry.msSystemNow()});
+
+    // Focus the tab's content area.
+    if (aTab.selected) {
+      browser.focus();
+    }
   },
 
   /**
    * Marks a given pending tab as restoring.
    *
    * @param aTab
    *        the pending tab to mark as restoring
    */
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -232,25 +232,26 @@ skip-if = true
 # Disabled on OS X:
 [browser_625016.js]
 skip-if = os == "mac" || (os == "linux" && debug) # linux, Bug 1348583
 
 [browser_906076_lazy_tabs.js]
 [browser_911547.js]
 [browser_1284886_suspend_tab.js]
 skip-if = !e10s
-[browser_send_async_message_oom.js]
+[browser_async_window_flushing.js]
+[browser_focus_after_restore.js]
+[browser_forget_async_closings.js]
 [browser_multiple_navigateAndRestore.js]
 run-if = e10s
-[browser_async_window_flushing.js]
-[browser_forget_async_closings.js]
 [browser_newtab_userTypedValue.js]
 [browser_parentProcessRestoreHash.js]
 run-if = e10s
 tags = openUILinkIn
+[browser_send_async_message_oom.js]
 [browser_sessionStoreContainer.js]
 [browser_windowStateContainer.js]
 skip-if = os == "linux" && !debug
 [browser_1234021.js]
 [browser_remoteness_flip_on_restore.js]
 run-if = e10s
 [browser_background_tab_crash.js]
 run-if = e10s && crashreporter
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_focus_after_restore.js
@@ -0,0 +1,19 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+add_task(async function test() {
+  gURLBar.focus();
+  is(document.activeElement, gURLBar.inputField, "urlbar is focused before restoring");
+
+  await promiseBrowserState({
+    windows: [{
+      tabs: [{
+        entries: [{
+          url: "http://example.org/", triggeringPrincipal_base64
+        }]
+      }],
+      selected: 1
+    }]
+  });
+  is(document.activeElement, gBrowser.selectedBrowser, "content area is focused after restoring");
+});