1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://testing-common/MockRegistrar.jsm");
var testserver = new HttpServer();
testserver.start(-1);
gPort = testserver.identity.primaryPort;
// register static files with server and interpolate port numbers in them
mapFile("/data/test_bug393285.xml", testserver);
const profileDir = gProfD.clone();
profileDir.append("extensions");
var addonIDs = ["test_bug393285_1@tests.mozilla.org",
"test_bug393285_2@tests.mozilla.org",
"test_bug393285_3a@tests.mozilla.org",
"test_bug393285_3b@tests.mozilla.org",
"test_bug393285_4@tests.mozilla.org",
"test_bug393285_5@tests.mozilla.org",
"test_bug393285_6@tests.mozilla.org",
"test_bug393285_7@tests.mozilla.org",
"test_bug393285_8@tests.mozilla.org",
"test_bug393285_9@tests.mozilla.org",
"test_bug393285_10@tests.mozilla.org",
"test_bug393285_11@tests.mozilla.org",
"test_bug393285_12@tests.mozilla.org",
"test_bug393285_13@tests.mozilla.org",
"test_bug393285_14@tests.mozilla.org"];
// A window watcher to deal with the blocklist UI dialog.
var WindowWatcher = {
openWindow: function(parent, url, name, features, args) {
// Should be called to list the newly blocklisted items
do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG);
// Simulate auto-disabling any softblocks
var list = args.wrappedJSObject.list;
list.forEach(function(aItem) {
if (!aItem.blocked)
aItem.disable = true;
});
// run the code after the blocklist is closed
Services.obs.notifyObservers(null, "addon-blocklist-closed", null);
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIWindowWatcher)
|| iid.equals(Ci.nsISupports))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher);
function load_blocklist(aFile, aCallback) {
Services.obs.addObserver(function() {
Services.obs.removeObserver(arguments.callee, "blocklist-updated");
do_execute_soon(aCallback);
}, "blocklist-updated", false);
Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
gPort + "/data/" + aFile);
var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
getService(Ci.nsITimerCallback);
blocklist.notify(null);
}
function end_test() {
testserver.stop(do_test_finished);
}
function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
writeInstallRDFForExtension({
id: "test_bug393285_1@tests.mozilla.org",
name: "extension 1",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_2@tests.mozilla.org",
name: "extension 2",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_3a@tests.mozilla.org",
name: "extension 3a",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_3b@tests.mozilla.org",
name: "extension 3b",
version: "2.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_4@tests.mozilla.org",
name: "extension 4",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_5@tests.mozilla.org",
name: "extension 5",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_6@tests.mozilla.org",
name: "extension 6",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_7@tests.mozilla.org",
name: "extension 7",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_8@tests.mozilla.org",
name: "extension 8",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_9@tests.mozilla.org",
name: "extension 9",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_10@tests.mozilla.org",
name: "extension 10",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_11@tests.mozilla.org",
name: "extension 11",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_12@tests.mozilla.org",
name: "extension 12",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_13@tests.mozilla.org",
name: "extension 13",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
writeInstallRDFForExtension({
id: "test_bug393285_14@tests.mozilla.org",
name: "extension 14",
version: "1.0",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "3"
}]
}, profileDir);
startupManager();
AddonManager.getAddonsByIDs(addonIDs, function(addons) {
for (let addon of addons) {
do_check_eq(addon.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
}
run_test_1();
});
}
function run_test_1() {
load_blocklist("test_bug393285.xml", function() {
restartManager();
var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]
.getService(Ci.nsIBlocklistService);
AddonManager.getAddonsByIDs(addonIDs,
function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
a11, a12, a13, a14, a15]) {
// No info in blocklist, shouldn't be blocked
do_check_false(blocklist.isAddonBlocklisted(a1, "1", "1.9"));
// Should always be blocked
do_check_true(blocklist.isAddonBlocklisted(a2, "1", "1.9"));
// Only version 1 should be blocked
do_check_true(blocklist.isAddonBlocklisted(a3, "1", "1.9"));
do_check_false(blocklist.isAddonBlocklisted(a4, "1", "1.9"));
// Should be blocked for app version 1
do_check_true(blocklist.isAddonBlocklisted(a5, "1", "1.9"));
do_check_false(blocklist.isAddonBlocklisted(a5, "2", "1.9"));
// Not blocklisted because we are a different OS
do_check_false(blocklist.isAddonBlocklisted(a6, "2", "1.9"));
// Blocklisted based on OS
do_check_true(blocklist.isAddonBlocklisted(a7, "2", "1.9"));
do_check_true(blocklist.isAddonBlocklisted(a8, "2", "1.9"));
// Not blocklisted because we are a different ABI
do_check_false(blocklist.isAddonBlocklisted(a9, "2", "1.9"));
// Blocklisted based on ABI
do_check_true(blocklist.isAddonBlocklisted(a10, "2", "1.9"));
do_check_true(blocklist.isAddonBlocklisted(a11, "2", "1.9"));
// Doesnt match both os and abi so not blocked
do_check_false(blocklist.isAddonBlocklisted(a12, "2", "1.9"));
do_check_false(blocklist.isAddonBlocklisted(a13, "2", "1.9"));
do_check_false(blocklist.isAddonBlocklisted(a14, "2", "1.9"));
// Matches both os and abi so blocked
do_check_true(blocklist.isAddonBlocklisted(a15, "2", "1.9"));
end_test();
});
});
}
|