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
|
@@ -1,120 +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
|
-
var assert = require('assert'),
|
|
21
|
-
crypto = require('crypto'),
|
|
22
|
-
fs = require('fs'),
|
|
23
|
-
path = require('path');
|
|
24
|
-
|
|
25
|
-
var extension = require('../../firefox/extension'),
|
|
26
|
-
io = require('../../io'),
|
|
27
|
-
zip = require('../../io/zip'),
|
|
28
|
-
it = require('../../testing').it;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var JETPACK_EXTENSION = path.join(__dirname,
|
|
32
|
-
'../../lib/test/data/firefox/jetpack-sample.xpi');
|
|
33
|
-
var NORMAL_EXTENSION = path.join(__dirname,
|
|
34
|
-
'../../lib/test/data/firefox/sample.xpi');
|
|
35
|
-
var WEBEXTENSION_EXTENSION = path.join(__dirname,
|
|
36
|
-
'../../lib/test/data/firefox/webextension.xpi');
|
|
37
|
-
|
|
38
|
-
var JETPACK_EXTENSION_ID = 'jid1-EaXX7k0wwiZR7w@jetpack';
|
|
39
|
-
var NORMAL_EXTENSION_ID = 'sample@seleniumhq.org';
|
|
40
|
-
var WEBEXTENSION_EXTENSION_ID = 'webextensions-selenium-example@example.com';
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
describe('extension', function() {
|
|
44
|
-
it('can install a jetpack xpi file', function() {
|
|
45
|
-
return io.tmpDir().then(function(dir) {
|
|
46
|
-
return extension.install(JETPACK_EXTENSION, dir).then(function(id) {
|
|
47
|
-
assert.equal(JETPACK_EXTENSION_ID, id);
|
|
48
|
-
var file = path.join(dir, id + '.xpi');
|
|
49
|
-
assert.ok(fs.existsSync(file), 'no such file: ' + file);
|
|
50
|
-
assert.ok(!fs.statSync(file).isDirectory());
|
|
51
|
-
|
|
52
|
-
var copiedSha1 = crypto.createHash('sha1')
|
|
53
|
-
.update(fs.readFileSync(file))
|
|
54
|
-
.digest('hex');
|
|
55
|
-
|
|
56
|
-
var goldenSha1 = crypto.createHash('sha1')
|
|
57
|
-
.update(fs.readFileSync(JETPACK_EXTENSION))
|
|
58
|
-
.digest('hex');
|
|
59
|
-
|
|
60
|
-
assert.equal(copiedSha1, goldenSha1);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('can install a normal xpi file', function() {
|
|
66
|
-
return io.tmpDir().then(function(dir) {
|
|
67
|
-
return extension.install(NORMAL_EXTENSION, dir).then(function(id) {
|
|
68
|
-
assert.equal(NORMAL_EXTENSION_ID, id);
|
|
69
|
-
|
|
70
|
-
var file = path.join(dir, NORMAL_EXTENSION_ID);
|
|
71
|
-
assert.ok(fs.statSync(file).isDirectory());
|
|
72
|
-
|
|
73
|
-
assert.ok(fs.existsSync(path.join(file, 'chrome.manifest')));
|
|
74
|
-
assert.ok(fs.existsSync(path.join(file, 'content/overlay.xul')));
|
|
75
|
-
assert.ok(fs.existsSync(path.join(file, 'content/overlay.js')));
|
|
76
|
-
assert.ok(fs.existsSync(path.join(file, 'install.rdf')));
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('can install a webextension xpi file', function() {
|
|
82
|
-
return io.tmpDir().then(function(dir) {
|
|
83
|
-
return extension.install(WEBEXTENSION_EXTENSION, dir).then(function(id) {
|
|
84
|
-
assert.equal(WEBEXTENSION_EXTENSION_ID, id);
|
|
85
|
-
var file = path.join(dir, id + '.xpi');
|
|
86
|
-
assert.ok(fs.existsSync(file), 'no such file: ' + file);
|
|
87
|
-
assert.ok(!fs.statSync(file).isDirectory());
|
|
88
|
-
|
|
89
|
-
var copiedSha1 = crypto.createHash('sha1')
|
|
90
|
-
.update(fs.readFileSync(file))
|
|
91
|
-
.digest('hex');
|
|
92
|
-
|
|
93
|
-
var goldenSha1 = crypto.createHash('sha1')
|
|
94
|
-
.update(fs.readFileSync(WEBEXTENSION_EXTENSION))
|
|
95
|
-
.digest('hex');
|
|
96
|
-
|
|
97
|
-
assert.equal(copiedSha1, goldenSha1);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('can install an extension from a directory', function() {
|
|
103
|
-
return io.tmpDir().then(function(srcDir) {
|
|
104
|
-
return zip.unzip(NORMAL_EXTENSION, srcDir)
|
|
105
|
-
.then(() => io.tmpDir())
|
|
106
|
-
.then(dstDir => {
|
|
107
|
-
return extension.install(srcDir, dstDir).then(function(id) {
|
|
108
|
-
assert.equal(NORMAL_EXTENSION_ID, id);
|
|
109
|
-
|
|
110
|
-
var dir = path.join(dstDir, NORMAL_EXTENSION_ID);
|
|
111
|
-
|
|
112
|
-
assert.ok(fs.existsSync(path.join(dir, 'chrome.manifest')));
|
|
113
|
-
assert.ok(fs.existsSync(path.join(dir, 'content/overlay.xul')));
|
|
114
|
-
assert.ok(fs.existsSync(path.join(dir, 'content/overlay.js')));
|
|
115
|
-
assert.ok(fs.existsSync(path.join(dir, 'install.rdf')));
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
@@ -1,244 +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
|
-
var path = require('path');
|
|
21
|
-
|
|
22
|
-
var firefox = require('../../firefox'),
|
|
23
|
-
io = require('../../io'),
|
|
24
|
-
test = require('../../lib/test'),
|
|
25
|
-
assert = require('../../testing/assert'),
|
|
26
|
-
Context = require('../../firefox').Context,
|
|
27
|
-
error = require('../..').error;
|
|
28
|
-
|
|
29
|
-
var {consume} = require('../../lib/promise');
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var JETPACK_EXTENSION = path.join(__dirname,
|
|
33
|
-
'../../lib/test/data/firefox/jetpack-sample.xpi');
|
|
34
|
-
var NORMAL_EXTENSION = path.join(__dirname,
|
|
35
|
-
'../../lib/test/data/firefox/sample.xpi');
|
|
36
|
-
var WEBEXTENSION_EXTENSION = path.join(__dirname,
|
|
37
|
-
'../../lib/test/data/firefox/webextension.xpi');
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
test.suite(function(env) {
|
|
41
|
-
describe('firefox', function() {
|
|
42
|
-
describe('Options', function() {
|
|
43
|
-
let driver;
|
|
44
|
-
|
|
45
|
-
beforeEach(function() {
|
|
46
|
-
driver = null;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
afterEach(function() {
|
|
50
|
-
if (driver) {
|
|
51
|
-
return driver.quit();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @param {...string} extensions the extensions to install.
|
|
57
|
-
* @return {!firefox.Profile} a new profile.
|
|
58
|
-
*/
|
|
59
|
-
function profileWithExtensions(...extensions) {
|
|
60
|
-
let profile = new firefox.Profile();
|
|
61
|
-
profile.setPreference('xpinstall.signatures.required', false);
|
|
62
|
-
extensions.forEach(ext => profile.addExtension(ext));
|
|
63
|
-
return profile;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Runs a test that requires Firefox Developer Edition. The test will be
|
|
68
|
-
* skipped if dev cannot be found on the current system.
|
|
69
|
-
*/
|
|
70
|
-
function runWithFirefoxDev(options, testFn) {
|
|
71
|
-
return firefox.Channel.AURORA.locate().then(exe => {
|
|
72
|
-
options.setBinary(exe);
|
|
73
|
-
driver = env.builder()
|
|
74
|
-
.setFirefoxOptions(options)
|
|
75
|
-
.build();
|
|
76
|
-
return driver.call(testFn);
|
|
77
|
-
}, err => {
|
|
78
|
-
console.warn(
|
|
79
|
-
'Skipping test: could not find Firefox Dev Edition: ' + err);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
describe('can start Firefox with custom preferences', function() {
|
|
84
|
-
function runTest(opt_dir) {
|
|
85
|
-
return consume(function*() {
|
|
86
|
-
let profile = new firefox.Profile(opt_dir);
|
|
87
|
-
profile.setPreference('general.useragent.override', 'foo;bar');
|
|
88
|
-
|
|
89
|
-
let options = new firefox.Options().setProfile(profile);
|
|
90
|
-
|
|
91
|
-
driver = env.builder().
|
|
92
|
-
setFirefoxOptions(options).
|
|
93
|
-
build();
|
|
94
|
-
|
|
95
|
-
yield driver.get('data:text/html,<html><div>content</div></html>');
|
|
96
|
-
|
|
97
|
-
var userAgent = yield driver.executeScript(
|
|
98
|
-
'return window.navigator.userAgent');
|
|
99
|
-
assert(userAgent).equalTo('foo;bar');
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
test.it('profile created from scratch', function() {
|
|
104
|
-
return runTest();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test.it('profile created from template', function() {
|
|
108
|
-
return io.tmpDir().then(runTest);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test.it('can start Firefox with a jetpack extension', function() {
|
|
113
|
-
let profile = profileWithExtensions(JETPACK_EXTENSION);
|
|
114
|
-
let options = new firefox.Options().setProfile(profile);
|
|
115
|
-
|
|
116
|
-
return runWithFirefoxDev(options, function*() {
|
|
117
|
-
yield loadJetpackPage(driver,
|
|
118
|
-
'data:text/html;charset=UTF-8,<html><div>content</div></html>');
|
|
119
|
-
|
|
120
|
-
let text =
|
|
121
|
-
yield driver.findElement({id: 'jetpack-sample-banner'}).getText();
|
|
122
|
-
assert(text).equalTo('Hello, world!');
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test.it('can start Firefox with a normal extension', function() {
|
|
127
|
-
let profile = profileWithExtensions(NORMAL_EXTENSION);
|
|
128
|
-
let options = new firefox.Options().setProfile(profile);
|
|
129
|
-
|
|
130
|
-
return runWithFirefoxDev(options, function*() {
|
|
131
|
-
yield driver.get('data:text/html,<html><div>content</div></html>');
|
|
132
|
-
|
|
133
|
-
let footer =
|
|
134
|
-
yield driver.findElement({id: 'sample-extension-footer'});
|
|
135
|
-
let text = yield footer.getText();
|
|
136
|
-
assert(text).equalTo('Goodbye');
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test.it('can start Firefox with a webextension extension', function() {
|
|
141
|
-
let profile = profileWithExtensions(WEBEXTENSION_EXTENSION);
|
|
142
|
-
let options = new firefox.Options().setProfile(profile);
|
|
143
|
-
|
|
144
|
-
return runWithFirefoxDev(options, function*() {
|
|
145
|
-
yield driver.get(test.Pages.echoPage);
|
|
146
|
-
|
|
147
|
-
let footer =
|
|
148
|
-
yield driver.findElement({id: 'webextensions-selenium-example'});
|
|
149
|
-
let text = yield footer.getText();
|
|
150
|
-
assert(text).equalTo('Content injected by webextensions-selenium-example');
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test.it('can start Firefox with multiple extensions', function() {
|
|
155
|
-
let profile =
|
|
156
|
-
profileWithExtensions(JETPACK_EXTENSION, NORMAL_EXTENSION);
|
|
157
|
-
let options = new firefox.Options().setProfile(profile);
|
|
158
|
-
|
|
159
|
-
return runWithFirefoxDev(options, function*() {
|
|
160
|
-
yield loadJetpackPage(driver,
|
|
161
|
-
'data:text/html;charset=UTF-8,<html><div>content</div></html>');
|
|
162
|
-
|
|
163
|
-
let banner =
|
|
164
|
-
yield driver.findElement({id: 'jetpack-sample-banner'}).getText();
|
|
165
|
-
assert(banner).equalTo('Hello, world!');
|
|
166
|
-
|
|
167
|
-
let footer =
|
|
168
|
-
yield driver.findElement({id: 'sample-extension-footer'})
|
|
169
|
-
.getText();
|
|
170
|
-
assert(footer).equalTo('Goodbye');
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
function loadJetpackPage(driver, url) {
|
|
175
|
-
// On linux the jetpack extension does not always run the first time
|
|
176
|
-
// we load a page. If this happens, just reload the page (a simple
|
|
177
|
-
// refresh doesn't appear to work).
|
|
178
|
-
return driver.wait(function() {
|
|
179
|
-
driver.get(url);
|
|
180
|
-
return driver.findElements({id: 'jetpack-sample-banner'})
|
|
181
|
-
.then(found => found.length > 0);
|
|
182
|
-
}, 3000);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
describe('binary management', function() {
|
|
187
|
-
var driver1, driver2;
|
|
188
|
-
|
|
189
|
-
test.ignore(env.isRemote).
|
|
190
|
-
it('can start multiple sessions with single binary instance', function*() {
|
|
191
|
-
var options = new firefox.Options().setBinary(new firefox.Binary);
|
|
192
|
-
env.builder().setFirefoxOptions(options);
|
|
193
|
-
driver1 = yield env.builder().build();
|
|
194
|
-
driver2 = yield env.builder().build();
|
|
195
|
-
// Ok if this doesn't fail.
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test.afterEach(function*() {
|
|
199
|
-
if (driver1) {
|
|
200
|
-
yield driver1.quit();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (driver2) {
|
|
204
|
-
yield driver2.quit();
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
describe('context switching', function() {
|
|
210
|
-
var driver;
|
|
211
|
-
|
|
212
|
-
test.beforeEach(function*() {
|
|
213
|
-
driver = yield env.builder().build();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test.afterEach(function() {
|
|
217
|
-
if (driver) {
|
|
218
|
-
return driver.quit();
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test.it('can get context', function() {
|
|
223
|
-
return assert(driver.getContext()).equalTo(Context.CONTENT);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
test.it('can set context', function*() {
|
|
227
|
-
yield driver.setContext(Context.CHROME);
|
|
228
|
-
let ctxt = yield driver.getContext();
|
|
229
|
-
assert(ctxt).equalTo(Context.CHROME);
|
|
230
|
-
|
|
231
|
-
yield driver.setContext(Context.CONTENT);
|
|
232
|
-
ctxt = yield driver.getContext();
|
|
233
|
-
assert(ctxt).equalTo(Context.CONTENT);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
test.it('throws on unknown context', function() {
|
|
237
|
-
return driver.setContext("foo").then(assert.fail, function(e) {
|
|
238
|
-
assert(e).instanceOf(error.InvalidArgumentError);
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
});
|
|
244
|
-
}, {browsers: ['firefox']});
|
|
@@ -1,140 +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
|
-
var assert = require('assert'),
|
|
21
|
-
fs = require('fs'),
|
|
22
|
-
path = require('path');
|
|
23
|
-
|
|
24
|
-
var promise = require('../..').promise,
|
|
25
|
-
Profile = require('../../firefox/profile').Profile,
|
|
26
|
-
decode = require('../../firefox/profile').decode,
|
|
27
|
-
loadUserPrefs = require('../../firefox/profile').loadUserPrefs,
|
|
28
|
-
io = require('../../io');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var JETPACK_EXTENSION = path.join(__dirname,
|
|
32
|
-
'../../lib/test/data/firefox/jetpack-sample.xpi');
|
|
33
|
-
var NORMAL_EXTENSION = path.join(__dirname,
|
|
34
|
-
'../../lib/test/data/firefox/sample.xpi');
|
|
35
|
-
var WEBEXTENSION_EXTENSION = path.join(__dirname,
|
|
36
|
-
'../../lib/test/data/firefox/webextension.xpi');
|
|
37
|
-
|
|
38
|
-
var JETPACK_EXTENSION_ID = 'jid1-EaXX7k0wwiZR7w@jetpack.xpi';
|
|
39
|
-
var NORMAL_EXTENSION_ID = 'sample@seleniumhq.org';
|
|
40
|
-
var WEBEXTENSION_EXTENSION_ID = 'webextensions-selenium-example@example.com';
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
describe('Profile', function() {
|
|
45
|
-
describe('setPreference', function() {
|
|
46
|
-
it('allows setting custom properties', function() {
|
|
47
|
-
var profile = new Profile();
|
|
48
|
-
assert.equal(undefined, profile.getPreference('foo'));
|
|
49
|
-
|
|
50
|
-
profile.setPreference('foo', 'bar');
|
|
51
|
-
assert.equal('bar', profile.getPreference('foo'));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('allows overriding mutable properties', function() {
|
|
55
|
-
var profile = new Profile();
|
|
56
|
-
|
|
57
|
-
profile.setPreference('browser.newtab.url', 'http://www.example.com');
|
|
58
|
-
assert.equal('http://www.example.com',
|
|
59
|
-
profile.getPreference('browser.newtab.url'));
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('writeToDisk', function() {
|
|
64
|
-
it('copies template directory recursively', function() {
|
|
65
|
-
var templateDir;
|
|
66
|
-
return io.tmpDir().then(function(td) {
|
|
67
|
-
templateDir = td;
|
|
68
|
-
var foo = path.join(templateDir, 'foo');
|
|
69
|
-
fs.writeFileSync(foo, 'Hello, world');
|
|
70
|
-
|
|
71
|
-
var bar = path.join(templateDir, 'subfolder/bar');
|
|
72
|
-
fs.mkdirSync(path.dirname(bar));
|
|
73
|
-
fs.writeFileSync(bar, 'Goodbye, world!');
|
|
74
|
-
|
|
75
|
-
return new Profile(templateDir).writeToDisk();
|
|
76
|
-
}).then(function(profileDir) {
|
|
77
|
-
assert.notEqual(profileDir, templateDir);
|
|
78
|
-
|
|
79
|
-
assert.equal('Hello, world',
|
|
80
|
-
fs.readFileSync(path.join(profileDir, 'foo')));
|
|
81
|
-
assert.equal('Goodbye, world!',
|
|
82
|
-
fs.readFileSync(path.join(profileDir, 'subfolder/bar')));
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('does not copy lock files', function() {
|
|
87
|
-
return io.tmpDir().then(function(dir) {
|
|
88
|
-
fs.writeFileSync(path.join(dir, 'parent.lock'), 'lock');
|
|
89
|
-
fs.writeFileSync(path.join(dir, 'lock'), 'lock');
|
|
90
|
-
fs.writeFileSync(path.join(dir, '.parentlock'), 'lock');
|
|
91
|
-
return new Profile(dir).writeToDisk();
|
|
92
|
-
}).then(function(dir) {
|
|
93
|
-
assert.ok(fs.existsSync(dir));
|
|
94
|
-
assert.ok(!fs.existsSync(path.join(dir, 'parent.lock')));
|
|
95
|
-
assert.ok(!fs.existsSync(path.join(dir, 'lock')));
|
|
96
|
-
assert.ok(!fs.existsSync(path.join(dir, '.parentlock')));
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('user.js', function() {
|
|
101
|
-
it('merges template user.js into preferences', function() {
|
|
102
|
-
return io.tmpDir().then(function(dir) {
|
|
103
|
-
fs.writeFileSync(path.join(dir, 'user.js'), [
|
|
104
|
-
'user_pref("browser.newtab.url", "http://www.example.com")',
|
|
105
|
-
'user_pref("dom.max_script_run_time", 1234)'
|
|
106
|
-
].join('\n'));
|
|
107
|
-
|
|
108
|
-
return new Profile(dir).writeToDisk();
|
|
109
|
-
}).then(function(profile) {
|
|
110
|
-
return loadUserPrefs(path.join(profile, 'user.js'));
|
|
111
|
-
}).then(function(prefs) {
|
|
112
|
-
assert.equal('http://www.example.com', prefs['browser.newtab.url']);
|
|
113
|
-
assert.equal(1234, prefs['dom.max_script_run_time']);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('extensions', function() {
|
|
119
|
-
it('are copied into new profile directory', function() {
|
|
120
|
-
var profile = new Profile();
|
|
121
|
-
profile.addExtension(JETPACK_EXTENSION);
|
|
122
|
-
profile.addExtension(NORMAL_EXTENSION);
|
|
123
|
-
profile.addExtension(WEBEXTENSION_EXTENSION);
|
|
124
|
-
|
|
125
|
-
return profile.writeToDisk().then(function(dir) {
|
|
126
|
-
dir = path.join(dir, 'extensions');
|
|
127
|
-
assertExists(JETPACK_EXTENSION_ID);
|
|
128
|
-
assertExists(NORMAL_EXTENSION_ID);
|
|
129
|
-
assertExists(WEBEXTENSION_EXTENSION_ID + '.xpi');
|
|
130
|
-
|
|
131
|
-
function assertExists(file) {
|
|
132
|
-
assert.ok(
|
|
133
|
-
fs.existsSync(path.join(dir, file)),
|
|
134
|
-
`expected ${file} to exist`);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
package/test/lib/events_test.js
DELETED
|
@@ -1,177 +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
|
-
const EventEmitter = require('../../lib/events').EventEmitter;
|
|
21
|
-
|
|
22
|
-
const assert = require('assert');
|
|
23
|
-
const sinon = require('sinon');
|
|
24
|
-
|
|
25
|
-
describe('EventEmitter', function() {
|
|
26
|
-
describe('#emit()', function() {
|
|
27
|
-
it('can emit events when nothing is registered', function() {
|
|
28
|
-
let emitter = new EventEmitter;
|
|
29
|
-
emitter.emit('foo');
|
|
30
|
-
// Ok if no errors are thrown.
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('can pass args to listeners on emit', function() {
|
|
34
|
-
let emitter = new EventEmitter;
|
|
35
|
-
let now = Date.now();
|
|
36
|
-
|
|
37
|
-
let messages = [];
|
|
38
|
-
emitter.on('foo', (arg) => messages.push(arg));
|
|
39
|
-
|
|
40
|
-
emitter.emit('foo', now);
|
|
41
|
-
assert.deepEqual([now], messages);
|
|
42
|
-
|
|
43
|
-
emitter.emit('foo', now + 15);
|
|
44
|
-
assert.deepEqual([now, now + 15], messages);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('#addListener()', function() {
|
|
49
|
-
it('can add multiple listeners for one event', function() {
|
|
50
|
-
let emitter = new EventEmitter;
|
|
51
|
-
let count = 0;
|
|
52
|
-
emitter.addListener('foo', () => count++);
|
|
53
|
-
emitter.addListener('foo', () => count++);
|
|
54
|
-
emitter.addListener('foo', () => count++);
|
|
55
|
-
emitter.emit('foo');
|
|
56
|
-
assert.equal(3, count);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('only registers each listener function once', function() {
|
|
60
|
-
let emitter = new EventEmitter;
|
|
61
|
-
let count = 0;
|
|
62
|
-
let onFoo = () => count++;
|
|
63
|
-
emitter.addListener('foo', onFoo);
|
|
64
|
-
emitter.addListener('foo', onFoo);
|
|
65
|
-
emitter.addListener('foo', onFoo);
|
|
66
|
-
|
|
67
|
-
emitter.emit('foo');
|
|
68
|
-
assert.equal(1, count);
|
|
69
|
-
|
|
70
|
-
emitter.emit('foo');
|
|
71
|
-
assert.equal(2, count);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('allows users to specify a custom scope', function() {
|
|
75
|
-
let obj = {
|
|
76
|
-
count: 0,
|
|
77
|
-
inc: function() {
|
|
78
|
-
this.count++;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
let emitter = new EventEmitter;
|
|
82
|
-
emitter.addListener('foo', obj.inc, obj);
|
|
83
|
-
|
|
84
|
-
emitter.emit('foo');
|
|
85
|
-
assert.equal(1, obj.count);
|
|
86
|
-
|
|
87
|
-
emitter.emit('foo');
|
|
88
|
-
assert.equal(2, obj.count);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('#once()', function() {
|
|
93
|
-
it('only calls registered callback once', function() {
|
|
94
|
-
let emitter = new EventEmitter;
|
|
95
|
-
let count = 0;
|
|
96
|
-
emitter.once('foo', () => count++);
|
|
97
|
-
emitter.once('foo', () => count++);
|
|
98
|
-
emitter.once('foo', () => count++);
|
|
99
|
-
|
|
100
|
-
emitter.emit('foo');
|
|
101
|
-
assert.equal(3, count);
|
|
102
|
-
|
|
103
|
-
emitter.emit('foo');
|
|
104
|
-
assert.equal(3, count);
|
|
105
|
-
|
|
106
|
-
emitter.emit('foo');
|
|
107
|
-
assert.equal(3, count);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe('#removeListeners()', function() {
|
|
112
|
-
it('only removes the given listener function', function() {
|
|
113
|
-
let emitter = new EventEmitter;
|
|
114
|
-
let count = 0;
|
|
115
|
-
emitter.addListener('foo', () => count++);
|
|
116
|
-
emitter.addListener('foo', () => count++);
|
|
117
|
-
|
|
118
|
-
let toRemove = () => count++;
|
|
119
|
-
emitter.addListener('foo', toRemove);
|
|
120
|
-
|
|
121
|
-
emitter.emit('foo');
|
|
122
|
-
assert.equal(3, count);
|
|
123
|
-
|
|
124
|
-
emitter.removeListener('foo', toRemove);
|
|
125
|
-
emitter.emit('foo');
|
|
126
|
-
assert.equal(5, count);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('#removeAllListeners()', function() {
|
|
131
|
-
it('only removes listeners for type if specified', function() {
|
|
132
|
-
let emitter = new EventEmitter;
|
|
133
|
-
let count = 0;
|
|
134
|
-
emitter.addListener('foo', () => count++);
|
|
135
|
-
emitter.addListener('foo', () => count++);
|
|
136
|
-
emitter.addListener('foo', () => count++);
|
|
137
|
-
emitter.addListener('bar', () => count++);
|
|
138
|
-
|
|
139
|
-
emitter.emit('foo');
|
|
140
|
-
assert.equal(3, count);
|
|
141
|
-
|
|
142
|
-
emitter.removeAllListeners('foo');
|
|
143
|
-
|
|
144
|
-
emitter.emit('foo');
|
|
145
|
-
assert.equal(3, count);
|
|
146
|
-
|
|
147
|
-
emitter.emit('bar');
|
|
148
|
-
assert.equal(4, count);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('removes absolutely all listeners if no type specified', function() {
|
|
152
|
-
let emitter = new EventEmitter;
|
|
153
|
-
let count = 0;
|
|
154
|
-
emitter.addListener('foo', () => count++);
|
|
155
|
-
emitter.addListener('bar', () => count++);
|
|
156
|
-
emitter.addListener('baz', () => count++);
|
|
157
|
-
emitter.addListener('baz', () => count++);
|
|
158
|
-
|
|
159
|
-
emitter.emit('foo');
|
|
160
|
-
assert.equal(1, count);
|
|
161
|
-
|
|
162
|
-
emitter.emit('baz');
|
|
163
|
-
assert.equal(3, count);
|
|
164
|
-
|
|
165
|
-
emitter.removeAllListeners();
|
|
166
|
-
|
|
167
|
-
emitter.emit('foo');
|
|
168
|
-
assert.equal(3, count);
|
|
169
|
-
|
|
170
|
-
emitter.emit('bar');
|
|
171
|
-
assert.equal(3, count);
|
|
172
|
-
|
|
173
|
-
emitter.emit('baz');
|
|
174
|
-
assert.equal(3, count);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|