summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js')
-rw-r--r--toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js73
1 files changed, 46 insertions, 27 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js b/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
index 06e29b376..9a41e827c 100644
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js
@@ -3,15 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cu = Components.utils;
-var Cr = Components.results;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+const Cr = Components.results;
const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
Cu.import("resource://testing-common/httpd.js");
-Cu.import("resource://testing-common/MockRegistrar.jsm");
var gTestserver = new HttpServer();
gTestserver.start(-1);
gPort = gTestserver.identity.primaryPort;
@@ -128,11 +127,19 @@ var PluginHost = {
if (iid.equals(Ci.nsIPluginHost)
|| iid.equals(Ci.nsISupports))
return this;
-
+
throw Components.results.NS_ERROR_NO_INTERFACE;
}
}
+var PluginHostFactory = {
+ createInstance: function (outer, iid) {
+ if (outer != null)
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+ return PluginHost.QueryInterface(iid);
+ }
+};
+
// Don't need the full interface, attempts to call other methods will just
// throw which is just fine
var WindowWatcher = {
@@ -145,7 +152,7 @@ var WindowWatcher = {
gNotificationCheck(args);
}
- // run the code after the blocklist is closed
+ //run the code after the blocklist is closed
Services.obs.notifyObservers(null, "addon-blocklist-closed", null);
// Call the next test after the blocklist has finished up
@@ -161,8 +168,20 @@ var WindowWatcher = {
}
}
-MockRegistrar.register("@mozilla.org/plugin/host;1", PluginHost);
-MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher);
+var WindowWatcherFactory = {
+ createInstance: function createInstance(outer, iid) {
+ if (outer != null)
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+ return WindowWatcher.QueryInterface(iid);
+ }
+};
+var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"),
+ "Fake Plugin Host",
+ "@mozilla.org/plugin/host;1", PluginHostFactory);
+registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
+ "Fake Window Watcher",
+ "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory);
function create_addon(addon) {
var installrdf = "<?xml version=\"1.0\"?>\n" +
@@ -211,7 +230,7 @@ function check_plugin_state(plugin) {
return plugin.disabled + "," + plugin.blocklisted;
}
-function create_blocklistURL(blockID) {
+function create_blocklistURL(blockID){
let url = Services.urlFormatter.formatURLPref(PREF_BLOCKLIST_ITEM_URL);
url = url.replace(/%blockID%/g, blockID);
return url;
@@ -239,7 +258,7 @@ function run_test() {
// Before every main test this is the state the add-ons are meant to be in
function check_initial_state(callback) {
- AddonManager.getAddonsByIDs(ADDONS.map(a => a.id), function(addons) {
+ AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
do_check_eq(check_addon_state(addons[0]), "true,false,false");
do_check_eq(check_addon_state(addons[1]), "false,false,false");
do_check_eq(check_addon_state(addons[2]), "false,false,false");
@@ -247,7 +266,7 @@ function check_initial_state(callback) {
do_check_eq(check_addon_state(addons[4]), "false,false,false");
do_check_eq(check_addon_state(addons[5]), "false,false,true");
do_check_eq(check_addon_state(addons[6]), "false,false,true");
-
+
do_check_eq(check_plugin_state(PLUGINS[0]), "true,false");
do_check_eq(check_plugin_state(PLUGINS[1]), "false,false");
do_check_eq(check_plugin_state(PLUGINS[2]), "false,false");
@@ -263,27 +282,27 @@ function check_initial_state(callback) {
function check_test_pt1() {
dump("Checking pt 1\n");
- AddonManager.getAddonsByIDs(ADDONS.map(a => a.id), callback_soon(function(addons) {
+ AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], callback_soon(function(addons) {
for (var i = 0; i < ADDONS.length; i++) {
if (!addons[i])
do_throw("Addon " + (i + 1) + " did not get installed correctly");
}
-
+
do_check_eq(check_addon_state(addons[0]), "false,false,false");
do_check_eq(check_addon_state(addons[1]), "false,false,false");
do_check_eq(check_addon_state(addons[2]), "false,false,false");
-
+
// Warn add-ons should be soft disabled automatically
do_check_eq(check_addon_state(addons[3]), "true,true,false");
do_check_eq(check_addon_state(addons[4]), "true,true,false");
-
+
// Blocked and incompatible should be app disabled only
do_check_eq(check_addon_state(addons[5]), "false,false,true");
do_check_eq(check_addon_state(addons[6]), "false,false,true");
-
+
// We've overridden the plugin host so we cannot tell what that would have
// initialised the plugins as
-
+
// Put the add-ons into the base state
addons[0].userDisabled = true;
addons[4].userDisabled = false;
@@ -335,14 +354,13 @@ function check_test_pt2() {
restartManager();
dump("Checking results pt 2\n");
- AddonManager.getAddonsByIDs(ADDONS.map(a => a.id), callback_soon(function(addons) {
+ AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], callback_soon(function(addons) {
// Should have disabled this add-on as requested
do_check_eq(check_addon_state(addons[2]), "true,true,false");
do_check_eq(check_plugin_state(PLUGINS[2]), "true,false");
// The blocked add-on should have changed to soft disabled
do_check_eq(check_addon_state(addons[5]), "true,true,false");
- do_check_eq(check_addon_state(addons[6]), "true,true,true");
do_check_eq(check_plugin_state(PLUGINS[5]), "true,false");
// These should have been unchanged
@@ -350,6 +368,7 @@ function check_test_pt2() {
do_check_eq(check_addon_state(addons[1]), "false,false,false");
do_check_eq(check_addon_state(addons[3]), "true,true,false");
do_check_eq(check_addon_state(addons[4]), "false,false,false");
+ do_check_eq(check_addon_state(addons[6]), "false,false,true");
do_check_eq(check_plugin_state(PLUGINS[0]), "true,false");
do_check_eq(check_plugin_state(PLUGINS[1]), "false,false");
do_check_eq(check_plugin_state(PLUGINS[3]), "true,false");
@@ -421,7 +440,7 @@ function check_test_pt3() {
let blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
getService(Ci.nsIBlocklistService);
- AddonManager.getAddonsByIDs(ADDONS.map(a => a.id), function(addons) {
+ AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
// All should have gained the blocklist state, user disabled as previously
do_check_eq(check_addon_state(addons[0]), "true,false,true");
do_check_eq(check_addon_state(addons[1]), "false,false,true");
@@ -437,11 +456,11 @@ function check_test_pt3() {
do_check_eq(check_addon_state(addons[3]), "false,false,true");
// Check blockIDs are correct
- do_check_eq(blocklist.getAddonBlocklistURL(addons[0]), create_blocklistURL(addons[0].id));
- do_check_eq(blocklist.getAddonBlocklistURL(addons[1]), create_blocklistURL(addons[1].id));
- do_check_eq(blocklist.getAddonBlocklistURL(addons[2]), create_blocklistURL(addons[2].id));
- do_check_eq(blocklist.getAddonBlocklistURL(addons[3]), create_blocklistURL(addons[3].id));
- do_check_eq(blocklist.getAddonBlocklistURL(addons[4]), create_blocklistURL(addons[4].id));
+ do_check_eq(blocklist.getAddonBlocklistURL(addons[0]),create_blocklistURL(addons[0].id));
+ do_check_eq(blocklist.getAddonBlocklistURL(addons[1]),create_blocklistURL(addons[1].id));
+ do_check_eq(blocklist.getAddonBlocklistURL(addons[2]),create_blocklistURL(addons[2].id));
+ do_check_eq(blocklist.getAddonBlocklistURL(addons[3]),create_blocklistURL(addons[3].id));
+ do_check_eq(blocklist.getAddonBlocklistURL(addons[4]),create_blocklistURL(addons[4].id));
// All plugins have the same blockID on the test
do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[0]), create_blocklistURL('test_bug455906_plugin'));
@@ -488,7 +507,7 @@ function check_test_pt4() {
restartManager();
dump("Checking results pt 4\n");
- AddonManager.getAddonsByIDs(ADDONS.map(a => a.id), function(addons) {
+ AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
// This should have become unblocked
do_check_eq(check_addon_state(addons[5]), "false,false,false");
do_check_eq(check_plugin_state(PLUGINS[5]), "false,false");