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

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

mercurial