Bug 1449255: Part 4a - Rename test_bug393285 to test_blocklist_osabi.js and modernize. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Tue, 27 Mar 2018 13:23:31 -0700
changeset 773469 64ac7d79ee1887aac5866bd2df4c921ea203b109
parent 773468 1c9ab99fbcac25be02517a61e69bcfe9a17fe39a
child 773470 e383a78dc263494915e6087f3a2812b360a5b7bb
push id104243
push usermaglione.k@gmail.com
push dateWed, 28 Mar 2018 00:15:32 +0000
reviewersaswan
bugs1449255, 393285
milestone61.0a1
Bug 1449255: Part 4a - Rename test_bug393285 to test_blocklist_osabi.js and modernize. r?aswan MozReview-Commit-ID: FPdc1y88ZXu
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
toolkit/mozapps/extensions/test/xpcshell/test_blocklist_osabi.js
toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js
toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -55,16 +55,18 @@ ChromeUtils.defineModuleGetter(this, "Ex
 ChromeUtils.defineModuleGetter(this, "HttpServer",
                                "resource://testing-common/httpd.js");
 ChromeUtils.defineModuleGetter(this, "MockAsyncShutdown",
                                "resource://testing-common/AddonTestUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "MockRegistrar",
                                "resource://testing-common/MockRegistrar.jsm");
 ChromeUtils.defineModuleGetter(this, "MockRegistry",
                                "resource://testing-common/MockRegistry.jsm");
+ChromeUtils.defineModuleGetter(this, "TestUtils",
+                               "resource://testing-common/TestUtils.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "aomStartup",
                                    "@mozilla.org/addons/addon-manager-startup;1",
                                    "amIAddonManagerStartup");
 
 const {
   awaitPromise,
   createAppInfo,
rename from toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js
rename to toolkit/mozapps/extensions/test/xpcshell/test_blocklist_osabi.js
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bug393285.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_osabi.js
@@ -1,323 +1,299 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
-
-ChromeUtils.import("resource://testing-common/MockRegistrar.jsm");
 var testserver = AddonTestUtils.createHttpServer({hosts: ["example.com"]});
 gPort = testserver.identity.primaryPort;
 
 testserver.registerDirectory("/data/", do_get_file("data"));
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
-var addonIDs = ["test_bug393285_1@tests.mozilla.org",
-                "test_bug393285_2@tests.mozilla.org",
-                "test_bug393285_3a@tests.mozilla.org",
-                "test_bug393285_3b@tests.mozilla.org",
-                "test_bug393285_4@tests.mozilla.org",
-                "test_bug393285_5@tests.mozilla.org",
-                "test_bug393285_6@tests.mozilla.org",
-                "test_bug393285_7@tests.mozilla.org",
-                "test_bug393285_8@tests.mozilla.org",
-                "test_bug393285_9@tests.mozilla.org",
-                "test_bug393285_10@tests.mozilla.org",
-                "test_bug393285_11@tests.mozilla.org",
-                "test_bug393285_12@tests.mozilla.org",
-                "test_bug393285_13@tests.mozilla.org",
-                "test_bug393285_14@tests.mozilla.org"];
+const ADDONS = {
+  "test_bug393285_1@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_1@tests.mozilla.org",
+      name: "extension 1",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // No info in blocklist, shouldn't be blocked
+    notBlocklisted: ["1", "1.9"],
+  },
+
+  "test_bug393285_2@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_2@tests.mozilla.org",
+      name: "extension 2",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Should always be blocked
+    blocklisted: ["1", "1.9"],
+  },
+
+  "test_bug393285_3a@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_3a@tests.mozilla.org",
+      name: "extension 3a",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Only version 1 should be blocked
+    blocklisted: ["1", "1.9"],
+  },
 
-// A window watcher to deal with the blocklist UI dialog.
-var WindowWatcher = {
-  openWindow(parent, url, name, features, args) {
-    // Should be called to list the newly blocklisted items
-    Assert.equal(url, URI_EXTENSION_BLOCKLIST_DIALOG);
+  "test_bug393285_3b@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_3b@tests.mozilla.org",
+      name: "extension 3b",
+      bootstrap: true,
+      version: "2.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Only version 1 should be blocked
+    notBlocklisted: ["1", "1.9"],
+  },
 
-    // Simulate auto-disabling any softblocks
-    var list = args.wrappedJSObject.list;
-    list.forEach(function(aItem) {
-      if (!aItem.blocked)
-        aItem.disable = true;
-    });
+  "test_bug393285_4@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_4@tests.mozilla.org",
+      name: "extension 4",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Should be blocked for app version 1
+    blocklisted: ["1", "1.9"],
+    notBlocklisted: ["2", "1.9"],
+  },
 
-    // run the code after the blocklist is closed
-    Services.obs.notifyObservers(null, "addon-blocklist-closed");
+  "test_bug393285_5@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_5@tests.mozilla.org",
+      name: "extension 5",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Not blocklisted because we are a different OS
+    notBlocklisted: ["2", "1.9"],
+  },
 
