|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Checks that blocklist entries using RegExp work as expected. This only covers |
|
6 // behavior specific to RegExp entries - general behavior is already tested |
|
7 // in test_blocklistchange.js. |
|
8 |
|
9 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
|
10 |
|
11 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; |
|
12 |
|
13 Cu.import("resource://testing-common/httpd.js"); |
|
14 var testserver = new HttpServer(); |
|
15 testserver.start(-1); |
|
16 gPort = testserver.identity.primaryPort; |
|
17 |
|
18 // register static files with server and interpolate port numbers in them |
|
19 mapFile("/data/test_blocklist_regexp_1.xml", testserver); |
|
20 |
|
21 const profileDir = gProfD.clone(); |
|
22 profileDir.append("extensions"); |
|
23 |
|
24 // Don't need the full interface, attempts to call other methods will just |
|
25 // throw which is just fine |
|
26 var WindowWatcher = { |
|
27 openWindow: function(parent, url, name, features, arguments) { |
|
28 // Should be called to list the newly blocklisted items |
|
29 do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG); |
|
30 |
|
31 // Simulate auto-disabling any softblocks |
|
32 var list = arguments.wrappedJSObject.list; |
|
33 list.forEach(function(aItem) { |
|
34 if (!aItem.blocked) |
|
35 aItem.disable = true; |
|
36 }); |
|
37 |
|
38 //run the code after the blocklist is closed |
|
39 Services.obs.notifyObservers(null, "addon-blocklist-closed", null); |
|
40 |
|
41 }, |
|
42 |
|
43 QueryInterface: function(iid) { |
|
44 if (iid.equals(Ci.nsIWindowWatcher) |
|
45 || iid.equals(Ci.nsISupports)) |
|
46 return this; |
|
47 |
|
48 throw Cr.NS_ERROR_NO_INTERFACE; |
|
49 } |
|
50 }; |
|
51 |
|
52 var WindowWatcherFactory = { |
|
53 createInstance: function createInstance(outer, iid) { |
|
54 if (outer != null) |
|
55 throw Cr.NS_ERROR_NO_AGGREGATION; |
|
56 return WindowWatcher.QueryInterface(iid); |
|
57 } |
|
58 }; |
|
59 |
|
60 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
|
61 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), |
|
62 "Fake Window Watcher", |
|
63 "@mozilla.org/embedcomp/window-watcher;1", |
|
64 WindowWatcherFactory); |
|
65 |
|
66 |
|
67 function load_blocklist(aFile, aCallback) { |
|
68 Services.obs.addObserver(function() { |
|
69 Services.obs.removeObserver(arguments.callee, "blocklist-updated"); |
|
70 |
|
71 do_execute_soon(aCallback); |
|
72 }, "blocklist-updated", false); |
|
73 |
|
74 Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + |
|
75 gPort + "/data/" + aFile); |
|
76 var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. |
|
77 getService(Ci.nsITimerCallback); |
|
78 blocklist.notify(null); |
|
79 } |
|
80 |
|
81 |
|
82 function end_test() { |
|
83 testserver.stop(do_test_finished); |
|
84 } |
|
85 |
|
86 |
|
87 function run_test() { |
|
88 do_test_pending(); |
|
89 |
|
90 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); |
|
91 |
|
92 writeInstallRDFForExtension({ |
|
93 id: "block1@tests.mozilla.org", |
|
94 version: "1.0", |
|
95 name: "RegExp blocked add-on", |
|
96 targetApplications: [{ |
|
97 id: "xpcshell@tests.mozilla.org", |
|
98 minVersion: "1", |
|
99 maxVersion: "3" |
|
100 }] |
|
101 }, profileDir); |
|
102 |
|
103 startupManager(); |
|
104 |
|
105 AddonManager.getAddonsByIDs(["block1@tests.mozilla.org"], function([a1]) { |
|
106 do_check_eq(a1.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED); |
|
107 |
|
108 run_test_1(); |
|
109 }); |
|
110 } |
|
111 |
|
112 function run_test_1() { |
|
113 load_blocklist("test_blocklist_regexp_1.xml", function() { |
|
114 restartManager(); |
|
115 |
|
116 AddonManager.getAddonsByIDs(["block1@tests.mozilla.org"], function([a1]) { |
|
117 // Blocklist contains two entries that will match this addon - ensure |
|
118 // that the first one is applied. |
|
119 do_check_neq(a1, null); |
|
120 do_check_eq(a1.blocklistState, Ci.nsIBlocklistService.STATE_SOFTBLOCKED); |
|
121 |
|
122 end_test(); |
|
123 }); |
|
124 }); |
|
125 } |