Bug 1391393 - When waiting on notifications, ensure async updates have completed before moving on. r?mak draft
authorMark Banner <standard8@mozilla.com>
Tue, 29 Aug 2017 22:34:25 +0100
changeset 655346 dd88b716d053f730e0c0ec1d924363a59056ffbd
parent 655345 4d694b3d403b2dc24280810861eb5b007a8577f0
child 728806 2da4c02bcc6546f621269ec11b7b51c0be1057e8
push id76844
push userbmo:standard8@mozilla.com
push dateTue, 29 Aug 2017 21:39:42 +0000
reviewersmak
bugs1391393
milestone57.0a1
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
browser/components/places/tests/browser/browser_bookmarkProperties_cancel.js
toolkit/components/places/tests/PlacesTestUtils.jsm
--- 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;
         }
       });