Bug 1398101 - Make sure all cleanup code paths are with `await` to ensure the cleanup process finished. r=MattN
authorSean Lee <selee@mozilla.com>
Wed, 27 Sep 2017 15:28:42 +0800
changeset 385837 f2808379c0282d2d69da2353fc89f23346294de2
parent 385836 50e7e1b822ec8601c01f20b1b69a5a2359d1ec75
child 385838 c17bd293033ba5dbfc3e3128bc1cb15fb689997f
push id53166
push userryanvm@gmail.com
push dateThu, 12 Oct 2017 13:52:11 +0000
treeherderautoland@f2808379c028 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1398101
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1398101 - Make sure all cleanup code paths are with `await` to ensure the cleanup process finished. r=MattN MozReview-Commit-ID: EH7WZ7C4hpa
browser/extensions/formautofill/test/mochitest/formautofill_common.js
browser/extensions/formautofill/test/mochitest/formautofill_parent_utils.js
--- a/browser/extensions/formautofill/test/mochitest/formautofill_common.js
+++ b/browser/extensions/formautofill/test/mochitest/formautofill_common.js
@@ -159,16 +159,18 @@ function formAutoFillCommonSetup() {
   formFillChromeScript = SpecialPowers.loadChromeScript(chromeURL);
   formFillChromeScript.addMessageListener("onpopupshown", ({results}) => {
     gLastAutoCompleteResults = results;
     if (gPopupShownListener) {
       gPopupShownListener({results});
     }
   });
 
-  SimpleTest.registerCleanupFunction(() => {
+  SimpleTest.registerCleanupFunction(async () => {
     formFillChromeScript.sendAsyncMessage("cleanup");
+    await formFillChromeScript.promiseOneMessage("cleanup-finished");
+
     formFillChromeScript.destroy();
     expectingPopup = null;
   });
 }
 
 formAutoFillCommonSetup();
--- a/browser/extensions/formautofill/test/mochitest/formautofill_parent_utils.js
+++ b/browser/extensions/formautofill/test/mochitest/formautofill_parent_utils.js
@@ -84,29 +84,39 @@ var ParentUtils = {
 
   async operateCreditCard(type, msgData, contentMsg) {
     await this._operateRecord(CREDITCARDS_COLLECTION_NAME, ...arguments);
   },
 
   async cleanUpAddresses() {
     const guids = (await this._getRecords(ADDRESSES_COLLECTION_NAME)).map(record => record.guid);
 
+    if (guids.length == 0) {
+      sendAsyncMessage("FormAutofillTest:AddressesCleanedUp");
+      return;
+    }
+
     await this.operateAddress("remove", {guids}, "FormAutofillTest:AddressesCleanedUp");
   },
 
   async cleanUpCreditCards() {
     const guids = (await this._getRecords(CREDITCARDS_COLLECTION_NAME)).map(record => record.guid);
 
+    if (guids.length == 0) {
+      sendAsyncMessage("FormAutofillTest:CreditCardsCleanedUp");
+      return;
+    }
+
     await this.operateCreditCard("remove", {guids}, "FormAutofillTest:CreditCardsCleanedUp");
   },
 
   async cleanup() {
-    Services.obs.removeObserver(this, "formautofill-storage-changed");
     await this.cleanUpAddresses();
     await this.cleanUpCreditCards();
+    Services.obs.removeObserver(this, "formautofill-storage-changed");
   },
 
   _areRecordsMatching(recordA, recordB, collectionName) {
     for (let field of profileStorage[collectionName].VALID_FIELDS) {
       if (recordA[field] !== recordB[field]) {
         return false;
       }
     }
@@ -191,10 +201,12 @@ addMessageListener("FormAutofillTest:Che
   ParentUtils.checkCreditCards(msg);
 });
 
 addMessageListener("FormAutofillTest:CleanUpCreditCards", (msg) => {
   ParentUtils.cleanUpCreditCards();
 });
 
 addMessageListener("cleanup", () => {
-  ParentUtils.cleanup();
+  ParentUtils.cleanup().then(() => {
+    sendAsyncMessage("cleanup-finished", {});
+  });
 });