Bug 520538 - -new-tab about:blank should focus the location bar. r=gavin
authorDão Gottwald <dao@mozilla.com>
Sun, 24 Jan 2010 17:10:07 +0100
changeset 37455 5fca1946778b3ad09701309e0e5c35e3c8a754e0
parent 37454 fb61277403e38a9b2d6dee7a9f9bef7e3d7ad1f0
child 37456 b3b2e90f743d4499249af0901c018cec07e04bba
push id11312
push userdgottwald@mozilla.com
push dateSun, 24 Jan 2010 16:10:47 +0000
treeherdermozilla-central@5fca1946778b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs520538
milestone1.9.3a1pre
Bug 520538 - -new-tab about:blank should focus the location bar. r=gavin
browser/base/content/browser.js
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug520538.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4515,16 +4515,23 @@ nsBrowserAccess.prototype = {
           needToFocusWin = true;
         }
 
         if (!win) {
           // we couldn't find a suitable window, a new one needs to be opened.
           return null;
         }
 
+        if (isExternal && (!aURI || aURI.spec == "about:blank")) {
+          win.BrowserOpenTab(); // this also focuses the location bar
+          win.focus();
+          newWindow = win.content;
+          break;
+        }
+
         let loadInBackground = gPrefService.getBoolPref("browser.tabs.loadDivertedInBackground");
         let referrer = aOpener ? makeURI(aOpener.location.href) : null;
 
         // If this is an external load, we need to load a blank tab first,
         // because loadflags can't be passed to loadOneTab.
         let loadBlankFirst = !aURI || isExternal;
         let tab = win.gBrowser.loadOneTab(loadBlankFirst ? "about:blank" : aURI.spec, {
                                           referrerURI: referrer,
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -96,16 +96,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_bug441778.js \
                  browser_bug455852.js \
                  browser_bug462673.js \
                  browser_bug481560.js \
                  browser_bug484315.js \
                  browser_bug477014.js \
                  browser_bug495058.js \
                  browser_bug517902.js \
+                 browser_bug520538.js \
                  browser_bug521216.js \
                  browser_bug537474.js \
                  browser_discovery.js \
                  browser_tabfocus.js \
                  discovery.html \
                  moz.png \
                  test_bug435035.html \
                  test_bug462673.html \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug520538.js
@@ -0,0 +1,15 @@
+function test() {
+  var tabs = gBrowser.tabContainer.childElementCount;
+  content.focus();
+  browserDOMWindow.openURI(makeURI("about:blank"),
+                           null,
+                           Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
+                           Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
+  is(gBrowser.tabContainer.childElementCount, tabs + 1,
+     "'-new-tab about:blank' opens a new tab");
+  is(gBrowser.selectedTab, gBrowser.tabContainer.childNodes[tabs],
+     "'-new-tab about:blank' selects the new tab");
+  is(document.activeElement, gURLBar.inputField,
+     "'-new-tab about:blank' focuses the location bar");
+  gBrowser.removeCurrentTab();
+}