Skip to content

Commit c42999e

Browse files
committed
[js] Fix some inconsistencies in the ControlFlow's execution logic. Details in
the file overview comment for promise.js Fixes #363 Fixes #677 Fixes #796
1 parent 24ea2c3 commit c42999e

File tree

19 files changed

+2083
-1023
lines changed

19 files changed

+2083
-1023
lines changed

Rakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ task :ide_bamboo => ["se_ide:assemble_ide_in_bamboo"]
161161
task :test_javascript => [
162162
'//javascript/atoms:test:run',
163163
'//javascript/webdriver:test:run',
164+
'//javascript/webdriver:es6_test:run',
164165
'//javascript/selenium-atoms:test:run',
165166
'//javascript/selenium-core:test:run']
166167
task :test_chrome => [ "//java/client/test/org/openqa/selenium/chrome:test:run" ]
@@ -475,7 +476,7 @@ desc "Calculate dependencies required for testing the automation atoms"
475476
task :calcdeps => "build/javascript/deps.js"
476477

477478
task :test_webdriverjs => [
478-
"//javascript/webdriver:test:run"
479+
"//javascript/webdriver:es6_test:run"
479480
]
480481

481482
desc "Generate a single file with WebDriverJS' public API"

javascript/node/deploy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ function generateDocs(outputDir, callback) {
395395
{'name': 'Changes', 'path': path.join(outputDir, 'CHANGES.md')}
396396
],
397397
'readme': path.join(outputDir, 'README.md'),
398-
'language': 'ES5',
398+
'language': 'ES6_STRICT',
399399
'sources': sourceFiles,
400400
'modules': moduleFiles,
401401
'excludes': [

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## v2.48.0-dev
22

3+
* Node v0.12.x users must run with --harmony. _This is the last release that
4+
will support v0.12.x_
5+
* FIXED: the `webdriver.promise.ControlFlow` now has a consistent execution
6+
order for tasks/callbacks scheduled in different turns of the JS event loop.
7+
Refer to the `webdriver.promise` documentation for more details.
38
* FIXED: a single `firefox.Binary` instance may be used to configure and
49
launch multiple FirefoxDriver sessions.
510

javascript/node/selenium-webdriver/test/promise_aplus_test.js

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,57 @@
2020
describe('Promises/A+ Compliance Tests', function() {
2121
var promise = require('../_base').require('webdriver.promise');
2222

23-
var nullFunction = function() {};
23+
// The promise spec does not define behavior for unhandled rejections and
24+
// assumes they are effectively swallowed. This is not the case with our
25+
// implementation, so we have to disable error propagation to test that the
26+
// rest of our behavior is compliant.
27+
// We run the tests with a separate instance of the control flow to ensure
28+
// disablign error propagation does not impact other tests.
29+
var flow = new promise.ControlFlow();
30+
flow.setPropagateUnhandledRejections(false);
2431

25-
before(function() {
26-
promise.controlFlow().on('uncaughtException', nullFunction);
27-
});
32+
function startsWith(str, prefix) {
33+
return str.indexOf(prefix) === 0;
34+
}
2835

29-
after(function() {
30-
promise.controlFlow().removeListener('uncaughtException', nullFunction);
31-
});
36+
function endsWith(str, suffix) {
37+
let len = str.length - suffix.length;
38+
return len >= 0 && str.indexOf(suffix, len) === len;
39+
}
40+
41+
// Skip the tests in 2.2.6.1/2. We are not compliant in these scenarios.
42+
var realDescribe = global.describe;
43+
global.describe = function(name, fn) {
44+
realDescribe(name, function() {
45+
var prefix = 'Promises/A+ Compliance Tests 2.2.6: '
46+
+ '`then` may be called multiple times on the same promise.';
47+
var suffix = 'even when one handler is added inside another handler';
48+
if (startsWith(this.fullTitle(), prefix)
49+
&& endsWith(this.fullTitle(), suffix)) {
50+
var realSpecify = global.specify;
51+
try {
52+
global.specify = function(name) {
53+
realSpecify(name);
54+
};
55+
fn();
56+
} finally {
57+
global.specify = realSpecify;
58+
}
59+
} else {
60+
fn();
61+
}
62+
});
63+
};
3264

3365
require('promises-aplus-tests').mocha({
34-
resolved: promise.fulfilled,
35-
rejected: promise.rejected,
66+
resolved: function(value) {
67+
return new promise.Promise((fulfill) => fulfill(value), flow);
68+
},
69+
rejected: function(error) {
70+
return new promise.Promise((_, reject) => reject(error), flow);
71+
},
3672
deferred: function() {
37-
var d = promise.defer();
73+
var d = new promise.Deferred(flow);
3874
return {
3975
resolve: d.fulfill,
4076
reject: d.reject,
@@ -43,4 +79,5 @@ describe('Promises/A+ Compliance Tests', function() {
4379
}
4480
});
4581

46-
});
82+
global.describe = realDescribe;
83+
});

javascript/remote/BUCK

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ js_binary(name = 'client',
4646
'--jscomp_error=uselessCode',
4747
'--jscomp_error=visibility',
4848

49+
'--language_in=ECMASCRIPT6_STRICT',
50+
'--language_out=ECMASCRIPT5_STRICT',
4951
'--third_party=false',
5052

5153
'--compilation_level=ADVANCED_OPTIMIZATIONS',
5254
],
5355
visibility = [
5456
'//java/server/src/org/openqa/selenium/remote/server:client',
5557
],
56-
)
58+
)

