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