Bug 1535188 - Make it impossible to do empty @alias searches. r=mak
authorDrew Willcoxon <adw@mozilla.com>
Thu, 14 Mar 2019 17:49:03 +0000
changeset 521920 d3889d245691
parent 521919 8337beedb635
child 521921 b11e72c5c268
push id10870
push usernbeleuzu@mozilla.com
push dateFri, 15 Mar 2019 20:00:07 +0000
treeherdermozilla-beta@c594aee5b7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1535188
milestone67.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 1535188 - Make it impossible to do empty @alias searches. r=mak Differential Revision: https://phabricator.services.mozilla.com/D23435
browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
browser/components/urlbar/tests/browser/browser_urlbarTokenAlias.js
--- a/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
+++ b/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
@@ -243,17 +243,17 @@ function makeUrlbarResult(tokens, info) 
             engine: [action.params.engineName, true],
             suggestion: [action.params.searchSuggestion, true],
             keyword: [action.params.alias, true],
             query: [action.params.searchQuery.trim(), true],
             icon: [info.icon, false],
             isKeywordOffer: [
               action.params.alias &&
                 !action.params.searchQuery.trim() &&
-                !info.style.includes("heuristic"),
+                action.params.alias.startsWith("@"),
               false,
             ],
           })
         );
       case "keyword": {
         let title = info.comment;
         if (tokens && tokens.length > 1) {
           title = bundle.formatStringFromName("bookmarkKeywordSearch",
--- a/browser/components/urlbar/tests/browser/browser_urlbarTokenAlias.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarTokenAlias.js
@@ -206,17 +206,18 @@ add_task(async function nonTokenAlias() 
 
   await UrlbarTestUtils.promisePopupClose(window,
     () => EventUtils.synthesizeKey("KEY_Escape"));
 
   engine.alias = ALIAS;
 });
 
 
-// Clicking on an @ alias in the popup should fill it in the urlbar input.
+// Clicking on an @ alias offer (an @ alias with an empty search string) 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
   // robustness don't assume it is.
   let testEngineItem;
@@ -236,16 +237,84 @@ add_task(async function clickAndFillAlia
   await promiseSearchComplete();
   await waitForAutocompleteResultAt(0);
   await 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} `);
 
+  // Press the enter key a couple of times.  Nothing should happen except a new
+  // search will start and its result should be the alias again.  The urlbar
+  // should still contain the alias.  An empty search results page should not
+  // load.  The test will hang if that happens.
+  for (let i = 0; i < 2; i++) {
+    EventUtils.synthesizeKey("KEY_Enter");
+    await promiseSearchComplete();
+    await waitForAutocompleteResultAt(0);
+    await assertAlias(true);
+    Assert.equal(gURLBar.textValue, `${ALIAS} `);
+  }
+
+  await UrlbarTestUtils.promisePopupClose(window,
+    () => EventUtils.synthesizeKey("KEY_Escape"));
+});
+
+
+// Pressing enter on an @ alias offer (an @ alias with an empty search string)
+// in the popup should fill it in the urlbar input.
+add_task(async function enterAndFillAlias() {
+  // 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
+  // robustness don't assume it is.
+  let index = 0;
+  for (;; index++) {
+    let details = await UrlbarTestUtils.getDetailsOfResultAt(window, index);
+    if (details.searchParams && details.searchParams.keyword == ALIAS) {
+      index++;
+      break;
+    }
+  }
+
+  if (!UrlbarPrefs.get("quantumbar")) {
+    // With awesomebar, the first result ends up preselected, so one fewer key
+    // down is needed to reach the engine.
+    index--;
+  }
+
+  // Key down to it and press enter.
+  EventUtils.synthesizeKey("KEY_ArrowDown", { repeat: index });
+  await UrlbarTestUtils.promisePopupClose(window, () => {
+    EventUtils.synthesizeKey("KEY_Enter");
+  });
+
+  // A new search will start and its result should be the alias.
+  await promiseSearchComplete();
+  await waitForAutocompleteResultAt(0);
+  await 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} `);
+
+  // Press the enter key a couple of times.  Nothing should happen except a new
+  // search will start and its result should be the alias again.  The urlbar
+  // should still contain the alias.  An empty search results page should not
+  // load.  The test will hang if that happens.
+  for (let i = 0; i < 2; i++) {
+    EventUtils.synthesizeKey("KEY_Enter");
+    await promiseSearchComplete();
+    await waitForAutocompleteResultAt(0);
+    await assertAlias(true);
+    Assert.equal(gURLBar.textValue, `${ALIAS} `);
+  }
+
   await UrlbarTestUtils.promisePopupClose(window,
     () => EventUtils.synthesizeKey("KEY_Escape"));
 });
 
 
 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.