toolkit/mozapps/extensions/test/xpcshell/test_duplicateplugins.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 const Ci = Components.interfaces;
michael@0 6
michael@0 7 // This verifies that duplicate plugins are coalesced and maintain their ID
michael@0 8 // across restarts.
michael@0 9
michael@0 10 var PLUGINS = [{
michael@0 11 name: "Duplicate Plugin 1",
michael@0 12 description: "A duplicate plugin",
michael@0 13 version: "1",
michael@0 14 blocklisted: false,
michael@0 15 enabledState: Ci.nsIPluginTag.STATE_ENABLED,
michael@0 16 get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED,
michael@0 17 filename: "/home/mozilla/.plugins/dupplugin1.so"
michael@0 18 }, {
michael@0 19 name: "Duplicate Plugin 1",
michael@0 20 description: "A duplicate plugin",
michael@0 21 version: "1",
michael@0 22 blocklisted: false,
michael@0 23 enabledState: Ci.nsIPluginTag.STATE_ENABLED,
michael@0 24 get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED,
michael@0 25 filename: "",
michael@0 26 filename: "/usr/lib/plugins/dupplugin1.so"
michael@0 27 }, {
michael@0 28 name: "Duplicate Plugin 2",
michael@0 29 description: "Another duplicate plugin",
michael@0 30 version: "1",
michael@0 31 blocklisted: false,
michael@0 32 enabledState: Ci.nsIPluginTag.STATE_ENABLED,
michael@0 33 get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED,
michael@0 34 filename: "/home/mozilla/.plugins/dupplugin2.so"
michael@0 35 }, {
michael@0 36 name: "Duplicate Plugin 2",
michael@0 37 description: "Another duplicate plugin",
michael@0 38 version: "1",
michael@0 39 blocklisted: false,
michael@0 40 enabledState: Ci.nsIPluginTag.STATE_ENABLED,
michael@0 41 get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED,
michael@0 42 filename: "",
michael@0 43 filename: "/usr/lib/plugins/dupplugin2.so"
michael@0 44 }, {
michael@0 45 name: "Non-duplicate Plugin", // 3
michael@0 46 description: "Not a duplicate plugin",
michael@0 47 version: "1",
michael@0 48 blocklisted: false,
michael@0 49 enabledState: Ci.nsIPluginTag.STATE_ENABLED,
michael@0 50 get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED,
michael@0 51 filename: "/home/mozilla/.plugins/dupplugin3.so"
michael@0 52 }, {
michael@0 53 name: "Non-duplicate Plugin", // 4
michael@0 54 description: "Not a duplicate because the descriptions are different",
michael@0 55 version: "1",
michael@0 56 blocklisted: false,
michael@0 57 enabledState: Ci.nsIPluginTag.STATE_ENABLED,
michael@0 58 get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED,
michael@0 59 filename: "",
michael@0 60 filename: "/usr/lib/plugins/dupplugin4.so"
michael@0 61 }, {
michael@0 62 name: "Another Non-duplicate Plugin", // 5
michael@0 63 description: "Not a duplicate plugin",
michael@0 64 version: "1",
michael@0 65 blocklisted: false,
michael@0 66 enabledState: Ci.nsIPluginTag.STATE_ENABLED,
michael@0 67 get disabled() this.enabledState == Ci.nsIPluginTag.STATE_DISABLED,
michael@0 68 filename: "/home/mozilla/.plugins/dupplugin5.so"
michael@0 69 }];
michael@0 70
michael@0 71 // A fake plugin host to return the plugins defined above
michael@0 72 var PluginHost = {
michael@0 73 getPluginTags: function(countRef) {
michael@0 74 countRef.value = PLUGINS.length;
michael@0 75 return PLUGINS;
michael@0 76 },
michael@0 77
michael@0 78 QueryInterface: function(iid) {
michael@0 79 if (iid.equals(Components.interfaces.nsIPluginHost)
michael@0 80 || iid.equals(Components.interfaces.nsISupports))
michael@0 81 return this;
michael@0 82
michael@0 83 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 var PluginHostFactory = {
michael@0 88 createInstance: function (outer, iid) {
michael@0 89 if (outer != null)
michael@0 90 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 91 return PluginHost.QueryInterface(iid);
michael@0 92 }
michael@0 93 };
michael@0 94
michael@0 95 var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
michael@0 96 registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"),
michael@0 97 "Fake Plugin Host",
michael@0 98 "@mozilla.org/plugin/host;1", PluginHostFactory);
michael@0 99
michael@0 100 var gPluginIDs = [null, null, null, null, null];
michael@0 101
michael@0 102 function run_test() {
michael@0 103 do_test_pending();
michael@0 104 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 105
michael@0 106 startupManager();
michael@0 107
michael@0 108 run_test_1();
michael@0 109 }
michael@0 110
michael@0 111 function found_plugin(aNum, aId) {
michael@0 112 if (gPluginIDs[aNum])
michael@0 113 do_throw("Found duplicate of plugin " + aNum);
michael@0 114 gPluginIDs[aNum] = aId;
michael@0 115 }
michael@0 116
michael@0 117 // Test that the plugins were coalesced and all appear in the returned list
michael@0 118 function run_test_1() {
michael@0 119 AddonManager.getAddonsByTypes(["plugin"], function(aAddons) {
michael@0 120 do_check_eq(aAddons.length, 5);
michael@0 121 aAddons.forEach(function(aAddon) {
michael@0 122 if (aAddon.name == "Duplicate Plugin 1") {
michael@0 123 found_plugin(0, aAddon.id);
michael@0 124 do_check_eq(aAddon.description, "A duplicate plugin");
michael@0 125 }
michael@0 126 else if (aAddon.name == "Duplicate Plugin 2") {
michael@0 127 found_plugin(1, aAddon.id);
michael@0 128 do_check_eq(aAddon.description, "Another duplicate plugin");
michael@0 129 }
michael@0 130 else if (aAddon.name == "Another Non-duplicate Plugin") {
michael@0 131 found_plugin(5, aAddon.id);
michael@0 132 do_check_eq(aAddon.description, "Not a duplicate plugin");
michael@0 133 }
michael@0 134 else if (aAddon.name == "Non-duplicate Plugin") {
michael@0 135 if (aAddon.description == "Not a duplicate plugin")
michael@0 136 found_plugin(3, aAddon.id);
michael@0 137 else if (aAddon.description == "Not a duplicate because the descriptions are different")
michael@0 138 found_plugin(4, aAddon.id);
michael@0 139 else
michael@0 140 do_throw("Found unexpected plugin with description " + aAddon.description);
michael@0 141 }
michael@0 142 else {
michael@0 143 do_throw("Found unexpected plugin " + aAddon.name);
michael@0 144 }
michael@0 145 });
michael@0 146
michael@0 147 run_test_2();
michael@0 148 });
michael@0 149 }
michael@0 150
michael@0 151 // Test that disabling a coalesced plugin disables all its tags
michael@0 152 function run_test_2() {
michael@0 153 AddonManager.getAddonByID(gPluginIDs[0], function(p) {
michael@0 154 do_check_false(p.userDisabled);
michael@0 155 p.userDisabled = true;
michael@0 156 do_check_true(PLUGINS[0].disabled);
michael@0 157 do_check_true(PLUGINS[1].disabled);
michael@0 158
michael@0 159 do_execute_soon(run_test_3);
michael@0 160 });
michael@0 161 }
michael@0 162
michael@0 163 // Test that IDs persist across restart
michael@0 164 function run_test_3() {
michael@0 165 restartManager();
michael@0 166
michael@0 167 AddonManager.getAddonByID(gPluginIDs[0], callback_soon(function(p) {
michael@0 168 do_check_neq(p, null);
michael@0 169 do_check_eq(p.name, "Duplicate Plugin 1");
michael@0 170 do_check_eq(p.description, "A duplicate plugin");
michael@0 171
michael@0 172 // Reorder the plugins and restart again
michael@0 173 [PLUGINS[0], PLUGINS[1]] = [PLUGINS[1], PLUGINS[0]];
michael@0 174 restartManager();
michael@0 175
michael@0 176 AddonManager.getAddonByID(gPluginIDs[0], function(p) {
michael@0 177 do_check_neq(p, null);
michael@0 178 do_check_eq(p.name, "Duplicate Plugin 1");
michael@0 179 do_check_eq(p.description, "A duplicate plugin");
michael@0 180
michael@0 181 do_execute_soon(do_test_finished);
michael@0 182 });
michael@0 183 }));
michael@0 184 }

mercurial