Bug 810376 - make content wait for document ready when switching frames, r=jgriffin, a=NPOTB CALENDAR_2_0b1_BUILD1 CALENDAR_2_0b1_RELEASE
authorMalini Das <mdas@mozilla.com>
Wed, 14 Nov 2012 13:34:30 -0500
changeset 114198 866bbd219b0e989f1be2f22e5615ba369cc2b87f
parent 114197 341b2b3db6217de3c26f4865bfe6f9374c16bec1
child 114199 4dc293ca7e6021861446844ec1a843b184acd8b9
child 114201 23534833ca52608b19ad300485a8451db41292d8
push idunknown
push userunknown
push dateunknown
reviewersjgriffin, NPOTB
bugs810376
milestone18.0a2
Bug 810376 - make content wait for document ready when switching frames, r=jgriffin, a=NPOTB
testing/marionette/marionette-listener.js
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -46,16 +46,18 @@ let importedScripts = FileUtils.getFile(
 // The sandbox we execute test scripts in. Gets lazily created in
 // createExecuteContentSandbox().
 let sandbox;
 
 // Flag to indicate whether an async script is currently running or not.
 let asyncTestRunning = false;
 let asyncTestCommandId;
 let asyncTestTimeoutId;
+//timer for doc changes
+let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
 
 /**
  * Called when listener is first started up. 
  * The listener sends its unique window ID and its current URI to the actor.
  * If the actor returns an ID, we start the listeners. Otherwise, nothing happens.
  */
 function registerSelf() {
   Services.io.manageOfflineStatus = false;
@@ -792,26 +794,38 @@ function clearElement(msg) {
   }
 }
 
 /**
  * Switch to frame given either the server-assigned element id,
  * its index in window.frames, or the iframe's name or id.
  */
 function switchToFrame(msg) {
+  function checkLoad() { 
+    let errorRegex = /about:.+(error)|(blocked)\?/;
+    if (curWindow.document.readyState == "complete") {
+      sendOk();
+      return;
+    } 
+    else if (curWindow.document.readyState == "interactive" && errorRegex.exec(curWindow.document.baseURI)) {
+      sendError("Error loading page", 13, null);
+      return;
+    }
+    checkTimer.initWithCallback(checkLoad, 100, Ci.nsITimer.TYPE_ONE_SHOT);
+  }
   let foundFrame = null;
   let frames = curWindow.document.getElementsByTagName("iframe");
   //Until Bug 761935 lands, we won't have multiple nested OOP iframes. We will only have one.
   //parWindow will refer to the iframe above the nested OOP frame.
   let parWindow = curWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                      .getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
   if ((msg.json.value == null) && (msg.json.element == null)) {
     curWindow = content;
     curWindow.focus();
-    sendOk();
+    checkTimer.initWithCallback(checkLoad, 100, Ci.nsITimer.TYPE_ONE_SHOT);
     return;
   }
   if (msg.json.element != undefined) {
     if (elementManager.seenItems[msg.json.element] != undefined) {
       let wantedFrame = elementManager.getKnownElement(msg.json.element, curWindow); //HTMLIFrameElement
       for (let i = 0; i < frames.length; i++) {
         if (frames[i] == wantedFrame) {
           curWindow = frames[i]; 
@@ -860,17 +874,17 @@ function switchToFrame(msg) {
     // The frame we want to switch to is a remote frame; notify our parent to handle
     // the switch.
     curWindow = content;
     sendToServer('Marionette:switchToFrame', {frame: foundFrame, win: parWindow});
   }
   else {
     curWindow = curWindow.contentWindow;
     curWindow.focus();
-    sendOk();
+    checkTimer.initWithCallback(checkLoad, 100, Ci.nsITimer.TYPE_ONE_SHOT);
   }
 }
 
 function getAppCacheStatus() {
   sendResponse({ value: curWindow.applicationCache.status });
 }
 
 // emulator callbacks