Fixup to part 5: use promise to resolve page load, an store curWin
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 06 Feb 2015 18:30:46 +0000
changeset 376515 aeb16527d971ac00fe094ca7a48f69d168ba5fa5
parent 376350 d8e70d12da67cfb91f2112e3dde032bc3412f369
child 376516 80633a15fe45b465ada1c11570468882eb40bab3
child 377820 0b316ab3809b96b16c0d19b2c7444c3ac19339f8
push id52703
push useratolfsen@mozilla.com
push dateFri, 06 Feb 2015 18:31:13 +0000
treeherdertry@80633a15fe45 [default view] [failures only]
milestone37.0a1
Fixup to part 5: use promise to resolve page load, an store curWin
testing/marionette/driver.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -1070,36 +1070,43 @@ GeckoDriver.prototype = {
       // and the browser in an unusable state. Return a generic error insted.
  
       // TODO: Error codes need to be refined as a part of bug 1100545 and
       // bug 945729.
       if (this.appName == "Firefox")
         throw new UnknownError("Cannot navigate in chrome context");
 
       this.getCurrentWindow().location.href = url;
-      let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-      let start = new Date().getTime();
-      let end = null;
+      yield this.pageLoadPromise();
+      break;
+    }
+  },
   
+  pageLoadPromise: Task.async(function* GD_pageLoadPromise() {
+    let win = this.getCurrentWindow();
+    let timeout = this.pageLoad;
+    let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+    let start = new Date().getTime();
+    let end;
+
+    yield new Promise((resolve) => {
       let checkLoad = function() {
         end = new Date().getTime();
         let elapse = end - start;
-        if (this.pageTimeout == null || elapse <= this.pageTimeout) {
-          if (curWindow.document.readyState == "complete") {
-            return;
-          } else {
+        if (timeout == null || elapse <= timeout) {
+          if (win.document.readyState == "complete")
+            resolve();
+          else
             checkTimer.initWithCallback(checkLoad, 100, Ci.nsITimer.TYPE_ONE_SHOT);
-          }
         } else {
           throw new UnknownError("Error loading page");
         }
       }
       checkTimer.initWithCallback(checkLoad, 100, Ci.nsITimer.TYPE_ONE_SHOT);
-      break;
-    }
+    });
   },
 
   /**
    * Get a string representing the current URL.
    *
    * On Desktop this returns a string representation of the URL of the
    * current top level browsing context.  This is equivalent to
    * document.location.href.