Debian Codegraph @

util/doh/Robot.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html style="margin:0px; padding:0px; border:0px none; overflow:hidden;">
3 <head>
4 <script>
5 // support document.domain
6 // Yes, we need this try/catch to handle document.domain.
7 // If one page explicitly sets document.domain,
8 // ALL pages (this page, test case, page to be tested) must also explicitly set document.domain,
9 // or you get Permission Denied.
10 // So it's not as easy as just setting document.domain to whatever the browser reports,
11 // because you don't know if the user explicitly set that.
12 try{
13 // Was the passed domain just a stupid browser default?
14 // If so, this statement will work.
15 var test=window.frameElement.ownerDocument;
16 }catch(e){
17 // Permission Denied.
18 // Means user explicitly set document.domain elsewhere.
19 // robot.js passes the document.domain as a GET parameter.
20 var domain=unescape(/[\\?&]domain=([^&#]*)/.exec(window.location.href)[1]);
21 document.domain=domain;
22 }
23
24 // Setup global "doh" and "robot" variables to point to doh and doh/robot modules that have already
25 // been loaded in parent frame (ie, the main document)
26 var doc = window.frameElement.ownerDocument;
27 var w = doc.parentWindow || doc.defaultView || top;
28 doh = w.require("doh/_browserRunner");
29 robot = w.require("doh/robot");
30
31 function init(){
32 var applet = document.getElementsByTagName('applet')[0];
33
34 robot._killApplet = function(){
35 document.body.removeChild(applet);
36 applet = null;
37 };
38 }
39
40 // the box that the applet writes into to test the user's keyboard capabilities
41 var _robotField = null;
42
43
44 /*
45 Robot uses the event handlers below to measure system-level
46 properties that the java.awt.Robot class just expects us to know
47 magically. For instance, we don't know how big the user set their mouse
48 wheel to be in the Control Panel, so we measure it using onmousewheel.
49 */
50
51 function _onfocus(robotField){
52 _robotField = robotField;
53 robot._initWheel();
54 }
55
56 function _onblur(e){
57 setTimeout(function(){
58 if(_robotField && _robotField.parentNode == document.body){
59 document.body.removeChild(_robotField);
60 }
61 },0);
62 }
63
64 var receivedMouseDown = false;
65 function _onmousedown(e){
66 if(receivedMouseDown){
67 return;
68 }
69 receivedMouseDown=true;
70 e = e||window.event;
71 if(e.screenX == 0||e.clientX == 0){ return; }
72 var docScreenX = e.screenX-e.clientX;
73 var docScreenY = e.screenY-e.clientY;
74 robot._setDocumentBounds(docScreenX, docScreenY);
75 if("stopPropagation" in e){ e.stopPropagation(); }
76 else { e.cancelBubble = false; }
77 return false;
78 }
79
80 function _onmousewheel(e){
81 e = e||window.event;
82 robot.mouseWheelSize = e.detail ? (e.detail * -1) : (e.wheelDelta / 120);
83 if(e.preventDefault){ e.preventDefault(); }
84 else { e.returnValue = false; }
85 robot._primePump = true;
86 robot._initKeyboard();
87 return false;
88 }
89
90 var charCode = 32;
91 var keystring = "";
92 var expectedlength = 0;
93
94 robot._nextKeyGroup = function(size){
95 // called from Robot
96 // moves to the next group of keys to press; shift, alt-graph etc.
97 expectedlength = size;
98 keystring = "";
99 };
100
101 function _onkeypress(e){
102 e = e||window.event;
103 var c = e.charCode ? e.charCode :
104 (e.keyCode ? e.keyCode :
105 (e.which ? e.which : 0)); // opera
106 if(robot._primePump){
107 // event pump was primed with spaces and JS finally received one
108 // tell robot to stop sending spaces now
109 if(c == 32){
110 robot._spaceReceived = true;
111 }
112 else if(c == 13){
113 // enter: start accepting keys
114 robot._primePump = false;
115 }
116 }
117 else if(c == 32){
118 keystring += String.fromCharCode(charCode);
119 charCode = 32;
120 if(keystring.length >= expectedlength){
121 robot._notified(keystring);
122 }
123 }
124 else if(c > 32){ // printable
125 charCode = c;
126 }
127 // keyboard discovery misbehaves on Safari/Mac
128 // prevent default action if possible
129 if(e.preventDefault){ e.preventDefault(); }
130 else { e.returnValue = false; }
131 return false;
132 }
133
134 var rf=null;
135 robot._onKeyboard = function(){
136 // called from Robot
137 // Robot calls _onKeyboard after it finishes discovering the keyboard
138 // need to untie from Java thread with setTimeout
139 setTimeout(function(){
140 rf.style.visibility = "hidden";
141 robot._run(window.frameElement);
142 }, 0);
143 };
144
145 // stubs to help FF23+ new security policies
146 window._onKeyboard=function(){
147 robot._onKeyboard();
148 }
149
150 window._nextKeyGroup=function(size){
151 robot._nextKeyGroup(size);
152 }
153 </script>
154 </head>
155 <body id="robotBody"
156 style="margin:0px; padding:0px; border:0px none;background-color:transparent;" onload="init()">
157 <input type="text" tabIndex="-1" style="border:0px none;margin:0px;padding:0px;width:200px;height:100px;background-color:white;z-index:9998;opacity:0;filter:alpha(opacity=0);cursor:default;"
158 onmousewheel="_onmousewheel(arguments[0])"
159 onmousedown="_onmousedown(arguments[0])"
160 onkeypress="_onkeypress(arguments[0])"
161 onfocus="_onfocus(this)"
162 onblur="_onblur(arguments[0])"></input>
163 <script>
164 rf = document.getElementsByTagName('input')[0];
165 if(rf.addEventListener){
166 rf.addEventListener('DOMMouseScroll', _onmousewheel, false);
167 }
168 </script>
169 <img src="robot/signature.png" style="width:3px; height:3px; position:absolute; left:0px; top:0px; z-index:9999"></img>
170 <script>
171 // taken from hostenv_browser.js
172 // Dojo is not always available to DOH
173 var needsSecurityManager='<param name="needsSecurityManager" value="'+((
174 (Math.max(navigator.appVersion.indexOf("WebKit"), navigator.appVersion.indexOf("Safari"), 0) > 0 && navigator.userAgent.indexOf("Chrome/") == -1 && parseFloat(navigator.appVersion.split("Version/")[1]) < 4) // Safari 3
175 || (document.all && navigator.userAgent.indexOf("Opera") == -1 && parseFloat(navigator.appVersion.split("MSIE ")[1]) < 8)) // IE6,7
176 ?"true":"false")+'">';
177 var appletString = '<applet width="1" height="1" code="DOHRobot.class" archive="robot/DOHRobot.jar" MAYSCRIPT style="position:absolute;left:0px;top:0px;"><param name="mayscript" value="true"><param name="scriptable" value="true"><param name="initial_focus" value="false">'+needsSecurityManager+'</applet>';
178 document.write(appletString);
179 // if no Java, the applet is officially dead
180 if(/MSIE/.test(navigator.appVersion)){
181 // navigator.javaEnabled() not known for its reliability in IE6
182 try{
183 // applet loads synchronously in IE6
184 document.applets[0].isActive();
185 }catch(e){
186 robot._appletDead=true;
187 // IE skips the dojo.robot XHR test below in the else
188 // since the no java behavior is the same as no applet behavior in IE
189 doh.run();
190 }
191 }else if(!navigator.javaEnabled()){
192 // FF, Safari, Opera etc.
193 // unreliable in IE6
194 robot._appletDead=true;
195 doh.run();
196 }else{
197 // Opera etc. have Java enabled, but load the applet asychronously so it might still be missing from server at this point
198 // Do an XHR to find out if the applet is there
199 // IE is taken care of in the first if, so no need for special ActiveX XHR for it
200 var dohRobotCheck=new XMLHttpRequest();
201 dohRobotCheck.onreadystatechange=function(){
202 if(dohRobotCheck.readyState == 4 && dohRobotCheck.status == 404){
203 // oops! no applet
204 // move the tests along
205 robot._appletDead=true;
206 doh.run();
207 }
208 };
209 dohRobotCheck.open("HEAD", "robot/DOHRobot.jar");
210 dohRobotCheck.send(null);
211 }
212 </script>
213 </body>
214 </html>