-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-extensions.3.ie.js
349 lines (299 loc) · 11.9 KB
/
user-extensions.3.ie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/**
* This file wraps the Snapsie ActiveX object, exposing a single saveSnapshot()
* method on a singleton object.
*
* See http://snapsie.sourceforge.net/
*/
/*****************
WALTY: I did not modify the code here, but I updated the activex source code, so it now try
to get the screen capture of whole PC, instead of the browser
Anyway, I give up the IE testing eventually, due to lack of support of selenium driver
for IE (should use webdriver instead).
*******************/
if(jQuery.browser.msie){
window.Snapsie = new function() {
// private fields
var nativeObj;
// private methods
function init() {
try {
nativeObj = new ActiveXObject('Snapsie.CoSnapsie');
}
catch (e) {
showException(e);
}
}
function showException(e) {
// alert(e + ', ' + (e.message ? e.message : ""));
throw e;
}
function isQuirksMode(inDocument) {
return (inDocument.compatMode == 'BackCompat');
}
function getDrawableElement(inDocument) {
if (isQuirksMode(inDocument)) {
return inDocument.getElementsByTagName('body')[0];
}
else {
// standards mode
return inDocument.documentElement;
}
}
/**
* Returns the canonical Windows path for a given path. This means
* basically replacing any forwards slashes with backslashes.
*
* @param path the path whose canonical form to return
*/
function getCanonicalPath(path) {
path = path.replace(/\//g, '\\');
path = path.replace(/\\\\/g, '\\');
return path;
}
// public methods
/**
* Saves a screenshot of the current document to a file. If frameId is
* specified, a screenshot of just the frame is captured instead.
*
* @param outputFile the file to which to save the screenshot
* @param frameId the frame to capture; omit to capture entire document
*/
this.saveSnapshot = function(outputFile, frameId) {
if (!nativeObj) {
var e = new Exception('Snapsie was not properly initialized');
showException(e);
return;
}
var currentDocument = selenium.browserbot.getDocument();
var drawableElement = getDrawableElement(currentDocument);
//var drawableElement = getDrawableElement(document);
var drawableInfo = {
overflow : drawableElement.style.overflow
, scrollLeft: drawableElement.scrollLeft
, scrollTop : drawableElement.scrollTop
};
drawableElement.style.overflow = 'hidden';
var capturableDocument;
var frameBCR = { left: 0, top: 0 };
if (arguments.length == 1) {
capturableDocument = currentDocument;
}
else {
var frame = currentDocument.getElementById(frameId);
capturableDocument = frame.document;
// scroll as much of the frame into view as possible
frameBCR = frame.getBoundingClientRect();
selenium.browserbot.getWindow().scroll(frameBCR.left, frameBCR.top);
//window.scroll(frameBCR.left, frameBCR.top);
frameBCR = frame.getBoundingClientRect();
}
try {
//alert("@9197:" + getCanonicalPath(outputFile) );
//alert("@9194: " + nativeObj);
//alert("@9195: " + nativeObj.saveSnapshot);
//alert("@9198:" + frameId);
//alert("@9198:" + drawableElement.clientWidth);
//alert("@9198:" + drawableElement.clientHeight);
//alert("@9198:" + frameBCR.left);
//alert("@9198:" + frameBCR.top);
nativeObj.saveSnapshot(
getCanonicalPath(outputFile),
frameId,
drawableElement.scrollWidth,
drawableElement.scrollHeight,
drawableElement.clientWidth,
drawableElement.clientHeight,
drawableElement.clientLeft,
drawableElement.clientTop,
frameBCR.left,
frameBCR.top
);
// alert("@9210: done");
}
catch (e) {
showException(e);
}
// revert
drawableElement.style.overflow = drawableInfo.overflow;
drawableElement.scrollLeft = drawableInfo.scrollLeft;
drawableElement.scrollTop = drawableInfo.scrollTop;
}
// initializers
init();
};
}
else
window.snapsie = null;
/*this one is not used any more*/
/*
function printStackTrace() {
var callstack = [];
var isCallstackPopulated = false;
try {
i.dont.exist+=0; //doesn't exist- that's the point
} catch(e) {
if (e.stack) { //Firefox
var lines = e.stack.split('\n');
for (var i=0, len=lines.length; i<len; i++) {
if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
callstack.push(lines[i]);
}
}
//Remove call to printStackTrace()
callstack.shift();
isCallstackPopulated = true;
}
else if (window.opera && e.message) { //Opera
var lines = e.message.split('\n');
for (var i=0, len=lines.length; i<len; i++) {
if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
var entry = lines[i];
//Append next line also since it has the file info
if (lines[i+1]) {
entry += ' at ' + lines[i+1];
i++;
}
callstack.push(entry);
}
}
//Remove call to printStackTrace()
callstack.shift();
isCallstackPopulated = true;
}
}
if (!isCallstackPopulated) { //IE and Safari
var currentFunction = arguments.callee.caller;
while (currentFunction) {
var fn = currentFunction.toString();
var fname = fn.substring(fn.indexOf('function') + 8, fn.indexOf('')) || 'anonymous';
callstack.push(fname);
currentFunction = currentFunction.caller;
}
}
alert(callstack);
}
*/
/*
if (jQuery.browser.msie) {
Selenium.prototype.doOpen = function(url, ignoreResponseCode) {
this.browserbot.isNewPageLoaded = function() {
var e;
if (this.pageLoadError) {
LOG.error("isNewPageLoaded found an old pageLoadError: " + this.pageLoadError);
if (this.pageLoadError.stack) {
LOG.warn("Stack is: " + this.pageLoadError.stack);
}
e = this.pageLoadError;
this.pageLoadError = null;
throw e;
}
if (self.ignoreResponseCode) {
return self.newPageLoaded;
} else {
if (self.isXhrSent && self.isXhrDone) {
if (!((self.xhrResponseCode >= 200 && self.xhrResponseCode <= 399) || self.xhrResponseCode == 0)) {
// TODO: for IE status like: 12002, 12007, ... provide corresponding statusText messages also.
LOG.error("XHR failed with message " + self.xhrStatusText);
e = "XHR ERROR: URL = " + self.xhrOpenLocation + " Response_Code = " + self.xhrResponseCode + " Error_Message = " + self.xhrStatusText;
self.abortXhr = false;
self.isXhrSent = false;
self.isXhrDone = false;
self.xhrResponseCode = null;
self.xhrStatusText = null;
throw new SeleniumError(e);
}
}
return self.newPageLoaded && (self.isXhrSent ? (self.abortXhr || self.isXhrDone) : true);
}
}; //end of browserbot override
if (ignoreResponseCode == null || ignoreResponseCode.length == 0) {
this.browserbot.ignoreResponseCode = true;
} else if (ignoreResponseCode.toLowerCase() == "true") {
this.browserbot.ignoreResponseCode = true;
} else {
this.browserbot.ignoreResponseCode = false;
}
this.browserbot.openLocation(url);
this.browserbot.pageLoadError = null;
if (window["proxyInjectionMode"] == null || !window["proxyInjectionMode"]) {
return this.makePageLoadCondition();
} // in PI mode, just return "OK"; the server will waitForLoad
};
}
*/
//alert(jQuery.browser.msie);
//
//override default fire event
Selenium.prototype.doFireEvent = function(locator, eventName) {
/**
* Explicitly simulate an event, to trigger the corresponding "on<em>event</em>"
* handler.
*
* @param locator an <a href="#locators">element locator</a>
* @param eventName the event name, e.g. "focus" or "blur"
*/
var element = this.browserbot.findElement(locator);
var doc = goog.dom.getOwnerDocument(element);
var view = goog.dom.getWindow(doc);
//walty
if (jQuery.browser.msie && view.jQuery){
view.jQuery(element).trigger(eventName);
return;
}
//default implementation
if (element.fireEvent && element.ownerDocument && element.ownerDocument.createEventObject) { // IE
var ieEvent = createEventObject(element, false, false, false, false);
element.fireEvent('on' + eventName, ieEvent);
} else {
var evt = doc.createEvent('HTMLEvents');
evt.initEvent(eventName, true, true);
element.dispatchEvent(evt);
}
};
function triggerKeyEvent(element, eventType, keySequence, canBubble, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) {
var keycode = getKeyCodeFromKeySequence(keySequence);
//walty
var doc = goog.dom.getOwnerDocument(element);
var view = goog.dom.getWindow(doc);
LOG.info("@9815: " + eventType + ", " + keySequence + ", " + keycode + ", " + (typeof keycode));
if (jQuery.browser.msie && view.jQuery){
if(keycode && (typeof keycode === "string"))
{
LOG.info("@9820: " + keycode);
keycode = parseInt(keycode); //the default is string
LOG.info("@9822");
}
LOG.info("@9817");
var e = view.jQuery.Event( eventType, { which: keycode, keyCode: keycode } );
LOG.info("@9743");
view.jQuery(element).trigger(e);
LOG.info("@9743");
return;
}
//original
canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
if (element.fireEvent && element.ownerDocument && element.ownerDocument.createEventObject) { // IE
var keyEvent = createEventObject(element, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown);
keyEvent.keyCode = keycode;
element.fireEvent('on' + eventType, keyEvent);
}
else {
var evt;
if (window.KeyEvent) {
var doc = goog.dom.getOwnerDocument(element);
var view = goog.dom.getWindow(doc);
evt = doc.createEvent('KeyEvents');
evt.initKeyEvent(eventType, true, true, view, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown, keycode, keycode);
} else {
evt = document.createEvent('UIEvents');
evt.shiftKey = shiftKeyDown;
evt.metaKey = metaKeyDown;
evt.altKey = altKeyDown;
evt.ctrlKey = controlKeyDown;
evt.initUIEvent(eventType, true, true, window, 1);
evt.keyCode = keycode;
evt.which = keycode;
}
element.dispatchEvent(evt);
}
}