Bug 1398101 - Make sure all cleanup code paths are with `await` to ensure the cleanup process finished. r=MattN
MozReview-Commit-ID: EH7WZ7C4hpa
--- 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", {});
+ });
});