Bug 1450154: Part 2 - Make test_install.js a bit less insane. ?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 29 Mar 2018 18:25:44 -0700
changeset 775105 5479f783fead20223aa61581055b5809bbe10529
parent 775102 e7513ed056434f7bd9120ae16b166415769aee0f
push id104605
push usermaglione.k@gmail.com
push dateFri, 30 Mar 2018 01:27:08 +0000
bugs1450154
milestone61.0a1
Bug 1450154: Part 2 - Make test_install.js a bit less insane. ?aswan MozReview-Commit-ID: I1ttVRYRavH
toolkit/mozapps/extensions/test/xpcshell/head_addons.js
toolkit/mozapps/extensions/test/xpcshell/test_install.js
--- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@@ -394,17 +394,19 @@ async function getAddons(ids) {
 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") {
+      if (value instanceof Ci.nsIURI) {
+        equal(addon[key] && addon[key].spec, value.spec, `Expected value of addon.${key}`);
+      } else if (value && typeof value === "object") {
         deepEqual(addon[key], value, `Expected value of addon.${key}`);
       } else {
         equal(addon[key], value, `Expected value of addon.${key}`);
       }
     }
   }
 }
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_install.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_install.js
@@ -110,16 +110,28 @@ const ZipReader = Components.Constructor
 
 // The test extension uses an insecure update url.
 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
