Bug 1447903: Part 0 - Add getAddons() and checkAddon() helpers to head_addons.js. r=aswan draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 25 Mar 2018 14:44:44 -0700
changeset 772359 81f979b3b3ff52f706de39422401ac6f21d408f8
parent 772358 cb18dc60106ab2e46e2361d5abc32dd70aeb3eb4
child 772360 1530b8284a67e92c6e1694443bd5c0ba555cae93
push id103897
push usermaglione.k@gmail.com
push dateMon, 26 Mar 2018 01:31:53 +0000
reviewersaswan
bugs1447903
milestone61.0a1
Bug 1447903: Part 0 - Add getAddons() and checkAddon() helpers to head_addons.js. r=aswan MozReview-Commit-ID: 3RsInwqtfRL
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -437,16 +437,66 @@ this.BootstrapMonitor = {
 AddonTestUtils.on("addon-manager-shutdown", () => BootstrapMonitor.shutdownCheck());
 
 function isNightlyChannel() {
   var channel = Services.prefs.getCharPref("app.update.channel", "default");
 
   return channel != "aurora" && channel != "beta" && channel != "release" && channel != "esr";
 }
 
+
+/**
+ * Returns a map of Addon objects for installed add-ons with the given
+ * IDs. The returned map contains a key for the ID of each add-on that
+ * is found. IDs for add-ons which do not exist are not present in the
+ * map.
+ *
+ * @param {sequence<string>} ids
+ *        The list of add-on IDs to get.
+ * @returns {Promise<string, Addon>}
+ *        Map of add-ons that were found.
+ */
+async function getAddons(ids) {
+  let addons = new Map();
+  for (let addon of await AddonManager.getAddonsByIDs(ids)) {
+    if (addon) {
+      addons.set(addon.id, addon);
+    }
+  }
+  return addons;
+}
+
+/**
+ * Checks that the given add-on has the given expected properties.
+ *
+ * @param {string} id
+ *        The id of the add-on.
+ * @param {Addon?} addon
+ *        The add-on object, or null if the add-on does not exist.
+ * @param {object?} expected
+ *        An object containing the expected values for properties of the
+ *        add-on, or null if the add-on is expected not to exist.
+ */
+function checkAddon(id, addon, expected) {
+  info(`Checking state of addon ${id}`);
+
+  if (expected === null) {
+    ok(!addon, `Addon ${id} should not exist`);
+  } else {
+    ok(addon, `Addon ${id} should exist`);
+    for (let [key, value] of Object.entries(expected)) {
+      if (value && typeof value === "object") {
+        deepEqual(addon[key], value, `Expected value of addon.${key}`);
+      } else {
+        equal(addon[key], value, `Expected value of addon.${key}`);
+      }
+    }
+  }
+}
+
 /**
  * Tests that an add-on does appear in the crash report annotations, if
  * crash reporting is enabled. The test will fail if the add-on is not in the
  * annotation.
  * @param  aId
  *         The ID of the add-on
  * @param  aVersion
  *         The version of the add-on