Backed out changeset 77b48431ba6f (bug 1560228) for failures on browser_keyword.js a=backout
authorBogdan Tara <btara@mozilla.com>
Sat, 27 Jul 2019 05:29:15 +0300
changeset 544768 581fdb8b8e9cda964d6020feb00efe1eec062b0d
parent 544767 b127f0561662cac7ad016cb8fa04cd6b5a1d49b6
child 544769 aa386c7dfa317eed6f11b1c660d3a9ead0361961
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1560228
milestone69.0
backs out77b48431ba6f4be89bc1497b16f22c086c2449dd
Backed out changeset 77b48431ba6f (bug 1560228) for failures on browser_keyword.js a=backout
browser/components/urlbar/tests/browser/browser_keyword.js
toolkit/components/places/UnifiedComplete.jsm
toolkit/components/places/tests/unifiedcomplete/test_restrict_searchstring.js
toolkit/components/places/tests/unifiedcomplete/test_search_engine_alias.js
toolkit/components/places/tests/unifiedcomplete/test_tab_matches.js
toolkit/components/places/tests/unifiedcomplete/xpcshell.ini
--- a/browser/components/urlbar/tests/browser/browser_keyword.js
+++ b/browser/components/urlbar/tests/browser/browser_keyword.js
@@ -228,17 +228,17 @@ add_task(async function test_keyword_wit
   // TODO Bug 1517140: keywords containing restriction chars should not be
   // allowed, or properly supported.
   let result = await promise_first_result("question?");
   Assert.equal(
     result.type,
     UrlbarUtils.RESULT_TYPE.SEARCH,
     "Result should be a search"
   );
-  Assert.equal(result.searchParams.query, "question?", "Check search query");
+  Assert.equal(result.searchParams.query, "question", "Check search query");
 
   result = await promise_first_result("question? something");
   Assert.equal(
     result.type,
     UrlbarUtils.RESULT_TYPE.KEYWORD,
     "Result should be a keyword"
   );
   Assert.equal(result.keyword, "question?", "Check search query");
--- a/toolkit/components/places/UnifiedComplete.jsm
+++ b/toolkit/components/places/UnifiedComplete.jsm
@@ -621,24 +621,32 @@ function Search(
   // Use the original string here, not the stripped one, so the tokenizer can
   // properly recognize token types.
   let { tokens } = UrlbarTokenizer.tokenize({
     searchString: unescapedSearchString,
   });
 
   // This allows to handle leading or trailing restriction characters specially.
   this._leadingRestrictionToken = null;
+  this._trailingRestrictionToken = null;
   if (tokens.length > 0) {
     if (
       UrlbarTokenizer.isRestrictionToken(tokens[0]) &&
       (tokens.length > 1 ||
         tokens[0].type == UrlbarTokenizer.TYPE.RESTRICT_SEARCH)
     ) {
       this._leadingRestrictionToken = tokens[0].value;
     }
+    if (
+      UrlbarTokenizer.isRestrictionToken(tokens[tokens.length - 1]) &&
+      (tokens.length > 1 ||
+        tokens[tokens.length - 1].type == UrlbarTokenizer.TYPE.RESTRICT_SEARCH)
+    ) {
+      this._trailingRestrictionToken = tokens[tokens.length - 1].value;
+    }
 
     // Check if the first token has a strippable prefix and remove it, but don't
     // create an empty token.
     if (prefix && tokens[0].value.length > prefix.length) {
       tokens[0].value = tokens[0].value.substring(prefix.length);
     }
   }
 
@@ -1705,24 +1713,27 @@ Search.prototype = {
     return true;
   },
 
   async _matchCurrentSearchEngine() {
     let engine = await PlacesSearchAutocompleteProvider.currentEngine();
     if (!engine || !this.pending) {
       return false;
     }
-    // Strip a leading search restriction char, because we prepend it to text
-    // when the search shortcut is used and it's not user typed. Don't strip
-    // other restriction chars, so that it's possible to search for things
-    // including one of those (e.g. "c#").
+    // Strip a leading or trailing restriction char.
     let query = this._trimmedOriginalSearchString;
-    if (this._leadingRestrictionToken === UrlbarTokenizer.RESTRICT.SEARCH) {
+    if (this._leadingRestrictionToken) {
       query = substringAfter(query, this._leadingRestrictionToken).trim();
     }
+    if (this._trailingRestrictionToken) {
+      query = query.substring(
+        0,
+        query.lastIndexOf(this._trailingRestrictionToken)
+      );
+    }
     this._addSearchEngineMatch({ engine, query });
     return true;
   },
 
   _addExtensionMatch(content, comment) {
     let count =
       this._counts[UrlbarUtils.RESULT_GROUP.EXTENSION] +
       this._counts[UrlbarUtils.RESULT_GROUP.HEURISTIC];
deleted file mode 100644
--- a/toolkit/components/places/tests/unifiedcomplete/test_restrict_searchstring.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/**
- * Test that restriction tokens are not removed from the search string, apart
- * from a leading search restriction token.
- */
-
-add_task(async function test_searchstring() {
-  for (let token of Object.values(UrlbarTokenizer.RESTRICT)) {
-    for (let search of [`${token} query`, `query ${token}`]) {
-      let searchQuery =
-        token == UrlbarTokenizer.RESTRICT.SEARCH &&
-        search.startsWith(UrlbarTokenizer.RESTRICT.SEARCH)
-          ? search.substring(2)
-          : search;
-      info(`Searching for "${search}", expecting "${searchQuery}"`);
-      await check_autocomplete({
-        search,
-        searchParam: "enable-actions",
-        matches: [
-          makeSearchMatch(search, {
-            engineName: "MozSearch",
-            searchQuery,
-            heuristic: true,
-          }),
-        ],
-      });
-    }
-  }
-});
--- a/toolkit/components/places/tests/unifiedcomplete/test_search_engine_alias.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_search_engine_alias.js
@@ -106,30 +106,25 @@ add_task(async function basicGetAndPost(
         }),
       ],
     });
 
     // When a restriction token is used before the alias, the alias should *not*
     // be recognized.  It should be treated as part of the search string.  Try
     // all the restriction tokens to test that.  We should get a single "search
     // with" heuristic result without an alias.
-    for (let token of Object.values(UrlbarTokenizer.RESTRICT)) {
-      let search = `${token} ${alias} query string`;
-      let searchQuery =
-        token == UrlbarTokenizer.RESTRICT.SEARCH &&
-        search.startsWith(UrlbarTokenizer.RESTRICT.SEARCH)
-          ? search.substring(2)
-          : search;
+    for (let restrictToken in UrlbarTokenizer.RESTRICT) {
+      let search = `${restrictToken} ${alias} query string`;
       await check_autocomplete({
         search,
         searchParam: "enable-actions",
         matches: [
           makeSearchMatch(search, {
             engineName: "MozSearch",
-            searchQuery,
+            searchQuery: search,
             heuristic: true,
           }),
         ],
       });
     }
   }
   await cleanup();
 });