javascript/remote/build.desc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ js_binary(name = "clientbin",
3030
"--jscomp_error=uselessCode",
3131
"--jscomp_error=visibility",
3232

33+
"--language_in=ECMASCRIPT6_STRICT",
34+
"--language_out=ECMASCRIPT5_STRICT",
3335
"--third_party=false",
3436

3537
"--compilation_level=ADVANCED_OPTIMIZATIONS",

javascript/safari-driver/BUCK

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ js_binary(name = 'client',
7070

7171
'--jscomp_warning=checkTypes',
7272

73+
'--language_in=ECMASCRIPT6_STRICT',
74+
'--language_out=ECMASCRIPT5_STRICT',
75+
7376
"--output_wrapper='%output%;window.onload = init;'",
7477
'--third_party=false',
7578
],

javascript/safari-driver/build.desc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ js_binary(
5959

6060
"--jscomp_warning=checkTypes",
6161

62+
"--language_in=ECMASCRIPT6_STRICT",
63+
"--language_out=ECMASCRIPT5_STRICT",
6264
"--output_wrapper='%output%;window.onload = init;'",
6365
"--third_party=false",
6466
])
@@ -103,6 +105,8 @@ js_binary(
103105
"--jscomp_error=uselessCode",
104106
"--jscomp_error=visibility",
105107

108+
"--language_in=ECMASCRIPT6_STRICT",
109+
"--language_out=ECMASCRIPT5_STRICT",
106110
"--output_wrapper='%output%;safaridriver.debug.init();'",
107111
"--third_party=false",
108112
],
@@ -157,6 +161,8 @@ js_binary(
157161
"--jscomp_error=uselessCode",
158162
"--jscomp_error=visibility",
159163

164+
"--language_in=ECMASCRIPT6_STRICT",
165+
"--language_out=ECMASCRIPT5_STRICT",
160166
"--output_wrapper='%output%;safaridriver.extension.init();'",
161167
"--third_party=false",
162168
],
@@ -210,6 +216,8 @@ js_module_binary(
210216

211217
"--jscomp_warning=checkTypes",
212218

219+
"--language_in=ECMASCRIPT6_STRICT",
220+
"--language_out=ECMASCRIPT5_STRICT",
213221
"--module_wrapper='base:%s;init();'",
214222
"--module_wrapper='commands:MODULES.injected_commands = function() {%s};'",
215223

@@ -268,6 +276,8 @@ js_module_binary(
268276
"--jscomp_error=uselessCode",
269277
"--jscomp_error=visibility",
270278

279+
"--language_in=ECMASCRIPT6_STRICT",
280+
"--language_out=ECMASCRIPT5_STRICT",
271281
"--module_wrapper='base:MODULES.page_base = function(){%s;this.init();};'",
272282
"--module_wrapper='element:MODULES.page_element = function() {%s};'",
273283
"--module_wrapper='script:MODULES.page_script = function() {%s};'",

javascript/webdriver/build.desc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,37 @@ js_binary(name = "webdriver",
9999
"--jscomp_error=uselessCode",
100100
"--jscomp_error=useOfGoogBase",
101101
"--jscomp_error=visibility",
102+
"--language_in=ECMASCRIPT6_STRICT",
103+
"--language_out=ECMASCRIPT5_STRICT",
102104
"--output_wrapper='(function(exports){%output%})(typeof exports===typeof {}&&exports===this?exports:this.webdriver=this.webdriver||{})'",
103105
"--third_party=false",
104106
])
105107

106108
js_test(name = "test",
107109
srcs = [
108-
"test/**/*.js",
109-
"test/**/*_test.html",
110+
"test/atoms/**/*_test.html",
110111
],
112+
test_dir = "test/atoms",
111113
deps = [
112114
":test_support_lib",
113115
"//java/client/test/org/openqa/selenium/javascript",
114116
"//java/server/test/org/openqa/selenium:server-with-tests:uber",
115117
])
118+
119+
# Tests that should only run in browsers with ES6 support.
120+
js_test(name = "es6_test",
121+
srcs = [
122+
"test/*.js",
123+
"test/e2e/**/*.js",
124+
"test/http/**/*.js",
125+
"test/testing/**/*.js",
126+
],
127+
deps = [
128+
":test_support_lib",
129+
"//java/client/test/org/openqa/selenium/javascript",
130+
"//java/server/test/org/openqa/selenium:server-with-tests:uber",
131+
],
132+
browsers = [
133+
"chrome",
134+
"ff"
135+
])

javascript/webdriver/logging.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ exports.getLogger = getLogger;
111111
* Logs all messages to the Console API.
112112
*/
113113
function consoleHandler(record) {
114-
if (typeof console === 'undefined') {
114+
if (typeof console === 'undefined' || !console) {
115115
return;
116116
}
117117
record = /** @type {!LogRecord} */(record);

0 commit comments

Comments
 (0)