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: const Ci = Components.interfaces; michael@0: michael@0: // This verifies that duplicate plugins are coalesced and maintain their ID michael@0: // across restarts. michael@0: michael@0: var PLUGINS = [{ michael@0: name: "Duplicate Plugin 1", michael@0: description: "A duplicate plugin", michael@0: version: "1", michael@0: blocklisted: false, michael@0: enabledState: Ci.nsIPluginTag.STATE_ENABLED, michael@0: get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED, michael@0: filename: "/home/mozilla/.plugins/dupplugin1.so" michael@0: }, { michael@0: name: "Duplicate Plugin 1", michael@0: description: "A duplicate plugin", michael@0: version: "1", michael@0: blocklisted: false, michael@0: enabledState: Ci.nsIPluginTag.STATE_ENABLED, michael@0: get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED, michael@0: filename: "", michael@0: filename: "/usr/lib/plugins/dupplugin1.so" michael@0: }, { michael@0: name: "Duplicate Plugin 2", michael@0: description: "Another duplicate plugin", michael@0: version: "1", michael@0: blocklisted: false, michael@0: enabledState: Ci.nsIPluginTag.STATE_ENABLED, michael@0: get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED, michael@0: filename: "/home/mozilla/.plugins/dupplugin2.so" michael@0: }, { michael@0: name: "Duplicate Plugin 2", michael@0: description: "Another duplicate plugin", michael@0: version: "1", michael@0: blocklisted: false, michael@0: enabledState: Ci.nsIPluginTag.STATE_ENABLED, michael@0: get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED, michael@0: filename: "", michael@0: filename: "/usr/lib/plugins/dupplugin2.so" michael@0: }, { michael@0: name: "Non-duplicate Plugin", // 3 michael@0: description: "Not a duplicate plugin", michael@0: version: "1", michael@0: blocklisted: false, michael@0: enabledState: Ci.nsIPluginTag.STATE_ENABLED, michael@0: get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED, michael@0: filename: "/home/mozilla/.plugins/dupplugin3.so" michael@0: }, { michael@0: name: "Non-duplicate Plugin", // 4 michael@0: description: "Not a duplicate because the descriptions are different", michael@0: version: "1", michael@0: blocklisted: false, michael@0: enabledState: Ci.nsIPluginTag.STATE_ENABLED, michael@0: get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED, michael@0: filename: "", michael@0: filename: "/usr/lib/plugins/dupplugin4.so" michael@0: }, { michael@0: name: "Another Non-duplicate Plugin", // 5 michael@0: description: "Not a duplicate plugin", michael@0: version: "1", michael@0: blocklisted: false, michael@0: enabledState: Ci.nsIPluginTag.STATE_ENABLED, michael@0: get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED, michael@0: filename: "/home/mozilla/.plugins/dupplugin5.so" michael@0: }]; michael@0: michael@0: // A fake plugin host to return the plugins defined above michael@0: var PluginHost = { michael@0: getPluginTags: function(countRef) { michael@0: countRef.value = PLUGINS.length; michael@0: return PLUGINS; michael@0: }, michael@0: michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Components.interfaces.nsIPluginHost) michael@0: || iid.equals(Components.interfaces.nsISupports)) michael@0: return this; michael@0: michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: } michael@0: } michael@0: michael@0: var PluginHostFactory = { michael@0: createInstance: function (outer, iid) { michael@0: if (outer != null) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return PluginHost.QueryInterface(iid); michael@0: } michael@0: }; michael@0: michael@0: var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); michael@0: registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"), michael@0: "Fake Plugin Host", michael@0: "@mozilla.org/plugin/host;1", PluginHostFactory); michael@0: michael@0: var gPluginIDs = [null, null, null, null, null]; michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: michael@0: startupManager(); michael@0: michael@0: run_test_1(); michael@0: } michael@0: michael@0: function found_plugin(aNum, aId) { michael@0: if (gPluginIDs[aNum]) michael@0: do_throw("Found duplicate of plugin " + aNum); michael@0: gPluginIDs[aNum] = aId; michael@0: } michael@0: michael@0: // Test that the plugins were coalesced and all appear in the returned list michael@0: function run_test_1() { michael@0: AddonManager.getAddonsByTypes(["plugin"], function(aAddons) { michael@0: do_check_eq(aAddons.length, 5); michael@0: aAddons.forEach(function(aAddon) { michael@0: if (aAddon.name == "Duplicate Plugin 1") { michael@0: found_plugin(0, aAddon.id); michael@0: do_check_eq(aAddon.description, "A duplicate plugin"); michael@0: } michael@0: else if (aAddon.name == "Duplicate Plugin 2") { michael@0: found_plugin(1, aAddon.id); michael@0: do_check_eq(aAddon.description, "Another duplicate plugin"); michael@0: } michael@0: else if (aAddon.name == "Another Non-duplicate Plugin") { michael@0: found_plugin(5, aAddon.id); michael@0: do_check_eq(aAddon.description, "Not a duplicate plugin"); michael@0: } michael@0: else if (aAddon.name == "Non-duplicate Plugin") { michael@0: if (aAddon.description == "Not a duplicate plugin") michael@0: found_plugin(3, aAddon.id); michael@0: else if (aAddon.description == "Not a duplicate because the descriptions are different") michael@0: found_plugin(4, aAddon.id); michael@0: else michael@0: do_throw("Found unexpected plugin with description " + aAddon.description); michael@0: } michael@0: else { michael@0: do_throw("Found unexpected plugin " + aAddon.name); michael@0: } michael@0: }); michael@0: michael@0: run_test_2(); michael@0: }); michael@0: } michael@0: michael@0: // Test that disabling a coalesced plugin disables all its tags michael@0: function run_test_2() { michael@0: AddonManager.getAddonByID(gPluginIDs[0], function(p) { michael@0: do_check_false(p.userDisabled); michael@0: p.userDisabled = true; michael@0: do_check_true(PLUGINS[0].disabled); michael@0: do_check_true(PLUGINS[1].disabled); michael@0: michael@0: do_execute_soon(run_test_3); michael@0: }); michael@0: } michael@0: michael@0: // Test that IDs persist across restart michael@0: function run_test_3() { michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID(gPluginIDs[0], callback_soon(function(p) { michael@0: do_check_neq(p, null); michael@0: do_check_eq(p.name, "Duplicate Plugin 1"); michael@0: do_check_eq(p.description, "A duplicate plugin"); michael@0: michael@0: // Reorder the plugins and restart again michael@0: [PLUGINS[0], PLUGINS[1]] = [PLUGINS[1], PLUGINS[0]]; michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID(gPluginIDs[0], function(p) { michael@0: do_check_neq(p, null); michael@0: do_check_eq(p.name, "Duplicate Plugin 1"); michael@0: do_check_eq(p.description, "A duplicate plugin"); michael@0: michael@0: do_execute_soon(do_test_finished); michael@0: }); michael@0: })); michael@0: }