From 7842fbb562bafa92286a140ca9340a86187f1592 Mon Sep 17 00:00:00 2001 From: Malini Das Date: Thu, 17 Oct 2013 11:25:11 -0400 Subject: [PATCH] Bug 927592 - add modal dialog handling when document is ready, and only in B2G, r=jgriffin --- testing/marionette/marionette-listener.js | 28 ++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/testing/marionette/marionette-listener.js b/testing/marionette/marionette-listener.js index caa5e992899a..23a86b065c11 100644 --- a/testing/marionette/marionette-listener.js +++ b/testing/marionette/marionette-listener.js @@ -59,6 +59,8 @@ let heartbeatCallback = function () {}; // Called by the simpletest methods. let originalOnError; //timer for doc changes let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); +//timer for readystate +let readyStateTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); // Send move events about this often let EVENT_INTERVAL = 30; // milliseconds // For assigning unique ids to all touches @@ -163,6 +165,20 @@ function startListeners() { addMessageListenerId("Marionette:deleteCookie", deleteCookie); } +/** + * Used during newSession and restart, called to set up the modal dialog listener in b2g + */ +function waitForReady() { + if (content.document.readyState == 'complete') { + readyStateTimer.cancel(); + content.addEventListener("mozbrowsershowmodalprompt", modalHandler, false); + content.addEventListener("unload", waitForReady, false); + } + else { + readyStateTimer.initWithCallback(waitForReady, 100, Ci.nsITimer.TYPE_ONE_SHOT); + } +} + /** * Called when we start a new session. It registers the * current environment, and resets all values @@ -170,7 +186,9 @@ function startListeners() { function newSession(msg) { isB2G = msg.json.B2G; resetValues(); - content.addEventListener("mozbrowsershowmodalprompt", modalHandler, false); + if (isB2G) { + readyStateTimer.initWithCallback(waitForReady, 100, Ci.nsITimer.TYPE_ONE_SHOT); + } } /** @@ -188,7 +206,9 @@ function sleepSession(msg) { */ function restart(msg) { removeMessageListener("Marionette:restart", restart); - content.addEventListener("mozbrowsershowmodalprompt", modalHandler, false); + if (isB2G) { + readyStateTimer.initWithCallback(waitForReady, 100, Ci.nsITimer.TYPE_ONE_SHOT); + } registerSelf(); } @@ -237,7 +257,9 @@ function deleteSession(msg) { removeMessageListenerId("Marionette:getAllCookies", getAllCookies); removeMessageListenerId("Marionette:deleteAllCookies", deleteAllCookies); removeMessageListenerId("Marionette:deleteCookie", deleteCookie); - content.removeEventListener("mozbrowsershowmodalprompt", modalHandler, false); + if (isB2G) { + content.removeEventListener("mozbrowsershowmodalprompt", modalHandler, false); + } this.elementManager.reset(); // reset frame to the top-most frame curFrame = content;