[Pkg-javascript-commits] [dojo] 22/27: Refactor robot so initRobot() and startRobot() are implemented as an asynchronous test fixtures. Also fixes priority of ready() call inside DOH. The default priority is 1000, so we need to be higher than that, so that DOH doesn't execute until the iframe's dojo.ready() call has finished

David Prévot taffit at moszumanska.debian.org
Sun Sep 14 16:23:06 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 1.7.6
in repository dojo.

commit 958ada1cf980d272d180de654183b16032e9e496
Author: Bill Keese <bill at dojotoolkit.org>
Date:   Wed Aug 13 09:13:58 2014 +0900

    Refactor robot so initRobot() and startRobot() are implemented as an asynchronous test fixtures.
    Also fixes priority of ready() call inside DOH.   The default priority is 1000,
    so we need to be higher than that, so that DOH doesn't execute until the iframe's dojo.ready() call has finished
    
    Fixes #16386.
    
    (cherry picked from 57cacb66b7ed89c4a9ca2eb4ec7587fb95ef1ab5
    and c52544a0e0ede89178bb3393cb4e737baf0026ca)
---
 robotx.js | 159 +++++++++++++++++++++++++++++---------------------------------
 1 file changed, 75 insertions(+), 84 deletions(-)

diff --git a/robotx.js b/robotx.js
index f434c55..05d9c63 100644
--- a/robotx.js
+++ b/robotx.js
@@ -1,4 +1,4 @@
-define(["./main", "./_base/sniff", "./robot"], function(dojo, has) {
+define(["./main", "require", "./robot"], function(dojo, require, robot) {
 
 dojo.experimental("dojo.robotx");
 
@@ -8,91 +8,76 @@ dojo.experimental("dojo.robotx");
 
 var iframe = null;
 
-var groupStarted=dojo.connect(doh, '_groupStarted', function(){
-	dojo.disconnect(groupStarted);
-	iframe.style.visibility="visible";
-});
+// urlLoaded is a Deferred that will be resolved whenever the iframe passed to initRobot() finishes loading, or reloads
+var urlLoaded;
+
+function attachIframe(url){
+	// summary:
+	//		Create iframe to load external app at specified url.   Iframe gets onload handler to  call onIframeLoad()
+	//		when specified URL finishes loading, and also if the iframe loads a different URL in the future.
+	// returns:
+	//		A Deferred that fires when everything has finished initializing
 
-var attachIframe = function(){
 	dojo.addOnLoad(function(){
 		var emptyStyle = {
-			overflow: dojo.isWebKit? 'hidden' : 'visible',
-			margin: '0px',
-			borderWidth: '0px',
-			height: '100%',
-			width: '100%'
+			overflow: "hidden",
+			margin: "0px",
+			borderWidth: "0px",
+			height: "100%",
+			width: "100%"
 		};
 		dojo.style(document.documentElement, emptyStyle);
 		dojo.style(document.body, emptyStyle);
-		document.body.appendChild(iframe);
-		var base=document.createElement('base');
-		base.href=iframe.src;
-		document.getElementsByTagName("head")[0].appendChild(base);
+
+		// Create the iframe for the external document.   Put it above the firebug-lite div (if such a div exists).
+		// console.log("creating iframe for external document");
+		iframe = document.createElement("iframe");
+		iframe.setAttribute("ALLOWTRANSPARENCY","true");
+		iframe.scrolling = dojo.isIE ? "yes" : "auto";
+		var scrollRoot = document.compatMode == "BackCompat" ? document.body : document.documentElement;
+		var consoleHeight = (document.getElementById("firebug") || {}).offsetHeight || 0;
+		dojo.style(iframe, {
+			border: "0px none",
+			padding: "0px",
+			margin: "0px",
+			width: "100%",
+			height: consoleHeight ? (scrollRoot.clientHeight - consoleHeight)+"px" : "100%"
+		});
+		iframe.src = url;
+
+		// Code to handle load event on iframe.  Seems like this should happen before setting iframe src on line above?
+		// Also, can't we use on() in all cases, even for old IE?
+		if(iframe.attachEvent !== undefined){
+			iframe.attachEvent("onload", onIframeLoad);
+		}else{
+			dojo.connect(iframe, "load", onIframeLoad);
+		}
+
+		dojo.place(iframe, dojo.body(), "first");
 	});
-};
-
-// Prevent race conditions between iframe loading and robot init.
-// If iframe is allowed to load while the robot is typing, sync XHRs can prevent the robot from completing its initialization.
-var robotReady=false;
-var robotFrame=null;
-var _run=doh.robot._run;
-doh.robot._run = function(frame){
-	// Called from robot when the robot completed its initialization.
-	robotReady = true;
-	robotFrame = frame;
-	doh.robot._run = _run;
-	// If initRobot was already called, then attach the iframe.
-	if(iframe.src){
-		attachIframe();
-	}
-};
+}
+
+
+function onIframeLoad(){
+	// summary:
+	//		Load handler when iframe specified to initRobot() finishes loading, or when it reloads.
+	//		It resolves the urlLoaded Deferred to make the rests of the tests runs.
 
-var onIframeLoad=function(){
-	// initial load handler: update the document and start the tests
 	doh.robot._updateDocument();
-	onIframeLoad = null;
-	var scrollRoot = (document.compatMode == 'BackCompat')? document.body : document.documentElement;
-	var consoleHeight = document.getElementById('robotconsole').offsetHeight;
-	if(consoleHeight){
-		iframe.style.height = (scrollRoot.clientHeight - consoleHeight)+"px";
-	}
+
 	// If dojo is present in the test case, then at least make a best effort to wait for it to load.
-	// The test must handle other race conditions like initial data queries by itself.
-	if(iframe.contentWindow.dojo){
-		iframe.contentWindow.dojo.addOnLoad(function(){
-			doh.robot._run(robotFrame);
+	// The test must handle other race conditions like initial data queries or asynchronous parses by itself.
+	if(iframe.contentWindow.require){
+		iframe.contentWindow.require(["dojo/ready"], function(ready){
+			ready(Infinity, function(){
+				setTimeout(function(){
+					urlLoaded.callback(true);
+				}, 500);	// 500ms fudge factor; otherwise focus doesn't work on IE8, see ValidationTextBox.js, TimeTextBox.js, etc.
+			});
 		});
 	}else{
-		doh.robot._run(robotFrame);
-	}
-};
-
-var iframeLoad=function(){
-	if(onIframeLoad){
-		onIframeLoad();
+		urlLoaded.callback(true);
 	}
-	var unloadConnect = dojo.connect(dojo.body(), 'onunload', function(){
-		dojo.global = window;
-		dojo.doc = document;
-		dojo.disconnect(unloadConnect);
-	});
-};
-
-// write the firebug console to a place it will fit
-dojo.config.debugContainerId = "robotconsole";
-dojo.config.debugHeight = dojo.config.debugHeight || 200;
-document.write('<div id="robotconsole" style="position:absolute;left:0px;bottom:0px;width:100%;"></div>');
-
-// write the iframe
-//document.writeln('<iframe id="robotapplication" style="visibility:hidden; border:0px none; padding:0px; margin:0px; position:absolute; left:0px; top:0px; width:100%; height:100%; z-index: 1;" src="'+dojo.config.robotURL+'" onload="iframeLoad();" ></iframe>');
-iframe = document.createElement('iframe');
-iframe.setAttribute("ALLOWTRANSPARENCY","true");
-iframe.scrolling = dojo.isIE? "yes" : "auto";
-dojo.style(iframe,{visibility:'hidden', border:'0px none', padding:'0px', margin:'0px', position:'absolute', left:'0px', top:'0px', width:'100%', height:'100%'});
-if(iframe['attachEvent'] !== undefined){
-	iframe.attachEvent('onload', iframeLoad);
-}else{
-	dojo.connect(iframe, 'onload', iframeLoad);
 }
 
 dojo.mixin(doh.robot,{
@@ -110,18 +95,24 @@ dojo.mixin(doh.robot,{
 
 	initRobot: function(/*String*/ url){
 		// summary:
-		//		Opens the application at the specified URL for testing, redirecting dojo to point to the application environment instead of the test environment.
-		//
+		//		Opens the application at the specified URL for testing, redirecting dojo to point to the application
+		//		environment instead of the test environment.
 		// url:
-		//		URL to open. Any of the test's dojo.doc calls (e.g. dojo.byId()), and any dijit.registry calls (e.g. dijit.byId()) will point to elements and widgets inside this application.
-		//
-
-		iframe.src=url;
-		// see above note about race conditions
-		if(robotReady){
-			attachIframe();
-
-		}
+		//		URL to open. Any of the test's dojo.doc calls (e.g. dojo.byId()), and any dijit.registry calls
+		//		(e.g. dijit.byId()) will point to elements and widgets inside this application.
+
+		doh.registerGroup("initialize robot", {
+			name: "load " + url,
+			timeout: 100000,	// could take more than 10s so setting to 100s
+			runTest: function(){
+				// Setup module level urlLoaded Deferred that will be resolved by onIframeLoad(), after the iframe
+				// has finished loading
+				urlLoaded = new doh.Deferred();
+				attachIframe(url);
+
+				return urlLoaded;
+			}
+		});
 	},
 
 	waitForPageToLoad: function(/*Function*/ submitActions){

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list