+  "test_bug393285_6@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_6@tests.mozilla.org",
+      name: "extension 6",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Blocklisted based on OS
+    blocklisted: ["2", "1.9"],
   },
 
-  QueryInterface(iid) {
-    if (iid.equals(Ci.nsIWindowWatcher)
-     || iid.equals(Ci.nsISupports))
-      return this;
+  "test_bug393285_7@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_7@tests.mozilla.org",
+      name: "extension 7",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Blocklisted based on OS
+    blocklisted: ["2", "1.9"],
+  },
+
+  "test_bug393285_8@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_8@tests.mozilla.org",
+      name: "extension 8",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Not blocklisted because we are a different ABI
+    notBlocklisted: ["2", "1.9"],
+  },
+
+  "test_bug393285_9@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_9@tests.mozilla.org",
+      name: "extension 9",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Blocklisted based on ABI
+    blocklisted: ["2", "1.9"],
+  },
+
+  "test_bug393285_10@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_10@tests.mozilla.org",
+      name: "extension 10",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Blocklisted based on ABI
+    blocklisted: ["2", "1.9"],
+  },
 
-    throw Cr.NS_ERROR_NO_INTERFACE;
-  }
+  "test_bug393285_11@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_11@tests.mozilla.org",
+      name: "extension 11",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Doesnt match both os and abi so not blocked
+    notBlocklisted: ["2", "1.9"],
+  },
+
+  "test_bug393285_12@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_12@tests.mozilla.org",
+      name: "extension 12",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Doesnt match both os and abi so not blocked
+    notBlocklisted: ["2", "1.9"],
+  },
+
+  "test_bug393285_13@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_13@tests.mozilla.org",
+      name: "extension 13",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Doesnt match both os and abi so not blocked
+    notBlocklisted: ["2", "1.9"],
+  },
+
+  "test_bug393285_14@tests.mozilla.org": {
+    "install.rdf": {
+      id: "test_bug393285_14@tests.mozilla.org",
+      name: "extension 14",
+      bootstrap: true,
+      version: "1.0",
+      targetApplications: [{
+        id: "xpcshell@tests.mozilla.org",
+        minVersion: "1",
+        maxVersion: "3"
+      }]
+    },
+    // Matches both os and abi so blocked
+    blocklisted: ["2", "1.9"],
+  },
 };
 
-MockRegistrar.register("@mozilla.org/embedcomp/window-watcher;1", WindowWatcher);
-
+const ADDON_IDS = Object.keys(ADDONS);
 
-function load_blocklist(aFile, aCallback) {
-  Services.obs.addObserver(function observer() {
-    Services.obs.removeObserver(observer, "blocklist-updated");
+async function loadBlocklist(file) {
+  let blocklistUpdated = TestUtils.topicObserved("blocklist-updated");
 
-    executeSoon(aCallback);
-  }, "blocklist-updated");
+  Services.prefs.setCharPref("extensions.blocklist.url",
+                             "http://example.com/data/" + file);
+  Services.blocklist.QueryInterface(Ci.nsITimerCallback).notify(null);
 
-  Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" +
-                             gPort + "/data/" + aFile);
-  var blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
-                  getService(Ci.nsITimerCallback);
-  blocklist.notify(null);
+  return blocklistUpdated;
 }
 
 
