selenium-webdriver 3.6.0 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +181 -0
- package/README.md +25 -27
- package/chrome.js +113 -127
- package/edge.js +42 -117
- package/example/chrome_android.js +8 -8
- package/example/chrome_mobile_emulation.js +8 -8
- package/example/firefox_channels.js +22 -18
- package/example/google_search_test.js +39 -26
- package/example/logging.js +39 -6
- package/firefox.js +769 -0
- package/http/index.js +41 -4
- package/http/util.js +11 -6
- package/ie.js +56 -97
- package/index.js +178 -114
- package/jasmine.json +11 -0
- package/lib/actions.js +68 -63
- package/lib/by.js +1 -1
- package/lib/capabilities.js +255 -192
- package/lib/command.js +26 -50
- package/lib/error.js +85 -44
- package/lib/http.js +133 -110
- package/lib/input.js +1044 -8
- package/lib/promise.js +222 -3323
- package/lib/proxy.js +134 -39
- package/lib/test/bootstrap_jasmine.js +28 -0
- package/lib/test/data/actions/click.html +24 -0
- package/lib/test/data/actions/drag.html +77 -0
- package/lib/test/data/actions/record_click.html +21 -0
- package/lib/test/data/chrome/download.html +2 -0
- package/lib/test/data/inputs.html +42 -0
- package/lib/test/data/selectPage.html +12 -0
- package/lib/test/data/simpleTest.html +5 -0
- package/lib/test/data/upload_invisible.html +45 -0
- package/lib/test/fileserver.js +23 -19
- package/lib/test/index.js +30 -212
- package/lib/test/resources.js +0 -1
- package/lib/webdriver.js +675 -936
- package/net/index.js +21 -25
- package/net/portprober.js +51 -68
- package/package.json +5 -3
- package/remote/index.js +5 -19
- package/safari.js +41 -128
- package/test/actions_test.js +173 -18
- package/test/{session_test.js → builder_test.js} +44 -37
- package/test/chrome/devtools_test.js +93 -0
- package/test/chrome/options_test.js +48 -154
- package/test/chrome/service_test.js +7 -7
- package/test/cookie_test.js +77 -63
- package/test/element_finding_test.js +206 -201
- package/test/execute_script_test.js +115 -114
- package/test/fingerprint_test.js +16 -15
- package/test/firefox_test.js +251 -0
- package/test/http/http_test.js +0 -1
- package/test/http/util_test.js +2 -2
- package/test/io/zip_test.js +6 -7
- package/test/lib/error_test.js +34 -7
- package/test/lib/http_test.js +8 -128
- package/test/lib/input_test.js +1379 -0
- package/test/lib/promise_test.js +473 -908
- package/test/lib/webdriver_test.js +296 -868
- package/test/logging_test.js +37 -43
- package/test/page_loading_test.js +71 -81
- package/test/proxy_test.js +64 -72
- package/test/rect_test.js +14 -25
- package/test/remote_test.js +10 -29
- package/test/safari_test.js +7 -71
- package/test/stale_element_test.js +20 -23
- package/test/tag_name_test.js +10 -9
- package/test/upload_test.js +27 -35
- package/test/window_test.js +72 -85
- package/testing/index.js +386 -314
- package/.npmignore +0 -2
- package/example/async_await_test.js +0 -69
- package/example/google_search_generator.js +0 -47
- package/example/parallel_flows.js +0 -51
- package/firefox/binary.js +0 -347
- package/firefox/extension.js +0 -224
- package/firefox/index.js +0 -576
- package/firefox/profile.js +0 -311
- package/lib/events.js +0 -210
- package/lib/test/data/firefox/jetpack-sample.xpi +0 -0
- package/lib/test/data/firefox/sample.xpi +0 -0
- package/lib/test/promise.js +0 -79
- package/opera.js +0 -405
- package/phantomjs.js +0 -282
- package/test/firefox/extension_test.js +0 -120
- package/test/firefox/firefox_test.js +0 -244
- package/test/firefox/profile_test.js +0 -140
- package/test/lib/events_test.js +0 -177
- package/test/lib/promise_aplus_test.js +0 -78
- package/test/lib/promise_error_test.js +0 -884
- package/test/lib/promise_flow_test.js +0 -2288
- package/test/lib/promise_generator_test.js +0 -310
- package/test/phantomjs/execute_phantomjs_test.js +0 -59
- package/test/testing/assert_test.js +0 -373
- package/test/testing/index_test.js +0 -224
- package/testing/assert.js +0 -378
package/firefox/profile.js
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
-
// or more contributor license agreements. See the NOTICE file
|
|
3
|
-
// distributed with this work for additional information
|
|
4
|
-
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
-
// to you under the Apache License, Version 2.0 (the
|
|
6
|
-
// "License"); you may not use this file except in compliance
|
|
7
|
-
// with the License. You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing,
|
|
12
|
-
// software distributed under the License is distributed on an
|
|
13
|
-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
// KIND, either express or implied. See the License for the
|
|
15
|
-
// specific language governing permissions and limitations
|
|
16
|
-
// under the License.
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @fileoverview Profile management module. This module is considered internal;
|
|
20
|
-
* users should use {@link selenium-webdriver/firefox}.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
'use strict';
|
|
24
|
-
|
|
25
|
-
const fs = require('fs'),
|
|
26
|
-
path = require('path'),
|
|
27
|
-
vm = require('vm');
|
|
28
|
-
|
|
29
|
-
const isDevMode = require('../lib/devmode'),
|
|
30
|
-
Symbols = require('../lib/symbols'),
|
|
31
|
-
io = require('../io'),
|
|
32
|
-
{Zip, unzip} = require('../io/zip'),
|
|
33
|
-
extension = require('./extension');
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Parses a user.js file in a Firefox profile directory.
|
|
38
|
-
* @param {string} f Path to the file to parse.
|
|
39
|
-
* @return {!Promise<!Object>} A promise for the parsed preferences as
|
|
40
|
-
* a JSON object. If the file does not exist, an empty object will be
|
|
41
|
-
* returned.
|
|
42
|
-
*/
|
|
43
|
-
function loadUserPrefs(f) {
|
|
44
|
-
return io.read(f).then(
|
|
45
|
-
function onSuccess(contents) {
|
|
46
|
-
var prefs = {};
|
|
47
|
-
var context = vm.createContext({
|
|
48
|
-
'user_pref': function(key, value) {
|
|
49
|
-
prefs[key] = value;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
vm.runInContext(contents.toString(), context, f);
|
|
53
|
-
return prefs;
|
|
54
|
-
},
|
|
55
|
-
function onError(err) {
|
|
56
|
-
if (err && err.code === 'ENOENT') {
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
throw err;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param {!Object} prefs The default preferences to write. Will be
|
|
67
|
-
* overridden by user.js preferences in the template directory and the
|
|
68
|
-
* frozen preferences required by WebDriver.
|
|
69
|
-
* @param {string} dir Path to the directory write the file to.
|
|
70
|
-
* @return {!Promise<string>} A promise for the profile directory,
|
|
71
|
-
* to be fulfilled when user preferences have been written.
|
|
72
|
-
*/
|
|
73
|
-
function writeUserPrefs(prefs, dir) {
|
|
74
|
-
var userPrefs = path.join(dir, 'user.js');
|
|
75
|
-
return loadUserPrefs(userPrefs).then(function(overrides) {
|
|
76
|
-
Object.assign(prefs, overrides);
|
|
77
|
-
|
|
78
|
-
let keys = Object.keys(prefs);
|
|
79
|
-
if (!keys.length) {
|
|
80
|
-
return dir;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let contents = Object.keys(prefs).map(function(key) {
|
|
84
|
-
return 'user_pref(' + JSON.stringify(key) + ', ' +
|
|
85
|
-
JSON.stringify(prefs[key]) + ');';
|
|
86
|
-
}).join('\n');
|
|
87
|
-
|
|
88
|
-
return new Promise((resolve, reject) => {
|
|
89
|
-
fs.writeFile(userPrefs, contents, function(err) {
|
|
90
|
-
err && reject(err) || resolve(dir);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Installs a group of extensions in the given profile directory. If the
|
|
99
|
-
* WebDriver extension is not included in this set, the default version
|
|
100
|
-
* bundled with this package will be installed.
|
|
101
|
-
* @param {!Array.<string>} extensions The extensions to install, as a
|
|
102
|
-
* path to an unpacked extension directory or a path to a xpi file.
|
|
103
|
-
* @param {string} dir The profile directory to install to.
|
|
104
|
-
* @return {!Promise<string>} A promise for the main profile directory
|
|
105
|
-
* once all extensions have been installed.
|
|
106
|
-
*/
|
|
107
|
-
function installExtensions(extensions, dir) {
|
|
108
|
-
var next = 0;
|
|
109
|
-
var extensionDir = path.join(dir, 'extensions');
|
|
110
|
-
|
|
111
|
-
return new Promise(function(fulfill, reject) {
|
|
112
|
-
io.mkdir(extensionDir).then(installNext, reject);
|
|
113
|
-
|
|
114
|
-
function installNext() {
|
|
115
|
-
if (next >= extensions.length) {
|
|
116
|
-
fulfill(dir);
|
|
117
|
-
} else {
|
|
118
|
-
install(extensions[next++]);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function install(ext) {
|
|
123
|
-
extension.install(ext, extensionDir).then(function(id) {
|
|
124
|
-
installNext();
|
|
125
|
-
}, reject);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Models a Firefox profile directory for use with the FirefoxDriver. The
|
|
134
|
-
* {@code Profile} directory uses an in-memory model until
|
|
135
|
-
* {@link #writeToDisk} or {@link #encode} is called.
|
|
136
|
-
*/
|
|
137
|
-
class Profile {
|
|
138
|
-
/**
|
|
139
|
-
* @param {string=} opt_dir Path to an existing Firefox profile directory to
|
|
140
|
-
* use a template for this profile. If not specified, a blank profile will
|
|
141
|
-
* be used.
|
|
142
|
-
*/
|
|
143
|
-
constructor(opt_dir) {
|
|
144
|
-
/** @private {!Object} */
|
|
145
|
-
this.preferences_ = {};
|
|
146
|
-
|
|
147
|
-
/** @private {(string|undefined)} */
|
|
148
|
-
this.template_ = opt_dir;
|
|
149
|
-
|
|
150
|
-
/** @private {!Array<string>} */
|
|
151
|
-
this.extensions_ = [];
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* @return {(string|undefined)} Path to an existing Firefox profile directory
|
|
156
|
-
* to use as a template when writing this Profile to disk.
|
|
157
|
-
*/
|
|
158
|
-
getTemplateDir() {
|
|
159
|
-
return this.template_;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Registers an extension to be included with this profile.
|
|
164
|
-
* @param {string} extension Path to the extension to include, as either an
|
|
165
|
-
* unpacked extension directory or the path to a xpi file.
|
|
166
|
-
*/
|
|
167
|
-
addExtension(extension) {
|
|
168
|
-
this.extensions_.push(extension);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* @return {!Array<string>} A list of extensions to install in this profile.
|
|
173
|
-
*/
|
|
174
|
-
getExtensions() {
|
|
175
|
-
return this.extensions_;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Sets a desired preference for this profile.
|
|
180
|
-
* @param {string} key The preference key.
|
|
181
|
-
* @param {(string|number|boolean)} value The preference value.
|
|
182
|
-
* @throws {Error} If attempting to set a frozen preference.
|
|
183
|
-
*/
|
|
184
|
-
setPreference(key, value) {
|
|
185
|
-
this.preferences_[key] = value;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Returns the currently configured value of a profile preference. This does
|
|
190
|
-
* not include any defaults defined in the profile's template directory user.js
|
|
191
|
-
* file (if a template were specified on construction).
|
|
192
|
-
* @param {string} key The desired preference.
|
|
193
|
-
* @return {(string|number|boolean|undefined)} The current value of the
|
|
194
|
-
* requested preference.
|
|
195
|
-
*/
|
|
196
|
-
getPreference(key) {
|
|
197
|
-
return this.preferences_[key];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* @return {!Object} A copy of all currently configured preferences.
|
|
202
|
-
*/
|
|
203
|
-
getPreferences() {
|
|
204
|
-
return Object.assign({}, this.preferences_);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Specifies which host the driver should listen for commands on. If not
|
|
209
|
-
* specified, the driver will default to "localhost". This option should be
|
|
210
|
-
* specified when "localhost" is not mapped to the loopback address
|
|
211
|
-
* (127.0.0.1) in `/etc/hosts`.
|
|
212
|
-
*
|
|
213
|
-
* @param {string} host the host the driver should listen for commands on
|
|
214
|
-
*/
|
|
215
|
-
setHost(host) {
|
|
216
|
-
this.preferences_['webdriver_firefox_allowed_hosts'] = host;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @return {boolean} Whether the FirefoxDriver is configured to automatically
|
|
221
|
-
* accept untrusted SSL certificates.
|
|
222
|
-
*/
|
|
223
|
-
acceptUntrustedCerts() {
|
|
224
|
-
return !!this.preferences_['webdriver_accept_untrusted_certs'];
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Sets whether the FirefoxDriver should automatically accept untrusted SSL
|
|
229
|
-
* certificates.
|
|
230
|
-
* @param {boolean} value .
|
|
231
|
-
*/
|
|
232
|
-
setAcceptUntrustedCerts(value) {
|
|
233
|
-
this.preferences_['webdriver_accept_untrusted_certs'] = !!value;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Sets whether to assume untrusted certificates come from untrusted issuers.
|
|
238
|
-
* @param {boolean} value .
|
|
239
|
-
*/
|
|
240
|
-
setAssumeUntrustedCertIssuer(value) {
|
|
241
|
-
this.preferences_['webdriver_assume_untrusted_issuer'] = !!value;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* @return {boolean} Whether to assume untrusted certs come from untrusted
|
|
246
|
-
* issuers.
|
|
247
|
-
*/
|
|
248
|
-
assumeUntrustedCertIssuer() {
|
|
249
|
-
return !!this.preferences_['webdriver_assume_untrusted_issuer'];
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Writes this profile to disk.
|
|
254
|
-
* @return {!Promise<string>} A promise for the path to the new profile
|
|
255
|
-
* directory.
|
|
256
|
-
*/
|
|
257
|
-
writeToDisk() {
|
|
258
|
-
var profileDir = io.tmpDir();
|
|
259
|
-
if (this.template_) {
|
|
260
|
-
profileDir = profileDir.then(function(dir) {
|
|
261
|
-
return io.copyDir(
|
|
262
|
-
/** @type {string} */(this.template_),
|
|
263
|
-
dir, /(parent\.lock|lock|\.parentlock)/);
|
|
264
|
-
}.bind(this));
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Freeze preferences for async operations.
|
|
268
|
-
let prefs = Object.assign({}, this.preferences_);
|
|
269
|
-
|
|
270
|
-
// Freeze extensions for async operations.
|
|
271
|
-
var extensions = this.extensions_.concat();
|
|
272
|
-
|
|
273
|
-
return profileDir.then(function(dir) {
|
|
274
|
-
return writeUserPrefs(prefs, dir);
|
|
275
|
-
}).then(function(dir) {
|
|
276
|
-
return installExtensions(extensions, dir);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Write profile to disk, compress its containing directory, and return
|
|
282
|
-
* it as a Base64 encoded string.
|
|
283
|
-
*
|
|
284
|
-
* @return {!Promise<string>} A promise for the encoded profile as
|
|
285
|
-
* Base64 string.
|
|
286
|
-
*
|
|
287
|
-
*/
|
|
288
|
-
encode() {
|
|
289
|
-
return this.writeToDisk().then(function(dir) {
|
|
290
|
-
let zip = new Zip;
|
|
291
|
-
return zip.addDir(dir)
|
|
292
|
-
.then(() => zip.toBuffer())
|
|
293
|
-
.then(buf => buf.toString('base64'));
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Encodes this profile as a zipped, base64 encoded directory.
|
|
299
|
-
* @return {!Promise<string>} A promise for the encoded profile.
|
|
300
|
-
*/
|
|
301
|
-
[Symbols.serialize]() {
|
|
302
|
-
return this.encode();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
// PUBLIC API
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
exports.Profile = Profile;
|
|
311
|
-
exports.loadUserPrefs = loadUserPrefs;
|
package/lib/events.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
-
// or more contributor license agreements. See the NOTICE file
|
|
3
|
-
// distributed with this work for additional information
|
|
4
|
-
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
-
// to you under the Apache License, Version 2.0 (the
|
|
6
|
-
// "License"); you may not use this file except in compliance
|
|
7
|
-
// with the License. You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing,
|
|
12
|
-
// software distributed under the License is distributed on an
|
|
13
|
-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
// KIND, either express or implied. See the License for the
|
|
15
|
-
// specific language governing permissions and limitations
|
|
16
|
-
// under the License.
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Describes an event listener registered on an {@linkplain EventEmitter}.
|
|
22
|
-
*/
|
|
23
|
-
class Listener {
|
|
24
|
-
/**
|
|
25
|
-
* @param {!Function} fn The actual listener function.
|
|
26
|
-
* @param {(Object|undefined)} scope The object in whose scope to invoke the
|
|
27
|
-
* listener.
|
|
28
|
-
* @param {boolean} oneshot Whether this listener should only be used once.
|
|
29
|
-
*/
|
|
30
|
-
constructor(fn, scope, oneshot) {
|
|
31
|
-
this.fn = fn;
|
|
32
|
-
this.scope = scope;
|
|
33
|
-
this.oneshot = oneshot;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/** @type {!WeakMap<!EventEmitter, !Map<string, !Set<!Listener>>>} */
|
|
39
|
-
const EVENTS = new WeakMap;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Object that can emit events for others to listen for.
|
|
44
|
-
*/
|
|
45
|
-
class EventEmitter {
|
|
46
|
-
/**
|
|
47
|
-
* Fires an event and calls all listeners.
|
|
48
|
-
* @param {string} type The type of event to emit.
|
|
49
|
-
* @param {...*} var_args Any arguments to pass to each listener.
|
|
50
|
-
*/
|
|
51
|
-
emit(type, var_args) {
|
|
52
|
-
let events = EVENTS.get(this);
|
|
53
|
-
if (!events) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let args = Array.prototype.slice.call(arguments, 1);
|
|
58
|
-
|
|
59
|
-
let listeners = events.get(type);
|
|
60
|
-
if (listeners) {
|
|
61
|
-
for (let listener of listeners) {
|
|
62
|
-
listener.fn.apply(listener.scope, args);
|
|
63
|
-
if (listener.oneshot) {
|
|
64
|
-
listeners.delete(listener);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Returns a mutable list of listeners for a specific type of event.
|
|
72
|
-
* @param {string} type The type of event to retrieve the listeners for.
|
|
73
|
-
* @return {!Set<!Listener>} The registered listeners for the given event
|
|
74
|
-
* type.
|
|
75
|
-
*/
|
|
76
|
-
listeners(type) {
|
|
77
|
-
let events = EVENTS.get(this);
|
|
78
|
-
if (!events) {
|
|
79
|
-
events = new Map;
|
|
80
|
-
EVENTS.set(this, events);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let listeners = events.get(type);
|
|
84
|
-
if (!listeners) {
|
|
85
|
-
listeners = new Set;
|
|
86
|
-
events.set(type, listeners);
|
|
87
|
-
}
|
|
88
|
-
return listeners;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Registers a listener.
|
|
93
|
-
* @param {string} type The type of event to listen for.
|
|
94
|
-
* @param {!Function} fn The function to invoke when the event is fired.
|
|
95
|
-
* @param {Object=} opt_self The object in whose scope to invoke the listener.
|
|
96
|
-
* @param {boolean=} opt_oneshot Whether the listener should b (e removed after
|
|
97
|
-
* the first event is fired.
|
|
98
|
-
* @return {!EventEmitter} A self reference.
|
|
99
|
-
* @private
|
|
100
|
-
*/
|
|
101
|
-
addListener_(type, fn, opt_self, opt_oneshot) {
|
|
102
|
-
let listeners = this.listeners(type);
|
|
103
|
-
for (let listener of listeners) {
|
|
104
|
-
if (listener.fn === fn) {
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
listeners.add(new Listener(fn, opt_self || undefined, !!opt_oneshot));
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Registers a listener.
|
|
114
|
-
* @param {string} type The type of event to listen for.
|
|
115
|
-
* @param {!Function} fn The function to invoke when the event is fired.
|
|
116
|
-
* @param {Object=} opt_self The object in whose scope to invoke the listener.
|
|
117
|
-
* @return {!EventEmitter} A self reference.
|
|
118
|
-
*/
|
|
119
|
-
addListener(type, fn, opt_self) {
|
|
120
|
-
return this.addListener_(type, fn, opt_self, false);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Registers a one-time listener which will be called only the first time an
|
|
125
|
-
* event is emitted, after which it will be removed.
|
|
126
|
-
* @param {string} type The type of event to listen for.
|
|
127
|
-
* @param {!Function} fn The function to invoke when the event is fired.
|
|
128
|
-
* @param {Object=} opt_self The object in whose scope to invoke the listener.
|
|
129
|
-
* @return {!EventEmitter} A self reference.
|
|
130
|
-
*/
|
|
131
|
-
once(type, fn, opt_self) {
|
|
132
|
-
return this.addListener_(type, fn, opt_self, true);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* An alias for {@link #addListener() addListener()}.
|
|
137
|
-
* @param {string} type The type of event to listen for.
|
|
138
|
-
* @param {!Function} fn The function to invoke when the event is fired.
|
|
139
|
-
* @param {Object=} opt_self The object in whose scope to invoke the listener.
|
|
140
|
-
* @return {!EventEmitter} A self reference.
|
|
141
|
-
*/
|
|
142
|
-
on(type, fn, opt_self) {
|
|
143
|
-
return this.addListener(type, fn, opt_self);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Removes a previously registered event listener.
|
|
148
|
-
* @param {string} type The type of event to unregister.
|
|
149
|
-
* @param {!Function} listenerFn The handler function to remove.
|
|
150
|
-
* @return {!EventEmitter} A self reference.
|
|
151
|
-
*/
|
|
152
|
-
removeListener(type, listenerFn) {
|
|
153
|
-
if (typeof type !== 'string' || typeof listenerFn !== 'function') {
|
|
154
|
-
throw TypeError('invalid args: expected (string, function), got ('
|
|
155
|
-
+ (typeof type) + ', ' + (typeof listenerFn) + ')');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
let events = EVENTS.get(this);
|
|
159
|
-
if (!events) {
|
|
160
|
-
return this;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
let listeners = events.get(type);
|
|
164
|
-
if (!listeners) {
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
let match;
|
|
169
|
-
for (let listener of listeners) {
|
|
170
|
-
if (listener.fn === listenerFn) {
|
|
171
|
-
match = listener;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (match) {
|
|
176
|
-
listeners.delete(match);
|
|
177
|
-
if (!listeners.size) {
|
|
178
|
-
events.delete(type);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return this;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Removes all listeners for a specific type of event. If no event is
|
|
186
|
-
* specified, all listeners across all types will be removed.
|
|
187
|
-
* @param {string=} opt_type The type of event to remove listeners from.
|
|
188
|
-
* @return {!EventEmitter} A self reference.
|
|
189
|
-
*/
|
|
190
|
-
removeAllListeners(opt_type) {
|
|
191
|
-
let events = EVENTS.get(this);
|
|
192
|
-
if (events) {
|
|
193
|
-
if (typeof opt_type === 'string') {
|
|
194
|
-
events.delete(opt_type);
|
|
195
|
-
} else {
|
|
196
|
-
EVENTS.delete(this);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return this;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// PUBLIC API
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
module.exports = {
|
|
208
|
-
EventEmitter: EventEmitter,
|
|
209
|
-
Listener: Listener
|
|
210
|
-
};
|
|
Binary file
|
|
Binary file
|
package/lib/test/promise.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
-
// or more contributor license agreements. See the NOTICE file
|
|
3
|
-
// distributed with this work for additional information
|
|
4
|
-
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
-
// to you under the Apache License, Version 2.0 (the
|
|
6
|
-
// "License"); you may not use this file except in compliance
|
|
7
|
-
// with the License. You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing,
|
|
12
|
-
// software distributed under the License is distributed on an
|
|
13
|
-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
// KIND, either express or implied. See the License for the
|
|
15
|
-
// specific language governing permissions and limitations
|
|
16
|
-
// under the License.
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Configures a block of mocha tests, ensuring the promise manager is either
|
|
23
|
-
* enabled or disabled for the tests' execution.
|
|
24
|
-
* for their execution.
|
|
25
|
-
*/
|
|
26
|
-
function withPromiseManager(enabled, fn) {
|
|
27
|
-
describe(`SELENIUM_PROMISE_MANAGER=${enabled}`, function() {
|
|
28
|
-
let saved;
|
|
29
|
-
|
|
30
|
-
function changeState() {
|
|
31
|
-
saved = process.env.SELENIUM_PROMISE_MANAGER;
|
|
32
|
-
process.env.SELENIUM_PROMISE_MANAGER = enabled;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function restoreState() {
|
|
36
|
-
if (saved === undefined) {
|
|
37
|
-
delete process.env.SELENIUM_PROMISE_MANAGER;
|
|
38
|
-
} else {
|
|
39
|
-
process.env.SELENIUM_PROMISE_MANAGER = saved;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
before(changeState);
|
|
44
|
-
after(restoreState);
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
changeState();
|
|
48
|
-
fn();
|
|
49
|
-
} finally {
|
|
50
|
-
restoreState();
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Defines a set of tests to run both with and without the promise manager
|
|
58
|
-
* enabled.
|
|
59
|
-
*/
|
|
60
|
-
exports.promiseManagerSuite = function(fn) {
|
|
61
|
-
withPromiseManager(true, fn);
|
|
62
|
-
withPromiseManager(false, fn);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Ensures the promise manager is enabled when the provided tests run.
|
|
68
|
-
*/
|
|
69
|
-
exports.enablePromiseManager = function(fn) {
|
|
70
|
-
withPromiseManager(true, fn);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Ensures the promise manager is disabled when the provided tests run.
|
|
76
|
-
*/
|
|
77
|
-
exports.disablePromiseManager = function(fn) {
|
|
78
|
-
withPromiseManager(false, fn);
|
|
79
|
-
};
|