diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/mozapps/extensions/test/xpcshell/test_softblocked.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_softblocked.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_softblocked.js | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_softblocked.js b/toolkit/mozapps/extensions/test/xpcshell/test_softblocked.js new file mode 100644 index 000000000..260b536e1 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_softblocked.js @@ -0,0 +1,109 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +const { utils: Cu, interfaces: Ci, classes: Cc, results: Cr } = Components; + +const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; + +Cu.import("resource://gre/modules/NetUtil.jsm"); +Cu.import("resource://testing-common/MockRegistrar.jsm"); + +// Allow insecure updates +Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false) + +const testserver = createHttpServer(); +gPort = testserver.identity.primaryPort; +testserver.registerDirectory("/data/", do_get_file("data")); + +// Don't need the full interface, attempts to call other methods will just +// throw which is just fine +var WindowWatcher = { + openWindow: function(parent, url, name, features, openArgs) { + // Should be called to list the newly blocklisted items + do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG); + + // Simulate auto-disabling any softblocks + var list = openArgs.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); + +const profileDir = gProfD.clone(); +profileDir.append("extensions"); + +function load_blocklist(aFile) { + return new Promise((resolve, reject) => { + Services.obs.addObserver(function() { + Services.obs.removeObserver(arguments.callee, "blocklist-updated"); + + resolve(); + }, "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 run_test() { + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); + run_next_test(); +} + +// Tests that an appDisabled add-on that becomes softBlocked remains disabled +// when becoming appEnabled +add_task(function* () { + writeInstallRDFForExtension({ + id: "softblock1@tests.mozilla.org", + version: "1.0", + name: "Softblocked add-on", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "2", + maxVersion: "3" + }] + }, profileDir); + + startupManager(); + + let s1 = yield promiseAddonByID("softblock1@tests.mozilla.org"); + + // Make sure to mark it as previously enabled. + s1.userDisabled = false; + + do_check_false(s1.softDisabled); + do_check_true(s1.appDisabled); + do_check_false(s1.isActive); + + yield load_blocklist("test_softblocked1.xml"); + + do_check_true(s1.softDisabled); + do_check_true(s1.appDisabled); + do_check_false(s1.isActive); + + yield promiseRestartManager("2"); + + s1 = yield promiseAddonByID("softblock1@tests.mozilla.org"); + + do_check_true(s1.softDisabled); + do_check_false(s1.appDisabled); + do_check_false(s1.isActive); +}); |