Skip to content

Commit

Permalink
Drop existing task callbacks when a task is cancelled due to an unhan…
Browse files Browse the repository at this point in the history
…ded error

in the current frame.

Fixes issue 8548
  • Loading branch information
jleyba committed Feb 28, 2015
1 parent 9805a70 commit cf2aefb
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
2 changes: 2 additions & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## v2.45.1-dev

* FIXED: 8548: Task callbacks are once again dropped if the task was cancelled
due to a previously uncaught error within the frame.
* FIXED: 8496: Extended the `chrome.Options` API to cover all configuration
options (e.g. mobile emulation and performance logging) documented on the
ChromeDriver [project site](https://sites.google.com/a/chromium.org/chromedriver/capabilities).
Expand Down
1 change: 1 addition & 0 deletions javascript/webdriver/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,7 @@ promise.Frame_ = goog.defineClass(webdriver.EventEmitter, {
if (child instanceof promise.Frame_) {
child.cancelRemainingTasks(error);
} else {
child.promise.callbacks_ = null;
child.cancel(error);
}
}
Expand Down
98 changes: 97 additions & 1 deletion javascript/webdriver/test/promise_error_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ function testFailsParentTaskIfAsyncScheduledTaskFails() {
}, 10);
return d.promise;
}).then(fail, assertIsStubError);

return waitForIdle().then(function() {
return d.promise;
}).then(fail, function(e) {
Expand Down Expand Up @@ -571,3 +571,99 @@ function testLongStackTraces_includesPromiseChainWhenEnabled() {
});
return waitForIdle();
}


function testFrameCancelsRemainingTasks_onUnhandledTaskFailure() {
var run = false;
return flow.execute(function() {
flow.execute(throwStubError);
flow.execute(function() { run = true; });
}).then(fail, function(e) {
assertIsStubError(e);
assertFalse(run);
});
}


function testFrameCancelsRemainingTasks_onUnhandledPromiseRejection() {
var run = false;
return flow.execute(function() {
webdriver.promise.rejected(new StubError);
flow.execute(function() { run = true; });
}).then(fail, function(e) {
assertIsStubError(e);
assertFalse(run);
});
}


function testRegisteredTaskCallbacksAreDroppedWhenTaskIsCancelled_return() {
var seen = [];
return flow.execute(function() {
flow.execute(throwStubError);

flow.execute(function() {
seen.push(1);
}).then(function() {
seen.push(2);
}, function() {
seen.push(3);
});
}).then(fail, function(e) {
assertIsStubError(e);
assertArrayEquals([], seen);
});
}


function testRegisteredTaskCallbacksAreDroppedWhenTaskIsCancelled_withReturn() {
var seen = [];
return flow.execute(function() {
flow.execute(throwStubError);

return flow.execute(function() {
seen.push(1);
}).then(function() {
seen.push(2);
}, function() {
seen.push(3);
});
}).then(fail, function(e) {
assertIsStubError(e);
assertArrayEquals([], seen);
});
}


function testTaskIsCancelledAfterWaitTimeout() {
var seen = [];
return flow.execute(function() {
flow.wait(function() {
webdriver.promies.delayed(100).then(goog.nullFunction);
}, 5);

return flow.execute(function() {
seen.push(1);
}).then(function() {
seen.push(2);
}, function() {
seen.push(3);
});
}).then(fail, function(e) {
assertArrayEquals([], seen);
});
}


function testTaskCallbacksGetCancellationErrorIfRegisteredAfterTaskIsCancelled() {
var task;
flow.execute(function() {
flow.execute(throwStubError);
task = flow.execute(goog.nullFunction);
}).then(fail, assertIsStubError);
return waitForIdle().then(function() {
return task.then(fail, function(e) {
assertTrue(e instanceof webdriver.promise.CancellationError);
});
});
}

0 comments on commit cf2aefb

Please sign in to comment.