Bug 1186393 - Make urlbar search suggestions call decodeURIComponent on the engine name. r=mak
authorDrew Willcoxon <adw@mozilla.com>
Wed, 16 Sep 2015 11:16:41 -0700
changeset 295448 1ab7fb448f605b6b4fabec673efc4ad890412834
parent 295429 e7d613b3bcfe1e865378bfac37de64560d1234ec
child 295449 ece591e2a86291760b5b6880dbe85cb28e14969a
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1186393
milestone43.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 1186393 - Make urlbar search suggestions call decodeURIComponent on the engine name. r=mak
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_urlbarSearchSuggestions.js
browser/base/content/test/general/browser_urlbarSearchSuggestionsNotification.js
browser/base/content/test/general/searchSuggestionEngine.xml
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -465,16 +465,17 @@ skip-if = e10s # Bug 1100700 - test reli
 [browser_urlbarAutoFillTrimURLs.js]
 [browser_urlbarCopying.js]
 [browser_urlbarDelete.js]
 [browser_urlbarEnter.js]
 [browser_urlbarEnterAfterMouseOver.js]
 skip-if = os == "linux" || e10s # Bug 1073339 - Investigate autocomplete test unreliability on Linux/e10s
 [browser_urlbarRevert.js]
 [browser_urlbarSearchSingleWordNotification.js]
+[browser_urlbarSearchSuggestions.js]
 [browser_urlbarSearchSuggestionsNotification.js]
 [browser_urlbarStop.js]
 [browser_urlbarTrimURLs.js]
 [browser_urlbar_autoFill_backspaced.js]
 [browser_urlbar_search_healthreport.js]
 [browser_urlbar_searchsettings.js]
 [browser_utilityOverlay.js]
 [browser_viewSourceInTabOnViewSource.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_urlbarSearchSuggestions.js
@@ -0,0 +1,63 @@
+const SUGGEST_URLBAR_PREF = "browser.urlbar.suggest.searches";
+const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml";
+
+// Must run first.
+add_task(function* prepare() {
+  Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true);
+  let engine = yield promiseNewSearchEngine(TEST_ENGINE_BASENAME);
+  let oldCurrentEngine = Services.search.currentEngine;
+  Services.search.currentEngine = engine;
+  registerCleanupFunction(function () {
+    Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF);
+    Services.search.currentEngine = oldCurrentEngine;
+
+    // Clicking suggestions causes visits to search results pages, so clear that
+    // history now.
+    yield PlacesTestUtils.clearHistory();
+
+    // Make sure the popup is closed for the next test.
+    gURLBar.blur();
+    Assert.ok(!gURLBar.popup.popupOpen, "popup should be closed");
+  });
+});
+
+add_task(function* clickSuggestion() {
+  gURLBar.focus();
+  yield promiseAutocompleteResultPopup("foo");
+  let [idx, suggestion] = yield promiseFirstSuggestion();
+  let item = gURLBar.popup.richlistbox.getItemAtIndex(idx);
+  let loadPromise = promiseTabLoaded(gBrowser.selectedTab);
+  item.click();
+  yield loadPromise;
+  let uri = Services.search.currentEngine.getSubmission(suggestion).uri;
+  Assert.ok(uri.equals(gBrowser.currentURI),
+            "The search results page should have loaded");
+});
+
+function getFirstSuggestion() {
+  let controller = gURLBar.popup.input.controller;
+  let matchCount = controller.matchCount;
+  let present = false;
+  for (let i = 0; i < matchCount; i++) {
+    let url = controller.getValueAt(i);
+    let mozActionMatch = url.match(/^moz-action:([^,]+),(.*)$/);
+    if (mozActionMatch) {
+      let [, type, paramStr] = mozActionMatch;
+      let params = JSON.parse(paramStr);
+      if (type == "searchengine" && "searchSuggestion" in params) {
+        return [i, params.searchSuggestion];
+      }
+    }
+  }
+  return [-1, null];
+}
+
+function promiseFirstSuggestion() {
+  return new Promise(resolve => {
+    let pair;
+    waitForCondition(() => {
+      pair = getFirstSuggestion();
+      return pair[0] >= 0;
+    }, () => resolve(pair));
+  });
+}
--- a/browser/base/content/test/general/browser_urlbarSearchSuggestionsNotification.js
+++ b/browser/base/content/test/general/browser_urlbarSearchSuggestionsNotification.js
@@ -209,23 +209,23 @@ function setUserMadeChoicePref(userMadeC
 }
 
 function suggestionsPresent() {
   let controller = gURLBar.popup.input.controller;
   let matchCount = controller.matchCount;
   let present = false;
   for (let i = 0; i < matchCount; i++) {
     let url = controller.getValueAt(i);
-    let [, type, paramStr] = url.match(/^moz-action:([^,]+),(.*)$/);
-    let params = {};
-    try {
-      params = JSON.parse(paramStr);
-    } catch (err) {}
-    if (type == "searchengine" && "searchSuggestion" in params) {
-      return true;
+    let mozActionMatch = url.match(/^moz-action:([^,]+),(.*)$/);
+    if (mozActionMatch) {
+      let [, type, paramStr] = mozActionMatch;
+      let params = JSON.parse(paramStr);
+      if (type == "searchengine" && "searchSuggestion" in params) {
+        return true;
+      }
     }
   }
   return false;
 }
 
 function promiseSuggestionsPresent() {
   return new Promise(resolve => {
     waitForCondition(suggestionsPresent, resolve);
--- a/browser/base/content/test/general/searchSuggestionEngine.xml
+++ b/browser/base/content/test/general/searchSuggestionEngine.xml
@@ -1,9 +1,9 @@
 <?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>
 <Url type="application/x-suggestions+json" method="GET" template="http://mochi.test:8888/browser/browser/base/content/test/general/searchSuggestionEngine.sjs?{searchTerms}"/>
-<Url type="text/html" method="GET" template="http://www.browser-searchSuggestionEngine.com/searchSuggestionEngine&amp;terms={searchTerms}" rel="searchform"/>
+<Url type="text/html" method="GET" template="http://mochi.test:8888/browser/browser/base/content/test/general/searchSuggestionEngine.sjs?{searchTerms}" rel="searchform"/>
 </SearchPlugin>
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -820,16 +820,17 @@ file, You can obtain one at http://mozil
             // a URL.
             action.params = {
               url: params,
             }
             return action;
           }
 
           for (let key of [
+            "engineName",
             "input",
             "searchQuery",
             "searchSuggestion",
           ]) {
             if (action.params[key]) {
               action.params[key] = decodeURIComponent(action.params[key]);
             }
           }