Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 */
6 let addonIDs = ["test_bug393285_1@tests.mozilla.org",
7 "test_bug393285_2@tests.mozilla.org",
8 "test_bug393285_3a@tests.mozilla.org",
9 "test_bug393285_4@tests.mozilla.org"];
11 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
13 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
15 Cu.import("resource://testing-common/httpd.js");
16 var testserver = new HttpServer();
17 testserver.start(-1);
18 gPort = testserver.identity.primaryPort;
20 // register static files with server and interpolate port numbers in them
21 mapFile("/data/test_bug393285.xml", testserver);
23 const profileDir = gProfD.clone();
24 profileDir.append("extensions");
26 // A window watcher to deal with the blocklist UI dialog.
27 var WindowWatcher = {
28 openWindow: function(parent, url, name, features, arguments) {
29 // Should be called to list the newly blocklisted items
30 do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG);
32 // Simulate auto-disabling any softblocks
33 var list = arguments.wrappedJSObject.list;
34 list.forEach(function(aItem) {
35 if (!aItem.blocked)
36 aItem.disable = true;
37 });
39 //run the code after the blocklist is closed
40 Services.obs.notifyObservers(null, "addon-blocklist-closed", null);
42 },
44 QueryInterface: function(iid) {
45 if (iid.equals(Ci.nsIWindowWatcher)
46 || iid.equals(Ci.nsISupports))
47 return this;
49 throw Cr.NS_ERROR_NO_INTERFACE;
50 }
51 };
53 var WindowWatcherFactory = {
54 createInstance: function createInstance(outer, iid) {
55 if (outer != null)
56 throw Cr.NS_ERROR_NO_AGGREGATION;
57 return WindowWatcher.QueryInterface(iid);
58 }
59 };
61 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
62 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
63 "Fake Window Watcher",
64 "@mozilla.org/embedcomp/window-watcher;1",
65 WindowWatcherFactory);
68 function load_blocklist(aFile, aCallback) {
69 Services.obs.addObserver(function() {
70 Services.obs.removeObserver(arguments.callee, "blocklist-updated");
72 do_execute_soon(aCallback);
73 }, "blocklist-updated", false);
75 Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
76 gPort + "/data/" + aFile);
77 var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
78 getService(Ci.nsITimerCallback);
79 blocklist.notify(null);
80 }
83 function end_test() {
84 testserver.stop(do_test_finished);
85 }
87 function run_test() {
88 do_test_pending();
90 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
92 writeInstallRDFForExtension({
93 id: "test_bug393285_1@tests.mozilla.org",
94 name: "extension 1",
95 version: "1.0",
96 targetApplications: [{
97 id: "xpcshell@tests.mozilla.org",
98 minVersion: "1",
99 maxVersion: "3"
100 }]
101 }, profileDir);
104 writeInstallRDFForExtension({
105 id: "test_bug393285_2@tests.mozilla.org",
106 name: "extension 2",
107 version: "1.0",
108 targetApplications: [{
109 id: "xpcshell@tests.mozilla.org",
110 minVersion: "1",
111 maxVersion: "3"
112 }]
113 }, profileDir);
115 writeInstallRDFForExtension({
116 id: "test_bug393285_3a@tests.mozilla.org",
117 name: "extension 3a",
118 version: "1.0",
119 targetApplications: [{
120 id: "xpcshell@tests.mozilla.org",
121 minVersion: "1",
122 maxVersion: "3"
123 }]
124 }, profileDir);
126 writeInstallRDFForExtension({
127 id: "test_bug393285_4@tests.mozilla.org",
128 name: "extension 4",
129 version: "1.0",
130 targetApplications: [{
131 id: "xpcshell@tests.mozilla.org",
132 minVersion: "1",
133 maxVersion: "3"
134 }]
135 }, profileDir);
137 startupManager();
139 AddonManager.getAddonsByIDs(addonIDs, function(addons) {
140 for (addon of addons) {
141 do_check_eq(addon.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
142 }
143 run_test_1();
144 });
145 }
147 function run_test_1() {
148 load_blocklist("test_bug393285.xml", function() {
149 restartManager();
151 var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]
152 .getService(Ci.nsIBlocklistService);
154 AddonManager.getAddonsByIDs(addonIDs,
155 function([a1, a2, a3, a4]) {
156 // No info in blocklist, shouldn't be blocked
157 do_check_false(blocklist.isAddonBlocklisted(a1, null, null));
159 // All these should be blocklisted for the current app.
160 do_check_true(blocklist.isAddonBlocklisted(a2, null, null));
161 do_check_true(blocklist.isAddonBlocklisted(a3, null, null));
162 do_check_true(blocklist.isAddonBlocklisted(a4, null, null));
164 end_test();
165 });
166 });
167 }