]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/robotx.js
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if (! dojo
. _hasResource
[ "dojo.robotx" ]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
. _hasResource
[ "dojo.robotx" ] = true ;
10 dojo
. provide ( "dojo.robotx" );
11 dojo
. require ( "dojo.robot" );
14 dojo
. experimental ( "dojo.robotx" );
16 // loads an external app into an iframe and points dojo.doc to the iframe document, allowing the robot to control it
17 // to use: set robotURL in djConfig to the URL you want to load
18 // dojo.require this file
24 var groupStarted
= dojo
. connect ( doh
, '_groupStarted' , function (){
25 dojo
. disconnect ( groupStarted
);
26 iframe
. style
. visibility
= "visible" ;
29 var attachIframe = function (){
30 dojo
. addOnLoad ( function (){
32 overflow
: dojo
. isWebKit
? 'hidden' : 'visible' ,
38 dojo
. style ( document
. documentElement
, emptyStyle
);
39 dojo
. style ( document
. body
, emptyStyle
);
40 document
. body
. appendChild ( iframe
);
41 var base
= document
. createElement ( 'base' );
43 document
. getElementsByTagName ( "head" )[ 0 ]. appendChild ( base
);
47 // Prevent race conditions between iframe loading and robot init.
48 // If iframe is allowed to load while the robot is typing, sync XHRs can prevent the robot from completing its initialization.
51 var _run
= doh
. robot
. _run
;
52 doh
. robot
. _run = function ( frame
){
53 // Called from robot when the robot completed its initialization.
57 // If initRobot was already called, then attach the iframe.
58 if ( iframe
. src
){ attachIframe (); }
61 var onIframeLoad = function (){
62 // initial load handler: update the document and start the tests
63 doh
. robot
. _updateDocument ();
65 var scrollRoot
= ( document
. compatMode
== 'BackCompat' )? document
. body
: document
. documentElement
;
66 var consoleHeight
= document
. getElementById ( 'robotconsole' ). offsetHeight
;
68 iframe
. style
. height
= ( scrollRoot
. clientHeight
- consoleHeight
)+ "px" ;
70 // If dojo is present in the test case, then at least make a best effort to wait for it to load.
71 // The test must handle other race conditions like initial data queries by itself.
72 if ( iframe
. contentWindow
. dojo
){
73 iframe
. contentWindow
. dojo
. addOnLoad ( function (){
74 doh
. robot
. _run ( robotFrame
);
77 doh
. robot
. _run ( robotFrame
);
81 var iframeLoad = function (){
85 var unloadConnect
= dojo
. connect ( dojo
. body (), 'onunload' , function (){
88 dojo
. disconnect ( unloadConnect
);
92 // write the firebug console to a place it will fit
93 dojo
. config
. debugContainerId
= "robotconsole" ;
94 dojo
. config
. debugHeight
= dojo
. config
. debugHeight
|| 200 ;
95 document
. write ( '<div id="robotconsole" style="position:absolute;left:0px;bottom:0px;width:100%;"></div>' );
98 //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>');
99 iframe
= document
. createElement ( 'iframe' );
100 iframe
. setAttribute ( "ALLOWTRANSPARENCY" , "true" );
101 iframe
. scrolling
= dojo
. isIE
? "yes" : "auto" ;
102 dojo
. style ( iframe
,{ visibility
: 'hidden' , border
: '0px none' , padding
: '0px' , margin
: '0px' , position
: 'absolute' , left
: '0px' , top
: '0px' , width
: '100%' , height
: '100%' });
103 if ( iframe
[ 'attachEvent' ] !== undefined ){
104 iframe
. attachEvent ( 'onload' , iframeLoad
);
106 dojo
. connect ( iframe
, 'onload' , iframeLoad
);
112 dojo
. mixin ( doh
. robot
,{
113 _updateDocument : function (){
114 dojo
. setContext ( iframe
. contentWindow
, iframe
. contentWindow
. document
);
115 var win
= dojo
. global
;
117 // allow the tests to subscribe to topics published by the iframe
118 dojo
. _topics
= win
. dojo
. _topics
;
123 initRobot : function ( /*String*/ url
){
125 // Opens the application at the specified URL for testing, redirecting dojo to point to the application environment instead of the test environment.
128 // 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.
132 // see above note about race conditions
139 waitForPageToLoad : function ( /*Function*/ submitActions
){
141 // Notifies DOH that the doh.robot is about to make a page change in the application it is driving,
142 // returning a doh.Deferred object the user should return in their runTest function as part of a DOH test.
145 // Notifies DOH that the doh.robot is about to make a page change in the application it is driving,
146 // returning a doh.Deferred object the user should return in their runTest function as part of a DOH test.
148 // runTest:function(){
149 // return waitForPageLoad(function(){ doh.robot.keyPress(dojo.keys.ENTER, 500); });
153 // The doh.robot will execute the actions the test passes into the submitActions argument (like clicking the submit button),
154 // expecting these actions to create a page change (like a form submit).
155 // After these actions execute and the resulting page loads, the next test will start.
158 var d
= new doh
. Deferred ();
159 // create iframe event handler to track submit progress
160 onIframeLoad = function (){
162 // set dojo.doc on every page change to point to the iframe doc so the robot works
163 doh
. robot
. _updateDocument ();