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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial