Bug 1533060 - Add a test for selecting a search suggestion after selecting a one-off button. r=adw
☠☠ backed out by 7520d595404d ☠ ☠
authorMark Banner <standard8@mozilla.com>
Thu, 07 Mar 2019 22:11:00 +0000
changeset 521049 8d02942b98f56c2ed93a153c644a8d4a0930d791
parent 521048 bff0dee7c2efaddffd9eea04f380995306fefb63
child 521050 6d82d52f6279fe2307238d2e9a9d7fdfbe7c7bb1
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1533060
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 1533060 - Add a test for selecting a search suggestion after selecting a one-off button. r=adw Depends on D22353,D22289 Differential Revision: https://phabricator.services.mozilla.com/D22529
browser/components/urlbar/tests/browser/browser_urlbarOneOffs_searchSuggestions.js
browser/components/urlbar/tests/browser/searchSuggestionEngine2.xml
--- a/browser/components/urlbar/tests/browser/browser_urlbarOneOffs_searchSuggestions.js
+++ b/browser/components/urlbar/tests/browser/browser_urlbarOneOffs_searchSuggestions.js
@@ -1,93 +1,161 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests various actions relating to search suggestions and the one-off buttons.
+ */
+
 const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";
+const TEST_ENGINE2_BASENAME = "searchSuggestionEngine2.xml";
+
+const serverInfo = {
+  scheme: "http",
+  host: "localhost",
+  port: 20709, // Must be identical to what is in searchSuggestionEngine2.xml
+};
 
 add_task(async function init() {
   await PlacesUtils.history.clear();
   await SpecialPowers.pushPrefEnv({
     set: [["browser.urlbar.oneOffSearches", true],
           ["browser.urlbar.suggest.searches", true]],
   });
   let engine = await SearchTestUtils.promiseNewSearchEngine(
     getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME);
+  let engine2 = await SearchTestUtils.promiseNewSearchEngine(
+    getRootDirectory(gTestPath) + TEST_ENGINE2_BASENAME);
   let oldDefaultEngine = await Services.search.getDefault();
+  await Services.search.moveEngine(engine2, 0);
   await Services.search.moveEngine(engine, 0);
   await Services.search.setDefault(engine);
   registerCleanupFunction(async function() {
     await Services.search.setDefault(oldDefaultEngine);
 
     await PlacesUtils.history.clear();
     // Make sure the popup is closed for the next test.
     await UrlbarTestUtils.promisePopupClose(window);
   });
 });
 
+async function withSecondSuggestion(testFn) {
+  await BrowserTestUtils.withNewTab(gBrowser, async () => {
+    let typedValue = "foo";
+    await promiseAutocompleteResultPopup(typedValue, window, true);
+    await promiseSuggestionsPresent();
+    assertState(0, -1, typedValue);
+
+    // Down to select the first search suggestion.
+    EventUtils.synthesizeKey("KEY_ArrowDown");
+    assertState(1, -1, "foofoo");
+
+    // Down to select the next search suggestion.
+    EventUtils.synthesizeKey("KEY_ArrowDown");
+    assertState(2, -1, "foobar");
+
+    await withHttpServer(serverInfo, () => {
+      return testFn();
+    });
+  });
+  await PlacesUtils.history.clear();
+}
+
 // Presses the Return key when a one-off is selected after selecting a search
 // suggestion.
-add_task(async function oneOffReturnAfterSuggestion() {
-  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+add_task(async function test_returnAfterSuggestion() {
+  await withSecondSuggestion(async () => {
+    // Alt+Down to select the first one-off.
+    EventUtils.synthesizeKey("KEY_ArrowDown", {altKey: true});
+    assertState(2, 0, "foobar");
 
-  let typedValue = "foo";
-  await promiseAutocompleteResultPopup(typedValue, window, true);
-  await promiseSuggestionsPresent();
-  assertState(0, -1, typedValue);
-
-  // Down to select the first search suggestion.
-  EventUtils.synthesizeKey("KEY_ArrowDown");
-  assertState(1, -1, "foofoo");
+    let resultsPromise =
+      BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
+                                     `http://mochi.test:8888/?terms=foobar`);
+    EventUtils.synthesizeKey("KEY_Enter");
+    await resultsPromise;
+  });
+});
 
-  // Down to select the next search suggestion.
-  EventUtils.synthesizeKey("KEY_ArrowDown");
-  assertState(2, -1, "foobar");
-
-  // Alt+Down to select the first one-off.
-  EventUtils.synthesizeKey("KEY_ArrowDown", {altKey: true});
-  assertState(2, 0, "foobar");
+// Presses the Return key when a non-default one-off is selected after selecting
+// a search suggestion.
+add_task(async function test_returnAfterSuggestion_nonDefault() {
+  await withSecondSuggestion(async () => {
+    // Alt+Down twice to select the second one-off.
+    EventUtils.synthesizeKey("KEY_ArrowDown", {altKey: true});
+    EventUtils.synthesizeKey("KEY_ArrowDown", {altKey: true});
+    assertState(2, 1, "foobar");
 
-  let resultsPromise =
-    BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
-                                   `http://mochi.test:8888/?terms=foobar`);
-  EventUtils.synthesizeKey("KEY_Enter");
-  await resultsPromise;
-
-  await PlacesUtils.history.clear();
-  BrowserTestUtils.removeTab(tab);
+    let resultsPromise =
+      BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
+                                     `http://localhost:20709/?terms=foobar`);
+    EventUtils.synthesizeKey("KEY_Enter");
+    await resultsPromise;
+  });
 });
 
 // Clicks a one-off engine after selecting a search suggestion.
