Bug 997909 - Make waitFor actually terminate if condition is never true, r=mdas
authorJonathan Griffin <jgriffin@mozilla.com>
Thu, 02 Oct 2014 10:09:33 -0700
changeset 231700 fb353d80bc49815b9f5c6794c3afc96c1346952b
parent 231699 b212e3c4cbf54ee0b4d1648d0f676ecee639c87b
child 231701 dd61c51e957c7d2060d42759f23885a68d0dcded
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs997909
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 997909 - Make waitFor actually terminate if condition is never true, r=mdas
testing/marionette/marionette-simpletest.js
--- a/testing/marionette/marionette-simpletest.js
+++ b/testing/marionette/marionette-simpletest.js
@@ -165,28 +165,29 @@ Marionette.prototype = {
           }
       }
       return ostring;
   },
 
   waitFor: function test_waitFor(callback, test, timeout) {
       this.heartbeatCallback();
       if (test()) {
-          callback();
-          return;
+        callback();
+        return;
       }
-      var now = Date.now();
-      var deadline = now + (typeof(timeout) == "undefined" ? this.timeout : timeout);
+      var now = new Date();
+      var deadline = (timeout instanceof Date) ? timeout :
+                     new Date(now.valueOf + (typeof(timeout) == "undefined" ? this.timeout : timeout))
       if (deadline <= now) {
         dump("waitFor timeout: " + test.toString() + "\n");
         // the script will timeout here, so no need to raise a separate
         // timeout exception
         return;
       }
-      this.window.setTimeout(this.waitFor.bind(this), 100, callback, test, deadline - now);
+      this.window.setTimeout(this.waitFor.bind(this), 100, callback, test, deadline);
   },
 
   runEmulatorCmd: function runEmulatorCmd(cmd, callback) {
     this.heartbeatCallback();
     this.scope.runEmulatorCmd(cmd, callback);
   },
 
   runEmulatorShell: function runEmulatorShell(args, callback) {