-function end_test() {
-  do_test_finished();
-}
-
-function run_test() {
-  do_test_pending();
-
+add_task(async function setup() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_1@tests.mozilla.org",
-    name: "extension 1",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_2@tests.mozilla.org",
-    name: "extension 2",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_3a@tests.mozilla.org",
-    name: "extension 3a",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_3b@tests.mozilla.org",
-    name: "extension 3b",
-    bootstrap: true,
-    version: "2.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
+  await promiseStartupManager();
 
-  writeInstallRDFForExtension({
-    id: "test_bug393285_4@tests.mozilla.org",
-    name: "extension 4",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_5@tests.mozilla.org",
-    name: "extension 5",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
+  for (let addon of Object.values(ADDONS)) {
+    await promiseInstallXPI(addon["install.rdf"]);
+  }
 
-  writeInstallRDFForExtension({
-    id: "test_bug393285_6@tests.mozilla.org",
-    name: "extension 6",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_7@tests.mozilla.org",
-    name: "extension 7",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_8@tests.mozilla.org",
-    name: "extension 8",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
+  let addons = await getAddons(ADDON_IDS);
+  for (let id of ADDON_IDS) {
+    equal(addons.get(id).blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED,
+          `Add-on ${id} should not initially be blocked`);
+  }
+});
 
-  writeInstallRDFForExtension({
-    id: "test_bug393285_9@tests.mozilla.org",
-    name: "extension 9",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_10@tests.mozilla.org",
-    name: "extension 10",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_11@tests.mozilla.org",
-    name: "extension 11",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_12@tests.mozilla.org",
-    name: "extension 12",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  writeInstallRDFForExtension({
-    id: "test_bug393285_13@tests.mozilla.org",
-    name: "extension 13",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
+add_task(async function test_1() {
+  await loadBlocklist("test_bug393285.xml");
 
-  writeInstallRDFForExtension({
-    id: "test_bug393285_14@tests.mozilla.org",
-    name: "extension 14",
-    bootstrap: true,
-    version: "1.0",
-    targetApplications: [{
-      id: "xpcshell@tests.mozilla.org",
-      minVersion: "1",
-      maxVersion: "3"
-    }]
-  }, profileDir);
-
-  startupManager();
-
-  AddonManager.getAddonsByIDs(addonIDs, function(addons) {
-    for (let addon of addons) {
-      Assert.equal(addon.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED);
+  let addons = await getAddons(ADDON_IDS);
+  for (let [id, options] of Object.entries(ADDONS)) {
+    if (options.blocklisted) {
+      ok(Services.blocklist.isAddonBlocklisted(addons.get(id), ...options.blocklisted),
+         `Add-on ${id} should be blocklisted in app/platform version ${options.blocklisted}`);
     }
-    run_test_1();
-  });
-}
-
-function run_test_1() {
-  load_blocklist("test_bug393285.xml", function() {
-    restartManager();
-
-    AddonManager.getAddonsByIDs(addonIDs,
-                               function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
-                                         a11, a12, a13, a14, a15]) {
-      // No info in blocklist, shouldn't be blocked
-      Assert.ok(!Services.blocklist.isAddonBlocklisted(a1, "1", "1.9"));
-
-      // Should always be blocked
-      Assert.ok(Services.blocklist.isAddonBlocklisted(a2, "1", "1.9"));
-
-      // Only version 1 should be blocked
-      Assert.ok(Services.blocklist.isAddonBlocklisted(a3, "1", "1.9"));
-      Assert.ok(!Services.blocklist.isAddonBlocklisted(a4, "1", "1.9"));
-
-      // Should be blocked for app version 1
-      Assert.ok(Services.blocklist.isAddonBlocklisted(a5, "1", "1.9"));
-      Assert.ok(!Services.blocklist.isAddonBlocklisted(a5, "2", "1.9"));
-
-      // Not blocklisted because we are a different OS
-      Assert.ok(!Services.blocklist.isAddonBlocklisted(a6, "2", "1.9"));
-
-      // Blocklisted based on OS
-      Assert.ok(Services.blocklist.isAddonBlocklisted(a7, "2", "1.9"));
-      Assert.ok(Services.blocklist.isAddonBlocklisted(a8, "2", "1.9"));
-
-      // Not blocklisted because we are a different ABI
-      Assert.ok(!Services.blocklist.isAddonBlocklisted(a9, "2", "1.9"));
-
-      // Blocklisted based on ABI
-      Assert.ok(Services.blocklist.isAddonBlocklisted(a10, "2", "1.9"));
-      Assert.ok(Services.blocklist.isAddonBlocklisted(a11, "2", "1.9"));
-
-      // Doesnt match both os and abi so not blocked
-      Assert.ok(!Services.blocklist.isAddonBlocklisted(a12, "2", "1.9"));
-      Assert.ok(!Services.blocklist.isAddonBlocklisted(a13, "2", "1.9"));
-      Assert.ok(!Services.blocklist.isAddonBlocklisted(a14, "2", "1.9"));
-
-      // Matches both os and abi so blocked
-      Assert.ok(Services.blocklist.isAddonBlocklisted(a15, "2", "1.9"));
-      end_test();
-    });
-  });
-}
+    if (options.notBlocklisted) {
+      ok(!Services.blocklist.isAddonBlocklisted(addons.get(id), ...options.notBlocklisted),
+         `Add-on ${id} should not be blocklisted in app/platform version ${options.notBlocklisted}`);
+    }
+  }
+});
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
@@ -23,35 +23,35 @@ tags = blocklist
 [test_bad_json.js]
 [test_badschema.js]
 [test_blocklist_gfx.js]
 tags = blocklist
 [test_blocklist_metadata_filters.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
 tags = blocklist
+[test_blocklist_osabi.js]
+# Bug 676992: test consistently hangs on Android
+skip-if = os == "android"
+tags = blocklist
 [test_blocklist_prefs.js]
 tags = blocklist
 [test_blocklist_regexp.js]
 skip-if = os == "android"
 tags = blocklist
 [test_blocklistchange.js]
 # Times out during parallel runs on desktop
 requesttimeoutfactor = 2
 tags = blocklist
 [test_bootstrap.js]
 skip-if = true # Bug 1358846 Bug 1365021 Bug 676992
 [test_bootstrap_const.js]
 [test_bootstrap_globals.js]
 [test_bug1180901_2.js]
 skip-if = os != "win"
-[test_bug393285.js]
-# Bug 676992: test consistently hangs on Android
-skip-if = os == "android"
-tags = blocklist
 [test_bug397778.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
 [test_bug406118.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
 tags = blocklist
 [test_bug430120.js]