toolkit/mozapps/extensions/test/xpcshell/test_blocklistchange.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_blocklistchange.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1433 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +// Checks that changes that cause an add-on to become unblocked or blocked have
     1.9 +// the right effect
    1.10 +
    1.11 +// The tests follow a mostly common pattern. First they start with the add-ons
    1.12 +// unblocked, then they make a change that causes the add-ons to become blocked
    1.13 +// then they make a similar change that keeps the add-ons blocked then they make
    1.14 +// a change that unblocks the add-ons. Some tests skip the initial part and
    1.15 +// start with add-ons detected as blocked.
    1.16 +
    1.17 +// softblock1 is enabled/disabled by the blocklist changes so its softDisabled
    1.18 +// property should always match its userDisabled property
    1.19 +
    1.20 +// softblock2 gets manually enabled then disabled after it becomes blocked so
    1.21 +// its softDisabled property should never become true after that
    1.22 +
    1.23 +// softblock3 does the same as softblock2 however it remains disabled
    1.24 +
    1.25 +// softblock4 is disabled while unblocked and so should never have softDisabled
    1.26 +// set to true and stay userDisabled. This add-on is not used in tests that
    1.27 +// start with add-ons blocked as it would be identical to softblock3
    1.28 +
    1.29 +// softblock5 is a theme. Currently themes just get disabled when they become
    1.30 +// softblocked and have to be manually re-enabled if they become completely
    1.31 +// unblocked (bug 657520)
    1.32 +
    1.33 +const Cc = Components.classes;
    1.34 +const Ci = Components.interfaces;
    1.35 +const Cu = Components.utils;
    1.36 +const Cr = Components.results;
    1.37 +
    1.38 +const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
    1.39 +
    1.40 +Cu.import("resource://gre/modules/NetUtil.jsm");
    1.41 +
    1.42 +// Allow insecure updates
    1.43 +Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false)
    1.44 +
    1.45 +Cu.import("resource://testing-common/httpd.js");
    1.46 +var testserver = new HttpServer();
    1.47 +testserver.start(-1);
    1.48 +gPort = testserver.identity.primaryPort;
    1.49 +
    1.50 +// register static files with server and interpolate port numbers in them
    1.51 +mapFile("/data/blocklistchange/addon_update1.rdf", testserver);
    1.52 +mapFile("/data/blocklistchange/addon_update2.rdf", testserver);
    1.53 +mapFile("/data/blocklistchange/addon_update3.rdf", testserver);
    1.54 +mapFile("/data/blocklistchange/addon_change.xml", testserver);
    1.55 +mapFile("/data/blocklistchange/app_update.xml", testserver);
    1.56 +mapFile("/data/blocklistchange/blocklist_update1.xml", testserver);
    1.57 +mapFile("/data/blocklistchange/blocklist_update2.xml", testserver);
    1.58 +mapFile("/data/blocklistchange/manual_update.xml", testserver);
    1.59 +
    1.60 +testserver.registerDirectory("/addons/", do_get_file("addons"));
    1.61 +
    1.62 +
    1.63 +var default_theme = {
    1.64 +  id: "default@tests.mozilla.org",
    1.65 +  version: "1.0",
    1.66 +  name: "Softblocked add-on",
    1.67 +  internalName: "classic/1.0",
    1.68 +  targetApplications: [{
    1.69 +    id: "xpcshell@tests.mozilla.org",
    1.70 +    minVersion: "1",
    1.71 +    maxVersion: "3"
    1.72 +  }]
    1.73 +};
    1.74 +
    1.75 +var softblock1_1 = {
    1.76 +  id: "softblock1@tests.mozilla.org",
    1.77 +  version: "1.0",
    1.78 +  name: "Softblocked add-on",
    1.79 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update1.rdf",
    1.80 +  targetApplications: [{
    1.81 +    id: "xpcshell@tests.mozilla.org",
    1.82 +    minVersion: "1",
    1.83 +    maxVersion: "3"
    1.84 +  }]
    1.85 +};
    1.86 +
    1.87 +var softblock1_2 = {
    1.88 +  id: "softblock1@tests.mozilla.org",
    1.89 +  version: "2.0",
    1.90 +  name: "Softblocked add-on",
    1.91 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update2.rdf",
    1.92 +  targetApplications: [{
    1.93 +    id: "xpcshell@tests.mozilla.org",
    1.94 +    minVersion: "1",
    1.95 +    maxVersion: "3"
    1.96 +  }]
    1.97 +};
    1.98 +
    1.99 +var softblock1_3 = {
   1.100 +  id: "softblock1@tests.mozilla.org",
   1.101 +  version: "3.0",
   1.102 +  name: "Softblocked add-on",
   1.103 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update3.rdf",
   1.104 +  targetApplications: [{
   1.105 +    id: "xpcshell@tests.mozilla.org",
   1.106 +    minVersion: "1",
   1.107 +    maxVersion: "3"
   1.108 +  }]
   1.109 +};
   1.110 +
   1.111 +var softblock2_1 = {
   1.112 +  id: "softblock2@tests.mozilla.org",
   1.113 +  version: "1.0",
   1.114 +  name: "Softblocked add-on",
   1.115 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update1.rdf",
   1.116 +  targetApplications: [{
   1.117 +    id: "xpcshell@tests.mozilla.org",
   1.118 +    minVersion: "1",
   1.119 +    maxVersion: "3"
   1.120 +  }]
   1.121 +};
   1.122 +
   1.123 +var softblock2_2 = {
   1.124 +  id: "softblock2@tests.mozilla.org",
   1.125 +  version: "2.0",
   1.126 +  name: "Softblocked add-on",
   1.127 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update2.rdf",
   1.128 +  targetApplications: [{
   1.129 +    id: "xpcshell@tests.mozilla.org",
   1.130 +    minVersion: "1",
   1.131 +    maxVersion: "3"
   1.132 +  }]
   1.133 +};
   1.134 +
   1.135 +var softblock2_3 = {
   1.136 +  id: "softblock2@tests.mozilla.org",
   1.137 +  version: "3.0",
   1.138 +  name: "Softblocked add-on",
   1.139 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update3.rdf",
   1.140 +  targetApplications: [{
   1.141 +    id: "xpcshell@tests.mozilla.org",
   1.142 +    minVersion: "1",
   1.143 +    maxVersion: "3"
   1.144 +  }]
   1.145 +};
   1.146 +
   1.147 +var softblock3_1 = {
   1.148 +  id: "softblock3@tests.mozilla.org",
   1.149 +  version: "1.0",
   1.150 +  name: "Softblocked add-on",
   1.151 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update1.rdf",
   1.152 +  targetApplications: [{
   1.153 +    id: "xpcshell@tests.mozilla.org",
   1.154 +    minVersion: "1",
   1.155 +    maxVersion: "3"
   1.156 +  }]
   1.157 +};
   1.158 +
   1.159 +var softblock3_2 = {
   1.160 +  id: "softblock3@tests.mozilla.org",
   1.161 +  version: "2.0",
   1.162 +  name: "Softblocked add-on",
   1.163 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update2.rdf",
   1.164 +  targetApplications: [{
   1.165 +    id: "xpcshell@tests.mozilla.org",
   1.166 +    minVersion: "1",
   1.167 +    maxVersion: "3"
   1.168 +  }]
   1.169 +};
   1.170 +
   1.171 +var softblock3_3 = {
   1.172 +  id: "softblock3@tests.mozilla.org",
   1.173 +  version: "3.0",
   1.174 +  name: "Softblocked add-on",
   1.175 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update3.rdf",
   1.176 +  targetApplications: [{
   1.177 +    id: "xpcshell@tests.mozilla.org",
   1.178 +    minVersion: "1",
   1.179 +    maxVersion: "3"
   1.180 +  }]
   1.181 +};
   1.182 +
   1.183 +var softblock4_1 = {
   1.184 +  id: "softblock4@tests.mozilla.org",
   1.185 +  version: "1.0",
   1.186 +  name: "Softblocked add-on",
   1.187 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update1.rdf",
   1.188 +  targetApplications: [{
   1.189 +    id: "xpcshell@tests.mozilla.org",
   1.190 +    minVersion: "1",
   1.191 +    maxVersion: "3"
   1.192 +  }]
   1.193 +};
   1.194 +
   1.195 +var softblock4_2 = {
   1.196 +  id: "softblock4@tests.mozilla.org",
   1.197 +  version: "2.0",
   1.198 +  name: "Softblocked add-on",
   1.199 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update2.rdf",
   1.200 +  targetApplications: [{
   1.201 +    id: "xpcshell@tests.mozilla.org",
   1.202 +    minVersion: "1",
   1.203 +    maxVersion: "3"
   1.204 +  }]
   1.205 +};
   1.206 +
   1.207 +var softblock4_3 = {
   1.208 +  id: "softblock4@tests.mozilla.org",
   1.209 +  version: "3.0",
   1.210 +  name: "Softblocked add-on",
   1.211 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update3.rdf",
   1.212 +  targetApplications: [{
   1.213 +    id: "xpcshell@tests.mozilla.org",
   1.214 +    minVersion: "1",
   1.215 +    maxVersion: "3"
   1.216 +  }]
   1.217 +};
   1.218 +
   1.219 +var softblock5_1 = {
   1.220 +  id: "softblock5@tests.mozilla.org",
   1.221 +  version: "1.0",
   1.222 +  name: "Softblocked add-on",
   1.223 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update1.rdf",
   1.224 +  internalName: "test/1.0",
   1.225 +  targetApplications: [{
   1.226 +    id: "xpcshell@tests.mozilla.org",
   1.227 +    minVersion: "1",
   1.228 +    maxVersion: "3"
   1.229 +  }]
   1.230 +};
   1.231 +
   1.232 +var softblock5_2 = {
   1.233 +  id: "softblock5@tests.mozilla.org",
   1.234 +  version: "2.0",
   1.235 +  name: "Softblocked add-on",
   1.236 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update2.rdf",
   1.237 +  internalName: "test/1.0",
   1.238 +  targetApplications: [{
   1.239 +    id: "xpcshell@tests.mozilla.org",
   1.240 +    minVersion: "1",
   1.241 +    maxVersion: "3"
   1.242 +  }]
   1.243 +};
   1.244 +
   1.245 +var softblock5_3 = {
   1.246 +  id: "softblock5@tests.mozilla.org",
   1.247 +  version: "3.0",
   1.248 +  name: "Softblocked add-on",
   1.249 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update3.rdf",
   1.250 +  internalName: "test/1.0",
   1.251 +  targetApplications: [{
   1.252 +    id: "xpcshell@tests.mozilla.org",
   1.253 +    minVersion: "1",
   1.254 +    maxVersion: "3"
   1.255 +  }]
   1.256 +};
   1.257 +
   1.258 +var hardblock_1 = {
   1.259 +  id: "hardblock@tests.mozilla.org",
   1.260 +  version: "1.0",
   1.261 +  name: "Hardblocked add-on",
   1.262 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update1.rdf",
   1.263 +  targetApplications: [{
   1.264 +    id: "xpcshell@tests.mozilla.org",
   1.265 +    minVersion: "1",
   1.266 +    maxVersion: "3"
   1.267 +  }]
   1.268 +};
   1.269 +
   1.270 +var hardblock_2 = {
   1.271 +  id: "hardblock@tests.mozilla.org",
   1.272 +  version: "2.0",
   1.273 +  name: "Hardblocked add-on",
   1.274 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update2.rdf",
   1.275 +  targetApplications: [{
   1.276 +    id: "xpcshell@tests.mozilla.org",
   1.277 +    minVersion: "1",
   1.278 +    maxVersion: "3"
   1.279 +  }]
   1.280 +};
   1.281 +
   1.282 +var hardblock_3 = {
   1.283 +  id: "hardblock@tests.mozilla.org",
   1.284 +  version: "3.0",
   1.285 +  name: "Hardblocked add-on",
   1.286 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update3.rdf",
   1.287 +  targetApplications: [{
   1.288 +    id: "xpcshell@tests.mozilla.org",
   1.289 +    minVersion: "1",
   1.290 +    maxVersion: "3"
   1.291 +  }]
   1.292 +};
   1.293 +
   1.294 +var regexpblock_1 = {
   1.295 +  id: "regexpblock@tests.mozilla.org",
   1.296 +  version: "1.0",
   1.297 +  name: "RegExp-blocked add-on",
   1.298 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update1.rdf",
   1.299 +  targetApplications: [{
   1.300 +    id: "xpcshell@tests.mozilla.org",
   1.301 +    minVersion: "1",
   1.302 +    maxVersion: "3"
   1.303 +  }]
   1.304 +};
   1.305 +
   1.306 +var regexpblock_2 = {
   1.307 +  id: "regexpblock@tests.mozilla.org",
   1.308 +  version: "2.0",
   1.309 +  name: "RegExp-blocked add-on",
   1.310 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update2.rdf",
   1.311 +  targetApplications: [{
   1.312 +    id: "xpcshell@tests.mozilla.org",
   1.313 +    minVersion: "1",
   1.314 +    maxVersion: "3"
   1.315 +  }]
   1.316 +};
   1.317 +
   1.318 +var regexpblock_3 = {
   1.319 +  id: "regexpblock@tests.mozilla.org",
   1.320 +  version: "3.0",
   1.321 +  name: "RegExp-blocked add-on",
   1.322 +  updateURL: "http://localhost:" + gPort + "/data/blocklistchange/addon_update3.rdf",
   1.323 +  targetApplications: [{
   1.324 +    id: "xpcshell@tests.mozilla.org",
   1.325 +    minVersion: "1",
   1.326 +    maxVersion: "3"
   1.327 +  }]
   1.328 +};
   1.329 +
   1.330 +const ADDON_IDS = ["softblock1@tests.mozilla.org",
   1.331 +                   "softblock2@tests.mozilla.org",
   1.332 +                   "softblock3@tests.mozilla.org",
   1.333 +                   "softblock4@tests.mozilla.org",
   1.334 +                   "softblock5@tests.mozilla.org",
   1.335 +                   "hardblock@tests.mozilla.org",
   1.336 +                   "regexpblock@tests.mozilla.org"];
   1.337 +
   1.338 +// Don't need the full interface, attempts to call other methods will just
   1.339 +// throw which is just fine
   1.340 +var WindowWatcher = {
   1.341 +  openWindow: function(parent, url, name, features, openArgs) {
   1.342 +    // Should be called to list the newly blocklisted items
   1.343 +    do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG);
   1.344 +
   1.345 +    // Simulate auto-disabling any softblocks
   1.346 +    var list = openArgs.wrappedJSObject.list;
   1.347 +    list.forEach(function(aItem) {
   1.348 +      if (!aItem.blocked)
   1.349 +        aItem.disable = true;
   1.350 +    });
   1.351 +
   1.352 +    //run the code after the blocklist is closed
   1.353 +    Services.obs.notifyObservers(null, "addon-blocklist-closed", null);
   1.354 +
   1.355 +  },
   1.356 +
   1.357 +  QueryInterface: function(iid) {
   1.358 +    if (iid.equals(Ci.nsIWindowWatcher)
   1.359 +     || iid.equals(Ci.nsISupports))
   1.360 +      return this;
   1.361 +
   1.362 +    throw Cr.NS_ERROR_NO_INTERFACE;
   1.363 +  }
   1.364 +};
   1.365 +
   1.366 +var WindowWatcherFactory = {
   1.367 +  createInstance: function createInstance(outer, iid) {
   1.368 +    if (outer != null)
   1.369 +      throw Components.results.NS_ERROR_NO_AGGREGATION;
   1.370 +    return WindowWatcher.QueryInterface(iid);
   1.371 +  }
   1.372 +};
   1.373 +
   1.374 +var InstallConfirm = {
   1.375 +  confirm: function(aWindow, aUrl, aInstalls, aInstallCount) {
   1.376 +    aInstalls.forEach(function(aInstall) {
   1.377 +      aInstall.install();
   1.378 +    });
   1.379 +  },
   1.380 +
   1.381 +  QueryInterface: function(iid) {
   1.382 +    if (iid.equals(Ci.amIWebInstallPrompt)
   1.383 +     || iid.equals(Ci.nsISupports))
   1.384 +      return this;
   1.385 +
   1.386 +    throw Cr.NS_ERROR_NO_INTERFACE;
   1.387 +  }
   1.388 +};
   1.389 +
   1.390 +var InstallConfirmFactory = {
   1.391 +  createInstance: function createInstance(outer, iid) {
   1.392 +    if (outer != null)
   1.393 +      throw Components.results.NS_ERROR_NO_AGGREGATION;
   1.394 +    return InstallConfirm.QueryInterface(iid);
   1.395 +  }
   1.396 +};
   1.397 +
   1.398 +var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
   1.399 +registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
   1.400 +                          "Fake Window Watcher",
   1.401 +                          "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory);
   1.402 +registrar.registerFactory(Components.ID("{f0863905-4dde-42e2-991c-2dc8209bc9ca}"),
   1.403 +                          "Fake Install Prompt",
   1.404 +                          "@mozilla.org/addons/web-install-prompt;1", InstallConfirmFactory);
   1.405 +
   1.406 +const profileDir = gProfD.clone();
   1.407 +profileDir.append("extensions");
   1.408 +
   1.409 +function load_blocklist(aFile, aCallback) {
   1.410 +  Services.obs.addObserver(function() {
   1.411 +    Services.obs.removeObserver(arguments.callee, "blocklist-updated");
   1.412 +
   1.413 +    do_execute_soon(aCallback);
   1.414 +  }, "blocklist-updated", false);
   1.415 +
   1.416 +  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/blocklistchange/" + aFile);
   1.417 +  var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
   1.418 +                  getService(Ci.nsITimerCallback);
   1.419 +  blocklist.notify(null);
   1.420 +}
   1.421 +
   1.422 +// Does a background update check for add-ons and waits for any started installs
   1.423 +// to complete
   1.424 +function background_update(aCallback) {
   1.425 +  var installCount = 0;
   1.426 +  var backgroundCheckCompleted = false;
   1.427 +
   1.428 +  AddonManager.addInstallListener({
   1.429 +    onNewInstall: function(aInstall) {
   1.430 +      installCount++;
   1.431 +    },
   1.432 +
   1.433 +    onInstallEnded: function(aInstall) {
   1.434 +      installCount--;
   1.435 +      // Wait until all started installs have completed
   1.436 +      if (installCount)
   1.437 +        return;
   1.438 +
   1.439 +      AddonManager.removeInstallListener(this);
   1.440 +
   1.441 +      // If the background check hasn't yet completed then let that call the
   1.442 +      // callback when it is done
   1.443 +      if (!backgroundCheckCompleted)
   1.444 +        return;
   1.445 +
   1.446 +      do_execute_soon(aCallback);
   1.447 +    }
   1.448 +  });
   1.449 +
   1.450 +  Services.obs.addObserver(function() {
   1.451 +    Services.obs.removeObserver(arguments.callee, "addons-background-update-complete");
   1.452 +    backgroundCheckCompleted = true;
   1.453 +
   1.454 +    // If any new installs have started then we'll call the callback once they
   1.455 +    // are completed
   1.456 +    if (installCount)
   1.457 +      return;
   1.458 +
   1.459 +    do_execute_soon(aCallback);
   1.460 +  }, "addons-background-update-complete", false);
   1.461 +
   1.462 +  AddonManagerPrivate.backgroundUpdateCheck();
   1.463 +}
   1.464 +
   1.465 +// Manually updates the test add-ons to the given version
   1.466 +function manual_update(aVersion, aCallback) {
   1.467 +  var installs = [];
   1.468 +  AddonManager.getInstallForURL("http://localhost:" + gPort + "/addons/blocklist_soft1_" + aVersion + ".xpi",
   1.469 +                                function(aInstall) {
   1.470 +    installs.push(aInstall);
   1.471 +    AddonManager.getInstallForURL("http://localhost:" + gPort + "/addons/blocklist_soft2_" + aVersion + ".xpi",
   1.472 +                                  function(aInstall) {
   1.473 +      installs.push(aInstall);
   1.474 +      AddonManager.getInstallForURL("http://localhost:" + gPort + "/addons/blocklist_soft3_" + aVersion + ".xpi",
   1.475 +                                    function(aInstall) {
   1.476 +        installs.push(aInstall);
   1.477 +        AddonManager.getInstallForURL("http://localhost:" + gPort + "/addons/blocklist_soft4_" + aVersion + ".xpi",
   1.478 +                                      function(aInstall) {
   1.479 +          installs.push(aInstall);
   1.480 +          AddonManager.getInstallForURL("http://localhost:" + gPort + "/addons/blocklist_soft5_" + aVersion + ".xpi",
   1.481 +                                        function(aInstall) {
   1.482 +            installs.push(aInstall);
   1.483 +            AddonManager.getInstallForURL("http://localhost:" + gPort + "/addons/blocklist_hard1_" + aVersion + ".xpi",
   1.484 +                                          function(aInstall) {
   1.485 +              installs.push(aInstall);
   1.486 +              AddonManager.getInstallForURL("http://localhost:" + gPort + "/addons/blocklist_regexp1_" + aVersion + ".xpi",
   1.487 +                                            function(aInstall) {
   1.488 +                installs.push(aInstall);
   1.489 +
   1.490 +                Services.obs.addObserver(function(aSubject, aTopic, aData) {
   1.491 +                  Services.obs.removeObserver(arguments.callee, "addon-install-blocked");
   1.492 +
   1.493 +                  aSubject.QueryInterface(Ci.amIWebInstallInfo);
   1.494 +
   1.495 +                  var installCount = aSubject.installs.length;
   1.496 +
   1.497 +                  var listener = {
   1.498 +                    installComplete: function() {
   1.499 +                      installCount--;
   1.500 +                      if (installCount)
   1.501 +                        return;
   1.502 +
   1.503 +                      do_execute_soon(aCallback);
   1.504 +                    },
   1.505 +
   1.506 +                    onDownloadCancelled: function(aInstall) {
   1.507 +                      this.installComplete();
   1.508 +                    },
   1.509 +
   1.510 +                    onInstallEnded: function(aInstall) {
   1.511 +                      this.installComplete();
   1.512 +                    }
   1.513 +                  };
   1.514 +
   1.515 +                  aSubject.installs.forEach(function(aInstall) {
   1.516 +                    aInstall.addListener(listener);
   1.517 +                  });
   1.518 +
   1.519 +                  aSubject.install();
   1.520 +                }, "addon-install-blocked", false);
   1.521 +
   1.522 +                AddonManager.installAddonsFromWebpage("application/x-xpinstall", null,
   1.523 +                                                      NetUtil.newURI("http://localhost:" + gPort + "/"),
   1.524 +                                                      installs);
   1.525 +              }, "application/x-xpinstall");
   1.526 +            }, "application/x-xpinstall");
   1.527 +          }, "application/x-xpinstall");
   1.528 +        }, "application/x-xpinstall");
   1.529 +      }, "application/x-xpinstall");
   1.530 +    }, "application/x-xpinstall");
   1.531 +  }, "application/x-xpinstall");
   1.532 +}
   1.533 +
   1.534 +// Checks that an add-ons properties match expected values
   1.535 +function check_addon(aAddon, aExpectedVersion, aExpectedUserDisabled,
   1.536 +                     aExpectedSoftDisabled, aExpectedState) {
   1.537 +  do_check_neq(aAddon, null);
   1.538 +  dump("Testing " + aAddon.id + " version " + aAddon.version + "\n");
   1.539 +  dump(aAddon.userDisabled + " " + aAddon.softDisabled + "\n");
   1.540 +
   1.541 +  do_check_eq(aAddon.version, aExpectedVersion);
   1.542 +  do_check_eq(aAddon.blocklistState, aExpectedState);
   1.543 +  do_check_eq(aAddon.userDisabled, aExpectedUserDisabled);
   1.544 +  do_check_eq(aAddon.softDisabled, aExpectedSoftDisabled);
   1.545 +  if (aAddon.softDisabled)
   1.546 +    do_check_true(aAddon.userDisabled);
   1.547 +
   1.548 +  if (aExpectedState == Ci.nsIBlocklistService.STATE_BLOCKED) {
   1.549 +    do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE));
   1.550 +    do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_DISABLE));
   1.551 +  }
   1.552 +  else if (aAddon.userDisabled) {
   1.553 +    do_check_true(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE));
   1.554 +    do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_DISABLE));
   1.555 +  }
   1.556 +  else {
   1.557 +    do_check_false(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_ENABLE));
   1.558 +    if (aAddon.type != "theme")
   1.559 +      do_check_true(hasFlag(aAddon.permissions, AddonManager.PERM_CAN_DISABLE));
   1.560 +  }
   1.561 +  do_check_eq(aAddon.appDisabled, aExpectedState == Ci.nsIBlocklistService.STATE_BLOCKED);
   1.562 +
   1.563 +  let willBeActive = aAddon.isActive;
   1.564 +  if (hasFlag(aAddon.pendingOperations, AddonManager.PENDING_DISABLE))
   1.565 +    willBeActive = false;
   1.566 +  else if (hasFlag(aAddon.pendingOperations, AddonManager.PENDING_ENABLE))
   1.567 +    willBeActive = true;
   1.568 +
   1.569 +  if (aExpectedUserDisabled || aExpectedState == Ci.nsIBlocklistService.STATE_BLOCKED) {
   1.570 +    do_check_false(willBeActive);
   1.571 +  }
   1.572 +  else {
   1.573 +    do_check_true(willBeActive);
   1.574 +  }
   1.575 +}
   1.576 +
   1.577 +function run_test() {
   1.578 +  do_test_pending("test_blocklistchange main");
   1.579 +
   1.580 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
   1.581 +  writeInstallRDFForExtension(default_theme, profileDir);
   1.582 +  writeInstallRDFForExtension(softblock1_1, profileDir);
   1.583 +  writeInstallRDFForExtension(softblock2_1, profileDir);
   1.584 +  writeInstallRDFForExtension(softblock3_1, profileDir);
   1.585 +  writeInstallRDFForExtension(softblock4_1, profileDir);
   1.586 +  writeInstallRDFForExtension(softblock5_1, profileDir);
   1.587 +  writeInstallRDFForExtension(hardblock_1, profileDir);
   1.588 +  writeInstallRDFForExtension(regexpblock_1, profileDir);
   1.589 +  startupManager();
   1.590 +
   1.591 +  AddonManager.getAddonsByIDs(ADDON_IDS, do_exception_wrap(function([s1, s2, s3, s4, s5, h, r]) {
   1.592 +    s4.userDisabled = true;
   1.593 +    s5.userDisabled = false;
   1.594 +
   1.595 +    run_next_test();
   1.596 +  }));
   1.597 +}
   1.598 +
   1.599 +// Starts with add-ons unblocked and then switches application versions to
   1.600 +// change add-ons to blocked and back
   1.601 +add_test(function run_app_update_test() {
   1.602 +  do_print("Test: " + arguments.callee.name);
   1.603 +  restartManager();
   1.604 +  load_blocklist("app_update.xml", function app_update_step_1() {
   1.605 +    restartManager();
   1.606 +
   1.607 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.608 +
   1.609 +      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.610 +      check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.611 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.612 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.613 +      check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.614 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.615 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.616 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "test/1.0");
   1.617 +
   1.618 +      do_execute_soon(app_update_step_2);
   1.619 +    })
   1.620 +  });
   1.621 +
   1.622 +  function app_update_step_2() {
   1.623 +    restartManager("2");
   1.624 +
   1.625 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.626 +
   1.627 +      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.628 +      check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.629 +      check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.630 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.631 +      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.632 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.633 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.634 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.635 +
   1.636 +      s2.userDisabled = false;
   1.637 +      s2.userDisabled = true;
   1.638 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.639 +      s3.userDisabled = false;
   1.640 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.641 +
   1.642 +      do_execute_soon(app_update_step_3);
   1.643 +    });
   1.644 +  }
   1.645 +
   1.646 +  function app_update_step_3() {
   1.647 +    restartManager();
   1.648 +
   1.649 +    restartManager("2.5");
   1.650 +
   1.651 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.652 +
   1.653 +      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.654 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.655 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.656 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.657 +      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.658 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.659 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.660 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.661 +
   1.662 +      do_execute_soon(app_update_step_4);
   1.663 +    });
   1.664 +  }
   1.665 +
   1.666 +  function app_update_step_4() {
   1.667 +    restartManager("1");
   1.668 +
   1.669 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.670 +
   1.671 +      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.672 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.673 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.674 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.675 +      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.676 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.677 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.678 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.679 +
   1.680 +      s1.userDisabled = false;
   1.681 +      s2.userDisabled = false;
   1.682 +      s5.userDisabled = false;
   1.683 +      run_next_test();
   1.684 +    });
   1.685 +  }
   1.686 +});
   1.687 +
   1.688 +// Starts with add-ons unblocked and then switches application versions to
   1.689 +// change add-ons to blocked and back. A DB schema change is faked to force a
   1.690 +// rebuild when the application version changes
   1.691 +add_test(function run_app_update_schema_test() {
   1.692 +  do_print("Test: " + arguments.callee.name);
   1.693 +  restartManager();
   1.694 +
   1.695 +  AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.696 +
   1.697 +    check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.698 +    check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.699 +    check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.700 +    check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.701 +    check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.702 +    check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.703 +    check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.704 +    do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "test/1.0");
   1.705 +
   1.706 +    do_execute_soon(update_schema_2);
   1.707 +  });
   1.708 +
   1.709 +  function update_schema_2() {
   1.710 +    shutdownManager();
   1.711 +
   1.712 +    changeXPIDBVersion(100);
   1.713 +    gAppInfo.version = "2";
   1.714 +    startupManager(true);
   1.715 +
   1.716 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.717 +
   1.718 +      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.719 +      check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.720 +      check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.721 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.722 +      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.723 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.724 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.725 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.726 +
   1.727 +      s2.userDisabled = false;
   1.728 +      s2.userDisabled = true;
   1.729 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.730 +      s3.userDisabled = false;
   1.731 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.732 +      do_execute_soon(update_schema_3);
   1.733 +    });
   1.734 +  }
   1.735 +
   1.736 +  function update_schema_3() {
   1.737 +    restartManager();
   1.738 +
   1.739 +    shutdownManager();
   1.740 +    changeXPIDBVersion(100);
   1.741 +    gAppInfo.version = "2.5";
   1.742 +    startupManager(true);
   1.743 +
   1.744 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.745 +
   1.746 +      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.747 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.748 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.749 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.750 +      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.751 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.752 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.753 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.754 +
   1.755 +      do_execute_soon(update_schema_4);
   1.756 +    });
   1.757 +  }
   1.758 +
   1.759 +  function update_schema_4() {
   1.760 +    shutdownManager();
   1.761 +
   1.762 +    changeXPIDBVersion(100);
   1.763 +    startupManager(false);
   1.764 +
   1.765 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.766 +
   1.767 +      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.768 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.769 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.770 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.771 +      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.772 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.773 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.774 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.775 +
   1.776 +      do_execute_soon(update_schema_5);
   1.777 +    });
   1.778 +  }
   1.779 +
   1.780 +  function update_schema_5() {
   1.781 +    shutdownManager();
   1.782 +
   1.783 +    changeXPIDBVersion(100);
   1.784 +    gAppInfo.version = "1";
   1.785 +    startupManager(true);
   1.786 +
   1.787 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.788 +
   1.789 +      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.790 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.791 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.792 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.793 +      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.794 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.795 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.796 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.797 +
   1.798 +      s1.userDisabled = false;
   1.799 +      s2.userDisabled = false;
   1.800 +      s5.userDisabled = false;
   1.801 +      run_next_test();
   1.802 +    });
   1.803 +  }
   1.804 +});
   1.805 +
   1.806 +// Starts with add-ons unblocked and then loads new blocklists to change add-ons
   1.807 +// to blocked and back again.
   1.808 +add_test(function run_blocklist_update_test() {
   1.809 +  do_print("Test: " + arguments.callee.name + "\n");
   1.810 +  load_blocklist("blocklist_update1.xml", function run_blocklist_update_1() {
   1.811 +    restartManager();
   1.812 +
   1.813 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.814 +
   1.815 +      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.816 +      check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.817 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.818 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.819 +      check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.820 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.821 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.822 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "test/1.0");
   1.823 +
   1.824 +      load_blocklist("blocklist_update2.xml", function run_blocklist_update_2() {
   1.825 +        restartManager();
   1.826 +
   1.827 +        AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.828 +
   1.829 +          check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.830 +          check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.831 +          check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.832 +          check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.833 +          check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.834 +          check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.835 +          check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.836 +          do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.837 +
   1.838 +          s2.userDisabled = false;
   1.839 +          s2.userDisabled = true;
   1.840 +          check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.841 +          s3.userDisabled = false;
   1.842 +          check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.843 +
   1.844 +          do_execute_soon(function restart_and_reload() {
   1.845 +           restartManager();
   1.846 +
   1.847 +           load_blocklist("blocklist_update2.xml", function run_blocklist_update_3() {
   1.848 +            restartManager();
   1.849 +
   1.850 +            AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.851 +
   1.852 +              check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.853 +              check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.854 +              check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.855 +              check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.856 +              check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.857 +              check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.858 +              check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.859 +              do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.860 +
   1.861 +              load_blocklist("blocklist_update1.xml", function run_blocklist_update_4() {
   1.862 +                restartManager();
   1.863 +
   1.864 +                AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.865 +
   1.866 +                  check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.867 +                  check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.868 +                  check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.869 +                  check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.870 +                  check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.871 +                  check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.872 +                  check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.873 +                  do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.874 +
   1.875 +                  s1.userDisabled = false;
   1.876 +                  s2.userDisabled = false;
   1.877 +                  s5.userDisabled = false;
   1.878 +                  run_next_test();
   1.879 +                });
   1.880 +              });
   1.881 +            });
   1.882 +           });
   1.883 +          });
   1.884 +        });
   1.885 +      });
   1.886 +    });
   1.887 +  });
   1.888 +});
   1.889 +
   1.890 +// Starts with add-ons unblocked and then new versions are installed outside of
   1.891 +// the app to change them to blocked and back again.
   1.892 +add_test(function run_addon_change_test() {
   1.893 +  do_print("Test: " + arguments.callee.name + "\n");
   1.894 +  load_blocklist("addon_change.xml", function run_addon_change_1() {
   1.895 +    restartManager();
   1.896 +
   1.897 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.898 +
   1.899 +      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.900 +      check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.901 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.902 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.903 +      check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.904 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.905 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
   1.906 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "test/1.0");
   1.907 +
   1.908 +      do_execute_soon(run_addon_change_2);
   1.909 +    });
   1.910 +  });
   1.911 +
   1.912 +  function run_addon_change_2() {
   1.913 +    shutdownManager();
   1.914 +
   1.915 +    writeInstallRDFForExtension(softblock1_2, profileDir);
   1.916 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_2.id), Date.now() + 10000);
   1.917 +    writeInstallRDFForExtension(softblock2_2, profileDir);
   1.918 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_2.id), Date.now() + 10000);
   1.919 +    writeInstallRDFForExtension(softblock3_2, profileDir);
   1.920 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_2.id), Date.now() + 10000);
   1.921 +    writeInstallRDFForExtension(softblock4_2, profileDir);
   1.922 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_2.id), Date.now() + 10000);
   1.923 +    writeInstallRDFForExtension(softblock5_2, profileDir);
   1.924 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_2.id), Date.now() + 10000);
   1.925 +    writeInstallRDFForExtension(hardblock_2, profileDir);
   1.926 +    setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_2.id), Date.now() + 10000);
   1.927 +    writeInstallRDFForExtension(regexpblock_2, profileDir);
   1.928 +    setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_2.id), Date.now() + 10000);
   1.929 +
   1.930 +    startupManager(false);
   1.931 +
   1.932 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.933 +
   1.934 +      check_addon(s1, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.935 +      check_addon(s2, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.936 +      check_addon(s3, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.937 +      check_addon(s4, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.938 +      check_addon(s5, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.939 +      check_addon(h, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.940 +      check_addon(r, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.941 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.942 +
   1.943 +      s2.userDisabled = false;
   1.944 +      s2.userDisabled = true;
   1.945 +      check_addon(s2, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.946 +      s3.userDisabled = false;
   1.947 +      check_addon(s3, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.948 +      do_execute_soon(run_addon_change_3);
   1.949 +    });
   1.950 +  }
   1.951 +
   1.952 +  function run_addon_change_3() {
   1.953 +    restartManager();
   1.954 +
   1.955 +    shutdownManager();
   1.956 +
   1.957 +    writeInstallRDFForExtension(softblock1_3, profileDir);
   1.958 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_3.id), Date.now() + 20000);
   1.959 +    writeInstallRDFForExtension(softblock2_3, profileDir);
   1.960 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_3.id), Date.now() + 20000);
   1.961 +    writeInstallRDFForExtension(softblock3_3, profileDir);
   1.962 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_3.id), Date.now() + 20000);
   1.963 +    writeInstallRDFForExtension(softblock4_3, profileDir);
   1.964 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_3.id), Date.now() + 20000);
   1.965 +    writeInstallRDFForExtension(softblock5_3, profileDir);
   1.966 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_3.id), Date.now() + 20000);
   1.967 +    writeInstallRDFForExtension(hardblock_3, profileDir);
   1.968 +    setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_3.id), Date.now() + 20000);
   1.969 +    writeInstallRDFForExtension(regexpblock_3, profileDir);
   1.970 +    setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_3.id), Date.now() + 20000);
   1.971 +
   1.972 +    startupManager(false);
   1.973 +
   1.974 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
   1.975 +
   1.976 +      check_addon(s1, "3.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.977 +      check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.978 +      check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.979 +      check_addon(s4, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.980 +      check_addon(s5, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
   1.981 +      check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.982 +      check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
   1.983 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
   1.984 +
   1.985 +      do_execute_soon(run_addon_change_4);
   1.986 +    });
   1.987 +  }
   1.988 +
   1.989 +  function run_addon_change_4() {
   1.990 +    shutdownManager();
   1.991 +
   1.992 +    writeInstallRDFForExtension(softblock1_1, profileDir);
   1.993 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_1.id), Date.now() + 30000);
   1.994 +    writeInstallRDFForExtension(softblock2_1, profileDir);
   1.995 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_1.id), Date.now() + 30000);
   1.996 +    writeInstallRDFForExtension(softblock3_1, profileDir);
   1.997 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_1.id), Date.now() + 30000);
   1.998 +    writeInstallRDFForExtension(softblock4_1, profileDir);
   1.999 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_1.id), Date.now() + 30000);
  1.1000 +    writeInstallRDFForExtension(softblock5_1, profileDir);
  1.1001 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_1.id), Date.now() + 30000);
  1.1002 +    writeInstallRDFForExtension(hardblock_1, profileDir);
  1.1003 +    setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_1.id), Date.now() + 30000);
  1.1004 +    writeInstallRDFForExtension(regexpblock_1, profileDir);
  1.1005 +    setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_1.id), Date.now() + 30000);
  1.1006 +
  1.1007 +    startupManager(false);
  1.1008 +
  1.1009 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1010 +
  1.1011 +      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1012 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1013 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1014 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1015 +      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1016 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1017 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1018 +      do_check_eq(Services.prefs.getCharPref("general.skins.selectedSkin"), "classic/1.0");
  1.1019 +
  1.1020 +      s1.userDisabled = false;
  1.1021 +      s2.userDisabled = false;
  1.1022 +      s5.userDisabled = false;
  1.1023 +      run_next_test();
  1.1024 +    });
  1.1025 +  }
  1.1026 +});
  1.1027 +
  1.1028 +// Starts with add-ons blocked and then new versions are installed outside of
  1.1029 +// the app to change them to unblocked.
  1.1030 +add_test(function run_addon_change_2_test() {
  1.1031 +  do_print("Test: " + arguments.callee.name + "\n");
  1.1032 +  shutdownManager();
  1.1033 +
  1.1034 +  getFileForAddon(profileDir, softblock1_1.id).remove(true);
  1.1035 +  getFileForAddon(profileDir, softblock2_1.id).remove(true);
  1.1036 +  getFileForAddon(profileDir, softblock3_1.id).remove(true);
  1.1037 +  getFileForAddon(profileDir, softblock4_1.id).remove(true);
  1.1038 +  getFileForAddon(profileDir, softblock5_1.id).remove(true);
  1.1039 +  getFileForAddon(profileDir, hardblock_1.id).remove(true);
  1.1040 +  getFileForAddon(profileDir, regexpblock_1.id).remove(true);
  1.1041 +
  1.1042 +  startupManager(false);
  1.1043 +  shutdownManager();
  1.1044 +
  1.1045 +  writeInstallRDFForExtension(softblock1_2, profileDir);
  1.1046 +  writeInstallRDFForExtension(softblock2_2, profileDir);
  1.1047 +  writeInstallRDFForExtension(softblock3_2, profileDir);
  1.1048 +  writeInstallRDFForExtension(softblock4_2, profileDir);
  1.1049 +  writeInstallRDFForExtension(softblock5_2, profileDir);
  1.1050 +  writeInstallRDFForExtension(hardblock_2, profileDir);
  1.1051 +  writeInstallRDFForExtension(regexpblock_2, profileDir);
  1.1052 +
  1.1053 +  startupManager(false);
  1.1054 +
  1.1055 +  AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1056 +
  1.1057 +    check_addon(s1, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1058 +    check_addon(s2, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1059 +    check_addon(s3, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1060 +    check_addon(h, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1061 +    check_addon(r, "2.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1062 +
  1.1063 +    s2.userDisabled = false;
  1.1064 +    s2.userDisabled = true;
  1.1065 +    check_addon(s2, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1066 +    s3.userDisabled = false;
  1.1067 +    check_addon(s3, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1068 +    do_execute_soon(addon_change_2_test_2);
  1.1069 +  });
  1.1070 +
  1.1071 +  function addon_change_2_test_2() {
  1.1072 +    restartManager();
  1.1073 +
  1.1074 +    shutdownManager();
  1.1075 +
  1.1076 +    writeInstallRDFForExtension(softblock1_3, profileDir);
  1.1077 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_3.id), Date.now() + 10000);
  1.1078 +    writeInstallRDFForExtension(softblock2_3, profileDir);
  1.1079 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_3.id), Date.now() + 10000);
  1.1080 +    writeInstallRDFForExtension(softblock3_3, profileDir);
  1.1081 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_3.id), Date.now() + 10000);
  1.1082 +    writeInstallRDFForExtension(softblock4_3, profileDir);
  1.1083 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_3.id), Date.now() + 10000);
  1.1084 +    writeInstallRDFForExtension(softblock5_3, profileDir);
  1.1085 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_3.id), Date.now() + 10000);
  1.1086 +    writeInstallRDFForExtension(hardblock_3, profileDir);
  1.1087 +    setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_3.id), Date.now() + 10000);
  1.1088 +    writeInstallRDFForExtension(regexpblock_3, profileDir);
  1.1089 +    setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_3.id), Date.now() + 10000);
  1.1090 +
  1.1091 +    startupManager(false);
  1.1092 +
  1.1093 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1094 +
  1.1095 +      check_addon(s1, "3.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1096 +      check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1097 +      check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1098 +      check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1099 +      check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1100 +
  1.1101 +      do_execute_soon(addon_change_2_test_3);
  1.1102 +    });
  1.1103 +  }
  1.1104 +
  1.1105 +  function addon_change_2_test_3() {
  1.1106 +    shutdownManager();
  1.1107 +
  1.1108 +    writeInstallRDFForExtension(softblock1_1, profileDir);
  1.1109 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock1_1.id), Date.now() + 20000);
  1.1110 +    writeInstallRDFForExtension(softblock2_1, profileDir);
  1.1111 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock2_1.id), Date.now() + 20000);
  1.1112 +    writeInstallRDFForExtension(softblock3_1, profileDir);
  1.1113 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock3_1.id), Date.now() + 20000);
  1.1114 +    writeInstallRDFForExtension(softblock4_1, profileDir);
  1.1115 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock4_1.id), Date.now() + 20000);
  1.1116 +    writeInstallRDFForExtension(softblock5_1, profileDir);
  1.1117 +    setExtensionModifiedTime(getFileForAddon(profileDir, softblock5_1.id), Date.now() + 20000);
  1.1118 +    writeInstallRDFForExtension(hardblock_1, profileDir);
  1.1119 +    setExtensionModifiedTime(getFileForAddon(profileDir, hardblock_1.id), Date.now() + 20000);
  1.1120 +    writeInstallRDFForExtension(regexpblock_1, profileDir);
  1.1121 +    setExtensionModifiedTime(getFileForAddon(profileDir, regexpblock_1.id), Date.now() + 20000);
  1.1122 +
  1.1123 +    startupManager(false);
  1.1124 +
  1.1125 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1126 +
  1.1127 +      check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1128 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1129 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1130 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1131 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1132 +
  1.1133 +      s1.userDisabled = false;
  1.1134 +      s2.userDisabled = false;
  1.1135 +      s4.userDisabled = true;
  1.1136 +      s5.userDisabled = false;
  1.1137 +      run_next_test();
  1.1138 +    });
  1.1139 +  }
  1.1140 +});
  1.1141 +
  1.1142 +// Add-ons are initially unblocked then attempts to upgrade to blocked versions
  1.1143 +// in the background which should fail
  1.1144 +add_test(function run_background_update_test() {
  1.1145 +  do_print("Test: " + arguments.callee.name + "\n");
  1.1146 +  restartManager();
  1.1147 +
  1.1148 +  AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1149 +
  1.1150 +    check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1151 +    check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1152 +    check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1153 +    check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1154 +    check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1155 +    check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1156 +    check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1157 +
  1.1158 +    background_update(function background_update_1() {
  1.1159 +      restartManager();
  1.1160 +
  1.1161 +      AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1162 +
  1.1163 +        check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1164 +        check_addon(s2, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1165 +        check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1166 +        check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1167 +        check_addon(s5, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1168 +        check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1169 +        check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1170 +
  1.1171 +        run_next_test();
  1.1172 +      });
  1.1173 +    });
  1.1174 +  });
  1.1175 +});
  1.1176 +
  1.1177 +// Starts with add-ons blocked and then new versions are detected and installed
  1.1178 +// automatically for unblocked versions.
  1.1179 +add_test(function run_background_update_2_test() {
  1.1180 +  do_print("Test: " + arguments.callee.name + "\n");
  1.1181 +  shutdownManager();
  1.1182 +
  1.1183 +  getFileForAddon(profileDir, softblock1_1.id).remove(true);
  1.1184 +  getFileForAddon(profileDir, softblock2_1.id).remove(true);
  1.1185 +  getFileForAddon(profileDir, softblock3_1.id).remove(true);
  1.1186 +  getFileForAddon(profileDir, softblock4_1.id).remove(true);
  1.1187 +  getFileForAddon(profileDir, softblock5_1.id).remove(true);
  1.1188 +  getFileForAddon(profileDir, hardblock_1.id).remove(true);
  1.1189 +  getFileForAddon(profileDir, regexpblock_1.id).remove(true);
  1.1190 +
  1.1191 +  startupManager(false);
  1.1192 +  shutdownManager();
  1.1193 +
  1.1194 +  writeInstallRDFForExtension(softblock1_3, profileDir);
  1.1195 +  writeInstallRDFForExtension(softblock2_3, profileDir);
  1.1196 +  writeInstallRDFForExtension(softblock3_3, profileDir);
  1.1197 +  writeInstallRDFForExtension(softblock4_3, profileDir);
  1.1198 +  writeInstallRDFForExtension(softblock5_3, profileDir);
  1.1199 +  writeInstallRDFForExtension(hardblock_3, profileDir);
  1.1200 +  writeInstallRDFForExtension(regexpblock_3, profileDir);
  1.1201 +
  1.1202 +  startupManager(false);
  1.1203 +
  1.1204 +  AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1205 +
  1.1206 +    check_addon(s1, "3.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1207 +    check_addon(s2, "3.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1208 +    check_addon(s3, "3.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1209 +    check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1210 +    check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1211 +
  1.1212 +    s2.userDisabled = false;
  1.1213 +    s2.userDisabled = true;
  1.1214 +    check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1215 +    s3.userDisabled = false;
  1.1216 +    check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1217 +
  1.1218 +    // make sure we're not in a handler when we restart
  1.1219 +    do_execute_soon(function restart_and_update() {
  1.1220 +     restartManager();
  1.1221 +
  1.1222 +     background_update(function background_update_2_1() {
  1.1223 +      restartManager();
  1.1224 +
  1.1225 +      AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1226 +
  1.1227 +        check_addon(s1, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1228 +        check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1229 +        check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1230 +        check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1231 +        check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1232 +
  1.1233 +        s1.userDisabled = false;
  1.1234 +        s2.userDisabled = false;
  1.1235 +        s4.userDisabled = true;
  1.1236 +        s5.userDisabled = true;
  1.1237 +        run_next_test();
  1.1238 +      });
  1.1239 +     });
  1.1240 +    });
  1.1241 +  });
  1.1242 +});
  1.1243 +
  1.1244 +// Starts with add-ons blocked and then simulates the user upgrading them to
  1.1245 +// unblocked versions.
  1.1246 +add_test(function run_manual_update_test() {
  1.1247 +  do_print("Test: " + arguments.callee.name + "\n");
  1.1248 +  restartManager();
  1.1249 +  load_blocklist("manual_update.xml", function manual_update_1() {
  1.1250 +    restartManager();
  1.1251 +
  1.1252 +    AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1253 +
  1.1254 +      check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1255 +      check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1256 +      check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1257 +      check_addon(s4, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1258 +      check_addon(s5, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1259 +      check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1260 +      check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1261 +
  1.1262 +      s2.userDisabled = false;
  1.1263 +      s2.userDisabled = true;
  1.1264 +      check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1265 +      s3.userDisabled = false;
  1.1266 +      check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1267 +
  1.1268 +      do_execute_soon(function restart_manual_update() {
  1.1269 +       restartManager();
  1.1270 +
  1.1271 +       manual_update("2", function manual_update_2() {
  1.1272 +        restartManager();
  1.1273 +
  1.1274 +        AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1275 +
  1.1276 +          check_addon(s1, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1277 +          check_addon(s2, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1278 +          check_addon(s3, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1279 +          check_addon(s4, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1280 +          check_addon(s5, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1281 +          // Can't manually update to a hardblocked add-on
  1.1282 +          check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1283 +          check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1284 +
  1.1285 +          manual_update("3", function manual_update_3() {
  1.1286 +            restartManager();
  1.1287 +
  1.1288 +            AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1289 +
  1.1290 +              check_addon(s1, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1291 +              check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1292 +              check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1293 +              check_addon(s4, "3.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1294 +              check_addon(s5, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1295 +              check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1296 +              check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1297 +
  1.1298 +              run_next_test();
  1.1299 +            });
  1.1300 +          });
  1.1301 +        });
  1.1302 +       });
  1.1303 +      });
  1.1304 +    });
  1.1305 +  });
  1.1306 +});
  1.1307 +
  1.1308 +// Starts with add-ons blocked and then new versions are installed outside of
  1.1309 +// the app to change them to unblocked.
  1.1310 +add_test(function run_manual_update_2_test() {
  1.1311 +  do_print("Test: " + arguments.callee.name + "\n");
  1.1312 +  shutdownManager();
  1.1313 +
  1.1314 +  getFileForAddon(profileDir, softblock1_1.id).remove(true);
  1.1315 +  getFileForAddon(profileDir, softblock2_1.id).remove(true);
  1.1316 +  getFileForAddon(profileDir, softblock3_1.id).remove(true);
  1.1317 +  getFileForAddon(profileDir, softblock4_1.id).remove(true);
  1.1318 +  getFileForAddon(profileDir, softblock5_1.id).remove(true);
  1.1319 +  getFileForAddon(profileDir, hardblock_1.id).remove(true);
  1.1320 +  getFileForAddon(profileDir, regexpblock_1.id).remove(true);
  1.1321 +
  1.1322 +  startupManager(false);
  1.1323 +  shutdownManager();
  1.1324 +
  1.1325 +  writeInstallRDFForExtension(softblock1_1, profileDir);
  1.1326 +  writeInstallRDFForExtension(softblock2_1, profileDir);
  1.1327 +  writeInstallRDFForExtension(softblock3_1, profileDir);
  1.1328 +  writeInstallRDFForExtension(softblock4_1, profileDir);
  1.1329 +  writeInstallRDFForExtension(softblock5_1, profileDir);
  1.1330 +  writeInstallRDFForExtension(hardblock_1, profileDir);
  1.1331 +  writeInstallRDFForExtension(regexpblock_1, profileDir);
  1.1332 +
  1.1333 +  startupManager(false);
  1.1334 +
  1.1335 +  AddonManager.getAddonsByIDs(ADDON_IDS, callback_soon(function([s1, s2, s3, s4, s5, h, r]) {
  1.1336 +
  1.1337 +    check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1338 +    check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1339 +    check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1340 +    check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1341 +    check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1342 +
  1.1343 +    s2.userDisabled = false;
  1.1344 +    s2.userDisabled = true;
  1.1345 +    check_addon(s2, "1.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1346 +    s3.userDisabled = false;
  1.1347 +    check_addon(s3, "1.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1348 +    restartManager();
  1.1349 +
  1.1350 +    manual_update("2", function manual_update_2_2() {
  1.1351 +      restartManager();
  1.1352 +
  1.1353 +      AddonManager.getAddonsByIDs(ADDON_IDS,
  1.1354 +       callback_soon(function([s1, s2, s3, s4, s5, h, r]) {
  1.1355 +
  1.1356 +        check_addon(s1, "2.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1357 +        check_addon(s2, "2.0", true, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1358 +        check_addon(s3, "2.0", false, false, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1359 +        // Can't manually update to a hardblocked add-on
  1.1360 +        check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1361 +        check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1362 +
  1.1363 +        restartManager();
  1.1364 +
  1.1365 +        manual_update("3", function manual_update_2_3() {
  1.1366 +          restartManager();
  1.1367 +
  1.1368 +          AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1369 +
  1.1370 +            check_addon(s1, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1371 +            check_addon(s2, "3.0", true, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1372 +            check_addon(s3, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1373 +            check_addon(h, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1374 +            check_addon(r, "3.0", false, false, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
  1.1375 +
  1.1376 +            s1.userDisabled = false;
  1.1377 +            s2.userDisabled = false;
  1.1378 +            s4.userDisabled = true;
  1.1379 +            run_next_test();
  1.1380 +          });
  1.1381 +        });
  1.1382 +      }));
  1.1383 +    });
  1.1384 +  }));
  1.1385 +});
  1.1386 +
  1.1387 +// Uses the API to install blocked add-ons from the local filesystem
  1.1388 +add_test(function run_local_install_test() {
  1.1389 +  do_print("Test: " + arguments.callee.name + "\n");
  1.1390 +  shutdownManager();
  1.1391 +
  1.1392 +  getFileForAddon(profileDir, softblock1_1.id).remove(true);
  1.1393 +  getFileForAddon(profileDir, softblock2_1.id).remove(true);
  1.1394 +  getFileForAddon(profileDir, softblock3_1.id).remove(true);
  1.1395 +  getFileForAddon(profileDir, softblock4_1.id).remove(true);
  1.1396 +  getFileForAddon(profileDir, softblock5_1.id).remove(true);
  1.1397 +  getFileForAddon(profileDir, hardblock_1.id).remove(true);
  1.1398 +  getFileForAddon(profileDir, regexpblock_1.id).remove(true);
  1.1399 +
  1.1400 +  startupManager(false);
  1.1401 +
  1.1402 +  installAllFiles([
  1.1403 +    do_get_file("addons/blocklist_soft1_1.xpi"),
  1.1404 +    do_get_file("addons/blocklist_soft2_1.xpi"),
  1.1405 +    do_get_file("addons/blocklist_soft3_1.xpi"),
  1.1406 +    do_get_file("addons/blocklist_soft4_1.xpi"),
  1.1407 +    do_get_file("addons/blocklist_soft5_1.xpi"),
  1.1408 +    do_get_file("addons/blocklist_hard1_1.xpi"),
  1.1409 +    do_get_file("addons/blocklist_regexp1_1.xpi")
  1.1410 +  ], function local_install_1() {
  1.1411 +    AddonManager.getAllInstalls(function(aInstalls) {
  1.1412 +      // Should have finished all installs without needing to restart
  1.1413 +      do_check_eq(aInstalls.length, 0);
  1.1414 +
  1.1415 +      AddonManager.getAddonsByIDs(ADDON_IDS, function([s1, s2, s3, s4, s5, h, r]) {
  1.1416 +
  1.1417 +        check_addon(s1, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1418 +        check_addon(s2, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1419 +        check_addon(s3, "1.0", true, true, Ci.nsIBlocklistService.STATE_SOFTBLOCKED);
  1.1420 +        check_addon(h, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1421 +        check_addon(r, "1.0", false, false, Ci.nsIBlocklistService.STATE_BLOCKED);
  1.1422 +
  1.1423 +        run_next_test();
  1.1424 +      });
  1.1425 +    });
  1.1426 +  });
  1.1427 +});
  1.1428 +
  1.1429 +add_test(function shutdown_httpserver() {
  1.1430 +  testserver.stop(function() {
  1.1431 +    do_test_finished("test_blocklistchange main");
  1.1432 +    // this really means "async test step done"; needs to be called
  1.1433 +    // even when there isn't a next test
  1.1434 +    run_next_test();
  1.1435 +  });
  1.1436 +});

mercurial