Bug 1463680 - Allow to install search engine with POST method via Policy Engine r=Felipe
☠☠ backed out by c3fde50a85f1 ☠ ☠
authorYUKI "Piro" Hiroshi <yuki@clear-code.com>
Tue, 12 Feb 2019 14:10:04 +0000
changeset 458736 fa4298251cf2
parent 458735 3c4a149e6f90
child 458737 99ec4f94c2fe
push id35548
push useropoprus@mozilla.com
push dateWed, 13 Feb 2019 09:48:26 +0000
treeherdermozilla-central@93e37c529818 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1463680
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 1463680 - Allow to install search engine with POST method via Policy Engine r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D19467
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -849,16 +849,17 @@ var Policies = {
                                        async function() {
             for (let newEngine of param.Add) {
               let newEngineParameters = {
                 template:    newEngine.URLTemplate,
                 iconURL:     newEngine.IconURL ? newEngine.IconURL.href : null,
                 alias:       newEngine.Alias,
                 description: newEngine.Description,
                 method:      newEngine.Method,
+                postData:    newEngine.PostData,
                 suggestURL:  newEngine.SuggestURLTemplate,
                 extensionID: "set-via-policy",
                 queryCharset: "UTF-8",
               };
               try {
                 await Services.search.addEngineWithDetails(newEngine.Name,
                                                            newEngineParameters);
               } catch (ex) {
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -633,16 +633,19 @@
               },
               "Method": {
                 "type": "string",
                 "enum": ["GET", "POST"]
               },
               "URLTemplate": {
                 "type": "string"
               },
+              "PostData": {
+                "type": "string"
+              },
               "SuggestURLTemplate": {
                 "type": "string"
               }
             }
           }
         },
         "Default": {
           "type": "string"
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js
@@ -240,8 +240,51 @@ add_task(async function test_install_and
   await TestUtils.waitForTick();
 
   // If this passes, it means that the specified engine was properly removed
   is(Services.search.getEngineByName("Foo"), null,
      "Specified search engine should not be installed");
 
   EnterprisePolicyTesting.resetRunOnceState();
 });
+
+add_task(async function test_install_post_method_engine() {
+  is(Services.search.getEngineByName("Post"), null,
+     "Engine \"Post\" should not be present when test starts");
+
+  await setupPolicyEngineWithJson({
+  "policies": {
+      "SearchEngines": {
+        "Add": [
+          {
+            "Name": "Post",
+            "Method": "POST",
+            "PostData": "q={searchTerms}&anotherParam=yes",
+            "URLTemplate": "http://example.com/",
+          },
+        ],
+      },
+    },
+  });
+
+  let engine = Services.search.getEngineByName("Post");
+  isnot(engine, null, "Specified search engine should be installed");
+
+  is(engine.wrappedJSObject._urls[0].method, "POST", "Method should be POST");
+
+  let submission = engine.getSubmission("term", "text/html");
+  isnot(submission.postData, null, "Post data should not be null");
+
+  let scriptableInputStream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
+  scriptableInputStream.init(submission.postData);
+  is(scriptableInputStream.read(scriptableInputStream.available()),
+     "q=term&anotherParam=yes",
+     "Post data should be present");
+
+  await setupPolicyEngineWithJson({
+  "policies": {
+      "SearchEngines": {
+        "Remove": ["Post"],
+      },
+    },
+  });
+  EnterprisePolicyTesting.resetRunOnceState();
+});