Bug 888784 - Make satchel tests wait for FormHistory to be clear when shutting down. r?mak
MozReview-Commit-ID: 9rxyT48VnNj
--- a/toolkit/components/satchel/test/parent_utils.js
+++ b/toolkit/components/satchel/test/parent_utils.js
@@ -18,18 +18,20 @@ var ParentUtils = {
let entries = [];
let numRows = gAutocompletePopup.view.matchCount;
for (let i = 0; i < numRows; i++) {
entries.push(gAutocompletePopup.view.getValueAt(i));
}
return entries;
},
- cleanUpFormHist() {
- FormHistory.update({ op: "remove" });
+ cleanUpFormHist(callback) {
+ FormHistory.update({ op: "remove" }, {
+ handleCompletion: callback,
+ });
},
updateFormHistory(changes) {
let handler = {
handleError(error) {
assert.ok(false, error);
sendAsyncMessage("formHistoryUpdated", { ok: false });
},
@@ -111,17 +113,19 @@ var ParentUtils = {
observe(subject, topic, data) {
assert.ok(topic === "satchel-storage-changed");
sendAsyncMessage("satchel-storage-changed", { subject: null, topic, data });
},
cleanup() {
gAutocompletePopup.removeEventListener("popupshown", this._popupshownListener);
- this.cleanUpFormHist();
+ this.cleanUpFormHist(() => {
+ sendAsyncMessage("cleanup-done");
+ });
},
};
ParentUtils._popupshownListener =
ParentUtils.popupshownListener.bind(ParentUtils);
gAutocompletePopup.addEventListener("popupshown", ParentUtils._popupshownListener);
ParentUtils.cleanUpFormHist();
--- a/toolkit/components/satchel/test/satchel_common.js
+++ b/toolkit/components/satchel/test/satchel_common.js
@@ -276,14 +276,20 @@ function satchelCommonSetup() {
gLastAutoCompleteResults = results;
if (gPopupShownListener) {
gPopupShownListener({results});
}
});
SimpleTest.registerCleanupFunction(() => {
gChromeScript.sendAsyncMessage("cleanup");
- gChromeScript.destroy();
+ return new Promise(resolve => {
+ gChromeScript.addMessageListener("cleanup-done", function done() {
+ gChromeScript.removeMessageListener("cleanup-done", done);
+ gChromeScript.destroy();
+ resolve();
+ });
+ });
});
}
satchelCommonSetup();