selenium-webdriver 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/chrome/prebuilt/Win32/Release/npchromedriver.dll +0 -0
- data/chrome/prebuilt/x64/Release/npchromedriver.dll +0 -0
- data/chrome/src/extension/background.html +9 -0
- data/chrome/src/extension/background.js +933 -0
- data/chrome/src/extension/content_script.js +1286 -0
- data/chrome/src/extension/manifest-nonwin.json +15 -0
- data/chrome/src/extension/manifest-win.json +16 -0
- data/chrome/src/extension/toolstrip.html +28 -0
- data/chrome/src/extension/utils.js +196 -0
- data/chrome/src/rb/lib/selenium/webdriver/chrome.rb +8 -0
- data/chrome/src/rb/lib/selenium/webdriver/chrome/bridge.rb +324 -0
- data/chrome/src/rb/lib/selenium/webdriver/chrome/command_executor.rb +70 -0
- data/chrome/src/rb/lib/selenium/webdriver/chrome/launcher.rb +119 -0
- data/common/src/js/abstractcommandprocessor.js +161 -0
- data/common/src/js/asserts.js +296 -0
- data/common/src/js/by.js +147 -0
- data/common/src/js/command.js +274 -0
- data/common/src/js/context.js +58 -0
- data/common/src/js/extension/README +2 -0
- data/common/src/js/extension/dommessenger.js +152 -0
- data/common/src/js/factory.js +55 -0
- data/common/src/js/future.js +118 -0
- data/common/src/js/key.js +117 -0
- data/common/src/js/localcommandprocessor.js +181 -0
- data/common/src/js/logging.js +249 -0
- data/common/src/js/testrunner.js +605 -0
- data/common/src/js/timing.js +89 -0
- data/common/src/js/wait.js +199 -0
- data/common/src/js/webdriver.js +853 -0
- data/common/src/js/webelement.js +683 -0
- data/common/src/rb/lib/selenium-webdriver.rb +1 -0
- data/common/src/rb/lib/selenium/webdriver.rb +52 -0
- data/common/src/rb/lib/selenium/webdriver/bridge_helper.rb +88 -0
- data/common/src/rb/lib/selenium/webdriver/child_process.rb +85 -0
- data/common/src/rb/lib/selenium/webdriver/core_ext/dir.rb +41 -0
- data/common/src/rb/lib/selenium/webdriver/driver.rb +128 -0
- data/common/src/rb/lib/selenium/webdriver/element.rb +126 -0
- data/common/src/rb/lib/selenium/webdriver/error.rb +68 -0
- data/common/src/rb/lib/selenium/webdriver/find.rb +69 -0
- data/common/src/rb/lib/selenium/webdriver/navigation.rb +23 -0
- data/common/src/rb/lib/selenium/webdriver/options.rb +50 -0
- data/common/src/rb/lib/selenium/webdriver/platform.rb +82 -0
- data/common/src/rb/lib/selenium/webdriver/target_locator.rb +23 -0
- data/firefox/prebuilt/nsICommandProcessor.xpt +0 -0
- data/firefox/prebuilt/nsINativeEvents.xpt +0 -0
- data/firefox/prebuilt/nsIResponseHandler.xpt +0 -0
- data/firefox/src/extension/chrome.manifest +3 -0
- data/firefox/src/extension/components/context.js +37 -0
- data/firefox/src/extension/components/driver-component.js +127 -0
- data/firefox/src/extension/components/firefoxDriver.js +706 -0
- data/firefox/src/extension/components/json2.js +273 -0
- data/firefox/src/extension/components/keytest.html +554 -0
- data/firefox/src/extension/components/nsCommandProcessor.js +586 -0
- data/firefox/src/extension/components/screenshooter.js +70 -0
- data/firefox/src/extension/components/socketListener.js +185 -0
- data/firefox/src/extension/components/utils.js +1200 -0
- data/firefox/src/extension/components/webLoadingListener.js +57 -0
- data/firefox/src/extension/components/webdriverserver.js +101 -0
- data/firefox/src/extension/components/wrappedElement.js +609 -0
- data/firefox/src/extension/content/fxdriver.xul +30 -0
- data/firefox/src/extension/content/server.js +95 -0
- data/firefox/src/extension/idl/nsICommandProcessor.idl +38 -0
- data/firefox/src/extension/idl/nsIResponseHandler.idl +34 -0
- data/firefox/src/extension/install.rdf +29 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox.rb +21 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/binary.rb +86 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/bridge.rb +426 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/extension_connection.rb +82 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb +132 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/profile.rb +174 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/profiles_ini.rb +60 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/util.rb +23 -0
- data/jobbie/prebuilt/Win32/Release/InternetExplorerDriver.dll +0 -0
- data/jobbie/prebuilt/x64/Release/InternetExplorerDriver.dll +0 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie.rb +14 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie/bridge.rb +552 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie/lib.rb +94 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie/util.rb +147 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote.rb +16 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/bridge.rb +374 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/capabilities.rb +105 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/commands.rb +53 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/default_http_client.rb +71 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/response.rb +43 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/server_error.rb +32 -0
- metadata +182 -0
@@ -0,0 +1,273 @@
|
|
1
|
+
/*
|
2
|
+
json2.js
|
3
|
+
2008-01-17
|
4
|
+
|
5
|
+
Public Domain
|
6
|
+
|
7
|
+
No warranty expressed or implied. Use at your own risk.
|
8
|
+
|
9
|
+
See http://www.JSON.org/js.html
|
10
|
+
|
11
|
+
This file creates a global JSON object containing two methods:
|
12
|
+
|
13
|
+
JSON.stringify(value, whitelist)
|
14
|
+
value any JavaScript value, usually an object or array.
|
15
|
+
|
16
|
+
whitelist an optional array prameter that determines how object
|
17
|
+
values are stringified.
|
18
|
+
|
19
|
+
This method produces a JSON text from a JavaScript value.
|
20
|
+
There are three possible ways to stringify an object, depending
|
21
|
+
on the optional whitelist parameter.
|
22
|
+
|
23
|
+
If an object has a toJSON method, then the toJSON() method will be
|
24
|
+
called. The value returned from the toJSON method will be
|
25
|
+
stringified.
|
26
|
+
|
27
|
+
Otherwise, if the optional whitelist parameter is an array, then
|
28
|
+
the elements of the array will be used to select members of the
|
29
|
+
object for stringification.
|
30
|
+
|
31
|
+
Otherwise, if there is no whitelist parameter, then all of the
|
32
|
+
members of the object will be stringified.
|
33
|
+
|
34
|
+
Values that do not have JSON representaions, such as undefined or
|
35
|
+
functions, will not be serialized. Such values in objects will be
|
36
|
+
dropped; in arrays will be replaced with null.
|
37
|
+
JSON.stringify(undefined) returns undefined. Dates will be
|
38
|
+
stringified as quoted ISO dates.
|
39
|
+
|
40
|
+
Example:
|
41
|
+
|
42
|
+
var text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
43
|
+
// text is '["e",{"pluribus":"unum"}]'
|
44
|
+
|
45
|
+
JSON.parse(text, filter)
|
46
|
+
This method parses a JSON text to produce an object or
|
47
|
+
array. It can throw a SyntaxError exception.
|
48
|
+
|
49
|
+
The optional filter parameter is a function that can filter and
|
50
|
+
transform the results. It receives each of the keys and values, and
|
51
|
+
its return value is used instead of the original value. If it
|
52
|
+
returns what it received, then structure is not modified. If it
|
53
|
+
returns undefined then the member is deleted.
|
54
|
+
|
55
|
+
Example:
|
56
|
+
|
57
|
+
// Parse the text. If a key contains the string 'date' then
|
58
|
+
// convert the value to a date.
|
59
|
+
|
60
|
+
myData = JSON.parse(text, function (key, value) {
|
61
|
+
return key.indexOf('date') >= 0 ? new Date(value) : value;
|
62
|
+
});
|
63
|
+
|
64
|
+
This is a reference implementation. You are free to copy, modify, or
|
65
|
+
redistribute.
|
66
|
+
|
67
|
+
Use your own copy. It is extremely unwise to load third party
|
68
|
+
code into your pages.
|
69
|
+
*/
|
70
|
+
|
71
|
+
/*jslint evil: true */
|
72
|
+
|
73
|
+
/*global JSON */
|
74
|
+
|
75
|
+
/*members "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
76
|
+
charCodeAt, floor, getUTCDate, getUTCFullYear, getUTCHours,
|
77
|
+
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, length,
|
78
|
+
parse, propertyIsEnumerable, prototype, push, replace, stringify, test,
|
79
|
+
toJSON, toString
|
80
|
+
*/
|
81
|
+
|
82
|
+
if (!this.JSON) {
|
83
|
+
|
84
|
+
JSON = function () {
|
85
|
+
|
86
|
+
function f(n) { // Format integers to have at least two digits.
|
87
|
+
return n < 10 ? '0' + n : n;
|
88
|
+
}
|
89
|
+
|
90
|
+
Date.prototype.toJSON = function () {
|
91
|
+
|
92
|
+
// Eventually, this method will be based on the date.toISOString method.
|
93
|
+
|
94
|
+
return this.getUTCFullYear() + '-' +
|
95
|
+
f(this.getUTCMonth() + 1) + '-' +
|
96
|
+
f(this.getUTCDate()) + 'T' +
|
97
|
+
f(this.getUTCHours()) + ':' +
|
98
|
+
f(this.getUTCMinutes()) + ':' +
|
99
|
+
f(this.getUTCSeconds()) + 'Z';
|
100
|
+
};
|
101
|
+
|
102
|
+
|
103
|
+
var m = { // table of character substitutions
|
104
|
+
'\b': '\\b',
|
105
|
+
'\t': '\\t',
|
106
|
+
'\n': '\\n',
|
107
|
+
'\f': '\\f',
|
108
|
+
'\r': '\\r',
|
109
|
+
'"' : '\\"',
|
110
|
+
'\\': '\\\\'
|
111
|
+
};
|
112
|
+
|
113
|
+
function stringify(value, whitelist) {
|
114
|
+
var a, // The array holding the partial texts.
|
115
|
+
i, // The loop counter.
|
116
|
+
k, // The member key.
|
117
|
+
l, // Length.
|
118
|
+
r = /["\\\x00-\x1f\x7f-\x9f]/g,
|
119
|
+
v; // The member value.
|
120
|
+
|
121
|
+
switch (typeof value) {
|
122
|
+
case 'string':
|
123
|
+
|
124
|
+
// If the string contains no control characters, no quote characters, and no
|
125
|
+
// backslash characters, then we can safely slap some quotes around it.
|
126
|
+
// Otherwise we must also replace the offending characters with safe sequences.
|
127
|
+
|
128
|
+
return r.test(value) ?
|
129
|
+
'"' + value.replace(r, function (a) {
|
130
|
+
var c = m[a];
|
131
|
+
if (c) {
|
132
|
+
return c;
|
133
|
+
}
|
134
|
+
c = a.charCodeAt();
|
135
|
+
return '\\u00' + Math.floor(c / 16).toString(16) +
|
136
|
+
(c % 16).toString(16);
|
137
|
+
}) + '"' :
|
138
|
+
'"' + value + '"';
|
139
|
+
|
140
|
+
case 'number':
|
141
|
+
|
142
|
+
// JSON numbers must be finite. Encode non-finite numbers as null.
|
143
|
+
|
144
|
+
return isFinite(value) ? String(value) : 'null';
|
145
|
+
|
146
|
+
case 'boolean':
|
147
|
+
case 'null':
|
148
|
+
return String(value);
|
149
|
+
|
150
|
+
case 'object':
|
151
|
+
|
152
|
+
// Due to a specification blunder in ECMAScript,
|
153
|
+
// typeof null is 'object', so watch out for that case.
|
154
|
+
|
155
|
+
if (!value) {
|
156
|
+
return 'null';
|
157
|
+
}
|
158
|
+
|
159
|
+
// If the object has a toJSON method, call it, and stringify the result.
|
160
|
+
|
161
|
+
if (typeof value.toJSON === 'function') {
|
162
|
+
return stringify(value.toJSON());
|
163
|
+
}
|
164
|
+
a = [];
|
165
|
+
if (typeof value.length === 'number' &&
|
166
|
+
!(value.propertyIsEnumerable('length'))) {
|
167
|
+
|
168
|
+
// The object is an array. Stringify every element. Use null as a placeholder
|
169
|
+
// for non-JSON values.
|
170
|
+
|
171
|
+
l = value.length;
|
172
|
+
for (i = 0; i < l; i += 1) {
|
173
|
+
a.push(stringify(value[i], whitelist) || 'null');
|
174
|
+
}
|
175
|
+
|
176
|
+
// Join all of the elements together and wrap them in brackets.
|
177
|
+
|
178
|
+
return '[' + a.join(',') + ']';
|
179
|
+
}
|
180
|
+
if (whitelist) {
|
181
|
+
|
182
|
+
// If a whitelist (array of keys) is provided, use it to select the components
|
183
|
+
// of the object.
|
184
|
+
|
185
|
+
l = whitelist.length;
|
186
|
+
for (i = 0; i < l; i += 1) {
|
187
|
+
k = whitelist[i];
|
188
|
+
if (typeof k === 'string') {
|
189
|
+
v = stringify(value[k], whitelist);
|
190
|
+
if (v) {
|
191
|
+
a.push(stringify(k) + ':' + v);
|
192
|
+
}
|
193
|
+
}
|
194
|
+
}
|
195
|
+
} else {
|
196
|
+
|
197
|
+
// Otherwise, iterate through all of the keys in the object.
|
198
|
+
|
199
|
+
for (k in value) {
|
200
|
+
if (typeof k === 'string') {
|
201
|
+
v = stringify(value[k], whitelist);
|
202
|
+
if (v) {
|
203
|
+
a.push(stringify(k) + ':' + v);
|
204
|
+
}
|
205
|
+
}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
// Join all of the member texts together and wrap them in braces.
|
210
|
+
|
211
|
+
return '{' + a.join(',') + '}';
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
return {
|
216
|
+
stringify: stringify,
|
217
|
+
parse: function (text, filter) {
|
218
|
+
var j;
|
219
|
+
|
220
|
+
function walk(k, v) {
|
221
|
+
var i, n;
|
222
|
+
if (v && typeof v === 'object') {
|
223
|
+
for (i in v) {
|
224
|
+
if (Object.prototype.hasOwnProperty.apply(v, [i])) {
|
225
|
+
n = walk(i, v[i]);
|
226
|
+
if (n !== undefined) {
|
227
|
+
v[i] = n;
|
228
|
+
}
|
229
|
+
}
|
230
|
+
}
|
231
|
+
}
|
232
|
+
return filter(k, v);
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
// Parsing happens in three stages. In the first stage, we run the text against
|
237
|
+
// regular expressions that look for non-JSON patterns. We are especially
|
238
|
+
// concerned with '()' and 'new' because they can cause invocation, and '='
|
239
|
+
// because it can cause mutation. But just to be safe, we want to reject all
|
240
|
+
// unexpected forms.
|
241
|
+
|
242
|
+
// We split the first stage into 4 regexp operations in order to work around
|
243
|
+
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
244
|
+
// replace all backslash pairs with '@' (a non-JSON character). Second, we
|
245
|
+
// replace all simple value tokens with ']' characters. Third, we delete all
|
246
|
+
// open brackets that follow a colon or comma or that begin the text. Finally,
|
247
|
+
// we look to see that the remaining characters are only whitespace or ']' or
|
248
|
+
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
249
|
+
|
250
|
+
if (/^[\],:{}\s]*$/.test(text.replace(/\\./g, '@').
|
251
|
+
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
|
252
|
+
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
253
|
+
|
254
|
+
// In the second stage we use the eval function to compile the text into a
|
255
|
+
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
256
|
+
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
257
|
+
// in parens to eliminate the ambiguity.
|
258
|
+
|
259
|
+
j = eval('(' + text + ')');
|
260
|
+
|
261
|
+
// In the optional third stage, we recursively walk the new structure, passing
|
262
|
+
// each name/value pair to a filter function for possible transformation.
|
263
|
+
|
264
|
+
return typeof filter === 'function' ? walk('', j) : j;
|
265
|
+
}
|
266
|
+
|
267
|
+
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
268
|
+
|
269
|
+
throw new SyntaxError('parseJSON');
|
270
|
+
}
|
271
|
+
};
|
272
|
+
}();
|
273
|
+
}
|
@@ -0,0 +1,554 @@
|
|
1
|
+
<html>
|
2
|
+
|
3
|
+
<head>
|
4
|
+
<title>Key Test</title>
|
5
|
+
|
6
|
+
<script>
|
7
|
+
// Derived from javascript for http://unixpapa.com/js/testkey.html by
|
8
|
+
// Jan Wolter and modified to test drive WebDriver's utils.js code in
|
9
|
+
// situ on FireFox to test the keyboard event generation code - noel
|
10
|
+
//
|
11
|
+
// NOTE don't run the keyboard tests in FireFox 3 on Win32 Vista with
|
12
|
+
// keyevent display on (turns your machine to sludge) - noel
|
13
|
+
|
14
|
+
var lines = 0;
|
15
|
+
var maxlines = 32 - 1;
|
16
|
+
|
17
|
+
function initPage() {
|
18
|
+
if (document.addEventListener) {
|
19
|
+
var script = document.createElement('script');
|
20
|
+
script.src = "utils.js";
|
21
|
+
document['body'].appendChild(script);
|
22
|
+
document.addEventListener("keydown", keydown, false);
|
23
|
+
document.addEventListener("keypress", keypress, false);
|
24
|
+
document.addEventListener("keyup", keyup, false);
|
25
|
+
} else if (document.attachEvent) {
|
26
|
+
document.attachEvent("onkeydown", keydown);
|
27
|
+
document.attachEvent("onkeypress", keypress);
|
28
|
+
document.attachEvent("onkeyup", keyup);
|
29
|
+
} else {
|
30
|
+
document.onkeydown = keydown;
|
31
|
+
document.onkeypress = keypress;
|
32
|
+
document.onkeyup = keyup;
|
33
|
+
}
|
34
|
+
|
35
|
+
document.testform.t.value += '';
|
36
|
+
resetlines();
|
37
|
+
}
|
38
|
+
|
39
|
+
function showmesg(t) {
|
40
|
+
var old = document.testform.t.value;
|
41
|
+
|
42
|
+
if (lines >= maxlines) {
|
43
|
+
var i = old.indexOf('\n');
|
44
|
+
if (i >= 0) {
|
45
|
+
old = old.substr(i + 1);
|
46
|
+
}
|
47
|
+
} else {
|
48
|
+
++lines;
|
49
|
+
}
|
50
|
+
|
51
|
+
document.testform.t.value = old + t + '\n';
|
52
|
+
}
|
53
|
+
|
54
|
+
function keyval(n) {
|
55
|
+
if (n == null)
|
56
|
+
return 'undefined';
|
57
|
+
var s = '' + n;
|
58
|
+
if (n >= 32 && n < 127)
|
59
|
+
s += ' (' + String.fromCharCode(n) + ')';
|
60
|
+
while (s.length < 9)
|
61
|
+
s += ' ';
|
62
|
+
return s;
|
63
|
+
}
|
64
|
+
|
65
|
+
function pressmesg(w, e) {
|
66
|
+
showmesg(w + ' keyCode=' + keyval(e.keyCode) +
|
67
|
+
' which=' + keyval(e.which) +
|
68
|
+
' charCode=' + keyval(e.charCode));
|
69
|
+
showmesg(' shiftKey=' + e.shiftKey +
|
70
|
+
' ctrlKey=' + e.ctrlKey +
|
71
|
+
' altKey=' + e.altKey +
|
72
|
+
' metaKey=' + e.metaKey);
|
73
|
+
}
|
74
|
+
|
75
|
+
function keymesg(w, e) {
|
76
|
+
showmesg(w + ' keyCode=' + keyval(e.keyCode) +
|
77
|
+
' which=' + keyval(e.which) +
|
78
|
+
' charCode=' + keyval(e.charCode));
|
79
|
+
// showmesg(' keyIdentifier=' + e.keyIdentifier +
|
80
|
+
// ' keyLocation=' + e.keyLocation);
|
81
|
+
showmesg(' shiftKey=' + e.shiftKey +
|
82
|
+
' ctrlKey=' + e.ctrlKey +
|
83
|
+
' altKey=' + e.altKey +
|
84
|
+
' metaKey=' + e.metaKey);
|
85
|
+
}
|
86
|
+
|
87
|
+
function keydown(e) {
|
88
|
+
if (document.testform.keydown.checked)
|
89
|
+
keymesg('keydown ', !e ? event : e);
|
90
|
+
}
|
91
|
+
|
92
|
+
function keyup(e) {
|
93
|
+
if (document.testform.keyup.checked)
|
94
|
+
keymesg('keyup ', !e ? event : e);
|
95
|
+
}
|
96
|
+
|
97
|
+
function keypress(e) {
|
98
|
+
if (document.testform.keypress.checked)
|
99
|
+
pressmesg('keypress', !e ? event : e);
|
100
|
+
}
|
101
|
+
|
102
|
+
function resetlines() {
|
103
|
+
lines = 0;
|
104
|
+
var elem = document.getElementById('typer');
|
105
|
+
elem.onclick = cleartype;
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
|
109
|
+
function cleartype() {
|
110
|
+
var elem = document.getElementById('typer');
|
111
|
+
elem.onclick = null;
|
112
|
+
elem.value = '';
|
113
|
+
}
|
114
|
+
|
115
|
+
function firefoxuseragent() {
|
116
|
+
var agent = navigator.userAgent;
|
117
|
+
if (!window.netscape) {
|
118
|
+
alert('userAgent Firefox required\n(' + agent + ')');
|
119
|
+
return false;
|
120
|
+
} else {
|
121
|
+
return true;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
function trytype() {
|
126
|
+
/*
|
127
|
+
* we could just generate key tables one day ...
|
128
|
+
var elem = document.getElementById('typer');
|
129
|
+
elem.value = '';
|
130
|
+
elem.focus();
|
131
|
+
for (var charCode = 0; charCode != 127; ++charCode)
|
132
|
+
Utils.type(null, elem, String.fromCharCode(charCode));
|
133
|
+
return false;
|
134
|
+
*/
|
135
|
+
|
136
|
+
window.setTimeout(function () {
|
137
|
+
var test = document.getElementById('results');
|
138
|
+
var elem = document.getElementById('typer');
|
139
|
+
|
140
|
+
/*
|
141
|
+
* security privileges needed to emit keyboard events
|
142
|
+
*/
|
143
|
+
if (firefoxuseragent()) {
|
144
|
+
var securityManager = netscape.security.PrivilegeManager;
|
145
|
+
securityManager.enablePrivilege('UniversalBrowserWrite');
|
146
|
+
securityManager.enablePrivilege('UniversalXPConnect');
|
147
|
+
} else {
|
148
|
+
return; // fail: wrong user agent
|
149
|
+
}
|
150
|
+
|
151
|
+
// Utils.debug = true;
|
152
|
+
|
153
|
+
test.innerHTML = "basic strings ...";
|
154
|
+
|
155
|
+
/*
|
156
|
+
* simple lowercase char string
|
157
|
+
*/
|
158
|
+
elem.value = '';
|
159
|
+
elem.focus();
|
160
|
+
Utils.type(null, elem, "abc def\r");
|
161
|
+
if (elem.value != "abc def")
|
162
|
+
alert("[" + elem.value + "]");
|
163
|
+
|
164
|
+
/*
|
165
|
+
* simple uppercase char string
|
166
|
+
*/
|
167
|
+
elem.value = '';
|
168
|
+
elem.focus();
|
169
|
+
Utils.type(null, elem, "ABC DEF");
|
170
|
+
if (elem.value != "ABC DEF")
|
171
|
+
alert("[" + elem.value + "]");
|
172
|
+
if (Utils.shiftCount != 6)
|
173
|
+
alert("[" + elem.value + "] 6 shifts expected");
|
174
|
+
|
175
|
+
/*
|
176
|
+
* simple mixedcase char string
|
177
|
+
*/
|
178
|
+
elem.value = '';
|
179
|
+
elem.focus();
|
180
|
+
Utils.type(null, elem, "me at eXample dot com");
|
181
|
+
if (elem.value != "me at eXample dot com")
|
182
|
+
alert("[" + elem.value + "]");
|
183
|
+
if (Utils.shiftCount != 1)
|
184
|
+
alert("[" + elem.value + "] 1 shift expected");
|
185
|
+
|
186
|
+
test.innerHTML = "arrow/movement keys ...";
|
187
|
+
|
188
|
+
var kLeft = '\uE012';
|
189
|
+
var kUp = '\uE013';
|
190
|
+
var kRight = '\uE014';
|
191
|
+
var kDown = '\uE015';
|
192
|
+
|
193
|
+
/*
|
194
|
+
* left arrow should not be printable
|
195
|
+
*/
|
196
|
+
elem.value = '';
|
197
|
+
elem.focus();
|
198
|
+
Utils.type(null, elem, kLeft);
|
199
|
+
if (elem.value != "")
|
200
|
+
alert("[" + elem.value + "]");
|
201
|
+
if (Utils.shiftCount != 0)
|
202
|
+
alert("[" + elem.value + "] 0 shifts expected");
|
203
|
+
|
204
|
+
/*
|
205
|
+
* same for all arrow keys, non printable
|
206
|
+
*/
|
207
|
+
elem.value = '';
|
208
|
+
elem.focus();
|
209
|
+
Utils.type(null, elem, "" + kDown + kUp + kLeft + kRight);
|
210
|
+
if (elem.value != "")
|
211
|
+
alert("[" + elem.value + "]");
|
212
|
+
if (Utils.shiftCount != 0)
|
213
|
+
alert("[" + elem.value + "] 0 shifts expected");
|
214
|
+
|
215
|
+
var kHome = '\uE011';
|
216
|
+
var kEnd = '\uE010';
|
217
|
+
var kPageUp = '\uE00E';
|
218
|
+
var kPageDown = '\uE00F';
|
219
|
+
|
220
|
+
/*
|
221
|
+
* should like all movement keys
|
222
|
+
*/
|
223
|
+
elem.value = '';
|
224
|
+
elem.focus();
|
225
|
+
Utils.type(null, elem, "abc" + kHome + "0" + kLeft +
|
226
|
+
kRight + kPageUp + kPageDown + kEnd + "1" + kHome +
|
227
|
+
"0" + kPageUp + kEnd + "111" + kHome + "00" + kEnd);
|
228
|
+
if (elem.value != "0000abc1111")
|
229
|
+
alert("[" + elem.value + "]");
|
230
|
+
if (Utils.shiftCount != 0)
|
231
|
+
alert("[" + elem.value + "] 0 shifts expected");
|
232
|
+
|
233
|
+
test.innerHTML = "delete/backspace keys ...";
|
234
|
+
|
235
|
+
var kDelete = '\uE017';
|
236
|
+
var kBackspace = '\uE003';
|
237
|
+
|
238
|
+
/*
|
239
|
+
* and delete and backspace keys too
|
240
|
+
*/
|
241
|
+
elem.value = '';
|
242
|
+
elem.focus();
|
243
|
+
Utils.type(null, elem, "abcdefghi" + kHome + kDelete +
|
244
|
+
kEnd + kBackspace + kLeft + kLeft + kBackspace +
|
245
|
+
kDelete + kDelete + '0' + kBackspace + kHome + '0' +
|
246
|
+
kDelete + kBackspace + 'E' + kDelete + kHome + 'C');
|
247
|
+
if (elem.value != "CEde")
|
248
|
+
alert("[" + elem.value + "]");
|
249
|
+
if (Utils.shiftCount != 2)
|
250
|
+
alert("[" + elem.value + "] 2 shifts expected");
|
251
|
+
|
252
|
+
test.innerHTML = "special space, number pad, function keys ...";
|
253
|
+
|
254
|
+
var kSpace = '\uE00D';
|
255
|
+
|
256
|
+
/*
|
257
|
+
* should print space special char
|
258
|
+
*/
|
259
|
+
elem.value = '';
|
260
|
+
elem.focus();
|
261
|
+
Utils.type(null, elem, "abcd" + kSpace + "fghi" +
|
262
|
+
kLeft + kLeft + kHome + kEnd + kSpace + "a");
|
263
|
+
if (elem.value != "abcd fghi a")
|
264
|
+
alert("[" + elem.value + "]");
|
265
|
+
|
266
|
+
var codes = "", result = elem.value;
|
267
|
+
for (var i = 0; i < result.length; ++i)
|
268
|
+
codes += result.charCodeAt(i) + '|';
|
269
|
+
if (codes != "97|98|99|100|32|102|103|104|105|32|97|")
|
270
|
+
alert("[" + codes + "]");
|
271
|
+
|
272
|
+
/*
|
273
|
+
* number pad and function keys
|
274
|
+
*/
|
275
|
+
var kSemiColon = '\uE018';
|
276
|
+
var kEquals = '\uE019';
|
277
|
+
var kNumberPad0 = '\uE01A';
|
278
|
+
var kNumberPad3 = '\uE01D';
|
279
|
+
var kNumberPad9 = '\uE023';
|
280
|
+
var kMulitply = '\uE024';
|
281
|
+
var kAdd = '\uE025';
|
282
|
+
var kSepartor = '\uE026';
|
283
|
+
var kSubtract = '\uE027';
|
284
|
+
var kDecimal = '\uE028';
|
285
|
+
var kDivide = '\uE029';
|
286
|
+
var kF2 = '\uE032';
|
287
|
+
|
288
|
+
elem.value = '';
|
289
|
+
elem.focus();
|
290
|
+
Utils.type(null, elem, "abcd" + kMulitply + kSubtract +
|
291
|
+
kAdd + kDecimal + kSepartor + kNumberPad0 + kNumberPad9 +
|
292
|
+
kAdd + kSemiColon + kEquals + kDivide + kNumberPad3);
|
293
|
+
if (elem.value != "abcd*-+.,09+;=/3")
|
294
|
+
alert("[" + elem.value + "]");
|
295
|
+
|
296
|
+
elem.value = '';
|
297
|
+
elem.focus();
|
298
|
+
Utils.type(null, elem, "FUNCTION" + kF2 + "-KEYS" + kF2);
|
299
|
+
if (Utils.shiftCount != 12)
|
300
|
+
alert("[" + elem.value + "] 12 shifts expected");
|
301
|
+
Utils.type(null, elem, kF2 + "-TO" + kF2 + "O");
|
302
|
+
if (elem.value != "FUNCTION-KEYS-TOO")
|
303
|
+
alert("[" + elem.value + "]");
|
304
|
+
|
305
|
+
test.innerHTML = "text selection and deletion ...";
|
306
|
+
|
307
|
+
var kShift = '\uE008';
|
308
|
+
|
309
|
+
/*
|
310
|
+
* should do full shift selection delete
|
311
|
+
*/
|
312
|
+
elem.value = '';
|
313
|
+
elem.focus();
|
314
|
+
Utils.type(null, elem, "abcd efgh")
|
315
|
+
if (elem.value != "abcd efgh")
|
316
|
+
alert("[" + elem.value + "]");
|
317
|
+
Utils.type(null, elem, kHome + kShift + kEnd + kDelete);
|
318
|
+
if (elem.value != "")
|
319
|
+
alert("[" + elem.value + "]");
|
320
|
+
|
321
|
+
/*
|
322
|
+
* various partial shift selection deletes
|
323
|
+
*/
|
324
|
+
elem.value = '';
|
325
|
+
elem.focus();
|
326
|
+
Utils.type(null, elem, "abcd efgh ijkl mnop qrst uvw xyz")
|
327
|
+
Utils.type(null, elem, kHome);
|
328
|
+
Utils.type(null, elem, kShift + kRight + kRight + kRight +
|
329
|
+
kRight + kRight + kDelete);
|
330
|
+
if (elem.value != "efgh ijkl mnop qrst uvw xyz")
|
331
|
+
alert("[" + elem.value + "]");
|
332
|
+
|
333
|
+
Utils.type(null, elem, kEnd + kShift + kLeft + kLeft +
|
334
|
+
kLeft + kLeft + kDelete);
|
335
|
+
if (elem.value != "efgh ijkl mnop qrst uvw")
|
336
|
+
alert("[" + elem.value + "]");
|
337
|
+
|
338
|
+
Utils.type(null, elem, kLeft + kLeft + kLeft + kLeft +
|
339
|
+
kShift + kEnd + kDelete);
|
340
|
+
if (elem.value != "efgh ijkl mnop qrst")
|
341
|
+
alert("[" + elem.value + "]");
|
342
|
+
|
343
|
+
Utils.type(null, elem, kHome + kRight + kRight + kRight +
|
344
|
+
kRight + kRight + kShift + kHome + kDelete);
|
345
|
+
if (elem.value != "ijkl mnop qrst")
|
346
|
+
alert("[" + elem.value + "]");
|
347
|
+
|
348
|
+
test.innerHTML = "non-shifted chars ...";
|
349
|
+
|
350
|
+
/*
|
351
|
+
* all numeric line chars etc, non shifted
|
352
|
+
*/
|
353
|
+
elem.focus();
|
354
|
+
elem.value = '';
|
355
|
+
Utils.type(null, elem, "`1234567890-=[]\\;,.\'");
|
356
|
+
if (elem.value != "`1234567890-=[]\\;,.\'")
|
357
|
+
alert("[" + elem.value + "]");
|
358
|
+
if (Utils.shiftCount != 0)
|
359
|
+
alert("[" + elem.value + "] zero shifts expected");
|
360
|
+
|
361
|
+
/*
|
362
|
+
* all lower alpha chars, non shifted
|
363
|
+
*/
|
364
|
+
elem.focus();
|
365
|
+
elem.value = '';
|
366
|
+
Utils.type(null, elem, "abcdefghijklmnopqrstuvwxyz");
|
367
|
+
if (elem.value != "abcdefghijklmnopqrstuvwxyz")
|
368
|
+
alert("[" + elem.value + "]");
|
369
|
+
if (Utils.shiftCount != 0)
|
370
|
+
alert("[" + elem.value + "] wrong shift count");
|
371
|
+
|
372
|
+
test.innerHTML = "shifted chars ...";
|
373
|
+
|
374
|
+
/*
|
375
|
+
* all upper alpha chars that need a shift key
|
376
|
+
*/
|
377
|
+
elem.focus();
|
378
|
+
elem.value = '';
|
379
|
+
Utils.type(null, elem, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
380
|
+
if (elem.value != "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
381
|
+
alert("[" + elem.value + "]");
|
382
|
+
if (Utils.shiftCount != 26)
|
383
|
+
alert("[" + elem.value + "] wrong shift count");
|
384
|
+
|
385
|
+
/*
|
386
|
+
* all special chars that need a shift key
|
387
|
+
*/
|
388
|
+
elem.focus();
|
389
|
+
elem.value = '';
|
390
|
+
Utils.type(null, elem, '~!@#$%^&*()_+{}:"<>?|END~');
|
391
|
+
if (elem.value != '~!@#$%^&*()_+{}:"<>?|END~')
|
392
|
+
alert("[" + elem.value + "]");
|
393
|
+
var expect = '~!@#$%^&*()_+{}:"<>?|END~'.length;
|
394
|
+
if (Utils.shiftCount != expect)
|
395
|
+
alert("[" + elem.value + "] wrong shift count: " +
|
396
|
+
Utils.shiftCount + " expected " + expect);
|
397
|
+
|
398
|
+
test.innerHTML = "ascii printables ...";
|
399
|
+
|
400
|
+
/*
|
401
|
+
* the lot: max ascii printables
|
402
|
+
*/
|
403
|
+
elem.focus();
|
404
|
+
elem.value = '';
|
405
|
+
var printables = "!\"#$%&'()*+,-./0123456789:;<=>?@ ABCDEFG" +
|
406
|
+
"HIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
407
|
+
Utils.type(null, elem, printables);
|
408
|
+
if (elem.value != printables)
|
409
|
+
alert("[" + elem.value + "]");
|
410
|
+
|
411
|
+
test.innerHTML = "select all, delete ...";
|
412
|
+
|
413
|
+
var kControl = '\uE009';
|
414
|
+
|
415
|
+
/*
|
416
|
+
* chord delete the lot: control home, shift end, delete
|
417
|
+
*/
|
418
|
+
Utils.type(null, elem, kControl + kHome);
|
419
|
+
Utils.type(null, elem, kShift + kEnd + kHome + kEnd +
|
420
|
+
kHome + kEnd + kHome + kEnd);
|
421
|
+
|
422
|
+
var selection = elem.selectionStart;
|
423
|
+
if (selection != 0)
|
424
|
+
alert(selection + " expect selection start 0");
|
425
|
+
selection = elem.selectionEnd;
|
426
|
+
var end = printables.length;
|
427
|
+
if (selection != end)
|
428
|
+
alert(selection + " expect selection end " + end);
|
429
|
+
|
430
|
+
Utils.type(null, elem, kDelete);
|
431
|
+
if (elem.value != "")
|
432
|
+
alert("[" + elem.value + "]");
|
433
|
+
|
434
|
+
test.innerHTML = "control key cut and paste ...";
|
435
|
+
|
436
|
+
var kNull = '\uE000';
|
437
|
+
|
438
|
+
/*
|
439
|
+
* chord select all, control cut (^x) and paste (^v)
|
440
|
+
*/
|
441
|
+
elem.focus();
|
442
|
+
elem.value = '';
|
443
|
+
var paste = "!\"#$%&'()*+,-./0123456789:;<=>?@ ABCD";
|
444
|
+
Utils.type(null, elem, paste);
|
445
|
+
if (elem.value != paste)
|
446
|
+
alert("[" + elem.value + "]");
|
447
|
+
|
448
|
+
Utils.type(null, elem, kHome + kNull + kShift + kEnd);
|
449
|
+
selection = elem.selectionStart;
|
450
|
+
if (selection != 0)
|
451
|
+
alert(selection + " expect selection start 0");
|
452
|
+
selection = elem.selectionEnd;
|
453
|
+
if (selection != (end = paste.length))
|
454
|
+
alert(selection + " expect selection end " + end);
|
455
|
+
|
456
|
+
Utils.type(null, elem, kControl + 'x'); // cut
|
457
|
+
if (elem.value != "")
|
458
|
+
alert("[" + elem.value + "]");
|
459
|
+
|
460
|
+
Utils.type(null, elem, kControl + 'v'); // paste
|
461
|
+
if (elem.value != paste)
|
462
|
+
alert("[" + elem.value + "]");
|
463
|
+
|
464
|
+
Utils.type(null, elem, kLeft + kLeft + kLeft + kShift + kEnd);
|
465
|
+
Utils.type(null, elem, kControl + 'x' + 'v');
|
466
|
+
if (elem.value != paste)
|
467
|
+
alert("[" + elem.value + "]");
|
468
|
+
|
469
|
+
Utils.type(null, elem, kHome + kControl + 'v');
|
470
|
+
Utils.type(null, elem, kHome + kControl + 'v' + 'v');
|
471
|
+
Utils.type(null, elem, kHome + kControl + 'v' + 'v' + 'v');
|
472
|
+
if (elem.value != "BCDBCDBCDBCDBCDBCD" + paste)
|
473
|
+
alert("[" + elem.value + "]");
|
474
|
+
Utils.type(null, elem, kEnd + kBackspace + "D");
|
475
|
+
if (elem.value != "BCDBCDBCDBCDBCDBCD" + paste)
|
476
|
+
alert("[" + elem.value + "]");
|
477
|
+
|
478
|
+
/*
|
479
|
+
* chord reverse selects and deletes
|
480
|
+
*/
|
481
|
+
Utils.type(null, elem, kShift + kHome + kNull + kDelete);
|
482
|
+
if (elem.value != "")
|
483
|
+
alert("[" + elem.value + "]");
|
484
|
+
|
485
|
+
Utils.type(null, elem, "done" + kHome);
|
486
|
+
Utils.type(null, elem, kShift + "ALL " + kHome); // note ALL
|
487
|
+
|
488
|
+
selection = elem.selectionStart;
|
489
|
+
if (selection != 0)
|
490
|
+
alert(selection + " expect selection start 0");
|
491
|
+
selection = elem.selectionEnd;
|
492
|
+
if (selection != (end = "ALL ".length))
|
493
|
+
alert(selection + " expect selection end " + end);
|
494
|
+
|
495
|
+
Utils.type(null, elem, kDelete);
|
496
|
+
if (elem.value != "done")
|
497
|
+
alert("[" + elem.value + "]");
|
498
|
+
|
499
|
+
Utils.type(null, elem, kEnd + kShift + kHome);
|
500
|
+
selection = elem.selectionStart;
|
501
|
+
if (selection != 0)
|
502
|
+
alert(selection + " expect selection start 0");
|
503
|
+
selection = elem.selectionEnd;
|
504
|
+
if (selection != (end = "done".length))
|
505
|
+
alert(selection + " expect selection end " + end);
|
506
|
+
|
507
|
+
Utils.type(null, elem, kDelete);
|
508
|
+
if (elem.value != "")
|
509
|
+
alert("[" + elem.value + "]");
|
510
|
+
|
511
|
+
test.innerHTML = "tests done ...";
|
512
|
+
|
513
|
+
}, 250);
|
514
|
+
|
515
|
+
return false;
|
516
|
+
}
|
517
|
+
|
518
|
+
</script>
|
519
|
+
|
520
|
+
</head>
|
521
|
+
|
522
|
+
<body id="body" onload="initPage();" topmargin="20" leftmargin="40">
|
523
|
+
|
524
|
+
<form name="testform">
|
525
|
+
<h2>KeyEvent Test</h2>
|
526
|
+
<p>
|
527
|
+
Hit keys to see the Javascript events triggered and the values
|
528
|
+
returned.
|
529
|
+
|
530
|
+
<p>
|
531
|
+
Show event handling for:
|
532
|
+
<input type="checkbox" name="keydown" value="1" checked> keydown
|
533
|
+
|
534
|
+
<input type="checkbox" name="keypress" value="1" checked> keypress
|
535
|
+
|
536
|
+
<input type="checkbox" name="keyup" value="1" checked> keyup
|
537
|
+
|
538
|
+
<br>
|
539
|
+
<textarea id="testarea" name="t" rows="32" cols="90"></textarea>
|
540
|
+
|
541
|
+
<p>
|
542
|
+
<input id="typer" type="input" value="Type here ..." size="120">
|
543
|
+
</p>
|
544
|
+
|
545
|
+
<input type="reset" onclick="resetlines();">
|
546
|
+
<input type="button" value="Run Tests" onclick="trytype();">
|
547
|
+
|
548
|
+
<pre id="results"></pre>
|
549
|
+
</form>
|
550
|
+
|
551
|
+
</body>
|
552
|
+
</html>
|
553
|
+
|
554
|
+
|