Bug 557665 - Allow specifying SearchForm as a normal <Url> in engine description files (part 2, tests). r=gavin
authorDrew Willcoxon <adw@mozilla.com>
Mon, 24 Mar 2014 20:41:15 -0700
changeset 175142 9301d710a707338390e861567ad595c97958ea9c
parent 175141 3f384a4d845a4d72da57ef2cf1c8967ee10f2e9b
child 175143 a98a5b57fdc246321b9a9558e9deab43f7f53d14
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersgavin
bugs557665
milestone31.0a1
Bug 557665 - Allow specifying SearchForm as a normal <Url> in engine description files (part 2, tests). r=gavin
browser/components/search/test/browser_google.js
toolkit/components/search/tests/xpcshell/data/engine-rel-searchform-post.xml
toolkit/components/search/tests/xpcshell/data/engine-rel-searchform.xml
toolkit/components/search/tests/xpcshell/test_rel_searchform.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
--- a/browser/components/search/test/browser_google.js
+++ b/browser/components/search/test/browser_google.js
@@ -156,14 +156,19 @@ function test() {
               "name": "client",
               "falseValue": "firefox",
               "trueValue": GOOGLE_CLIENT,
               "condition": "defaultEngine",
               "mozparam": true,
             },
           },
         },
+        {
+          type: "text/html",
+          method: "GET",
+          template: "https://www.google.com/",
+        },
       ],
     },
   };
 
   isSubObjectOf(EXPECTED_ENGINE, engine, "Google");
 }
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/data/engine-rel-searchform-post.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
+<ShortName>engine-rel-searchform-post.xml</ShortName>
+<Url type="text/html" method="POST" template="http://engine-rel-searchform-post.xml/POST" rel="searchform"/>
+<SearchForm>http://engine-rel-searchform-post.xml/?search</SearchForm>
+</SearchPlugin>
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/data/engine-rel-searchform.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
+<ShortName>engine-rel-searchform.xml</ShortName>
+<Url type="text/html" method="GET" template="http://engine-rel-searchform.xml/?search" rel="searchform"/>
+</SearchPlugin>
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_rel_searchform.js
@@ -0,0 +1,66 @@
+/* Any copyright is dedicated to the Public Domain.
+ *    http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ * Tests that <Url rel="searchform"/> is properly recognized as a searchForm.
+ */
+
+"use strict";
+
+const Ci = Components.interfaces;
+
+Components.utils.import("resource://testing-common/httpd.js");
+
+let engines = [
+  "engine-rel-searchform.xml",
+  "engine-rel-searchform-post.xml",
+];
+
+function search_observer(aSubject, aTopic, aData) {
+  let engine = aSubject.QueryInterface(Ci.nsISearchEngine);
+  do_print("Observer: " + aData + " for " + engine.name);
+
+  if (aData != "engine-added")
+    return;
+
+  let idx = engines.indexOf(engine.name);
+  if (idx < 0)
+    // The engine is some other engine unrelated to the test, so ignore it.
+    return;
+
+  // The final searchForm of the engine should be a URL whose domain is the
+  // <ShortName> in the engine's XML and that has a ?search parameter.  The
+  // point of the ?search parameter is to avoid accidentally matching the value
+  // returned as a last resort by Engine's searchForm getter, which is simply
+  // the prePath of the engine's first HTML <Url>.
+  do_check_eq(engine.searchForm, "http://" + engine.name + "/?search");
+
+  engines.splice(idx, 1);
+  if (!engines.length)
+    do_test_finished();
+}
+
+function run_test() {
+  removeMetadata();
+  updateAppInfo();
+
+  let httpServer = new HttpServer();
+  httpServer.start(-1);
+  httpServer.registerDirectory("/", do_get_cwd());
+
+  do_register_cleanup(function cleanup() {
+    httpServer.stop(function() {});
+    Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
+  });
+
+  do_test_pending();
+  Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
+
+  for (let basename of engines) {
+    Services.search.addEngine("http://localhost:" +
+                              httpServer.identity.primaryPort +
+                              "/data/" + basename,
+                              Ci.nsISearchEngine.DATA_XML,
+                              null, false);
+  }
+}
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -2,16 +2,18 @@
 head = head_search.js
 tail =
 firefox-appdir = browser
 support-files =
   data/chrome.manifest
   data/engine.src
   data/engine.xml
   data/engine2.xml
+  data/engine-rel-searchform.xml
+  data/engine-rel-searchform-post.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/searchTest.jar
 
@@ -32,8 +34,9 @@ support-files =
 [test_addEngine_callback.js]
 [test_multipleIcons.js]
 [test_resultDomain.js]
 [test_serialize_file.js]
 [test_async.js]
 [test_sync.js]
 [test_sync_fallback.js]
 [test_sync_delay_fallback.js]
+[test_rel_searchform.js]