Bug 1398101 - Make sure all cleanup code paths are with `await` to ensure the cleanup process finished. r=MattN draft
authorSean Lee <selee@mozilla.com>
Wed, 27 Sep 2017 15:28:42 +0800
changeset 678955 cc0b2fe4d45a3647c6151ff99578cd63406623d7
parent 678954 1d476384f375c7b4b62945029dd124549e33693c
child 735477 a9c91916797d248a66d3fb9f33d25a9c27658a06
push id84082
push userbmo:selee@mozilla.com
push dateThu, 12 Oct 2017 03:34:15 +0000
reviewersMattN
bugs1398101
milestone58.0a1
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", {});
+  });
 });