Bug 1255066 - Wrap condition fn for BrowserTestUtils.waitForCondition in Task.spawn. r=mak
authorNihanth Subramanya <nhnt11@gmail.com>
Mon, 21 Mar 2016 01:41:54 -0700
changeset 290428 31249c60481310fe11d2d753eba7c4d79154169b
parent 290427 aa4952efc92f03b8e7255795cb37af6c68c693a1
child 290429 0d8ca812e2faade05f149e82db86b849d1d7e7a5
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1255066
milestone48.0a1
Bug 1255066 - Wrap condition fn for BrowserTestUtils.waitForCondition in Task.spawn. r=mak MozReview-Commit-ID: 8YoDfF6d15G
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -964,55 +964,56 @@ this.BrowserTestUtils = {
     });
   },
 
   /**
    * Will poll a condition function until it returns true.
    *
    * @param condition
    *        A condition function that must return true or false. If the
-   *        condition ever throws, this is also treated as a false.
+   *        condition ever throws, this is also treated as a false. The
+   *        function can be a generator.
    * @param interval
    *        The time interval to poll the condition function. Defaults
    *        to 100ms.
    * @param attempts
    *        The number of times to poll before giving up and rejecting
    *        if the condition has not yet returned true. Defaults to 50
    *        (~5 seconds for 100ms intervals)
    * @return Promise
    *        Resolves when condition is true.
    *        Rejects if timeout is exceeded or condition ever throws.
    */
   waitForCondition(condition, msg, interval=100, maxTries=50) {
     return new Promise((resolve, reject) => {
       let tries = 0;
-      let intervalID = setInterval(() => {
+      let intervalID = setInterval(Task.async(function* () {
         if (tries >= maxTries) {
           clearInterval(intervalID);
           msg += ` - timed out after ${maxTries} tries.`;
           reject(msg);
           return;
         }
 
         let conditionPassed = false;
         try {
-          conditionPassed = condition();
+          conditionPassed = yield condition();
         } catch(e) {
           msg += ` - threw exception: ${e}`;
           clearInterval(intervalID);
           reject(msg);
           return;
         }
 
         if (conditionPassed) {
           clearInterval(intervalID);
           resolve();
         }
         tries++;
-      }, interval);
+      }), interval);
     });
   },
 
   /**
    * Waits for a <xul:notification> with a particular value to appear
    * for the <xul:notificationbox> of the passed in browser.
    *
    * @param tabbrowser (<xul:tabbrowser>)