Skip to content

Commit cf2aefb

Browse files
committed
Drop existing task callbacks when a task is cancelled due to an unhanded error
in the current frame. Fixes issue 8548
1 parent 9805a70 commit cf2aefb

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

javascript/node/selenium-webdriver/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## v2.45.1-dev
22

3+
* FIXED: 8548: Task callbacks are once again dropped if the task was cancelled
4+
due to a previously uncaught error within the frame.
35
* FIXED: 8496: Extended the `chrome.Options` API to cover all configuration
46
options (e.g. mobile emulation and performance logging) documented on the
57
ChromeDriver [project site](https://sites.google.com/a/chromium.org/chromedriver/capabilities).

javascript/webdriver/promise.js

+1
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,7 @@ promise.Frame_ = goog.defineClass(webdriver.EventEmitter, {
21672167
if (child instanceof promise.Frame_) {
21682168
child.cancelRemainingTasks(error);
21692169
} else {
2170+
child.promise.callbacks_ = null;
21702171
child.cancel(error);
21712172
}
21722173
}

javascript/webdriver/test/promise_error_test.js

+97-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ function testFailsParentTaskIfAsyncScheduledTaskFails() {
464464
}, 10);
465465
return d.promise;
466466
}).then(fail, assertIsStubError);
467-
467+
468468
return waitForIdle().then(function() {
469469
return d.promise;
470470
}).then(fail, function(e) {
@@ -571,3 +571,99 @@ function testLongStackTraces_includesPromiseChainWhenEnabled() {
571571
});
572572
return waitForIdle();
573573
}
574+
575+
576+
function testFrameCancelsRemainingTasks_onUnhandledTaskFailure() {
577+
var run = false;
578+
return flow.execute(function() {
579+
flow.execute(throwStubError);
580+
flow.execute(function() { run = true; });
581+
}).then(fail, function(e) {
582+
assertIsStubError(e);
583+
assertFalse(run);
584+
});
585+
}
586+
587+
588+
function testFrameCancelsRemainingTasks_onUnhandledPromiseRejection() {
589+
var run = false;
590+
return flow.execute(function() {
591+
webdriver.promise.rejected(new StubError);
592+
flow.execute(function() { run = true; });
593+
}).then(fail, function(e) {
594+
assertIsStubError(e);
595+
assertFalse(run);
596+
});
597+
}
598+
599+
600+
function testRegisteredTaskCallbacksAreDroppedWhenTaskIsCancelled_return() {
601+
var seen = [];
602+
return flow.execute(function() {
603+
flow.execute(throwStubError);
604+
605+
flow.execute(function() {
606+
seen.push(1);
607+
}).then(function() {
608+
seen.push(2);
609+
}, function() {
610+
seen.push(3);
611+
});
612+
}).then(fail, function(e) {
613+
assertIsStubError(e);
614+
assertArrayEquals([], seen);
615+
});
616+
}
617+
618+
619+
function testRegisteredTaskCallbacksAreDroppedWhenTaskIsCancelled_withReturn() {
620+
var seen = [];
621+
return flow.execute(function() {
622+
flow.execute(throwStubError);
623+
624+
return flow.execute(function() {
625+
seen.push(1);
626+
}).then(function() {
627+
seen.push(2);
628+
}, function() {
629+
seen.push(3);
630+
});
631+
}).then(fail, function(e) {
632+
assertIsStubError(e);
633+
assertArrayEquals([], seen);
634+
});
635+
}
636+
637+
638+
function testTaskIsCancelledAfterWaitTimeout() {
639+
var seen = [];
640+
return flow.execute(function() {
641+
flow.wait(function() {
642+
webdriver.promies.delayed(100).then(goog.nullFunction);
643+
}, 5);
644+
645+
return flow.execute(function() {
646+
seen.push(1);
647+
}).then(function() {
648+
seen.push(2);
649+
}, function() {
650+
seen.push(3);
651+
});
652+
}).then(fail, function(e) {
653+
assertArrayEquals([], seen);
654+
});
655+
}
656+
657+
658+
function testTaskCallbacksGetCancellationErrorIfRegisteredAfterTaskIsCancelled() {
659+
var task;
660+
flow.execute(function() {
661+
flow.execute(throwStubError);
662+
task = flow.execute(goog.nullFunction);
663+
}).then(fail, assertIsStubError);
664+
return waitForIdle().then(function() {
665+
return task.then(fail, function(e) {
666+
assertTrue(e instanceof webdriver.promise.CancellationError);
667+
});
668+
});
669+
}

0 commit comments

Comments
 (0)