Bug 1159717 - Loading the search form from an empty search bar should send the purpose. r=markh, a=sledru
authorFlorian Quèze <florian@queze.net>
Thu, 21 May 2015 11:53:15 +0200
changeset 274718 fb66d813383e8914da4b3baa5a2c3e6a62140931
parent 274717 025477515ea4b30d479db3d7d414a294baf27984
child 274719 6dfba2fa6c41f5b56beab0662571a9c914bed5f0
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh, sledru
bugs1159717
milestone40.0a2
Bug 1159717 - Loading the search form from an empty search bar should send the purpose. r=markh, a=sledru
toolkit/components/search/nsSearchService.js
toolkit/components/search/tests/xpcshell/data/engine-rel-searchform-purpose.xml
toolkit/components/search/tests/xpcshell/test_purpose.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -2856,20 +2856,24 @@ Engine.prototype = {
     return this._name;
   },
 
   get type() {
     return this._type;
   },
 
   get searchForm() {
+    return this._getSearchFormWithPurpose();
+  },
+
+  _getSearchFormWithPurpose(aPurpose = "") {
     // First look for a <Url rel="searchform">
     var searchFormURL = this._getURLOfType(URLTYPE_SEARCH_HTML, "searchform");
     if (searchFormURL) {
-      let submission = searchFormURL.getSubmission("", this);
+      let submission = searchFormURL.getSubmission("", this, aPurpose);
 
       // If the rel=searchform URL is not type="get" (i.e. has postData),
       // ignore it, since we can only return a URL.
       if (!submission.postData)
         return submission.uri.spec;
     }
 
     if (!this._searchForm) {
@@ -2942,17 +2946,17 @@ Engine.prototype = {
 
     var url = this._getURLOfType(aResponseType);
 
     if (!url)
       return null;
 
     if (!aData) {
       // Return a dummy submission object with our searchForm attribute
-      return new Submission(makeURI(this.searchForm), null);
+      return new Submission(makeURI(this._getSearchFormWithPurpose(aPurpose)), null);
     }
 
     LOG("getSubmission: In data: \"" + aData + "\"; Purpose: \"" + aPurpose + "\"");
     var data = "";
     try {
       data = gTextToSubURI.ConvertAndEscape(this.queryCharset, aData);
     } catch (ex) {
       LOG("getSubmission: Falling back to default queryCharset!");
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/data/engine-rel-searchform-purpose.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
+<ShortName>engine-rel-searchform-purpose</ShortName>
+<Url type="text/html" method="GET" template="http://www.google.com/search" resultdomain="google.com" rel="searchform">
+  <Param name="q" value="{searchTerms}"/>
+  <!-- Dynamic parameters -->
+  <MozParam name="channel" condition="purpose" purpose="contextmenu" value="rcs"/>
+  <MozParam name="channel" condition="purpose" purpose="keyword" value="fflb"/>
+  <MozParam name="channel" condition="purpose" purpose="searchbar" value="sb"/>
+</Url>
+</SearchPlugin>
--- a/toolkit/components/search/tests/xpcshell/test_purpose.js
+++ b/toolkit/components/search/tests/xpcshell/test_purpose.js
@@ -41,10 +41,18 @@ add_task(function* test_purpose() {
   base = "http://www.google.com/search?q=foo&client=firefox";
   check_submission("&channel=none", "foo", "application/x-moz-default-purpose");
   check_submission("&channel=none", "foo", "application/x-moz-default-purpose", null);
   check_submission("&channel=none", "foo", "application/x-moz-default-purpose", "");
   check_submission("&channel=rcs",  "foo", "application/x-moz-default-purpose", "contextmenu");
   check_submission("&channel=fflb", "foo", "application/x-moz-default-purpose", "keyword");
   check_submission("",              "foo", "application/x-moz-default-purpose", "invalid");
 
+  // Tests for a purpose on the search form (ie. empty query).
+  [engine] = yield addTestEngines([
+    { name: "engine-rel-searchform-purpose", xmlFileName: "engine-rel-searchform-purpose.xml" }
+  ]);
+  base = "http://www.google.com/search?q=";
+  check_submission("&channel=sb", "", null,        "searchbar");
+  check_submission("&channel=sb", "", "text/html", "searchbar");
+
   do_test_finished();
 });
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -7,16 +7,17 @@ support-files =
   data/chrome.manifest
   data/engine.src
   data/engine.xml
   data/engine2.xml
   data/engine-fr.xml
   data/engineMaker.sjs
   data/engine-rel-searchform.xml
   data/engine-rel-searchform-post.xml
+  data/engine-rel-searchform-purpose.xml
   data/engineImages.xml
   data/ico-size-16x16-png.ico
   data/invalid-engine.xml
   data/search-metadata.json
   data/search.json
   data/search.sqlite
   data/searchSuggestions.sjs
   data/searchTest.jar