Bug 1391393 - When waiting on notifications, ensure async updates have completed before moving on. r?mak
This attempts to avoid issues with intermittent failures - especially canceling the properties dialog
where undo fires straight away, by ensuring the async updates have completed, and the notifier has
had time to complete its actions.
MozReview-Commit-ID: Hk7KdQ228Zx
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_cancel.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_cancel.js
@@ -91,18 +91,15 @@ add_task(async function test_cancel_with
let promiseTitleChangeNotification = promiseBookmarksNotification(
"onItemChanged", (itemId, prop, isAnno, val) => prop == "title" && val == "n");
fillBookmarkTextField("editBMPanel_namePicker", "n", dialogWin);
// The dialog is instant apply.
await promiseTitleChangeNotification;
-
- // Ensure that the addition really is finished before we hit cancel.
- await PlacesTestUtils.promiseAsyncUpdates();
}
);
Assert.ok(PlacesTransactions.undo.calledOnce,
"undo should have been called once.");
});
});
--- a/toolkit/components/places/tests/PlacesTestUtils.jsm
+++ b/toolkit/components/places/tests/PlacesTestUtils.jsm
@@ -328,17 +328,20 @@ this.PlacesTestUtils = Object.freeze({
let proxifiedObserver = new Proxy({}, {
get: (target, name) => {
if (name == "QueryInterface")
return XPCOMUtils.generateQI([iface]);
if (name == notification)
return (...args) => {
if (conditionFn.apply(this, args)) {
PlacesUtils[type].removeObserver(proxifiedObserver);
- resolve();
+ // We delay resolving until after we've completed our updates
+ // to let the notifier finish its work before moving on to
+ // the next part of the test.
+ PlacesTestUtils.promiseAsyncUpdates().then(resolve);
}
}
if (name == "skipTags" || name == "skipDescendantsOnItemRemoval") {
return false;
}
return () => false;
}
});