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