dom/plugins/test/unit/test_plugin_default_state_xpi.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 Cu.import("resource://gre/modules/Services.jsm");
michael@0 6 Cu.import("resource://gre/modules/Promise.jsm");
michael@0 7
michael@0 8 const ADDON_ID = "test-plugin-from-xpi@tests.mozilla.org";
michael@0 9 const XRE_EXTENSIONS_DIR_LIST = "XREExtDL";
michael@0 10 const NS_APP_PLUGINS_DIR_LIST = "APluginsDL";
michael@0 11
michael@0 12 const gPluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
michael@0 13 const gXPCOMABI = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).XPCOMABI;
michael@0 14 let gProfileDir = null;
michael@0 15
michael@0 16 function getAddonRoot(profileDir, id) {
michael@0 17 let dir = profileDir.clone();
michael@0 18 dir.append("extensions");
michael@0 19 Assert.ok(dir.exists(), "Extensions dir should exist: " + dir.path);
michael@0 20 dir.append(id);
michael@0 21 return dir;
michael@0 22 }
michael@0 23
michael@0 24 function getTestaddonFilename() {
michael@0 25 let abiPart = "";
michael@0 26 if (gIsOSX) {
michael@0 27 abiPart = "_" + gXPCOMABI;
michael@0 28 }
michael@0 29 return "testaddon" + abiPart + ".xpi";
michael@0 30 }
michael@0 31
michael@0 32 function run_test() {
michael@0 33 loadAddonManager();
michael@0 34 gProfileDir = do_get_profile();
michael@0 35 do_register_cleanup(() => shutdownManager());
michael@0 36 run_next_test();
michael@0 37 }
michael@0 38
michael@0 39 add_task(function* test_state() {
michael@0 40 // Remove test so we will have only one "Test Plug-in" registered.
michael@0 41 // xpcshell tests have plugins in per-test profiles, so that's fine.
michael@0 42 let file = get_test_plugin();
michael@0 43 file.remove(true);
michael@0 44 file = get_test_plugin(true);
michael@0 45 file.remove(true);
michael@0 46
michael@0 47 Services.prefs.setIntPref("plugin.default.state", Ci.nsIPluginTag.STATE_CLICKTOPLAY);
michael@0 48 Services.prefs.setIntPref("plugin.defaultXpi.state", Ci.nsIPluginTag.STATE_ENABLED);
michael@0 49
michael@0 50 let success = yield installAddon(getTestaddonFilename());
michael@0 51 Assert.ok(success, "Should have installed addon.");
michael@0 52 let addonDir = getAddonRoot(gProfileDir, ADDON_ID);
michael@0 53
michael@0 54 let provider = {
michael@0 55 classID: Components.ID("{0af6b2d7-a06c-49b7-babc-636d292b0dbb}"),
michael@0 56 QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
michael@0 57 Ci.nsIDirectoryServiceProvider2]),
michael@0 58
michael@0 59 getFile: function (prop, persistant) {
michael@0 60 throw Cr.NS_ERROR_FAILURE;
michael@0 61 },
michael@0 62
michael@0 63 getFiles: function (prop) {
michael@0 64 let result = [];
michael@0 65
michael@0 66 switch (prop) {
michael@0 67 case XRE_EXTENSIONS_DIR_LIST:
michael@0 68 result.push(addonDir);
michael@0 69 break;
michael@0 70 case NS_APP_PLUGINS_DIR_LIST:
michael@0 71 let pluginDir = addonDir.clone();
michael@0 72 pluginDir.append("plugins");
michael@0 73 result.push(pluginDir);
michael@0 74 break;
michael@0 75 default:
michael@0 76 throw Cr.NS_ERROR_FAILURE;
michael@0 77 }
michael@0 78
michael@0 79 return {
michael@0 80 QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
michael@0 81 hasMoreElements: () => result.length > 0,
michael@0 82 getNext: () => result.shift(),
michael@0 83 };
michael@0 84 },
michael@0 85 };
michael@0 86
michael@0 87 let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
michael@0 88 dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
michael@0 89
michael@0 90 // We installed a non-restartless addon, need to restart the manager.
michael@0 91 restartManager();
michael@0 92 gPluginHost.reloadPlugins();
michael@0 93
michael@0 94 Assert.ok(addonDir.exists(), "Addon path should exist: " + addonDir.path);
michael@0 95 Assert.ok(addonDir.isDirectory(), "Addon path should be a directory: " + addonDir.path);
michael@0 96 let pluginDir = addonDir.clone();
michael@0 97 pluginDir.append("plugins");
michael@0 98 Assert.ok(pluginDir.exists(), "Addon plugins path should exist: " + pluginDir.path);
michael@0 99 Assert.ok(pluginDir.isDirectory(), "Addon plugins path should be a directory: " + pluginDir.path);
michael@0 100
michael@0 101 let addon = yield getAddonByID(ADDON_ID);
michael@0 102 Assert.ok(!addon.appDisabled, "Addon should not be appDisabled");
michael@0 103 Assert.ok(addon.isActive, "Addon should be active");
michael@0 104 Assert.ok(addon.isCompatible, "Addon should be compatible");
michael@0 105 Assert.ok(!addon.userDisabled, "Addon should not be user disabled");
michael@0 106
michael@0 107 let testPlugin = get_test_plugintag();
michael@0 108 Assert.notEqual(testPlugin, null, "Test plugin should have been found");
michael@0 109 Assert.equal(testPlugin.enabledState, Ci.nsIPluginTag.STATE_ENABLED, "Test plugin from addon should have state enabled");
michael@0 110
michael@0 111 pluginDir.append(testPlugin.filename);
michael@0 112 Assert.ok(pluginDir.exists(), "Plugin file should exist in addon directory: " + pluginDir.path);
michael@0 113
michael@0 114 testPlugin = get_test_plugintag("Second Test Plug-in");
michael@0 115 Assert.notEqual(testPlugin, null, "Second test plugin should have been found");
michael@0 116 Assert.equal(testPlugin.enabledState, Ci.nsIPluginTag.STATE_ENABLED, "Second test plugin from addon should have state enabled");
michael@0 117 });

mercurial