michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /* michael@0: * Test that a search engine's identifier can be extracted from the filename. michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: const Ci = Components.interfaces; michael@0: const SEARCH_APP_DIR = 1; michael@0: michael@0: function run_test() { michael@0: removeMetadata(); michael@0: removeCacheFile(); michael@0: do_load_manifest("data/chrome.manifest"); michael@0: michael@0: let url = "chrome://testsearchplugin/locale/searchplugins/"; michael@0: Services.prefs.setCharPref("browser.search.jarURIs", url); michael@0: Services.prefs.setBoolPref("browser.search.loadFromJars", true); michael@0: michael@0: updateAppInfo(); michael@0: michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_test(function test_identifier() { michael@0: let engineFile = gProfD.clone(); michael@0: engineFile.append("searchplugins"); michael@0: engineFile.append("test-search-engine.xml"); michael@0: engineFile.parent.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); michael@0: michael@0: // Copy the test engine to the test profile. michael@0: let engineTemplateFile = do_get_file("data/engine.xml"); michael@0: engineTemplateFile.copyTo(engineFile.parent, "test-search-engine.xml"); michael@0: michael@0: let search = Services.search.init(function initComplete(aResult) { michael@0: do_print("init'd search service"); michael@0: do_check_true(Components.isSuccessCode(aResult)); michael@0: michael@0: let profileEngine = Services.search.getEngineByName("Test search engine"); michael@0: let jarEngine = Services.search.getEngineByName("bug645970"); michael@0: michael@0: do_check_true(profileEngine instanceof Ci.nsISearchEngine); michael@0: do_check_true(jarEngine instanceof Ci.nsISearchEngine); michael@0: michael@0: // An engine loaded from the profile directory won't have an identifier, michael@0: // because it's not built-in. michael@0: do_check_eq(profileEngine.identifier, null); michael@0: michael@0: // An engine loaded from a JAR will have an identifier corresponding to michael@0: // the filename inside the JAR. (In this case it's the same as the name.) michael@0: do_check_eq(jarEngine.identifier, "bug645970"); michael@0: michael@0: removeMetadata(); michael@0: removeCacheFile(); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: