Bug 810376 - wait for readystate==complete in chrome when switching frames, r=jgriffin
authorMalini Das <mdas@mozilla.com>
Thu, 15 Nov 2012 10:07:24 -0500
changeset 113383 e320680de4fc20e9af4be509e3cf3ee2ce52f8e9
parent 113382 bb8baf35a2733da29046d89e0f22b5c85cc00767
child 113384 0e76d45e8c3787c82ed0c421276e6d4c3445dedd
push id23870
push userryanvm@gmail.com
push dateFri, 16 Nov 2012 01:21:36 +0000
treeherdermozilla-central@58ebb638a7ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs810376
milestone19.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 810376 - wait for readystate==complete in chrome when switching frames, r=jgriffin
testing/marionette/marionette-actors.js
--- a/testing/marionette/marionette-actors.js
+++ b/testing/marionette/marionette-actors.js
@@ -1018,35 +1018,49 @@ MarionetteDriverActor.prototype = {
    *
    * @param object aRequest
    *        'element' is the element to switch to
    *        'value' if element is not set, then this
    *                holds either the id, name or index 
    *                of the frame to switch to
    */
   switchToFrame: function MDA_switchToFrame(aRequest) {
+    let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+    let checkLoad = function() { 
+      let errorRegex = /about:.+(error)|(blocked)\?/;
+      if (curWindow.document.readyState == "complete") { 
+        this.sendOk();
+        return;
+      } 
+      else if (curWindow.document.readyState == "interactive" && errorRegex.exec(curWindow.document.baseURI)) {
+        this.sendError("Error loading page", 13, null);
+        return;
+      }
+      
+      checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
+    }
     let curWindow = this.getCurrentWindow();
     if (this.context == "chrome") {
       let foundFrame = null;
       if ((aRequest.value == null) && (aRequest.element == null)) {
         this.curFrame = null;
         this.mainFrame.focus();
-        this.sendOk();
+        checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
         return;
       }
       if (aRequest.element != undefined) {
         if (this.curBrowser.elementManager.seenItems[aRequest.element] != undefined) {
           let wantedFrame = this.curBrowser.elementManager.getKnownElement(aRequest.element, curWindow); //HTMLIFrameElement
           let numFrames = curWindow.frames.length;
           for (let i = 0; i < numFrames; i++) {
             if (curWindow.frames[i].frameElement == wantedFrame) {
               curWindow = curWindow.frames[i]; 
               this.curFrame = curWindow;
               this.curFrame.focus();
-              this.sendOk();
+              checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
               return;
           }
         }
       }
     }
     switch(typeof(aRequest.value)) {
       case "string" :
         let foundById = null;
@@ -1071,17 +1085,17 @@ MarionetteDriverActor.prototype = {
           foundFrame = aRequest.value;
         }
         break;
       }
       if (foundFrame != null) {
         curWindow = curWindow.frames[foundFrame];
         this.curFrame = curWindow;
         this.curFrame.focus();
-        this.sendOk();
+        checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
       } else {
         this.sendError("Unable to locate frame: " + aRequest.value, 8, null);
       }
     }
     else {
       if ((aRequest.value == null) && (aRequest.element == null) &&
           (this.currentRemoteFrame !== null)) {
         // We're currently using a ChromeMessageSender for a remote frame, so this