]> git.wh0rd.org - tt-rss.git/blob - lib/dojo/robotx.js
remove call-by-reference to comply with php 5.4
[tt-rss.git] / lib / dojo / robotx.js
1 /*
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
5 */
6
7
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");
12
13
14 dojo.experimental("dojo.robotx");
15
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
19
20 (function(){
21
22 var iframe = null;
23
24 var groupStarted=dojo.connect(doh, '_groupStarted', function(){
25 dojo.disconnect(groupStarted);
26 iframe.style.visibility="visible";
27 });
28
29 var attachIframe = function(){
30 dojo.addOnLoad(function(){
31 var emptyStyle = {
32 overflow: dojo.isWebKit? 'hidden' : 'visible',
33 margin: '0px',
34 borderWidth: '0px',
35 height: '100%',
36 width: '100%'
37 };
38 dojo.style(document.documentElement, emptyStyle);
39 dojo.style(document.body, emptyStyle);
40 document.body.appendChild(iframe);
41 var base=document.createElement('base');
42 base.href=iframe.src;
43 document.getElementsByTagName("head")[0].appendChild(base);
44 });
45 };
46
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.
49 var robotReady=false;
50 var robotFrame=null;
51 var _run=doh.robot._run;
52 doh.robot._run=function(frame){
53 // Called from robot when the robot completed its initialization.
54 robotReady = true;
55 robotFrame = frame;
56 doh.robot._run=_run;
57 // If initRobot was already called, then attach the iframe.
58 if(iframe.src){ attachIframe(); }
59 }
60
61 var onIframeLoad=function(){
62 // initial load handler: update the document and start the tests
63 doh.robot._updateDocument();
64 onIframeLoad = null;
65 var scrollRoot = (document.compatMode == 'BackCompat')? document.body : document.documentElement;
66 var consoleHeight = document.getElementById('robotconsole').offsetHeight;
67 if(consoleHeight){
68 iframe.style.height = (scrollRoot.clientHeight - consoleHeight)+"px";
69 }
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);
75 });
76 }else{
77 doh.robot._run(robotFrame);
78 }
79 };
80
81 var iframeLoad=function(){
82 if(onIframeLoad){
83 onIframeLoad();
84 }
85 var unloadConnect = dojo.connect(dojo.body(), 'onunload', function(){
86 dojo.global = window;
87 dojo.doc = document;
88 dojo.disconnect(unloadConnect);
89 });
90 };
91
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>');
96
97 // write the iframe
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);
105 }else{
106 dojo.connect(iframe, 'onload', iframeLoad);
107 }
108
109
110
111
112 dojo.mixin(doh.robot,{
113 _updateDocument: function(){
114 dojo.setContext(iframe.contentWindow, iframe.contentWindow.document);
115 var win = dojo.global;
116 if(win["dojo"]){
117 // allow the tests to subscribe to topics published by the iframe
118 dojo._topics = win.dojo._topics;
119 }
120
121 },
122
123 initRobot: function(/*String*/ url){
124 // summary:
125 // Opens the application at the specified URL for testing, redirecting dojo to point to the application environment instead of the test environment.
126 //
127 // url:
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.
129 //
130
131 iframe.src=url;
132 // see above note about race conditions
133 if(robotReady){
134 attachIframe();
135
136 }
137 },
138
139 waitForPageToLoad: function(/*Function*/ submitActions){
140 // summary:
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.
143 //
144 // description:
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.
147 // Example:
148 // runTest:function(){
149 // return waitForPageLoad(function(){ doh.robot.keyPress(dojo.keys.ENTER, 500); });
150 // }
151 //
152 // submitActions:
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.
156 //
157
158 var d = new doh.Deferred();
159 // create iframe event handler to track submit progress
160 onIframeLoad = function(){
161 onIframeLoad = null;
162 // set dojo.doc on every page change to point to the iframe doc so the robot works
163 doh.robot._updateDocument();
164 d.callback(true);
165 };
166 submitActions();
167 return d;
168 }
169
170 });
171 })();
172
173 }