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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4 */
michael@0 5
michael@0 6 const Cc = Components.classes;
michael@0 7 const Ci = Components.interfaces;
michael@0 8 const Cu = Components.utils;
michael@0 9 const Cr = Components.results;
michael@0 10
michael@0 11 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
michael@0 12
michael@0 13 Cu.import("resource://testing-common/httpd.js");
michael@0 14 var gTestserver = new HttpServer();
michael@0 15 gTestserver.start(-1);
michael@0 16 gPort = gTestserver.identity.primaryPort;
michael@0 17
michael@0 18 // register static files with server and interpolate port numbers in them
michael@0 19 mapFile("/data/bug455906_warn.xml", gTestserver);
michael@0 20 mapFile("/data/bug455906_start.xml", gTestserver);
michael@0 21 mapFile("/data/bug455906_block.xml", gTestserver);
michael@0 22 mapFile("/data/bug455906_empty.xml", gTestserver);
michael@0 23
michael@0 24 // Workaround for Bug 658720 - URL formatter can leak during xpcshell tests
michael@0 25 const PREF_BLOCKLIST_ITEM_URL = "extensions.blocklist.itemURL";
michael@0 26 Services.prefs.setCharPref(PREF_BLOCKLIST_ITEM_URL, "http://localhost:" + gPort + "/blocklist/%blockID%");
michael@0 27
michael@0 28 var ADDONS = [{
michael@0 29 // Tests how the blocklist affects a disabled add-on
michael@0 30 id: "test_bug455906_1@tests.mozilla.org",
michael@0 31 name: "Bug 455906 Addon Test 1",
michael@0 32 version: "5",
michael@0 33 appVersion: "3"
michael@0 34 }, {
michael@0 35 // Tests how the blocklist affects an enabled add-on
michael@0 36 id: "test_bug455906_2@tests.mozilla.org",
michael@0 37 name: "Bug 455906 Addon Test 2",
michael@0 38 version: "5",
michael@0 39 appVersion: "3"
michael@0 40 }, {
michael@0 41 // Tests how the blocklist affects an enabled add-on, to be disabled by the notification
michael@0 42 id: "test_bug455906_3@tests.mozilla.org",
michael@0 43 name: "Bug 455906 Addon Test 3",
michael@0 44 version: "5",
michael@0 45 appVersion: "3"
michael@0 46 }, {
michael@0 47 // Tests how the blocklist affects a disabled add-on that was already warned about
michael@0 48 id: "test_bug455906_4@tests.mozilla.org",
michael@0 49 name: "Bug 455906 Addon Test 4",
michael@0 50 version: "5",
michael@0 51 appVersion: "3"
michael@0 52 }, {
michael@0 53 // Tests how the blocklist affects an enabled add-on that was already warned about
michael@0 54 id: "test_bug455906_5@tests.mozilla.org",
michael@0 55 name: "Bug 455906 Addon Test 5",
michael@0 56 version: "5",
michael@0 57 appVersion: "3"
michael@0 58 }, {
michael@0 59 // Tests how the blocklist affects an already blocked add-on
michael@0 60 id: "test_bug455906_6@tests.mozilla.org",
michael@0 61 name: "Bug 455906 Addon Test 6",
michael@0 62 version: "5",
michael@0 63 appVersion: "3"
michael@0 64 }, {
michael@0 65 // Tests how the blocklist affects an incompatible add-on
michael@0 66 id: "test_bug455906_7@tests.mozilla.org",
michael@0 67 name: "Bug 455906 Addon Test 7",
michael@0 68 version: "5",
michael@0 69 appVersion: "2"
michael@0 70 }, {
michael@0 71 // Spare add-on used to ensure we get a notification when switching lists
michael@0 72 id: "dummy_bug455906_1@tests.mozilla.org",
michael@0 73 name: "Dummy Addon 1",
michael@0 74 version: "5",
michael@0 75 appVersion: "3"
michael@0 76 }, {
michael@0 77 // Spare add-on used to ensure we get a notification when switching lists
michael@0 78 id: "dummy_bug455906_2@tests.mozilla.org",
michael@0 79 name: "Dummy Addon 2",
michael@0 80 version: "5",
michael@0 81 appVersion: "3"
michael@0 82 }];
michael@0 83
michael@0 84 function MockPlugin(name, version, enabledState) {
michael@0 85 this.name = name;
michael@0 86 this.version = version;
michael@0 87 this.enabledState = enabledState;
michael@0 88 }
michael@0 89 Object.defineProperty(MockPlugin.prototype, "blocklisted", {
michael@0 90 get: function MockPlugin_getBlocklisted() {
michael@0 91 let bls = Cc["@mozilla.org/extensions/blocklist;1"].getService(Ci.nsIBlocklistService);
michael@0 92 return bls.getPluginBlocklistState(this) == bls.STATE_BLOCKED;
michael@0 93 }
michael@0 94 });
michael@0 95 Object.defineProperty(MockPlugin.prototype, "disabled", {
michael@0 96 get: function MockPlugin_getDisabled() {
michael@0 97 return this.enabledState == Ci.nsIPluginTag.STATE_DISABLED;
michael@0 98 }
michael@0 99 });
michael@0 100
michael@0 101 var PLUGINS = [
michael@0 102 // Tests how the blocklist affects a disabled plugin
michael@0 103 new MockPlugin("test_bug455906_1", "5", Ci.nsIPluginTag.STATE_DISABLED),
michael@0 104 // Tests how the blocklist affects an enabled plugin
michael@0 105 new MockPlugin("test_bug455906_2", "5", Ci.nsIPluginTag.STATE_ENABLED),
michael@0 106 // Tests how the blocklist affects an enabled plugin, to be disabled by the notification
michael@0 107 new MockPlugin("test_bug455906_3", "5", Ci.nsIPluginTag.STATE_ENABLED),
michael@0 108 // Tests how the blocklist affects a disabled plugin that was already warned about
michael@0 109 new MockPlugin("test_bug455906_4", "5", Ci.nsIPluginTag.STATE_DISABLED),
michael@0 110 // Tests how the blocklist affects an enabled plugin that was already warned about
michael@0 111 new MockPlugin("test_bug455906_5", "5", Ci.nsIPluginTag.STATE_ENABLED),
michael@0 112 // Tests how the blocklist affects an already blocked plugin
michael@0 113 new MockPlugin("test_bug455906_6", "5", Ci.nsIPluginTag.STATE_ENABLED)
michael@0 114 ];
michael@0 115
michael@0 116 var gNotificationCheck = null;
michael@0 117 var gTestCheck = null;
michael@0 118
michael@0 119 // A fake plugin host for the blocklist service to use
michael@0 120 var PluginHost = {
michael@0 121 getPluginTags: function(countRef) {
michael@0 122 countRef.value = PLUGINS.length;
michael@0 123 return PLUGINS;
michael@0 124 },
michael@0 125
michael@0 126 QueryInterface: function(iid) {
michael@0 127 if (iid.equals(Ci.nsIPluginHost)
michael@0 128 || iid.equals(Ci.nsISupports))
michael@0 129 return this;
michael@0 130
michael@0 131 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 132 }
michael@0 133 }
michael@0 134
michael@0 135 var PluginHostFactory = {
michael@0 136 createInstance: function (outer, iid) {
michael@0 137 if (outer != null)
michael@0 138 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 139 return PluginHost.QueryInterface(iid);
michael@0 140 }
michael@0 141 };
michael@0 142
michael@0 143 // Don't need the full interface, attempts to call other methods will just
michael@0 144 // throw which is just fine
michael@0 145 var WindowWatcher = {
michael@0 146 openWindow: function(parent, url, name, features, windowArguments) {
michael@0 147 // Should be called to list the newly blocklisted items
michael@0 148 do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG);
michael@0 149
michael@0 150 if (gNotificationCheck) {
michael@0 151 var args = windowArguments.wrappedJSObject;
michael@0 152 gNotificationCheck(args);
michael@0 153 }
michael@0 154
michael@0 155 //run the code after the blocklist is closed
michael@0 156 Services.obs.notifyObservers(null, "addon-blocklist-closed", null);
michael@0 157
michael@0 158 // Call the next test after the blocklist has finished up
michael@0 159 do_timeout(0, gTestCheck);
michael@0 160 },
michael@0 161
michael@0 162 QueryInterface: function(iid) {
michael@0 163 if (iid.equals(Ci.nsIWindowWatcher)
michael@0 164 || iid.equals(Ci.nsISupports))
michael@0 165 return this;
michael@0 166
michael@0 167 throw Cr.NS_ERROR_NO_INTERFACE;
michael@0 168 }
michael@0 169 }
michael@0 170
michael@0 171 var WindowWatcherFactory = {
michael@0 172 createInstance: function createInstance(outer, iid) {
michael@0 173 if (outer != null)
michael@0 174 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 175 return WindowWatcher.QueryInterface(iid);
michael@0 176 }
michael@0 177 };
michael@0 178 var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
michael@0 179 registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"),
michael@0 180 "Fake Plugin Host",
michael@0 181 "@mozilla.org/plugin/host;1", PluginHostFactory);
michael@0 182 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
michael@0 183 "Fake Window Watcher",
michael@0 184 "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory);
michael@0 185
michael@0 186 function create_addon(addon) {
michael@0 187 var installrdf = "<?xml version=\"1.0\"?>\n" +
michael@0 188 "\n" +
michael@0 189 "<RDF xmlns=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" +
michael@0 190 " xmlns:em=\"http://www.mozilla.org/2004/em-rdf#\">\n" +
michael@0 191 " <Description about=\"urn:mozilla:install-manifest\">\n" +
michael@0 192 " <em:id>" + addon.id + "</em:id>\n" +
michael@0 193 " <em:version>" + addon.version + "</em:version>\n" +
michael@0 194 " <em:targetApplication>\n" +
michael@0 195 " <Description>\n" +
michael@0 196 " <em:id>xpcshell@tests.mozilla.org</em:id>\n" +
michael@0 197 " <em:minVersion>" + addon.appVersion + "</em:minVersion>\n" +
michael@0 198 " <em:maxVersion>" + addon.appVersion + "</em:maxVersion>\n" +
michael@0 199 " </Description>\n" +
michael@0 200 " </em:targetApplication>\n" +
michael@0 201 " <em:name>" + addon.name + "</em:name>\n" +
michael@0 202 " </Description>\n" +
michael@0 203 "</RDF>\n";
michael@0 204 var target = gProfD.clone();
michael@0 205 target.append("extensions");
michael@0 206 target.append(addon.id);
michael@0 207 target.append("install.rdf");
michael@0 208 target.create(target.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
michael@0 209 var stream = Cc["@mozilla.org/network/file-output-stream;1"].
michael@0 210 createInstance(Ci.nsIFileOutputStream);
michael@0 211 stream.init(target,
michael@0 212 FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
michael@0 213 FileUtils.PERMS_FILE, 0);
michael@0 214 stream.write(installrdf, installrdf.length);
michael@0 215 stream.close();
michael@0 216 }
michael@0 217
michael@0 218 function load_blocklist(file) {
michael@0 219 Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/" + file);
michael@0 220 var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
michael@0 221 getService(Ci.nsITimerCallback);
michael@0 222 blocklist.notify(null);
michael@0 223 }
michael@0 224
michael@0 225 function check_addon_state(addon) {
michael@0 226 return addon.userDisabled + "," + addon.softDisabled + "," + addon.appDisabled;
michael@0 227 }
michael@0 228
michael@0 229 function check_plugin_state(plugin) {
michael@0 230 return plugin.disabled + "," + plugin.blocklisted;
michael@0 231 }
michael@0 232
michael@0 233 function create_blocklistURL(blockID){
michael@0 234 let url = Services.urlFormatter.formatURLPref(PREF_BLOCKLIST_ITEM_URL);
michael@0 235 url = url.replace(/%blockID%/g, blockID);
michael@0 236 return url;
michael@0 237 }
michael@0 238
michael@0 239 // Performs the initial setup
michael@0 240 function run_test() {
michael@0 241 // Setup for test
michael@0 242 dump("Setting up tests\n");
michael@0 243 // Rather than keeping lots of identical add-ons in version control, just
michael@0 244 // write them into the profile.
michael@0 245 for (let addon of ADDONS)
michael@0 246 create_addon(addon);
michael@0 247
michael@0 248 // Copy the initial blocklist into the profile to check add-ons start in the
michael@0 249 // right state.
michael@0 250 copyBlocklistToProfile(do_get_file("data/bug455906_start.xml"));
michael@0 251
michael@0 252 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8");
michael@0 253 startupManager();
michael@0 254
michael@0 255 do_test_pending();
michael@0 256 check_test_pt1();
michael@0 257 }
michael@0 258
michael@0 259 // Before every main test this is the state the add-ons are meant to be in
michael@0 260 function check_initial_state(callback) {
michael@0 261 AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
michael@0 262 do_check_eq(check_addon_state(addons[0]), "true,false,false");
michael@0 263 do_check_eq(check_addon_state(addons[1]), "false,false,false");
michael@0 264 do_check_eq(check_addon_state(addons[2]), "false,false,false");
michael@0 265 do_check_eq(check_addon_state(addons[3]), "true,true,false");
michael@0 266 do_check_eq(check_addon_state(addons[4]), "false,false,false");
michael@0 267 do_check_eq(check_addon_state(addons[5]), "false,false,true");
michael@0 268 do_check_eq(check_addon_state(addons[6]), "false,false,true");
michael@0 269
michael@0 270 do_check_eq(check_plugin_state(PLUGINS[0]), "true,false");
michael@0 271 do_check_eq(check_plugin_state(PLUGINS[1]), "false,false");
michael@0 272 do_check_eq(check_plugin_state(PLUGINS[2]), "false,false");
michael@0 273 do_check_eq(check_plugin_state(PLUGINS[3]), "true,false");
michael@0 274 do_check_eq(check_plugin_state(PLUGINS[4]), "false,false");
michael@0 275 do_check_eq(check_plugin_state(PLUGINS[5]), "false,true");
michael@0 276
michael@0 277 callback();
michael@0 278 });
michael@0 279 }
michael@0 280
michael@0 281 // Tests the add-ons were installed and the initial blocklist applied as expected
michael@0 282 function check_test_pt1() {
michael@0 283 dump("Checking pt 1\n");
michael@0 284
michael@0 285 AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], callback_soon(function(addons) {
michael@0 286 for (var i = 0; i < ADDONS.length; i++) {
michael@0 287 if (!addons[i])
michael@0 288 do_throw("Addon " + (i + 1) + " did not get installed correctly");
michael@0 289 }
michael@0 290
michael@0 291 do_check_eq(check_addon_state(addons[0]), "false,false,false");
michael@0 292 do_check_eq(check_addon_state(addons[1]), "false,false,false");
michael@0 293 do_check_eq(check_addon_state(addons[2]), "false,false,false");
michael@0 294
michael@0 295 // Warn add-ons should be soft disabled automatically
michael@0 296 do_check_eq(check_addon_state(addons[3]), "true,true,false");
michael@0 297 do_check_eq(check_addon_state(addons[4]), "true,true,false");
michael@0 298
michael@0 299 // Blocked and incompatible should be app disabled only
michael@0 300 do_check_eq(check_addon_state(addons[5]), "false,false,true");
michael@0 301 do_check_eq(check_addon_state(addons[6]), "false,false,true");
michael@0 302
michael@0 303 // We've overridden the plugin host so we cannot tell what that would have
michael@0 304 // initialised the plugins as
michael@0 305
michael@0 306 // Put the add-ons into the base state
michael@0 307 addons[0].userDisabled = true;
michael@0 308 addons[4].userDisabled = false;
michael@0 309
michael@0 310 restartManager();
michael@0 311 check_initial_state(function() {
michael@0 312 gNotificationCheck = check_notification_pt2;
michael@0 313 gTestCheck = check_test_pt2;
michael@0 314 load_blocklist("bug455906_warn.xml");
michael@0 315 });
michael@0 316 }));
michael@0 317 }
michael@0 318
michael@0 319 function check_notification_pt2(args) {
michael@0 320 dump("Checking notification pt 2\n");
michael@0 321 do_check_eq(args.list.length, 4);
michael@0 322
michael@0 323 for (let addon of args.list) {
michael@0 324 if (addon.item instanceof Ci.nsIPluginTag) {
michael@0 325 switch (addon.item.name) {
michael@0 326 case "test_bug455906_2":
michael@0 327 do_check_false(addon.blocked);
michael@0 328 break;
michael@0 329 case "test_bug455906_3":
michael@0 330 do_check_false(addon.blocked);
michael@0 331 addon.disable = true;
michael@0 332 break;
michael@0 333 default:
michael@0 334 do_throw("Unknown addon: " + addon.item.name);
michael@0 335 }
michael@0 336 }
michael@0 337 else {
michael@0 338 switch (addon.item.id) {
michael@0 339 case "test_bug455906_2@tests.mozilla.org":
michael@0 340 do_check_false(addon.blocked);
michael@0 341 break;
michael@0 342 case "test_bug455906_3@tests.mozilla.org":
michael@0 343 do_check_false(addon.blocked);
michael@0 344 addon.disable = true;
michael@0 345 break;
michael@0 346 default:
michael@0 347 do_throw("Unknown addon: " + addon.item.id);
michael@0 348 }
michael@0 349 }
michael@0 350 }
michael@0 351 }
michael@0 352
michael@0 353 function check_test_pt2() {
michael@0 354 restartManager();
michael@0 355 dump("Checking results pt 2\n");
michael@0 356
michael@0 357 AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], callback_soon(function(addons) {
michael@0 358 // Should have disabled this add-on as requested
michael@0 359 do_check_eq(check_addon_state(addons[2]), "true,true,false");
michael@0 360 do_check_eq(check_plugin_state(PLUGINS[2]), "true,false");
michael@0 361
michael@0 362 // The blocked add-on should have changed to soft disabled
michael@0 363 do_check_eq(check_addon_state(addons[5]), "true,true,false");
michael@0 364 do_check_eq(check_plugin_state(PLUGINS[5]), "true,false");
michael@0 365
michael@0 366 // These should have been unchanged
michael@0 367 do_check_eq(check_addon_state(addons[0]), "true,false,false");
michael@0 368 do_check_eq(check_addon_state(addons[1]), "false,false,false");
michael@0 369 do_check_eq(check_addon_state(addons[3]), "true,true,false");
michael@0 370 do_check_eq(check_addon_state(addons[4]), "false,false,false");
michael@0 371 do_check_eq(check_addon_state(addons[6]), "false,false,true");
michael@0 372 do_check_eq(check_plugin_state(PLUGINS[0]), "true,false");
michael@0 373 do_check_eq(check_plugin_state(PLUGINS[1]), "false,false");
michael@0 374 do_check_eq(check_plugin_state(PLUGINS[3]), "true,false");
michael@0 375 do_check_eq(check_plugin_state(PLUGINS[4]), "false,false");
michael@0 376
michael@0 377 // Back to starting state
michael@0 378 addons[2].userDisabled = false;
michael@0 379 addons[5].userDisabled = false;
michael@0 380 PLUGINS[2].enabledState = Ci.nsIPluginTag.STATE_ENABLED;
michael@0 381 PLUGINS[5].enabledState = Ci.nsIPluginTag.STATE_ENABLED;
michael@0 382 restartManager();
michael@0 383 gNotificationCheck = null;
michael@0 384 gTestCheck = run_test_pt3;
michael@0 385 load_blocklist("bug455906_start.xml");
michael@0 386 }));
michael@0 387 }
michael@0 388
michael@0 389 function run_test_pt3() {
michael@0 390 restartManager();
michael@0 391 check_initial_state(function() {
michael@0 392 gNotificationCheck = check_notification_pt3;
michael@0 393 gTestCheck = check_test_pt3;
michael@0 394 load_blocklist("bug455906_block.xml");
michael@0 395 });
michael@0 396 }
michael@0 397
michael@0 398 function check_notification_pt3(args) {
michael@0 399 dump("Checking notification pt 3\n");
michael@0 400 do_check_eq(args.list.length, 6);
michael@0 401
michael@0 402 for (let addon of args.list) {
michael@0 403 if (addon.item instanceof Ci.nsIPluginTag) {
michael@0 404 switch (addon.item.name) {
michael@0 405 case "test_bug455906_2":
michael@0 406 do_check_true(addon.blocked);
michael@0 407 break;
michael@0 408 case "test_bug455906_3":
michael@0 409 do_check_true(addon.blocked);
michael@0 410 break;
michael@0 411 case "test_bug455906_5":
michael@0 412 do_check_true(addon.blocked);
michael@0 413 break;
michael@0 414 default:
michael@0 415 do_throw("Unknown addon: " + addon.item.name);
michael@0 416 }
michael@0 417 }
michael@0 418 else {
michael@0 419 switch (addon.item.id) {
michael@0 420 case "test_bug455906_2@tests.mozilla.org":
michael@0 421 do_check_true(addon.blocked);
michael@0 422 break;
michael@0 423 case "test_bug455906_3@tests.mozilla.org":
michael@0 424 do_check_true(addon.blocked);
michael@0 425 break;
michael@0 426 case "test_bug455906_5@tests.mozilla.org":
michael@0 427 do_check_true(addon.blocked);
michael@0 428 break;
michael@0 429 default:
michael@0 430 do_throw("Unknown addon: " + addon.item.id);
michael@0 431 }
michael@0 432 }
michael@0 433 }
michael@0 434 }
michael@0 435
michael@0 436 function check_test_pt3() {
michael@0 437 restartManager();
michael@0 438 dump("Checking results pt 3\n");
michael@0 439
michael@0 440 let blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
michael@0 441 getService(Ci.nsIBlocklistService);
michael@0 442
michael@0 443 AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
michael@0 444 // All should have gained the blocklist state, user disabled as previously
michael@0 445 do_check_eq(check_addon_state(addons[0]), "true,false,true");
michael@0 446 do_check_eq(check_addon_state(addons[1]), "false,false,true");
michael@0 447 do_check_eq(check_addon_state(addons[2]), "false,false,true");
michael@0 448 do_check_eq(check_addon_state(addons[4]), "false,false,true");
michael@0 449 do_check_eq(check_plugin_state(PLUGINS[0]), "true,true");
michael@0 450 do_check_eq(check_plugin_state(PLUGINS[1]), "false,true");
michael@0 451 do_check_eq(check_plugin_state(PLUGINS[2]), "false,true");
michael@0 452 do_check_eq(check_plugin_state(PLUGINS[3]), "true,true");
michael@0 453 do_check_eq(check_plugin_state(PLUGINS[4]), "false,true");
michael@0 454
michael@0 455 // Should have gained the blocklist state but no longer be soft disabled
michael@0 456 do_check_eq(check_addon_state(addons[3]), "false,false,true");
michael@0 457
michael@0 458 // Check blockIDs are correct
michael@0 459 do_check_eq(blocklist.getAddonBlocklistURL(addons[0]),create_blocklistURL(addons[0].id));
michael@0 460 do_check_eq(blocklist.getAddonBlocklistURL(addons[1]),create_blocklistURL(addons[1].id));
michael@0 461 do_check_eq(blocklist.getAddonBlocklistURL(addons[2]),create_blocklistURL(addons[2].id));
michael@0 462 do_check_eq(blocklist.getAddonBlocklistURL(addons[3]),create_blocklistURL(addons[3].id));
michael@0 463 do_check_eq(blocklist.getAddonBlocklistURL(addons[4]),create_blocklistURL(addons[4].id));
michael@0 464
michael@0 465 // All plugins have the same blockID on the test
michael@0 466 do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[0]), create_blocklistURL('test_bug455906_plugin'));
michael@0 467 do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[1]), create_blocklistURL('test_bug455906_plugin'));
michael@0 468 do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[2]), create_blocklistURL('test_bug455906_plugin'));
michael@0 469 do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[3]), create_blocklistURL('test_bug455906_plugin'));
michael@0 470 do_check_eq(blocklist.getPluginBlocklistURL(PLUGINS[4]), create_blocklistURL('test_bug455906_plugin'));
michael@0 471
michael@0 472 // Shouldn't be changed
michael@0 473 do_check_eq(check_addon_state(addons[5]), "false,false,true");
michael@0 474 do_check_eq(check_addon_state(addons[6]), "false,false,true");
michael@0 475 do_check_eq(check_plugin_state(PLUGINS[5]), "false,true");
michael@0 476
michael@0 477 // Back to starting state
michael@0 478 gNotificationCheck = null;
michael@0 479 gTestCheck = run_test_pt4;
michael@0 480 load_blocklist("bug455906_start.xml");
michael@0 481 });
michael@0 482 }
michael@0 483
michael@0 484 function run_test_pt4() {
michael@0 485 AddonManager.getAddonByID(ADDONS[4].id, callback_soon(function(addon) {
michael@0 486 addon.userDisabled = false;
michael@0 487 PLUGINS[4].enabledState = Ci.nsIPluginTag.STATE_ENABLED;
michael@0 488 restartManager();
michael@0 489 check_initial_state(function() {
michael@0 490 gNotificationCheck = check_notification_pt4;
michael@0 491 gTestCheck = check_test_pt4;
michael@0 492 load_blocklist("bug455906_empty.xml");
michael@0 493 });
michael@0 494 }));
michael@0 495 }
michael@0 496
michael@0 497 function check_notification_pt4(args) {
michael@0 498 dump("Checking notification pt 4\n");
michael@0 499
michael@0 500 // Should be just the dummy add-on to force this notification
michael@0 501 do_check_eq(args.list.length, 1);
michael@0 502 do_check_false(args.list[0].item instanceof Ci.nsIPluginTag);
michael@0 503 do_check_eq(args.list[0].item.id, "dummy_bug455906_2@tests.mozilla.org");
michael@0 504 }
michael@0 505
michael@0 506 function check_test_pt4() {
michael@0 507 restartManager();
michael@0 508 dump("Checking results pt 4\n");
michael@0 509
michael@0 510 AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(addons) {
michael@0 511 // This should have become unblocked
michael@0 512 do_check_eq(check_addon_state(addons[5]), "false,false,false");
michael@0 513 do_check_eq(check_plugin_state(PLUGINS[5]), "false,false");
michael@0 514
michael@0 515 // Should get re-enabled
michael@0 516 do_check_eq(check_addon_state(addons[3]), "false,false,false");
michael@0 517
michael@0 518 // No change for anything else
michael@0 519 do_check_eq(check_addon_state(addons[0]), "true,false,false");
michael@0 520 do_check_eq(check_addon_state(addons[1]), "false,false,false");
michael@0 521 do_check_eq(check_addon_state(addons[2]), "false,false,false");
michael@0 522 do_check_eq(check_addon_state(addons[4]), "false,false,false");
michael@0 523 do_check_eq(check_addon_state(addons[6]), "false,false,true");
michael@0 524 do_check_eq(check_plugin_state(PLUGINS[0]), "true,false");
michael@0 525 do_check_eq(check_plugin_state(PLUGINS[1]), "false,false");
michael@0 526 do_check_eq(check_plugin_state(PLUGINS[2]), "false,false");
michael@0 527 do_check_eq(check_plugin_state(PLUGINS[3]), "true,false");
michael@0 528 do_check_eq(check_plugin_state(PLUGINS[4]), "false,false");
michael@0 529
michael@0 530 finish();
michael@0 531 });
michael@0 532 }
michael@0 533
michael@0 534 function finish() {
michael@0 535 gTestserver.stop(do_test_finished);
michael@0 536 }

mercurial