diff options
author | Andrew Dolgov <[email protected]> | 2011-11-08 20:40:44 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2011-11-08 20:40:44 +0400 |
commit | 81bea17aefb26859f825b9293c7c99192874806e (patch) | |
tree | fb244408ca271affa2899adb634788802c9a89d8 /lib/dojo/robotx.js | |
parent | 870a70e109ac9e80a88047044530de53d0404ec7 (diff) |
upgrade Dojo to 1.6.1
Diffstat (limited to 'lib/dojo/robotx.js')
-rw-r--r-- | lib/dojo/robotx.js | 77 |
1 files changed, 55 insertions, 22 deletions
diff --git a/lib/dojo/robotx.js b/lib/dojo/robotx.js index 7f49b64a0..3a07c6903 100644 --- a/lib/dojo/robotx.js +++ b/lib/dojo/robotx.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ @@ -9,6 +9,8 @@ if(!dojo._hasResource["dojo.robotx"]){ //_hasResource checks added by build. Do dojo._hasResource["dojo.robotx"] = true; dojo.provide("dojo.robotx"); dojo.require("dojo.robot"); + + dojo.experimental("dojo.robotx"); // loads an external app into an iframe and points dojo.doc to the iframe document, allowing the robot to control it @@ -16,18 +18,48 @@ dojo.experimental("dojo.robotx"); // dojo.require this file (function(){ -// have to wait for test page to load before testing! -doh.robot._runsemaphore.lock.push("dojo.robotx.lock"); -var iframe = document.getElementById('robotapplication'); +var iframe = null; var groupStarted=dojo.connect(doh, '_groupStarted', function(){ dojo.disconnect(groupStarted); iframe.style.visibility="visible"; }); +var attachIframe = function(){ + dojo.addOnLoad(function(){ + var emptyStyle = { + overflow: dojo.isWebKit? 'hidden' : 'visible', + 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); + }); +}; + +// 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(); } +} + var onIframeLoad=function(){ - //iframe = document.getElementById('robotapplication'); + // initial load handler: update the document and start the tests doh.robot._updateDocument(); onIframeLoad = null; var scrollRoot = (document.compatMode == 'BackCompat')? document.body : document.documentElement; @@ -35,7 +67,15 @@ var onIframeLoad=function(){ if(consoleHeight){ iframe.style.height = (scrollRoot.clientHeight - consoleHeight)+"px"; } - doh.run(); + // 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); + }); + }else{ + doh.robot._run(robotFrame); + } }; var iframeLoad=function(){ @@ -66,6 +106,9 @@ if(iframe['attachEvent'] !== undefined){ dojo.connect(iframe, 'onload', iframeLoad); } + + + dojo.mixin(doh.robot,{ _updateDocument: function(){ dojo.setContext(iframe.contentWindow, iframe.contentWindow.document); @@ -84,22 +127,13 @@ dojo.mixin(doh.robot,{ // 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; - dojo.addOnLoad(function(){ - var emptyStyle = { - overflow: dojo.isWebKit? 'hidden' : 'visible', - 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=url; - document.getElementsByTagName("head")[0].appendChild(base); - }); + // see above note about race conditions + if(robotReady){ + attachIframe(); + + } }, waitForPageToLoad: function(/*Function*/ submitActions){ @@ -134,7 +168,6 @@ dojo.mixin(doh.robot,{ } }); - })(); } |