1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/search/tests/xpcshell/test_identifiers.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/* 1.8 + * Test that a search engine's identifier can be extracted from the filename. 1.9 + */ 1.10 + 1.11 +"use strict"; 1.12 + 1.13 +const Ci = Components.interfaces; 1.14 +const SEARCH_APP_DIR = 1; 1.15 + 1.16 +function run_test() { 1.17 + removeMetadata(); 1.18 + removeCacheFile(); 1.19 + do_load_manifest("data/chrome.manifest"); 1.20 + 1.21 + let url = "chrome://testsearchplugin/locale/searchplugins/"; 1.22 + Services.prefs.setCharPref("browser.search.jarURIs", url); 1.23 + Services.prefs.setBoolPref("browser.search.loadFromJars", true); 1.24 + 1.25 + updateAppInfo(); 1.26 + 1.27 + run_next_test(); 1.28 +} 1.29 + 1.30 +add_test(function test_identifier() { 1.31 + let engineFile = gProfD.clone(); 1.32 + engineFile.append("searchplugins"); 1.33 + engineFile.append("test-search-engine.xml"); 1.34 + engineFile.parent.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); 1.35 + 1.36 + // Copy the test engine to the test profile. 1.37 + let engineTemplateFile = do_get_file("data/engine.xml"); 1.38 + engineTemplateFile.copyTo(engineFile.parent, "test-search-engine.xml"); 1.39 + 1.40 + let search = Services.search.init(function initComplete(aResult) { 1.41 + do_print("init'd search service"); 1.42 + do_check_true(Components.isSuccessCode(aResult)); 1.43 + 1.44 + let profileEngine = Services.search.getEngineByName("Test search engine"); 1.45 + let jarEngine = Services.search.getEngineByName("bug645970"); 1.46 + 1.47 + do_check_true(profileEngine instanceof Ci.nsISearchEngine); 1.48 + do_check_true(jarEngine instanceof Ci.nsISearchEngine); 1.49 + 1.50 + // An engine loaded from the profile directory won't have an identifier, 1.51 + // because it's not built-in. 1.52 + do_check_eq(profileEngine.identifier, null); 1.53 + 1.54 + // An engine loaded from a JAR will have an identifier corresponding to 1.55 + // the filename inside the JAR. (In this case it's the same as the name.) 1.56 + do_check_eq(jarEngine.identifier, "bug645970"); 1.57 + 1.58 + removeMetadata(); 1.59 + removeCacheFile(); 1.60 + run_next_test(); 1.61 + }); 1.62 +}); 1.63 +