Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 /*
5 * Test that a search purpose can be specified and that query parameters for
6 * that purpose are included in the search URL.
7 */
9 "use strict";
11 const Ci = Components.interfaces;
13 Components.utils.import("resource://testing-common/httpd.js");
15 function search_observer(aSubject, aTopic, aData) {
16 let engine = aSubject.QueryInterface(Ci.nsISearchEngine);
17 do_print("Observer: " + aData + " for " + engine.name);
19 if (aData != "engine-added")
20 return;
22 if (engine.name != "Test search engine")
23 return;
25 function check_submission(aExpected, aSearchTerm, aType, aPurpose) {
26 do_check_eq(engine.getSubmission(aSearchTerm, aType, aPurpose).uri.spec,
27 base + aExpected);
28 }
30 let base = "http://www.google.com/search?q=foo&ie=utf-8&oe=utf-8&aq=t&client=firefox";
31 check_submission("", "foo");
32 check_submission("", "foo", null);
33 check_submission("", "foo", "text/html");
34 check_submission("&channel=rcs", "foo", null, "contextmenu");
35 check_submission("&channel=rcs", "foo", "text/html", "contextmenu");
36 check_submission("&channel=fflb", "foo", null, "keyword");
37 check_submission("&channel=fflb", "foo", "text/html", "keyword");
38 check_submission("", "foo", "text/html", "invalid");
40 // Tests for a param that varies with a purpose but has a default value.
41 base = "http://www.google.com/search?q=foo&client=firefox";
42 check_submission("&channel=none", "foo", "application/x-moz-default-purpose");
43 check_submission("&channel=none", "foo", "application/x-moz-default-purpose", null);
44 check_submission("&channel=none", "foo", "application/x-moz-default-purpose", "");
45 check_submission("&channel=rcs", "foo", "application/x-moz-default-purpose", "contextmenu");
46 check_submission("&channel=fflb", "foo", "application/x-moz-default-purpose", "keyword");
47 check_submission("", "foo", "application/x-moz-default-purpose", "invalid");
49 do_test_finished();
50 };
52 function run_test() {
53 removeMetadata();
54 updateAppInfo();
55 do_load_manifest("data/chrome.manifest");
57 let httpServer = new HttpServer();
58 httpServer.start(-1);
59 httpServer.registerDirectory("/", do_get_cwd());
61 do_register_cleanup(function cleanup() {
62 httpServer.stop(function() {});
63 Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
64 });
66 do_test_pending();
67 Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
69 Services.search.addEngine("http://localhost:" +
70 httpServer.identity.primaryPort +
71 "/data/engine.xml",
72 Ci.nsISearchEngine.DATA_XML,
73 null, false);
74 }