Bug 1295072 - Focus urlbar after opening an empty new tab r=kmag
☠☠ backed out by 951bab16551a ☠ ☠
authorTomislav Jovanovic <tomica@gmail.com>
Sat, 04 Feb 2017 20:48:38 +0100
changeset 479276 70253d6678af8e2f2b4386c77e825af9f600fe46
parent 479275 c3360defc8792ce2e3620a11d4310ca09f1e4e64
child 479277 d2a01f76d88f836438078efabf9ca55c048b073e
push id44211
push userbmo:hskupin@gmail.com
push dateMon, 06 Feb 2017 12:18:11 +0000
reviewerskmag
bugs1295072
milestone54.0a1
Bug 1295072 - Focus urlbar after opening an empty new tab r=kmag MozReview-Commit-ID: 3dzCzHTxQrh
browser/components/extensions/ext-tabs.js
browser/components/extensions/test/browser/browser_ext_tabs_create.js
--- a/browser/components/extensions/ext-tabs.js
+++ b/browser/components/extensions/ext-tabs.js
@@ -413,16 +413,20 @@ extensions.registerSchemaAPI("tabs", "ad
           if (createProperties.index !== null) {
             window.gBrowser.moveTabTo(tab, createProperties.index);
           }
 
           if (createProperties.pinned) {
             window.gBrowser.pinTab(tab);
           }
 
+          if (active && !url) {
+            window.focusAndSelectUrlBar();
+          }
+
           if (createProperties.url && createProperties.url !== window.BROWSER_NEW_TAB_URL) {
             // We can't wait for a location change event for about:newtab,
             // since it may be pre-rendered, in which case its initial
             // location change event has already fired.
 
             // Mark the tab as initializing, so that operations like
             // `executeScript` wait until the requested URL is loaded in
             // the tab before dispatching messages to the inner window
--- a/browser/components/extensions/test/browser/browser_ext_tabs_create.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_create.js
@@ -1,13 +1,13 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-add_task(function* () {
+add_task(function* test_create_options() {
   let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:robots");
   gBrowser.selectedTab = tab;
 
   // TODO: Multiple windows.
 
   // Using pre-loaded new tab pages interferes with onUpdated events.
   // It probably shouldn't.
   SpecialPowers.setBoolPref("browser.newtab.preload", false);
@@ -159,8 +159,40 @@ add_task(function* () {
 
   yield extension.startup();
   yield extension.awaitFinish("tabs.create");
   yield extension.unload();
 
   yield BrowserTestUtils.removeTab(tab);
 });
 
+add_task(function* test_urlbar_focus() {
+  const extension = ExtensionTestUtils.loadExtension({
+    background() {
+      browser.test.onMessage.addListener(async (cmd, ...args) => {
+        const result = await browser.tabs[cmd](...args);
+        browser.test.sendMessage("result", result);
+      });
+    },
+  });
+
+  yield extension.startup();
+
+  // Test content is focused after opening a regular url
+  extension.sendMessage("create", {url: "https://example.com"});
+  const tab1 = yield extension.awaitMessage("result");
+
+  is(document.activeElement.tagName, "browser", "Content focused after opening a web page");
+
+  extension.sendMessage("remove", tab1.id);
+  yield extension.awaitMessage("result");
+
+  // Test urlbar is focused after opening an empty tab
+  extension.sendMessage("create", {});
+  const tab2 = yield extension.awaitMessage("result");
+
+  ok(gURLBar.focused, "Urlbar focused after opening an empty tab");
+
+  extension.sendMessage("remove", tab2.id);
+  yield extension.awaitMessage("result");
+
+  yield extension.unload();
+});