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: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/Promise.jsm"); michael@0: michael@0: const ADDON_ID = "test-plugin-from-xpi@tests.mozilla.org"; michael@0: const XRE_EXTENSIONS_DIR_LIST = "XREExtDL"; michael@0: const NS_APP_PLUGINS_DIR_LIST = "APluginsDL"; michael@0: michael@0: const gPluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); michael@0: const gXPCOMABI = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).XPCOMABI; michael@0: let gProfileDir = null; michael@0: michael@0: function getAddonRoot(profileDir, id) { michael@0: let dir = profileDir.clone(); michael@0: dir.append("extensions"); michael@0: Assert.ok(dir.exists(), "Extensions dir should exist: " + dir.path); michael@0: dir.append(id); michael@0: return dir; michael@0: } michael@0: michael@0: function getTestaddonFilename() { michael@0: let abiPart = ""; michael@0: if (gIsOSX) { michael@0: abiPart = "_" + gXPCOMABI; michael@0: } michael@0: return "testaddon" + abiPart + ".xpi"; michael@0: } michael@0: michael@0: function run_test() { michael@0: loadAddonManager(); michael@0: gProfileDir = do_get_profile(); michael@0: do_register_cleanup(() => shutdownManager()); michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function* test_state() { michael@0: // Remove test so we will have only one "Test Plug-in" registered. michael@0: // xpcshell tests have plugins in per-test profiles, so that's fine. michael@0: let file = get_test_plugin(); michael@0: file.remove(true); michael@0: file = get_test_plugin(true); michael@0: file.remove(true); michael@0: michael@0: Services.prefs.setIntPref("plugin.default.state", Ci.nsIPluginTag.STATE_CLICKTOPLAY); michael@0: Services.prefs.setIntPref("plugin.defaultXpi.state", Ci.nsIPluginTag.STATE_ENABLED); michael@0: michael@0: let success = yield installAddon(getTestaddonFilename()); michael@0: Assert.ok(success, "Should have installed addon."); michael@0: let addonDir = getAddonRoot(gProfileDir, ADDON_ID); michael@0: michael@0: let provider = { michael@0: classID: Components.ID("{0af6b2d7-a06c-49b7-babc-636d292b0dbb}"), michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider, michael@0: Ci.nsIDirectoryServiceProvider2]), michael@0: michael@0: getFile: function (prop, persistant) { michael@0: throw Cr.NS_ERROR_FAILURE; michael@0: }, michael@0: michael@0: getFiles: function (prop) { michael@0: let result = []; michael@0: michael@0: switch (prop) { michael@0: case XRE_EXTENSIONS_DIR_LIST: michael@0: result.push(addonDir); michael@0: break; michael@0: case NS_APP_PLUGINS_DIR_LIST: michael@0: let pluginDir = addonDir.clone(); michael@0: pluginDir.append("plugins"); michael@0: result.push(pluginDir); michael@0: break; michael@0: default: michael@0: throw Cr.NS_ERROR_FAILURE; michael@0: } michael@0: michael@0: return { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]), michael@0: hasMoreElements: () => result.length > 0, michael@0: getNext: () => result.shift(), michael@0: }; michael@0: }, michael@0: }; michael@0: michael@0: let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); michael@0: dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider); michael@0: michael@0: // We installed a non-restartless addon, need to restart the manager. michael@0: restartManager(); michael@0: gPluginHost.reloadPlugins(); michael@0: michael@0: Assert.ok(addonDir.exists(), "Addon path should exist: " + addonDir.path); michael@0: Assert.ok(addonDir.isDirectory(), "Addon path should be a directory: " + addonDir.path); michael@0: let pluginDir = addonDir.clone(); michael@0: pluginDir.append("plugins"); michael@0: Assert.ok(pluginDir.exists(), "Addon plugins path should exist: " + pluginDir.path); michael@0: Assert.ok(pluginDir.isDirectory(), "Addon plugins path should be a directory: " + pluginDir.path); michael@0: michael@0: let addon = yield getAddonByID(ADDON_ID); michael@0: Assert.ok(!addon.appDisabled, "Addon should not be appDisabled"); michael@0: Assert.ok(addon.isActive, "Addon should be active"); michael@0: Assert.ok(addon.isCompatible, "Addon should be compatible"); michael@0: Assert.ok(!addon.userDisabled, "Addon should not be user disabled"); michael@0: michael@0: let testPlugin = get_test_plugintag(); michael@0: Assert.notEqual(testPlugin, null, "Test plugin should have been found"); michael@0: Assert.equal(testPlugin.enabledState, Ci.nsIPluginTag.STATE_ENABLED, "Test plugin from addon should have state enabled"); michael@0: michael@0: pluginDir.append(testPlugin.filename); michael@0: Assert.ok(pluginDir.exists(), "Plugin file should exist in addon directory: " + pluginDir.path); michael@0: michael@0: testPlugin = get_test_plugintag("Second Test Plug-in"); michael@0: Assert.notEqual(testPlugin, null, "Second test plugin should have been found"); michael@0: Assert.equal(testPlugin.enabledState, Ci.nsIPluginTag.STATE_ENABLED, "Second test plugin from addon should have state enabled"); michael@0: });