+function checkInstall(install, expected) {
+  for (let [key, value] of Object.entries(expected)) {
+    if (value instanceof Ci.nsIURI) {
+      equal(install[key] && install[key].spec, value.spec, `Expected value of install.${key}`);
+    } else if (value && typeof value === "object") {
+      deepEqual(install[key], value, `Expected value of install.${key}`);
+    } else {
+      equal(install[key], value, `Expected value of install.${key}`);
+    }
+  }
+}
+
 add_task(async function setup() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   await promiseStartupManager();
 
   // Make sure we only register once despite multiple calls
   AddonManager.addInstallListener(InstallListener);
   AddonManager.addAddonListener(AddonListener);
@@ -140,34 +152,37 @@ add_task(async function setup() {
 add_task(async function test_1() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let install = await AddonManager.getInstallForFile(XPIS.test_install1);
   ensure_test_completed();
 
-  notEqual(install, null);
-  equal(install.type, "extension");
-  equal(install.version, "1.0");
-  equal(install.name, "Test 1");
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
-  ok(install.addon.hasResource("install.rdf"));
-  notEqual(install.addon.syncGUID, null);
-  equal(install.addon.install, install);
-  equal(install.addon.size, ADDON1_SIZE);
-  let file = XPIS.test_install1;
-  let uri = Services.io.newFileURI(file).spec;
-  equal(install.addon.getResourceURI("install.rdf").spec, "jar:" + uri + "!/install.rdf");
-  equal(install.addon.iconURL, "jar:" + uri + "!/icon.png");
-  equal(install.addon.icon64URL, "jar:" + uri + "!/icon64.png");
-  equal(install.iconURL, null);
+  let uri = Services.io.newFileURI(XPIS.test_install1);
+  checkInstall(install, {
+    type: "extension",
+    version: "1.0",
+    name: "Test 1",
+    state: AddonManager.STATE_DOWNLOADED,
+    iconURL: null,
+    sourceURI: uri,
+  });
 
-  equal(install.sourceURI.spec, uri);
-  equal(install.addon.sourceURI.spec, uri);
+  let {addon} = install;
+  checkAddon("addon1@tests.mozilla.org", addon, {
+    install,
+    size: ADDON1_SIZE,
+    iconURL: `jar:${uri.spec}!/icon.png`,
+    icon64URL: `jar:${uri.spec}!/icon64.png`,
+    sourceURI: uri,
+  });
+  notEqual(addon.syncGUID, null);
+  ok(addon.hasResource("install.rdf"));
+  equal(addon.getResourceURI("install.rdf").spec, `jar:${uri.spec}!/install.rdf`);
 
   let activeInstalls = await AddonManager.getAllInstalls();
   equal(activeInstalls.length, 1);
   equal(activeInstalls[0], install);
 
   let fooInstalls = await AddonManager.getInstallsByTypes(["foo"]);
   equal(fooInstalls.length, 0);
 
@@ -187,78 +202,80 @@ add_task(async function test_1() {
     ], () => {
       resolve(install.addon.syncGUID);
     });
     install.install();
   });
 
   ensure_test_completed();
 
-  let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org");
+  addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org");
   ok(addon);
 
   let pendingAddons = await AddonManager.getAddonsWithOperationsByTypes(null);
   equal(pendingAddons.length, 0);
 
   uri = NetUtil.newURI(addon.iconURL);
   if (uri instanceof Ci.nsIJARURI) {
-    let archiveURI = uri.JARFile;
-    let archiveFile = archiveURI.QueryInterface(Ci.nsIFileURL).file;
-    let zipReader = new ZipReader(archiveFile);
+    let {file} = uri.JARFile.QueryInterface(Ci.nsIFileURL);
+    let zipReader = new ZipReader(file);
     try {
       ok(zipReader.hasEntry(uri.JAREntry));
     } finally {
       zipReader.close();
     }
   } else {
-    let iconFile = uri.QueryInterface(Ci.nsIFileURL).file;
-    ok(iconFile.exists());
+    let {file} = uri.QueryInterface(Ci.nsIFileURL);
+    ok(file.exists());
   }
 
   let updateDate = Date.now();
 
   ok(!hasFlag(addon.permissions, AddonManager.PERM_CAN_ENABLE));
   ok(hasFlag(addon.permissions, AddonManager.PERM_CAN_DISABLE));
 
   await promiseRestartManager();
 
   activeInstalls = await AddonManager.getAllInstalls();
   equal(activeInstalls, 0);
 
   let a1 = await AddonManager.getAddonByID("addon1@tests.mozilla.org");
-  notEqual(a1, null);
+  let uri2 = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org");
+
+  checkAddon("addon1@tests.mozilla.org", a1, {
+    syncGUID: installSyncGUID,
+    type: "extension",
+    version: "1.0",
+    name: "Test 1",
+    foreignInstall: false,
+    size: ADDON1_SIZE,
+    iconURL: uri2 + "icon.png",
+    icon64URL: uri2 + "icon64.png",
+    sourceURI: Services.io.newFileURI(XPIS.test_install1),
+  });
+
   notEqual(a1.syncGUID, null);
   ok(a1.syncGUID.length >= 9);
-  equal(a1.syncGUID, installSyncGUID);
-  equal(a1.type, "extension");
-  equal(a1.version, "1.0");
-  equal(a1.name, "Test 1");
+
   ok(isExtensionInBootstrappedList(profileDir, a1.id));
   ok(XPIS.test_install1.exists());
   do_check_in_crash_annotation(a1.id, a1.version);
-  equal(a1.size, ADDON1_SIZE);
-  ok(!a1.foreignInstall);
 
-  equal(a1.sourceURI.spec,
-        Services.io.newFileURI(XPIS.test_install1).spec);
   let difference = a1.installDate.getTime() - updateDate;
   if (Math.abs(difference) > MAX_TIME_DIFFERENCE)
     do_throw("Add-on install time was out by " + difference + "ms");
 
   difference = a1.updateDate.getTime() - updateDate;
   if (Math.abs(difference) > MAX_TIME_DIFFERENCE)
     do_throw("Add-on update time was out by " + difference + "ms");
 
   ok(a1.hasResource("install.rdf"));
   ok(!a1.hasResource("foo.bar"));
 
-  let uri2 = do_get_addon_root_uri(profileDir, "addon1@tests.mozilla.org");
   equal(a1.getResourceURI("install.rdf").spec, uri2 + "install.rdf");
-  equal(a1.iconURL, uri2 + "icon.png");
-  equal(a1.icon64URL, uri2 + "icon64.png");
 
   // Ensure that extension bundle (or icon if unpacked) has updated
   // lastModifiedDate.
   let testURI = a1.getResourceURI(TEST_UNPACKED ? "icon.png" : "");
   let testFile = testURI.QueryInterface(Ci.nsIFileURL).file;
   ok(testFile.exists());
   difference = testFile.lastModifiedTime - Date.now();
   ok(Math.abs(difference) < MAX_TIME_DIFFERENCE);
@@ -268,22 +285,23 @@ add_task(async function test_1() {
   await promiseRestartManager();
   do_check_not_in_crash_annotation(id, version);
 });
 
 // Tests that an install from a url downloads.
 add_task(async function test_2() {
   let url = "http://example.com/addons/test_install2_1.xpi";
   let install = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall", null, "Test 2", null, "1.0");
-  notEqual(install, null);
-  equal(install.version, "1.0");
-  equal(install.name, "Test 2");
-  equal(install.state, AddonManager.STATE_AVAILABLE);
-  equal(install.iconURL, null);
-  equal(install.sourceURI.spec, url);
+  checkInstall(install, {
+    version: "1.0",
+    name: "Test 2",
+    state: AddonManager.STATE_AVAILABLE,
+    iconURL: null,
+    sourceURI: Services.io.newURI(url),
+  });
 
   let activeInstalls = await AddonManager.getAllInstalls();
   equal(activeInstalls.length, 1);
   equal(activeInstalls[0], install);
 
   install = await new Promise(resolve => {
     prepare_test({}, [
       "onDownloadStarted",
@@ -300,21 +318,23 @@ add_task(async function test_2() {
         });
       }
     });
 
     install.install();
   });
 
   ensure_test_completed();
-  equal(install.version, "2.0");
-  equal(install.name, "Real Test 2");
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
+  checkInstall(install, {
+    version: "2.0",
+    name: "Real Test 2",
+    state: AddonManager.STATE_DOWNLOADED,
+    iconURL: null,
+  });
   equal(install.addon.install, install);
-  equal(install.iconURL, null);
 
   install = await new Promise(resolve => {
     prepare_test({
       "addon2@tests.mozilla.org": [
         ["onInstalling", false],
         "onInstalled"
       ]
     }, [
@@ -322,85 +342,88 @@ add_task(async function test_2() {
       "onInstallEnded",
     ], resolve);
     install.install();
   });
 
   let updateDate = Date.now();
 
   ensure_test_completed();
-  let olda2 = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
-  ok(olda2);
 
   await promiseRestartManager();
 
   let installs = await AddonManager.getAllInstalls();
   equal(installs, 0);
 
   let a2 = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
-  notEqual(a2, null);
+  checkAddon("addon2@tests.mozilla.org", a2, {
+    type: "extension",
+    version: "2.0",
+    name: "Real Test 2",
+    sourceURI: Services.io.newURI(url),
+  });
   notEqual(a2.syncGUID, null);
-  equal(a2.type, "extension");
-  equal(a2.version, "2.0");
-  equal(a2.name, "Real Test 2");
+
   ok(isExtensionInBootstrappedList(profileDir, a2.id));
   ok(XPIS.test_install2_1.exists());
+
   do_check_in_crash_annotation(a2.id, a2.version);
-  equal(a2.sourceURI.spec,
-        "http://example.com/addons/test_install2_1.xpi");
 
   let difference = a2.installDate.getTime() - updateDate;
   if (Math.abs(difference) > MAX_TIME_DIFFERENCE)
     do_throw("Add-on install time was out by " + difference + "ms");
 
   difference = a2.updateDate.getTime() - updateDate;
   if (Math.abs(difference) > MAX_TIME_DIFFERENCE)
     do_throw("Add-on update time was out by " + difference + "ms");
 
-  gInstallDate = a2.installDate.getTime();
+  gInstallDate = a2.installDate;
 });
 
 // Tests that installing a new version of an existing add-on works
 add_task(async function test_4() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://example.com/addons/test_install2_2.xpi";
   let install = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall", null, "Test 3", null, "3.0");
   ensure_test_completed();
 
-  notEqual(install, null);
-  equal(install.version, "3.0");
-  equal(install.name, "Test 3");
-  equal(install.state, AddonManager.STATE_AVAILABLE);
+  checkInstall(install, {
+    version: "3.0",
+    name: "Test 3",
+    state: AddonManager.STATE_AVAILABLE,
+    existingAddon: null,
+  });
 
   let activeInstalls = await AddonManager.getAllInstalls();
   equal(activeInstalls.length, 1);
   equal(activeInstalls[0], install);
-  equal(install.existingAddon, null);
 
   install = await new Promise(resolve => {
     prepare_test({}, [
       "onDownloadStarted",
       "onDownloadEnded",
     ], install1 => {
       resolve(install1);
       return false;
     });
     install.install();
   });
 
   ensure_test_completed();
 
-  equal(install.version, "3.0");
-  equal(install.name, "Real Test 3");
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
-  ok(install.existingAddon);
-  equal(install.existingAddon.id, "addon2@tests.mozilla.org");
+  checkInstall(install, {
+    version: "3.0",
+    name: "Real Test 3",
+    state: AddonManager.STATE_DOWNLOADED,
+    existingAddon: await AddonManager.getAddonByID("addon2@tests.mozilla.org"),
+  });
+
   equal(install.addon.install, install);
 
   // Installation will continue when there is nothing returned.
   install = await new Promise(resolve => {
     prepare_test({
       "addon2@tests.mozilla.org": [
         ["onInstalling", false],
         "onInstalled",
@@ -415,29 +438,31 @@ add_task(async function test_4() {
   ensure_test_completed();
 
   await promiseRestartManager();
 
   let installs2 = await AddonManager.getInstallsByTypes(null);
   equal(installs2.length, 0);
 
   let a2 = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
-  notEqual(a2, null);
-  equal(a2.type, "extension");
-  equal(a2.version, "3.0");
-  equal(a2.name, "Real Test 3");
-  ok(a2.isActive);
+  checkAddon("addon2@tests.mozilla.org", a2, {
+    type: "extension",
+    version: "3.0",
+    name: "Real Test 3",
+    isActive: true,
+    foreignInstall: false,
+    sourceURI: Services.io.newURI(url),
+    installDate: gInstallDate,
+  });
+
   ok(isExtensionInBootstrappedList(profileDir, a2.id));
   ok(XPIS.test_install2_2.exists());
+
   do_check_in_crash_annotation(a2.id, a2.version);
-  equal(a2.sourceURI.spec,
-        "http://example.com/addons/test_install2_2.xpi");
-  ok(!a2.foreignInstall);
 
-  equal(a2.installDate.getTime(), gInstallDate);
   // Update date should be later (or the same if this test is too fast)
   ok(a2.installDate <= a2.updateDate);
 
   a2.uninstall();
 });
 
 // Tests that an install that requires a compatibility update works
 add_task(async function test_6() {
@@ -446,20 +471,21 @@ add_task(async function test_6() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://example.com/addons/test_install3.xpi";
   let install = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall", null, "Real Test 4", null, "1.0");
   ensure_test_completed();
 
-  notEqual(install, null);
-  equal(install.version, "1.0");
-  equal(install.name, "Real Test 4");
-  equal(install.state, AddonManager.STATE_AVAILABLE);
+  checkInstall(install, {
+    version: "1.0",
+    name: "Real Test 4",
+    state: AddonManager.STATE_AVAILABLE,
+  });
 
   let activeInstalls = await AddonManager.getInstallsByTypes(null);
   equal(activeInstalls.length, 1);
   equal(activeInstalls[0], install);
 
   install = await new Promise(resolve => {
     prepare_test({}, [
       "onDownloadStarted",
@@ -467,21 +493,25 @@ add_task(async function test_6() {
     ], install1 => {
       resolve(install1);
       return false;
     });
     install.install();
   });
 
   ensure_test_completed();
-  equal(install.version, "1.0");
-  equal(install.name, "Real Test 4");
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
-  equal(install.existingAddon, null);
-  ok(!install.addon.appDisabled);
+  checkInstall(install, {
+    version: "1.0",
+    name: "Real Test 4",
+    state: AddonManager.STATE_DOWNLOADED,
+    existingAddon: null,
+  });
+  checkAddon("addon3@tests.mozilla.org", install.addon, {
+    appDisabled: false,
+  });
 
   // Continue the install
   await new Promise(resolve => {
     prepare_test({
       "addon3@tests.mozilla.org": [
         ["onInstalling", false],
         "onInstalled",
       ]
@@ -495,24 +525,27 @@ add_task(async function test_6() {
   ensure_test_completed();
 
   await promiseRestartManager();
 
   let installs = await AddonManager.getAllInstalls();
   equal(installs, 0);
 
   let a3 = await AddonManager.getAddonByID("addon3@tests.mozilla.org");
-  notEqual(a3, null);
+  checkAddon("addon3@tests.mozilla.org", a3, {
+    type: "extension",
+    version: "1.0",
+    name: "Real Test 4",
+    isActive: true,
+    appDisabled: false,
+  });
   notEqual(a3.syncGUID, null);
-  equal(a3.type, "extension");
-  equal(a3.version, "1.0");
-  equal(a3.name, "Real Test 4");
-  ok(a3.isActive);
-  ok(!a3.appDisabled);
+
   ok(isExtensionInBootstrappedList(profileDir, a3.id));
+
   ok(XPIS.test_install3.exists());
   a3.uninstall();
 });
 
 add_task(async function test_8() {
   await promiseRestartManager();
 
   AddonManager.addInstallListener(InstallListener);
@@ -536,44 +569,48 @@ add_task(async function test_8() {
       "onInstallEnded",
     ], resolve);
     install.install();
   });
 
   await promiseRestartManager();
 
   let a3 = await AddonManager.getAddonByID("addon3@tests.mozilla.org");
-  notEqual(a3, null);
+  checkAddon("addon3@tests.mozilla.org", a3, {
+    type: "extension",
+    version: "1.0",
+    name: "Real Test 4",
+    isActive: true,
+    appDisabled: false,
+  });
   notEqual(a3.syncGUID, null);
-  equal(a3.type, "extension");
-  equal(a3.version, "1.0");
-  equal(a3.name, "Real Test 4");
-  ok(a3.isActive);
-  ok(!a3.appDisabled);
+
   ok(isExtensionInBootstrappedList(profileDir, a3.id));
+
   ok(XPIS.test_install3.exists());
   a3.uninstall();
 });
 
 // Test that after cancelling a download it is removed from the active installs
 add_task(async function test_9() {
   await promiseRestartManager();
 
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://example.com/addons/test_install3.xpi";
   let install = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall", null, "Real Test 4", null, "1.0");
   ensure_test_completed();
 
-  notEqual(install, null);
-  equal(install.version, "1.0");
-  equal(install.name, "Real Test 4");
-  equal(install.state, AddonManager.STATE_AVAILABLE);
+  checkInstall(install, {
+    version: "1.0",
+    name: "Real Test 4",
+    state: AddonManager.STATE_AVAILABLE,
+  });
 
   let activeInstalls = await AddonManager.getInstallsByTypes(null);
   equal(activeInstalls.length, 1);
   equal(activeInstalls[0], install);
 
   install = await new Promise(resolve => {
     prepare_test({}, [
       "onDownloadStarted",
@@ -700,37 +737,44 @@ add_task(async function test_16() {
       }
     });
     aInstall.install();
   });
 
   await promiseRestartManager();
 
   let a2 = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
-  ok(a2.userDisabled);
-  ok(!a2.isActive);
+  checkAddon("addon2@tests.mozilla.org", a2, {
+    userDisabled: true,
+    isActive: false,
+  });
 
   let url_2 = "http://example.com/addons/test_install2_2.xpi";
   let aInstall_2 = await AddonManager.getInstallForURL(url_2, null, "application/x-xpinstall");
   await new Promise(resolve => {
     aInstall_2.addListener({
       onInstallEnded() {
         resolve();
       }
     });
     aInstall_2.install();
   });
 
-  ok(aInstall_2.addon.userDisabled);
+  checkAddon("addon2@tests.mozilla.org", aInstall_2.addon, {
+    userDisabled: true,
+    isActive: false,
+  });
 
   await promiseRestartManager();
 
   let a2_2 = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
-  ok(a2_2.userDisabled);
-  ok(!a2_2.isActive);
+  checkAddon("addon2@tests.mozilla.org", a2_2, {
+    userDisabled: true,
+    isActive: false,
+  });
 
   a2_2.uninstall();
 });
 
 // Verify that changing the userDisabled value before onInstallEnded works
 add_task(async function test_17() {
   await promiseRestartManager();
 
@@ -745,18 +789,20 @@ add_task(async function test_17() {
     aInstall.install();
   });
 
   ok(!aInstall.addon.userDisabled);
 
   await promiseRestartManager();
 
   let a2 = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
-  ok(!a2.userDisabled);
-  ok(a2.isActive);
+  checkAddon("addon2@tests.mozilla.org", a2, {
+    userDisabled: false,
+    isActive: true,
+  });
 
   let url_2 = "http://example.com/addons/test_install2_2.xpi";
   let aInstall_2 = await AddonManager.getInstallForURL(url_2, null, "application/x-xpinstall");
 
   await new Promise(resolve => {
     aInstall_2.addListener({
       onInstallStarted() {
         ok(!aInstall_2.addon.userDisabled);
@@ -767,18 +813,20 @@ add_task(async function test_17() {
         resolve();
       }
     });
     aInstall_2.install();
   });
   await promiseRestartManager();
 
   let a2_2 = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
-  ok(a2_2.userDisabled);
-  ok(!a2_2.isActive);
+  checkAddon("addon2@tests.mozilla.org", a2_2, {
+    userDisabled: true,
+    isActive: false,
+  });
 
   a2_2.uninstall();
 });
 
 // Verify that changing the userDisabled value before onInstallEnded works
 add_task(async function test_18() {
   await promiseRestartManager();
 
@@ -796,18 +844,20 @@ add_task(async function test_18() {
       }
     });
     aInstall.install();
   });
 
   await promiseRestartManager();
 
   let a2 = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
-  ok(a2.userDisabled);
-  ok(!a2.isActive);
+  checkAddon("addon2@tests.mozilla.org", a2, {
+    userDisabled: true,
+    isActive: false,
+  });
 
   let url_2 = "http://example.com/addons/test_install2_2.xpi";
   let aInstall_2 = await AddonManager.getInstallForURL(url_2, null, "application/x-xpinstall");
   await new Promise(resolve => {
     aInstall_2.addListener({
       onInstallStarted() {
         ok(aInstall_2.addon.userDisabled);
         aInstall_2.addon.userDisabled = false;
@@ -818,18 +868,20 @@ add_task(async function test_18() {
       }
     });
     aInstall_2.install();
   });
 
   await promiseRestartManager();
 
   let a2_2 = await AddonManager.getAddonByID("addon2@tests.mozilla.org");
-  ok(!a2_2.userDisabled);
-  ok(a2_2.isActive);
+  checkAddon("addon2@tests.mozilla.org", a2_2, {
+    isActive: true,
+    userDisabled: false,
+  });
 
   a2_2.uninstall();
 });
 
 
 // Checks that metadata is not stored if the pref is set to false
 add_task(async function test_18_1() {
   await promiseRestartManager();
@@ -923,18 +975,19 @@ add_task(async function test_22() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://example.com/addons/test_install3.xpi";
   let aInstall = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall");
   ensure_test_completed();
 
-  notEqual(aInstall, null);
-  equal(aInstall.state, AddonManager.STATE_AVAILABLE);
+  checkInstall(aInstall, {
+    state: AddonManager.STATE_AVAILABLE,
+  });
 
   let install = await new Promise(resolve => {
     prepare_test({}, [
       "onDownloadStarted",
       "onDownloadEnded",
     ], install1 => {
       prepare_test({}, [
         "onDownloadCancelled"
@@ -976,18 +1029,19 @@ add_task(async function test_23() {
     "onNewInstall"
   ]);
 
   let url = "http://example.com/addons/test_install3.xpi";
   let install = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall", do_get_file_hash(XPIS.test_install3));
 
   ensure_test_completed();
 
-  notEqual(install, null);
-  equal(install.state, AddonManager.STATE_AVAILABLE);
+  checkInstall(install, {
+    state: AddonManager.STATE_AVAILABLE,
+  });
 
   await new Promise(resolve => {
     prepare_test({}, [
       "onDownloadStarted",
       "onDownloadEnded",
     ], () => {
       prepare_test({}, [
         "onDownloadCancelled"
@@ -1029,18 +1083,19 @@ add_task(async function test_24() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://example.com/addons/test_install3.xpi";
   let aInstall = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall", "sha1:foo");
   ensure_test_completed();
 
-  notEqual(aInstall, null);
-  equal(aInstall.state, AddonManager.STATE_AVAILABLE);
+  checkInstall(aInstall, {
+    state: AddonManager.STATE_AVAILABLE,
+  });
 
   let install = await new Promise(resolve => {
     prepare_test({}, [
       "onDownloadStarted",
       "onDownloadFailed",
     ], resolve);
     aInstall.install();
   });
@@ -1060,19 +1115,20 @@ add_task(async function test_25() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = Services.io.newFileURI(XPIS.test_install3).spec;
   let aInstall = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall", do_get_file_hash(XPIS.test_install3));
   ensure_test_completed();
 
-  notEqual(aInstall, null);
-  equal(aInstall.state, AddonManager.STATE_DOWNLOADED);
-  equal(aInstall.error, 0);
+  checkInstall(aInstall, {
+    state: AddonManager.STATE_DOWNLOADED,
+    error: 0,
+  });
 
   prepare_test({ }, [
     "onDownloadCancelled"
   ]);
 
   aInstall.cancel();
 
   ensure_test_completed();
@@ -1127,18 +1183,19 @@ add_task(async function test_27() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://example.com/addons/test_install3.xpi";
   let aInstall = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall");
   ensure_test_completed();
 
-  notEqual(aInstall, null);
-  equal(aInstall.state, AddonManager.STATE_AVAILABLE);
+  checkInstall(aInstall, {
+    state: AddonManager.STATE_AVAILABLE,
+  });
 
   aInstall.addListener({
     onDownloadProgress() {
       aInstall.removeListener(this);
       aInstall.cancel();
     }
   });
 
@@ -1183,20 +1240,21 @@ add_task(async function test_29() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let url = "http://example.com/addons/test_install6.xpi";
   let install = await AddonManager.getInstallForURL(url, null, "application/x-xpinstall", null, "Addon Test 6", null, "1.0");
   ensure_test_completed();
 
-  notEqual(install, null);
-  equal(install.version, "1.0");
-  equal(install.name, "Addon Test 6");
-  equal(install.state, AddonManager.STATE_AVAILABLE);
+  checkInstall(install, {
+    version: "1.0",
+    name: "Addon Test 6",
+    state: AddonManager.STATE_AVAILABLE,
+  });
 
   let activeInstalls = await AddonManager.getInstallsByTypes(null);
   equal(activeInstalls.length, 1);
   equal(activeInstalls[0], install);
 
   install = await new Promise(resolve => {
     prepare_test({}, [
       "onDownloadStarted",
@@ -1204,20 +1262,23 @@ add_task(async function test_29() {
     ], install2 => {
       resolve(install2);
       return false;
     });
     install.install();
   });
 
   // ensure_test_completed();
-  equal(install.state, AddonManager.STATE_DOWNLOADED);
-  notEqual(install.addon, null);
-  ok(!install.addon.isCompatible);
-  ok(install.addon.appDisabled);
+  checkInstall(install, {
+    state: AddonManager.STATE_DOWNLOADED,
+  });
+  checkAddon("addon6@tests.mozilla.org", install.addon, {
+    isCompatible: false,
+    appDisabled: true,
+  });
 
   await new Promise(resolve => {
     prepare_test({}, [
       "onDownloadCancelled"
     ], resolve);
     install.cancel();
   });
 });
@@ -1227,12 +1288,13 @@ add_task(async function test_29() {
 add_task(async function test_30() {
   prepare_test({ }, [
     "onNewInstall"
   ]);
 
   let install = await AddonManager.getInstallForFile(XPIS.test_install7);
   ensure_test_completed();
 
-  notEqual(install, null);
-  equal(install.state, AddonManager.STATE_DOWNLOAD_FAILED);
-  equal(install.error, AddonManager.ERROR_CORRUPT_FILE);
+  checkInstall(install, {
+    state: AddonManager.STATE_DOWNLOAD_FAILED,
+    error: AddonManager.ERROR_CORRUPT_FILE,
+  });
 });