toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug455906.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,536 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 + */
     1.8 +
     1.9 +const Cc = Components.classes;
    1.10 +const Ci = Components.interfaces;
    1.11 +const Cu = Components.utils;
    1.12 +const Cr = Components.results;
    1.13 +
    1.14 +const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
    1.15 +
    1.16 +Cu.import("resource://testing-common/httpd.js");
    1.17 +var gTestserver = new HttpServer();
    1.18 +gTestserver.start(-1);
    1.19 +gPort = gTestserver.identity.primaryPort;
    1.20 +
    1.21 +// register static files with server and interpolate port numbers in them
    1.22 +mapFile("/data/bug455906_warn.xml", gTestserver);
    1.23 +mapFile("/data/bug455906_start.xml", gTestserver);
    1.24 +mapFile("/data/bug455906_block.xml", gTestserver);
    1.25 +mapFile("/data/bug455906_empty.xml", gTestserver);
    1.26 +
    1.27 +// Workaround for Bug 658720 - URL formatter can leak during xpcshell tests
    1.28 +const PREF_BLOCKLIST_ITEM_URL = "extensions.blocklist.itemURL";
    1.29 +Services.prefs.setCharPref(PREF_BLOCKLIST_ITEM_URL, "http://localhost:" + gPort + "/blocklist/%blockID%");
    1.30 +
    1.31 +var ADDONS = [{
    1.32 +  // Tests how the blocklist affects a disabled add-on
    1.33 +  id: "test_bug455906_1@tests.mozilla.org",
    1.34 +  name: "Bug 455906 Addon Test 1",
    1.35 +  version: "5",
    1.36 +  appVersion: "3"
    1.37 +}, {
    1.38 +  // Tests how the blocklist affects an enabled add-on
    1.39 +  id: "test_bug455906_2@tests.mozilla.org",
    1.40 +  name: "Bug 455906 Addon Test 2",
    1.41 +  version: "5",
    1.42 +  appVersion: "3"
    1.43 +}, {
    1.44 +  // Tests how the blocklist affects an enabled add-on, to be disabled by the notification
    1.45 +  id: "test_bug455906_3@tests.mozilla.org",
    1.46 +  name: "Bug 455906 Addon Test 3",
    1.47 +  version: "5",
    1.48 +  appVersion: "3"
    1.49 +}, {
    1.50 +  // Tests how the blocklist affects a disabled add-on that was already warned about
    1.51 +  id: "test_bug455906_4@tests.mozilla.org",
    1.52 +  name: "Bug 455906 Addon Test 4",
    1.53 +  version: "5",
    1.54 +  appVersion: "3"
    1.55 +}, {
    1.56 +  // Tests how the blocklist affects an enabled add-on that was already warned about
    1.57 +  id: "test_bug455906_5@tests.mozilla.org",
    1.58 +  name: "Bug 455906 Addon Test 5",
    1.59 +  version: "5",
    1.60 +  appVersion: "3"
    1.61 +}, {
    1.62 +  // Tests how the blocklist affects an already blocked add-on
    1.63 +  id: "test_bug455906_6@tests.mozilla.org",
    1.64 +  name: "Bug 455906 Addon Test 6",
    1.65 +  version: "5",
    1.66 +  appVersion: "3"
    1.67 +}, {
    1.68 +  // Tests how the blocklist affects an incompatible add-on
    1.69 +  id: "test_bug455906_7@tests.mozilla.org",
    1.70 +  name: "Bug 455906 Addon Test 7",
    1.71 +  version: "5",
    1.72 +  appVersion: "2"
    1.73 +}, {
    1.74 +  // Spare add-on used to ensure we get a notification when switching lists
    1.75 +  id: "dummy_bug455906_1@tests.mozilla.org",
    1.76 +  name: "Dummy Addon 1",
    1.77 +  version: "5",
    1.78 +  appVersion: "3"
    1.79 +}, {
    1.80 +  // Spare add-on used to ensure we get a notification when switching lists
    1.81 +  id: "dummy_bug455906_2@tests.mozilla.org",
    1.82 +  name: "Dummy Addon 2",
    1.83 +  version: "5",
    1.84 +  appVersion: "3"
    1.85 +}];
    1.86 +
    1.87 +function MockPlugin(name, version, enabledState) {
    1.88 +  this.name = name;
    1.89 +  this.version = version;
    1.90 +  this.enabledState = enabledState;
    1.91 +}
    1.92 +Object.defineProperty(MockPlugin.prototype, "blocklisted", {
    1.93 +  get: function MockPlugin_getBlocklisted() {
    1.94 +    let bls = Cc["@mozilla.org/extensions/blocklist;1"].getService(Ci.nsIBlocklistService);
    1.95 +    return bls.getPluginBlocklistState(this) == bls.STATE_BLOCKED;
    1.96 +  }
    1.97 +});
    1.98 +Object.defineProperty(MockPlugin.prototype, "disabled", {
    1.99 +  get: function MockPlugin_getDisabled() {
   1.100 +    return this.enabledState == Ci.nsIPluginTag.STATE_DISABLED;
   1.101 +  }
   1.102 +});
   1.103 +
   1.104 +var PLUGINS = [
   1.105 +  // Tests how the blocklist affects a disabled plugin
   1.106 +  new MockPlugin("test_bug455906_1", "5", Ci.nsIPluginTag.STATE_DISABLED),
   1.107 +  // Tests how the blocklist affects an enabled plugin
   1.108 +  new MockPlugin("test_bug455906_2", "5", Ci.nsIPluginTag.STATE_ENABLED),
   1.109 +  // Tests how the blocklist affects an enabled plugin, to be disabled by the notification
   1.110 +  new MockPlugin("test_bug455906_3", "5", Ci.nsIPluginTag.STATE_ENABLED),
   1.111 +  // Tests how the blocklist affects a disabled plugin that was already warned about
   1.112 +  new MockPlugin("test_bug455906_4", "5", Ci.nsIPluginTag.STATE_DISABLED),
   1.113 +  // Tests how the blocklist affects an enabled plugin that was already warned about
   1.114 +  new MockPlugin("test_bug455906_5", "5", Ci.nsIPluginTag.STATE_ENABLED),
   1.115 +  // Tests how the blocklist affects an already blocked plugin
   1.116 +  new MockPlugin("test_bug455906_6", "5", Ci.nsIPluginTag.STATE_ENABLED)
   1.117 +];
   1.118 +
   1.119 +var gNotificationCheck = null;
   1.120 +var gTestCheck = null;
   1.121 +
   1.122 +// A fake plugin host for the blocklist service to use
   1.123 +var PluginHost = {
   1.124 +  getPluginTags: function(countRef) {
   1.125 +    countRef.value = PLUGINS.length;
   1.126 +    return PLUGINS;
   1.127 +  },
   1.128 +
   1.129 +  QueryInterface: function(iid) {
   1.130 +    if (iid.equals(Ci.nsIPluginHost)
   1.131 +     || iid.equals(Ci.nsISupports))
   1.132 +      return this;
   1.133 +  
   1.134 +    throw Components.results.NS_ERROR_NO_INTERFACE;
   1.135 +  }
   1.136 +}
   1.137 +
   1.138 +var PluginHostFactory = {
   1.139 +  createInstance: function (outer, iid) {
   1.140 +    if (outer != null)
   1.141 +      throw Components.results.NS_ERROR_NO_AGGREGATION;
   1.142 +    return PluginHost.QueryInterface(iid);
   1.143 +  }
   1.144 +};
   1.145 +
   1.146 +// Don't need the full interface, attempts to call other methods will just
   1.147 +// throw which is just fine
   1.148 +var WindowWatcher = {
   1.149 +  openWindow: function(parent, url, name, features, windowArguments) {
   1.150 +    // Should be called to list the newly blocklisted items
   1.151 +    do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG);
   1.152 +
   1.153 +    if (gNotificationCheck) {
   1.154 +      var args = windowArguments.wrappedJSObject;
   1.155 +      gNotificationCheck(args);
   1.156 +    }
   1.157 +
   1.158 +    //run the code after the blocklist is closed
   1.159 +    Services.obs.notifyObservers(null, "addon-blocklist-closed", null);
   1.160 +
   1.161 +    // Call the next test after the blocklist has finished up
   1.162 +    do_timeout(0, gTestCheck);
   1.163 +  },
   1.164 +
   1.165 +  QueryInterface: function(iid) {
   1.166 +    if (iid.equals(Ci.nsIWindowWatcher)
   1.167 +     || iid.equals(Ci.nsISupports))
   1.168 +      return this;
   1.169 +
   1.170 +    throw Cr.NS_ERROR_NO_INTERFACE;
   1.171 +  }
   1.172 +}
   1.173 +
   1.174 +var WindowWatcherFactory = {
   1.175 +  createInstance: function createInstance(outer, iid) {
   1.176 +    if (outer != null)
   1.177 +      throw Components.results.NS_ERROR_NO_AGGREGATION;
   1.178 +    return WindowWatcher.QueryInterface(iid);
   1.179 +  }
   1.180 +};
   1.181 +var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
   1.182 +registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"),
   1.183 +                          "Fake Plugin Host",
   1.184 +                          "@mozilla.org/plugin/host;1", PluginHostFactory);
   1.185 +registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
   1.186 +                          "Fake Window Watcher",
   1.187 +                          "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory);
   1.188 +
   1.189 +function create_addon(addon) {
   1.190 +  var installrdf = "<?xml version=\"1.0\"?>\n" +
   1.191 +                   "\n" +
   1.192 +                   "<RDF xmlns=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" +
   1.193 +                   "     xmlns:em=\"http://www.mozilla.org/2004/em-rdf#\">\n" +
   1.194 +                   "  <Description about=\"urn:mozilla:install-manifest\">\n" +
   1.195 +                   "    <em:id>" + addon.id + "</em:id>\n" +
   1.196 +                   "    <em:version>" + addon.version + "</em:version>\n" +
   1.197 +                   "    <em:targetApplication>\n" +
   1.198 +                   "      <Description>\n" +
   1.199 +                   "        <em:id>xpcshell@tests.mozilla.org</em:id>\n" +
   1.200 +                   "        <em:minVersion>" + addon.appVersion + "</em:minVersion>\n" +
   1.201 +                   "        <em:maxVersion>" + addon.appVersion + "</em:maxVersion>\n" +
   1.202 +                   "      </Description>\n" +
   1.203 +                   "    </em:targetApplication>\n" +
   1.204 +                   "    <em:name>" + addon.name + "</em:name>\n" +
   1.205 +                   "  </Description>\n" +
   1.206 +                   "</RDF>\n";
   1.207 +  var target = gProfD.clone();
   1.208 +  target.append("extensions");
   1.209 +  target.append(addon.id);
   1.210 +  target.append("install.rdf");
   1.211 +  target.create(target.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
   1.212 +  var stream = Cc["@mozilla.org/network/file-output-stream;1"].
   1.213 +               createInstance(Ci.nsIFileOutputStream);
   1.214 +  stream.init(target,
   1.215 +              FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
   1.216 +              FileUtils.PERMS_FILE, 0);
   1.217 +  stream.write(installrdf, installrdf.length);
   1.218 +  stream.close();
   1.219 +}
   1.220 +
   1.221 +function load_blocklist(file) {
   1.222 +  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/" + file);
   1.223 +  var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
   1.224 +                  getService(Ci.nsITimerCallback);
   1.225 +  blocklist.notify(null);
   1.226 +}
   1.227 +
   1.228 +function check_addon_state(addon) {
   1.229 +  return addon.userDisabled + "," + addon.softDisabled + "," + addon.appDisabled;
   1.230 +}
   1.231 +
   1.232 +function check_plugin_state(plugin) {
   1.233 +  return plugin.disabled + "," + plugin.blocklisted;
   1.234 +}
   1.235 +
   1.236 +function create_blocklistURL(blockID){
   1.237 +  let url = Services.urlFormatter.formatURLPref(PREF_BLOCKLIST_ITEM_URL);
   1.238 +  url = url.replace(/%blockID%/g, blockID);
   1.239 +  return url;
   1.240 +}
   1.241 +
   1.242 +// Performs the initial setup
   1.243 +function run_test() {
   1.244 +  // Setup for test
   1.245 +  dump("Setting up tests\n");
   1.246 +  // Rather than keeping lots of identical add-ons in version control, just
   1.247 +  // write them into the profile.
   1.248 +  for (let addon of ADDONS)
   1.249 +    create_addon(addon);
   1.250 +
   1.251 +  // Copy the initial blocklist into the profile to check add-ons start in the
   1.252 +  // right state.
   1.253 +  copyBlocklistToProfile(do_get_file("data/bug455906_start.xml"));
   1.254 +
   1.255 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8");
   1.256 +  startupManager();
   1.257 +
   1.258 +  do_test_pending();
   1.259 +  check_test_pt1();
   1.260 +}
   1.261 +
   1.262 +// Before every main test this is the state the add-ons are meant to be in
   1.263 +function check_initial_state(callback) {
   1.264 +  AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
   1.265 +    do_check_eq(check_addon_state(addons[0]), "true,false,false");
   1.266 +    do_check_eq(check_addon_state(addons[1]), "false,false,false");
   1.267 +    do_check_eq(check_addon_state(addons[2]), "false,false,false");
   1.268 +    do_check_eq(check_addon_state(addons[3]), "true,true,false");
   1.269 +    do_check_eq(check_addon_state(addons[4]), "false,false,false");
   1.270 +    do_check_eq(check_addon_state(addons[5]), "false,false,true");
   1.271 +    do_check_eq(check_addon_state(addons[6]), "false,false,true");
   1.272 +  
   1.273 +    do_check_eq(check_plugin_state(PLUGINS[0]), "true,false");
   1.274 +    do_check_eq(check_plugin_state(PLUGINS[1]), "false,false");
   1.275 +    do_check_eq(check_plugin_state(PLUGINS[2]), "false,false");
   1.276 +    do_check_eq(check_plugin_state(PLUGINS[3]), "true,false");
   1.277 +    do_check_eq(check_plugin_state(PLUGINS[4]), "false,false");
   1.278 +    do_check_eq(check_plugin_state(PLUGINS[5]), "false,true");
   1.279 +
   1.280 +    callback();
   1.281 +  });
   1.282 +}
   1.283 +
   1.284 +// Tests the add-ons were installed and the initial blocklist applied as expected
   1.285 +function check_test_pt1() {
   1.286 +  dump("Checking pt 1\n");
   1.287 +
   1.288 +  AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], callback_soon(function(addons) {
   1.289 +    for (var i = 0; i < ADDONS.length; i++) {
   1.290 +      if (!addons[i])
   1.291 +        do_throw("Addon " + (i + 1) + " did not get installed correctly");
   1.292 +    }
   1.293 +  
   1.294 +    do_check_eq(check_addon_state(addons[0]), "false,false,false");
   1.295 +    do_check_eq(check_addon_state(addons[1]), "false,false,false");
   1.296 +    do_check_eq(check_addon_state(addons[2]), "false,false,false");
   1.297 +  
   1.298 +    // Warn add-ons should be soft disabled automatically
   1.299 +    do_check_eq(check_addon_state(addons[3]), "true,true,false");
   1.300 +    do_check_eq(check_addon_state(addons[4]), "true,true,false");
   1.301 +  
   1.302 +    // Blocked and incompatible should be app disabled only
   1.303 +    do_check_eq(check_addon_state(addons[5]), "false,false,true");
   1.304 +    do_check_eq(check_addon_state(addons[6]), "false,false,true");
   1.305 +  
   1.306 +    // We've overridden the plugin host so we cannot tell what that would have
   1.307 +    // initialised the plugins as
   1.308 +  
   1.309 +    // Put the add-ons into the base state
   1.310 +    addons[0].userDisabled = true;
   1.311 +    addons[4].userDisabled = false;
   1.312 +
   1.313 +    restartManager();
   1.314 +    check_initial_state(function() {
   1.315 +      gNotificationCheck = check_notification_pt2;
   1.316 +      gTestCheck = check_test_pt2;
   1.317 +      load_blocklist("bug455906_warn.xml");
   1.318 +    });
   1.319 +  }));
   1.320 +}
   1.321 +
   1.322 +function check_notification_pt2(args) {
   1.323 +  dump("Checking notification pt 2\n");
   1.324 +  do_check_eq(args.list.length, 4);
   1.325 +
   1.326 +  for (let addon of args.list) {
   1.327 +    if (addon.item instanceof Ci.nsIPluginTag) {
   1.328 +      switch (addon.item.name) {
   1.329 +        case "test_bug455906_2":
   1.330 +          do_check_false(addon.blocked);
   1.331 +          break;
   1.332 +        case "test_bug455906_3":
   1.333 +          do_check_false(addon.blocked);
   1.334 +          addon.disable = true;
   1.335 +          break;
   1.336 +        default:
   1.337 +          do_throw("Unknown addon: " + addon.item.name);
   1.338 +      }
   1.339 +    }
   1.340 +    else {
   1.341 +      switch (addon.item.id) {
   1.342 +        case "test_bug455906_2@tests.mozilla.org":
   1.343 +          do_check_false(addon.blocked);
   1.344 +          break;
   1.345 +        case "test_bug455906_3@tests.mozilla.org":
   1.346 +          do_check_false(addon.blocked);
   1.347 +          addon.disable = true;
   1.348 +          break;
   1.349 +        default:
   1.350 +          do_throw("Unknown addon: " + addon.item.id);
   1.351 +      }
   1.352 +    }
   1.353 +  }
   1.354 +}
   1.355 +
   1.356 +function check_test_pt2() {
   1.357 +  restartManager();
   1.358 +  dump("Checking results pt 2\n");
   1.359 +
   1.360 +  AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], callback_soon(function(addons) {
   1.361 +    // Should have disabled this add-on as requested
   1.362 +    do_check_eq(check_addon_state(addons[2]), "true,true,false");
   1.363 +    do_check_eq(check_plugin_state(PLUGINS[2]), "true,false");
   1.364 +
   1.365 +    // The blocked add-on should have changed to soft disabled
   1.366 +    do_check_eq(check_addon_state(addons[5]), "true,true,false");
   1.367 +    do_check_eq(check_plugin_state(PLUGINS[5]), "true,false");
   1.368 +
   1.369 +    // These should have been unchanged
   1.370 +    do_check_eq(check_addon_state(addons[0]), "true,false,false");
   1.371 +    do_check_eq(check_addon_state(addons[1]), "false,false,false");
   1.372 +    do_check_eq(check_addon_state(addons[3]), "true,true,false");
   1.373 +    do_check_eq(check_addon_state(addons[4]), "false,false,false");
   1.374 +    do_check_eq(check_addon_state(addons[6]), "false,false,true");
   1.375 +    do_check_eq(check_plugin_state(PLUGINS[0]), "true,false");
   1.376 +    do_check_eq(check_plugin_state(PLUGINS[1]), "false,false");
   1.377 +    do_check_eq(check_plugin_state(PLUGINS[3]), "true,false");
   1.378 +    do_check_eq(check_plugin_state(PLUGINS[4]), "false,false");
   1.379 +
   1.380 +    // Back to starting state
   1.381 +    addons[2].userDisabled = false;
   1.382 +    addons[5].userDisabled = false;
   1.383 +    PLUGINS[2].enabledState = Ci.nsIPluginTag.STATE_ENABLED;
   1.384 +    PLUGINS[5].enabledState = Ci.nsIPluginTag.STATE_ENABLED;
   1.385 +    restartManager();
   1.386 +    gNotificationCheck = null;
   1.387 +    gTestCheck = run_test_pt3;
   1.388 +    load_blocklist("bug455906_start.xml");
   1.389 +  }));
   1.390 +}
   1.391 +
   1.392 +function run_test_pt3() {
   1.393 +  restartManager();
   1.394 +  check_initial_state(function() {
   1.395 +    gNotificationCheck = check_notification_pt3;
   1.396 +    gTestCheck = check_test_pt3;
   1.397 +    load_blocklist("bug455906_block.xml");
   1.398 +  });
   1.399 +}
   1.400 +
   1.401 +function check_notification_pt3(args) {
   1.402 +  dump("Checking notification pt 3\n");
   1.403 +  do_check_eq(args.list.length, 6);
   1.404 +
   1.405 +  for (let addon of args.list) {
   1.406 +    if (addon.item instanceof Ci.nsIPluginTag) {
   1.407 +      switch (addon.item.name) {
   1.408 +        case "test_bug455906_2":
   1.409 +          do_check_true(addon.blocked);
   1.410 +          break;
   1.411 +        case "test_bug455906_3":
   1.412 +          do_check_true(addon.blocked);
   1.413 +          break;
   1.414 +        case "test_bug455906_5":
   1.415 +          do_check_true(addon.blocked);
   1.416 +          break;
   1.417 +        default:
   1.418 +          do_throw("Unknown addon: " + addon.item.name);
   1.419 +      }
   1.420 +    }
   1.421 +    else {
   1.422 +      switch (addon.item.id) {
   1.423 +        case "test_bug455906_2@tests.mozilla.org":
   1.424 +          do_check_true(addon.blocked);
   1.425 +          break;
   1.426 +        case "test_bug455906_3@tests.mozilla.org":
   1.427 +          do_check_true(addon.blocked);
   1.428 +          break;
   1.429 +        case "test_bug455906_5@tests.mozilla.org":
   1.430 +          do_check_true(addon.blocked);
   1.431 +          break;
   1.432 +        default:
   1.433 +          do_throw("Unknown addon: " + addon.item.id);
   1.434 +      }
   1.435 +    }
   1.436 +  }
   1.437 +}
   1.438 +
   1.439 +function check_test_pt3() {
   1.440 +  restartManager();
   1.441 +  dump("Checking results pt 3\n");
   1.442 +
   1.443 +  let blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
   1.444 +                  getService(Ci.nsIBlocklistService);
   1.445 +
   1.446 +  AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
   1.447 +    // All should have gained the blocklist state, user disabled as previously
   1.448 +    do_check_eq(check_addon_state(addons[0]), "true,false,true");
   1.449 +    do_check_eq(check_addon_state(addons[1]), "false,false,true");
   1.450 +    do_check_eq(check_addon_state(addons[2]), "false,false,true");
   1.451 +    do_check_eq(check_addon_state(addons[4]), "false,false,true");
   1.452 +    do_check_eq(check_plugin_state(PLUGINS[0]), "true,true");
   1.453 +    do_check_eq(check_plugin_state(PLUGINS[1]), "false,true");
   1.454 +    do_check_eq(check_plugin_state(PLUGINS[2]), "false,true");
   1.455 +    do_check_eq(check_plugin_state(PLUGINS[3]), "true,true");
   1.456 +    do_check_eq(check_plugin_state(PLUGINS[4]), "false,true");
   1.457 +
   1.458 +    // Should have gained the blocklist state but no longer be soft disabled
   1.459 +    do_check_eq(check_addon_state(addons[3]), "false,false,true");
   1.460 +
   1.461 +    // Check blockIDs are correct
   1.462 +    do_check_eq(blocklist.getAddonBlocklistURL(addons[0]),create_blocklistURL(addons[0].id));
   1.463 +    do_check_eq(blocklist.getAddonBlocklistURL(addons[1]),create_blocklistURL(addons[1].id));
   1.464 +    do_check_eq(blocklist.getAddonBlocklistURL(addons[2]),create_blocklistURL(addons[2].id));
   1.465 +    do_check_eq(blocklist.getAddonBlocklistURL(addons[3]),create_blocklistURL(addons[3].id));
   1.466 +    do_check_eq(blocklist.getAddonBlocklistURL(addons[4]),create_blocklistURL(addons[4].id));
   1.467 +
   1.468 +    // All plugins have the same blockID on the test
   1.469 +    do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[0]), create_blocklistURL('test_bug455906_plugin'));
   1.470 +    do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[1]), create_blocklistURL('test_bug455906_plugin'));
   1.471 +    do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[2]), create_blocklistURL('test_bug455906_plugin'));
   1.472 +    do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[3]), create_blocklistURL('test_bug455906_plugin'));
   1.473 +    do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[4]), create_blocklistURL('test_bug455906_plugin'));
   1.474 +
   1.475 +    // Shouldn't be changed
   1.476 +    do_check_eq(check_addon_state(addons[5]), "false,false,true");
   1.477 +    do_check_eq(check_addon_state(addons[6]), "false,false,true");
   1.478 +    do_check_eq(check_plugin_state(PLUGINS[5]), "false,true");
   1.479 +
   1.480 +    // Back to starting state
   1.481 +    gNotificationCheck = null;
   1.482 +    gTestCheck = run_test_pt4;
   1.483 +    load_blocklist("bug455906_start.xml");
   1.484 +  });
   1.485 +}
   1.486 +
   1.487 +function run_test_pt4() {
   1.488 +  AddonManager.getAddonByID(ADDONS[4].id, callback_soon(function(addon) {
   1.489 +    addon.userDisabled = false;
   1.490 +    PLUGINS[4].enabledState = Ci.nsIPluginTag.STATE_ENABLED;
   1.491 +    restartManager();
   1.492 +    check_initial_state(function() {
   1.493 +      gNotificationCheck = check_notification_pt4;
   1.494 +      gTestCheck = check_test_pt4;
   1.495 +      load_blocklist("bug455906_empty.xml");
   1.496 +    });
   1.497 +  }));
   1.498 +}
   1.499 +
   1.500 +function check_notification_pt4(args) {
   1.501 +  dump("Checking notification pt 4\n");
   1.502 +
   1.503 +  // Should be just the dummy add-on to force this notification
   1.504 +  do_check_eq(args.list.length, 1);
   1.505 +  do_check_false(args.list[0].item instanceof Ci.nsIPluginTag);
   1.506 +  do_check_eq(args.list[0].item.id, "dummy_bug455906_2@tests.mozilla.org");
   1.507 +}
   1.508 +
   1.509 +function check_test_pt4() {
   1.510 +  restartManager();
   1.511 +  dump("Checking results pt 4\n");
   1.512 +
   1.513 +  AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
   1.514 +    // This should have become unblocked
   1.515 +    do_check_eq(check_addon_state(addons[5]), "false,false,false");
   1.516 +    do_check_eq(check_plugin_state(PLUGINS[5]), "false,false");
   1.517 +
   1.518 +    // Should get re-enabled
   1.519 +    do_check_eq(check_addon_state(addons[3]), "false,false,false");
   1.520 +
   1.521 +    // No change for anything else
   1.522 +    do_check_eq(check_addon_state(addons[0]), "true,false,false");
   1.523 +    do_check_eq(check_addon_state(addons[1]), "false,false,false");
   1.524 +    do_check_eq(check_addon_state(addons[2]), "false,false,false");
   1.525 +    do_check_eq(check_addon_state(addons[4]), "false,false,false");
   1.526 +    do_check_eq(check_addon_state(addons[6]), "false,false,true");
   1.527 +    do_check_eq(check_plugin_state(PLUGINS[0]), "true,false");
   1.528 +    do_check_eq(check_plugin_state(PLUGINS[1]), "false,false");
   1.529 +    do_check_eq(check_plugin_state(PLUGINS[2]), "false,false");
   1.530 +    do_check_eq(check_plugin_state(PLUGINS[3]), "true,false");
   1.531 +    do_check_eq(check_plugin_state(PLUGINS[4]), "false,false");
   1.532 +
   1.533 +    finish();
   1.534 +  });
   1.535 +}
   1.536 +
   1.537 +function finish() {
   1.538 +  gTestserver.stop(do_test_finished);
   1.539 +}

mercurial