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

mercurial