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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:dee2410d64d1
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /*
5 * Test that a search engine's identifier can be extracted from the filename.
6 */
7
8 "use strict";
9
10 const Ci = Components.interfaces;
11 const SEARCH_APP_DIR = 1;
12
13 function run_test() {
14 removeMetadata();
15 removeCacheFile();
16 do_load_manifest("data/chrome.manifest");
17
18 let url = "chrome://testsearchplugin/locale/searchplugins/";
19 Services.prefs.setCharPref("browser.search.jarURIs", url);
20 Services.prefs.setBoolPref("browser.search.loadFromJars", true);
21
22 updateAppInfo();
23
24 run_next_test();
25 }
26
27 add_test(function test_identifier() {
28 let engineFile = gProfD.clone();
29 engineFile.append("searchplugins");
30 engineFile.append("test-search-engine.xml");
31 engineFile.parent.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
32
33 // Copy the test engine to the test profile.
34 let engineTemplateFile = do_get_file("data/engine.xml");
35 engineTemplateFile.copyTo(engineFile.parent, "test-search-engine.xml");
36
37 let search = Services.search.init(function initComplete(aResult) {
38 do_print("init'd search service");
39 do_check_true(Components.isSuccessCode(aResult));
40
41 let profileEngine = Services.search.getEngineByName("Test search engine");
42 let jarEngine = Services.search.getEngineByName("bug645970");
43
44 do_check_true(profileEngine instanceof Ci.nsISearchEngine);
45 do_check_true(jarEngine instanceof Ci.nsISearchEngine);
46
47 // An engine loaded from the profile directory won't have an identifier,
48 // because it's not built-in.
49 do_check_eq(profileEngine.identifier, null);
50
51 // An engine loaded from a JAR will have an identifier corresponding to
52 // the filename inside the JAR. (In this case it's the same as the name.)
53 do_check_eq(jarEngine.identifier, "bug645970");
54
55 removeMetadata();
56 removeCacheFile();
57 run_next_test();
58 });
59 });
60

mercurial