Bug 1449628 - Use an uninstall listener to avoid test timeout. r?felipe draft
authorMichael Kaply <mozilla@kaply.com>
Wed, 28 Mar 2018 17:27:14 -0500
changeset 774445 7c1e13e617895729721aba28daae0773e8a57449
parent 774444 6aa3b57955fed5e137d0306478e1a4b424a6d392
push id104404
push usermozilla@kaply.com
push dateWed, 28 Mar 2018 22:27:33 +0000
reviewersfelipe
bugs1449628
milestone61.0a1
Bug 1449628 - Use an uninstall listener to avoid test timeout. r?felipe MozReview-Commit-ID: K9ayuReuH2c
browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js
--- a/browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_extensions.js
@@ -33,37 +33,53 @@ add_task(async function test_addon_locke
     let removeBtn = content.document.getAnonymousElementByAttribute(flashEntry, "anonid", "remove-btn");
     is(removeBtn.hidden, true, "Remove button should be hidden");
     is(disableBtn.hidden, true, "Disable button should be hidden");
   });
   BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function test_addon_uninstall() {
+  let uninstallPromise = wait_for_addon_uninstall();
   await setupPolicyEngineWithJson({
     "policies": {
       "Extensions": {
         "Uninstall": [
           addonID
         ]
       }
     }
   });
+  await uninstallPromise;
   let addon = await AddonManager.getAddonByID(addonID);
   is(addon, null, "Addon should be uninstalled.");
 });
 
 function wait_for_addon_install() {
   return new Promise((resolve, reject) => {
       AddonManager.addInstallListener({
         onInstallEnded(install, addon) {
-          if (addon.id == addonID)
-          resolve();
+          if (addon.id == addonID) {
+            resolve();
+          }
         },
         onDownloadFailed: (install) => {
           reject();
         },
         onInstallFailed: (install) => {
           reject();
         },
       });
   });
 }
+
+function wait_for_addon_uninstall() {
+ return new Promise(resolve => {
+    let listener = {};
+    listener.onUninstalled = addon => {
+      if (addon.id == addonID) {
+        AddonManager.removeAddonListener(listener);
+        resolve();
+      }
+    };
+    AddonManager.addAddonListener(listener);
+  });
+}