Bug 1299428 - Searching an URL looking string using a one-off button doesn't open a search result. r=adw draft
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 02 Nov 2016 18:32:38 +0100
changeset 432796 85defe58d3437461d04ce3b9aa2e860bc2dbcb4f
parent 432795 87119d3298b34e454bd0712510b8b612e975c67b
child 535754 44761dffebcc3a649447560ca6ff34930f0ae842
push id34425
push usermak77@bonardo.net
push dateWed, 02 Nov 2016 20:09:13 +0000
reviewersadw
bugs1299428
milestone52.0a1
Bug 1299428 - Searching an URL looking string using a one-off button doesn't open a search result. r=adw MozReview-Commit-ID: FA9qkqLw5Cw
browser/base/content/test/urlbar/browser_urlbarOneOffs.js
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/test/urlbar/browser_urlbarOneOffs.js
+++ b/browser/base/content/test/urlbar/browser_urlbarOneOffs.js
@@ -169,43 +169,51 @@ add_task(function* searchWith() {
 
   yield hidePopup();
 });
 
 // Clicks a one-off.
 add_task(function* oneOffClick() {
   gBrowser.selectedTab = gBrowser.addTab();
 
-  let typedValue = "foo";
+  // We are explicitly using something that looks like a url, to make the test
+  // stricter. Even if it looks like a url, we should search.
+  let typedValue = "foo.bar";
   yield promiseAutocompleteResultPopup(typedValue);
 
   assertState(0, -1, typedValue);
 
   let oneOffs = gURLBar.popup.oneOffSearchButtons.getSelectableButtons(true);
-  let resultsPromise = promiseSearchResultsLoaded();
+  let resultsPromise =
+    BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
+                                   "http://mochi.test:8888/");
   EventUtils.synthesizeMouseAtCenter(oneOffs[0], {});
   yield resultsPromise;
 
   gBrowser.removeTab(gBrowser.selectedTab);
 });
 
 // Presses the Return key when a one-off is selected.
 add_task(function* oneOffReturn() {
   gBrowser.selectedTab = gBrowser.addTab();
 
-  let typedValue = "foo";
+  // We are explicitly using something that looks like a url, to make the test
+  // stricter. Even if it looks like a url, we should search.
+  let typedValue = "foo.bar";
   yield promiseAutocompleteResultPopup(typedValue, window, true);
 
   assertState(0, -1, typedValue);
 
   // Alt+Down to select the first one-off.
   EventUtils.synthesizeKey("VK_DOWN", { altKey: true })
   assertState(0, 0, typedValue);
 
-  let resultsPromise = promiseSearchResultsLoaded();
+  let resultsPromise =
+    BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false,
+                                   "http://mochi.test:8888/");
   EventUtils.synthesizeKey("VK_RETURN", {})
   yield resultsPromise;
 
   gBrowser.removeTab(gBrowser.selectedTab);
 });
 
 
 function assertState(result, oneOff, textValue = undefined) {
@@ -217,17 +225,8 @@ function assertState(result, oneOff, tex
     Assert.equal(gURLBar.textValue, textValue, "Expected textValue");
   }
 }
 
 function* hidePopup() {
   EventUtils.synthesizeKey("VK_ESCAPE", {});
   yield promisePopupHidden(gURLBar.popup);
 }
-
-function promiseSearchResultsLoaded() {
-  let tab = gBrowser.selectedTab;
-  return promiseTabLoadEvent(tab).then(() => {
-    Assert.equal(tab.linkedBrowser.currentURI.spec,
-                 "http://mochi.test:8888/",
-                 'Expected "search results" page loaded');
-  });
-}
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -468,34 +468,23 @@ file, You can obtain one at http://mozil
                   event,
                   where,
                   openUILinkParams,
                   actionDetails
                 );
                 break;
             }
           } else if (selectedOneOff && selectedOneOff.engine) {
-            // If there's a selected one-off button and the input value is a
-            // search query (or "keyword" in URI-fixup terminology), then load a
-            // search using the one-off's engine.
-            let value = this.oneOffSearchQuery;
-            let fixup;
-            try {
-              fixup = Services.uriFixup.getFixupURIInfo(
-                value,
-                Services.uriFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP
-              );
-            } catch (ex) {}
-            if (!fixup || !fixup.keywordProviderName) {
-              return;
-            }
-
+            // If there's a selected one-off button then load a search using
+            // the one-off's engine.
             [url, postData] =
-              this._parseAndRecordSearchEngineLoad(selectedOneOff.engine, value,
-                                                   event, where, openUILinkParams);
+              this._parseAndRecordSearchEngineLoad(selectedOneOff.engine,
+                                                   this.oneOffSearchQuery,
+                                                   event, where,
+                                                   openUILinkParams);
           } else {
             // This is a fallback for add-ons and old testing code that directly
             // set value and try to confirm it. UnifiedComplete should always
             // resolve to a valid url.
             try {
               new URL(url);
             } catch (ex) {
               let lastLocationChange = browser.lastLocationChange;