michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /* michael@0: * Test that a search purpose can be specified and that query parameters for michael@0: * that purpose are included in the search URL. michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: const Ci = Components.interfaces; michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: michael@0: function search_observer(aSubject, aTopic, aData) { michael@0: let engine = aSubject.QueryInterface(Ci.nsISearchEngine); michael@0: do_print("Observer: " + aData + " for " + engine.name); michael@0: michael@0: if (aData != "engine-added") michael@0: return; michael@0: michael@0: if (engine.name != "Test search engine") michael@0: return; michael@0: michael@0: function check_submission(aExpected, aSearchTerm, aType, aPurpose) { michael@0: do_check_eq(engine.getSubmission(aSearchTerm, aType, aPurpose).uri.spec, michael@0: base + aExpected); michael@0: } michael@0: michael@0: let base = "http://www.google.com/search?q=foo&ie=utf-8&oe=utf-8&aq=t&client=firefox"; michael@0: check_submission("", "foo"); michael@0: check_submission("", "foo", null); michael@0: check_submission("", "foo", "text/html"); michael@0: check_submission("&channel=rcs", "foo", null, "contextmenu"); michael@0: check_submission("&channel=rcs", "foo", "text/html", "contextmenu"); michael@0: check_submission("&channel=fflb", "foo", null, "keyword"); michael@0: check_submission("&channel=fflb", "foo", "text/html", "keyword"); michael@0: check_submission("", "foo", "text/html", "invalid"); michael@0: michael@0: // Tests for a param that varies with a purpose but has a default value. michael@0: base = "http://www.google.com/search?q=foo&client=firefox"; michael@0: check_submission("&channel=none", "foo", "application/x-moz-default-purpose"); michael@0: check_submission("&channel=none", "foo", "application/x-moz-default-purpose", null); michael@0: check_submission("&channel=none", "foo", "application/x-moz-default-purpose", ""); michael@0: check_submission("&channel=rcs", "foo", "application/x-moz-default-purpose", "contextmenu"); michael@0: check_submission("&channel=fflb", "foo", "application/x-moz-default-purpose", "keyword"); michael@0: check_submission("", "foo", "application/x-moz-default-purpose", "invalid"); michael@0: michael@0: do_test_finished(); michael@0: }; michael@0: michael@0: function run_test() { michael@0: removeMetadata(); michael@0: updateAppInfo(); michael@0: do_load_manifest("data/chrome.manifest"); michael@0: michael@0: let httpServer = new HttpServer(); michael@0: httpServer.start(-1); michael@0: httpServer.registerDirectory("/", do_get_cwd()); michael@0: michael@0: do_register_cleanup(function cleanup() { michael@0: httpServer.stop(function() {}); michael@0: Services.obs.removeObserver(search_observer, "browser-search-engine-modified"); michael@0: }); michael@0: michael@0: do_test_pending(); michael@0: Services.obs.addObserver(search_observer, "browser-search-engine-modified", false); michael@0: michael@0: Services.search.addEngine("http://localhost:" + michael@0: httpServer.identity.primaryPort + michael@0: "/data/engine.xml", michael@0: Ci.nsISearchEngine.DATA_XML, michael@0: null, false); michael@0: }