Bug 1507568 - Clicking a @shortcut in the urlbar popup should fill it in the input instead of visiting the site. r=mak
authorDrew Willcoxon <adw@mozilla.com>
Tue, 20 Nov 2018 10:36:29 +0000
changeset 506462 efa49008bfc788e3354d6150eab71a7f105e3102
parent 506461 d6591e3f56bbe90561faeb01470cca02d9085e36
child 506463 8f7476054232c929476c1a5112bb855f6ba7612f
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1507568
milestone65.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 1507568 - Clicking a @shortcut in the urlbar popup should fill it in the input instead of visiting the site. r=mak Differential Revision: https://phabricator.services.mozilla.com/D12203
browser/base/content/test/urlbar/browser.ini
browser/base/content/test/urlbar/browser_urlbarHighlightSearchAlias.js
browser/base/content/test/urlbar/browser_urlbarTokenAlias.js
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/test/urlbar/browser.ini
+++ b/browser/base/content/test/urlbar/browser.ini
@@ -91,17 +91,16 @@ support-files =
 [browser_urlbarDecode.js]
 [browser_urlbarDelete.js]
 [browser_urlbarEnter.js]
 [browser_urlbar_whereToOpen.js]
 [browser_urlbarEnterAfterMouseOver.js]
 skip-if = os == "linux" # Bug 1073339 - Investigate autocomplete test unreliability on Linux/e10s
 [browser_urlbarFocusedCmdK.js]
 [browser_urlbarHashChangeProxyState.js]
-[browser_urlbarHighlightSearchAlias.js]
 [browser_urlbarKeepStateAcrossTabSwitches.js]
 [browser_urlbarOneOffs.js]
 support-files =
   searchSuggestionEngine.xml
   searchSuggestionEngine.sjs
 [browser_urlbarOneOffs_searchSuggestions.js]
 support-files =
   searchSuggestionEngine.xml
@@ -128,16 +127,17 @@ support-files =
 support-files =
   searchSuggestionEngine.xml
   searchSuggestionEngine.sjs
 [browser_urlbarSearchTelemetry.js]
 support-files =
   searchSuggestionEngine.xml
   searchSuggestionEngine.sjs
 [browser_urlbarStop.js]
+[browser_urlbarTokenAlias.js]
 [browser_urlbarUpdateForDomainCompletion.js]
 [browser_urlbar_autoFill_backspaced.js]
 [browser_urlbar_canonize_on_autofill.js]
 [browser_urlbar_blanking.js]
 support-files =
   file_blank_but_not_blank.html
 [browser_urlbar_locationchange_urlbar_edit_dos.js]
 support-files =
rename from browser/base/content/test/urlbar/browser_urlbarHighlightSearchAlias.js
rename to browser/base/content/test/urlbar/browser_urlbarTokenAlias.js
--- a/browser/base/content/test/urlbar/browser_urlbarHighlightSearchAlias.js
+++ b/browser/base/content/test/urlbar/browser_urlbarTokenAlias.js
@@ -1,12 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-// This test checks the urlbar.highlightSearchAlias() function.
+// This test checks "@" search engine aliases ("token aliases") in the urlbar.
 
 "use strict";
 
 const ALIAS = "@test";
 
 add_task(async function init() {
   Services.search.addEngineWithDetails("Test", {
     alias: ALIAS,
@@ -203,16 +203,53 @@ add_task(async function nonTokenAlias() 
 
   EventUtils.synthesizeKey("KEY_Escape");
   await promisePopupHidden(gURLBar.popup);
 
   engine.alias = ALIAS;
 });
 
 
+// Clicking on an @ alias in the popup should fill it in the urlbar input.
+add_task(async function clickAndFillAlias() {
+  // Do a search for "@" to show all the @ aliases.
+  gURLBar.search("@");
+  await promiseSearchComplete();
+
+  // Find our test engine in the results.  It's probably last, but for test
+  // robustness don't assume it is.
+  let testEngineItem;
+  for (let i = 0; !testEngineItem; i++) {
+    let item = await waitForAutocompleteResultAt(i);
+    let action = PlacesUtils.parseActionUrl(item.getAttribute("url"));
+    if (action && action.params.alias == ALIAS) {
+      testEngineItem = item;
+    }
+  }
+
+  // Click it.
+  let hiddenPromise = promisePopupHidden(gURLBar.popup);
+  EventUtils.synthesizeMouseAtCenter(testEngineItem, {});
+
+  // The popup will close and then open again with the new search string, which
+  // should be the test alias.
+  await hiddenPromise;
+  await promiseSearchComplete();
+  await promisePopupShown(gURLBar.popup);
+  assertAlias(true);
+
+  // The urlbar input value should be the alias followed by a space so that it's
+  // ready for the user to start typing.
+  Assert.equal(gURLBar.textValue, `${ALIAS} `);
+
+  EventUtils.synthesizeKey("KEY_Escape");
+  await promisePopupHidden(gURLBar.popup);
+});
+
+
 async function doSimpleTest(revertBetweenSteps) {
   // When autofill is enabled, searching for "@tes" will autofill to "@test",
   // which gets in the way of this test task, so temporarily disable it.
   Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
   registerCleanupFunction(() => {
     Services.prefs.clearUserPref("browser.urlbar.autoFill");
   });
 
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -762,16 +762,27 @@ file, You can obtain one at http://mozil
                 // open in the current tab.
                 where = "current";
                 break;
               case "searchengine":
                 if (selectedOneOff && selectedOneOff.engine) {
                   // Replace the engine with the selected one-off engine.
                   action.params.engineName = selectedOneOff.engine.name;
                 }
+                // If the selected result is an @alias offer -- an @alias with
+                // an empty query string -- then instead of loading the engine's
+                // empty search results page, put the @alias in the input so
+                // that the user can type a search query and search directly
+                // from the urlbar.
+                if (action.params.alias &&
+                    action.params.alias.startsWith("@") &&
+                    !action.params.searchQuery) {
+                  this.search(action.params.input);
+                  return;
+                }
                 const actionDetails = {
                   isSuggestion: !!action.params.searchSuggestion,
                   alias: action.params.alias,
                 };
                 [url, postData] = this._parseAndRecordSearchEngineLoad(
                   action.params.engineName,
                   action.params.searchSuggestion || action.params.searchQuery,
                   event,