-add_task(async function oneOffClickAfterSuggestion() {
-  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+add_task(async function test_clickAfterSuggestion() {
+  await withSecondSuggestion(async () => {
+    let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window).getSelectableButtons(true);
+    let resultsPromise =
+      BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
+                                     `http://mochi.test:8888/?terms=foobar`);
+    EventUtils.synthesizeMouseAtCenter(oneOffs[0], {});
+    await resultsPromise;
+  });
+});
 
-  let typedValue = "foo";
-  await promiseAutocompleteResultPopup(typedValue, window, true);
-  await promiseSuggestionsPresent();
-  assertState(0, -1, typedValue);
-
-  // Down to select the first search suggestion.
-  EventUtils.synthesizeKey("KEY_ArrowDown");
-  assertState(1, -1, "foofoo");
+// Clicks a non-default one-off engine after selecting a search suggestion.
+add_task(async function test_clickAfterSuggestion_nonDefault() {
+  await withSecondSuggestion(async () => {
+    let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window).getSelectableButtons(true);
+    let resultsPromise =
+      BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
+                                     `http://localhost:20709/?terms=foobar`);
+    EventUtils.synthesizeMouseAtCenter(oneOffs[1], {});
+    await resultsPromise;
+  });
+});
 
-  // Down to select the next search suggestion.
-  EventUtils.synthesizeKey("KEY_ArrowDown");
-  assertState(2, -1, "foobar");
+// Selects a non-default one-off engine and then selects a search suggestion.
+add_task(async function test_selectOneOffThenSuggestion() {
+  if (!UrlbarPrefs.get("quantumbar")) {
+    // The legacy address bar doesn't work correctly for this scenario.
+    return;
+  }
+  await BrowserTestUtils.withNewTab(gBrowser, async () => {
+    let typedValue = "foo";
+    await promiseAutocompleteResultPopup(typedValue, window, true);
+    await promiseSuggestionsPresent();
+    assertState(0, -1, typedValue);
 
-  let oneOffs = UrlbarTestUtils.getOneOffSearchButtons(window).getSelectableButtons(true);
-  let resultsPromise =
-    BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
-                                   `http://mochi.test:8888/?terms=foobar`);
-  EventUtils.synthesizeMouseAtCenter(oneOffs[0], {});
-  await resultsPromise;
+    // Select a non-default one-off engine.
+    EventUtils.synthesizeKey("KEY_ArrowDown", {altKey: true});
+    EventUtils.synthesizeKey("KEY_ArrowDown", {altKey: true});
+    assertState(0, 1, "foo");
 
-  await PlacesUtils.history.clear();
-  BrowserTestUtils.removeTab(tab);
+    // Now click the second suggestion.
+    await withHttpServer(serverInfo, async () => {
+      let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 2);
+
+      let resultsPromise =
+        BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
+                                       `http://localhost:20709/?terms=foobar`);
+      EventUtils.synthesizeMouseAtCenter(result.element.row, {});
+      await resultsPromise;
+    });
+  });
 });
 
 add_task(async function overridden_engine_not_reused() {
   info("An overridden search suggestion item should not be reused by a search with another engine");
-  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+  await BrowserTestUtils.withNewTab(gBrowser, async () => {
     let typedValue = "foo";
     await promiseAutocompleteResultPopup(typedValue, window, true);
     await promiseSuggestionsPresent();
     // Down to select the first search suggestion.
     EventUtils.synthesizeKey("KEY_ArrowDown");
     assertState(1, -1, "foofoo");
     // ALT+Down to select the second search engine.
     EventUtils.synthesizeKey("KEY_ArrowDown", {altKey: true});
@@ -98,17 +166,17 @@ add_task(async function overridden_engin
     let label = result.displayed.action;
     // Run again the query, check the label has been replaced.
     await UrlbarTestUtils.promisePopupClose(window);
     await promiseAutocompleteResultPopup(typedValue, window, true);
     await promiseSuggestionsPresent();
     assertState(0, -1, "foo");
     result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1);
     Assert.notEqual(result.displayed.action, label, "The label should have been updated");
-    BrowserTestUtils.removeTab(tab);
+  });
 });
 
 function assertState(result, oneOff, textValue = undefined) {
   Assert.equal(UrlbarTestUtils.getSelectedIndex(window), result,
     "Expected result should be selected");
   Assert.equal(UrlbarTestUtils.getOneOffSearchButtons(window).selectedButtonIndex,
     oneOff, "Expected one-off should be selected");
   if (textValue !== undefined) {
--- a/browser/components/urlbar/tests/browser/searchSuggestionEngine2.xml
+++ b/browser/components/urlbar/tests/browser/searchSuggestionEngine2.xml
@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- Any copyright is dedicated to the Public Domain.
    - http://creativecommons.org/publicdomain/zero/1.0/ -->
 
 <SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
-<ShortName>browser_searchSuggestionEngine searchSuggestionEngine.xml</ShortName>
+<ShortName>browser_searchSuggestionEngine2 searchSuggestionEngine2.xml</ShortName>
 <!-- Redirect the actual search request to the test-server because of proxy restriction -->
 <Url type="application/x-suggestions+json" method="GET" template="http://mochi.test:8888/browser/browser/components/urlbar/tests/browser/searchSuggestionEngine.sjs?{searchTerms}"/>
 <!-- Redirect speculative connect to a local http server we run for this test -->
 <Url type="text/html" method="GET" template="http://localhost:20709/" rel="searchform">
   <Param name="terms" value="{searchTerms}"/>
 </Url>
 </SearchPlugin>