--- a/toolkit/components/places/tests/unifiedcomplete/test_tab_matches.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_tab_matches.js
@@ -219,17 +219,17 @@ add_task(async function test_tab_matches
   info("tab match search with restriction character");
   addOpenPages(uri1, 1);
   await check_autocomplete({
     search: UrlbarTokenizer.RESTRICT.OPENPAGE + " abc",
     searchParam: "enable-actions",
     matches: [
       makeSearchMatch(UrlbarTokenizer.RESTRICT.OPENPAGE + " abc", {
         heuristic: true,
-        searchQuery: UrlbarTokenizer.RESTRICT.OPENPAGE + " abc",
+        searchQuery: "abc",
       }),
       makeSwitchToTabMatch("http://abc.com/", { title: "ABC rocks" }),
     ],
   });
 
   info("tab match with not-addable pages");
   await check_autocomplete({
     search: "mozilla",
@@ -242,17 +242,17 @@ add_task(async function test_tab_matches
 
   info("tab match with not-addable pages and restriction character");
   await check_autocomplete({
     search: UrlbarTokenizer.RESTRICT.OPENPAGE + " mozilla",
     searchParam: "enable-actions",
     matches: [
       makeSearchMatch(UrlbarTokenizer.RESTRICT.OPENPAGE + " mozilla", {
         heuristic: true,
-        searchQuery: UrlbarTokenizer.RESTRICT.OPENPAGE + " mozilla",
+        searchQuery: "mozilla",
       }),
       makeSwitchToTabMatch("about:mozilla"),
     ],
   });
 
   info("tab match with not-addable pages and only restriction character");
   await check_autocomplete({
     search: UrlbarTokenizer.RESTRICT.OPENPAGE,
--- a/toolkit/components/places/tests/unifiedcomplete/xpcshell.ini
+++ b/toolkit/components/places/tests/unifiedcomplete/xpcshell.ini
@@ -38,17 +38,16 @@ support-files =
 [test_keywords.js]
 [test_multi_word_search.js]
 [test_PlacesSearchAutocompleteProvider.js]
 skip-if = appname == "thunderbird"
 [test_preloaded_sites.js]
 [test_query_url.js]
 [test_remote_tab_matches.js]
 skip-if = !sync
-[test_restrict_searchstring.js]
 [test_search_engine_alias.js]
 [test_search_engine_default.js]
 [test_search_engine_host.js]
 [test_search_engine_restyle.js]
 [test_search_suggestions.js]
 [test_special_search.js]
 [test_swap_protocol.js]
 [test_tab_matches.js]