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