toolkit/components/search/tests/xpcshell/test_rel_searchform.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /*
michael@0 5 * Tests that <Url rel="searchform"/> is properly recognized as a searchForm.
michael@0 6 */
michael@0 7
michael@0 8 "use strict";
michael@0 9
michael@0 10 const Ci = Components.interfaces;
michael@0 11
michael@0 12 Components.utils.import("resource://testing-common/httpd.js");
michael@0 13
michael@0 14 let engines = [
michael@0 15 "engine-rel-searchform.xml",
michael@0 16 "engine-rel-searchform-post.xml",
michael@0 17 ];
michael@0 18
michael@0 19 function search_observer(aSubject, aTopic, aData) {
michael@0 20 let engine = aSubject.QueryInterface(Ci.nsISearchEngine);
michael@0 21 do_print("Observer: " + aData + " for " + engine.name);
michael@0 22
michael@0 23 if (aData != "engine-added")
michael@0 24 return;
michael@0 25
michael@0 26 let idx = engines.indexOf(engine.name);
michael@0 27 if (idx < 0)
michael@0 28 // The engine is some other engine unrelated to the test, so ignore it.
michael@0 29 return;
michael@0 30
michael@0 31 // The final searchForm of the engine should be a URL whose domain is the
michael@0 32 // <ShortName> in the engine's XML and that has a ?search parameter. The
michael@0 33 // point of the ?search parameter is to avoid accidentally matching the value
michael@0 34 // returned as a last resort by Engine's searchForm getter, which is simply
michael@0 35 // the prePath of the engine's first HTML <Url>.
michael@0 36 do_check_eq(engine.searchForm, "http://" + engine.name + "/?search");
michael@0 37
michael@0 38 engines.splice(idx, 1);
michael@0 39 if (!engines.length)
michael@0 40 do_test_finished();
michael@0 41 }
michael@0 42
michael@0 43 function run_test() {
michael@0 44 removeMetadata();
michael@0 45 updateAppInfo();
michael@0 46
michael@0 47 let httpServer = new HttpServer();
michael@0 48 httpServer.start(-1);
michael@0 49 httpServer.registerDirectory("/", do_get_cwd());
michael@0 50
michael@0 51 do_register_cleanup(function cleanup() {
michael@0 52 httpServer.stop(function() {});
michael@0 53 Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
michael@0 54 });
michael@0 55
michael@0 56 do_test_pending();
michael@0 57 Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
michael@0 58
michael@0 59 for (let basename of engines) {
michael@0 60 Services.search.addEngine("http://localhost:" +
michael@0 61 httpServer.identity.primaryPort +
michael@0 62 "/data/" + basename,
michael@0 63 Ci.nsISearchEngine.DATA_XML,
michael@0 64 null, false);
michael@0 65 }
michael@0 66 }

mercurial