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: * Tests that is properly recognized as a searchForm.
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: let engines = [
michael@0: "engine-rel-searchform.xml",
michael@0: "engine-rel-searchform-post.xml",
michael@0: ];
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: let idx = engines.indexOf(engine.name);
michael@0: if (idx < 0)
michael@0: // The engine is some other engine unrelated to the test, so ignore it.
michael@0: return;
michael@0:
michael@0: // The final searchForm of the engine should be a URL whose domain is the
michael@0: // in the engine's XML and that has a ?search parameter. The
michael@0: // point of the ?search parameter is to avoid accidentally matching the value
michael@0: // returned as a last resort by Engine's searchForm getter, which is simply
michael@0: // the prePath of the engine's first HTML .
michael@0: do_check_eq(engine.searchForm, "http://" + engine.name + "/?search");
michael@0:
michael@0: engines.splice(idx, 1);
michael@0: if (!engines.length)
michael@0: do_test_finished();
michael@0: }
michael@0:
michael@0: function run_test() {
michael@0: removeMetadata();
michael@0: updateAppInfo();
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: for (let basename of engines) {
michael@0: Services.search.addEngine("http://localhost:" +
michael@0: httpServer.identity.primaryPort +
michael@0: "/data/" + basename,
michael@0: Ci.nsISearchEngine.DATA_XML,
michael@0: null, false);
michael@0: }
michael@0: }