Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Unified Diff: LayoutTests/fast/js/Promise-bindings-check-exception.html

Issue 232563003: API functions returning Promises should not throw exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/fast/js/Promise-bindings-check-exception-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/fast/js/Promise-bindings-check-exception.html
diff --git a/LayoutTests/fast/js/Promise-bindings-check-exception.html b/LayoutTests/fast/js/Promise-bindings-check-exception.html
new file mode 100644
index 0000000000000000000000000000000000000000..46149dd2a4f4f3f19c6e99f529c11ecf9cb00511
--- /dev/null
+++ b/LayoutTests/fast/js/Promise-bindings-check-exception.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<script src="../../resources/js-test.js"></script>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+// http://heycam.github.io/webidl/#es-operations
+description('Operations that return a Promise type should handle exceptions ' +
+ 'by returning a rejected Promise with the exception.')
+
+window.jsTestIsAsync = true;
+
+var reason;
+
+function shouldBeRejected(promise, message) {
+ return promise.then(function() {
+ testFailed('Resolved unexpectedly: ' + message);
+ }, function(e) {
+ reason = e;
+ testPassed('Rejected as expected: ' + message);
+ shouldBeTrue('reason instanceof Error');
+ debug(e);
+ });
+}
+
+function shouldBeResolved(promise, message) {
+ return promise.then(function() {
+ testPassed('Resolved as expected: ' + message);
+ }, function(e) {
+ testFailed('Rejected unexpectedly: ' + message);
+ reason = e;
+ shouldBeTrue('reason instanceof Error');
+ debug(e);
+ });
+}
+
+var check = internals.promiseCheck.bind(internals);
+var check2 = internals.promiseCheckWithoutExceptionState.bind(internals);
+var check3 = internals.promiseCheckRange.bind(internals);
+
+Promise.resolve().then(function() {
+ return shouldBeRejected(check(), 'no arguments');
+}).then(function() {
+ return shouldBeResolved(check(3, true, {}, '', ['']), 'valid arguments');
+}).then(function() {
+ return shouldBeResolved(check(null, true, {}, '', []), 'convert(long)');
+}).then(function() {
+ return shouldBeResolved(check(3, {}, {}, '', []), 'convert(boolean)');
+}).then(function() {
+ return shouldBeRejected(check(3, true, 3, '', []), 'type error(Dictionary)');
+}).then(function() {
+ return shouldBeResolved(check(3, true, {}, {}, []), 'convert(String)');
+}).then(function() {
+ var x = {
+ toString: function() {
+ throw Error('Thrown from toString');
+ }
+ };
+ return shouldBeRejected(check(3, true, {}, x, []), 'conversion error(toString)');
+}).then(function() {
+ var x = {
+ toString: function() {
+ throw Error('Thrown from toString');
+ }
+ };
+ return shouldBeRejected(check(3, true, {}, '', [x]), 'conversion error([String])');
+}).then(function() {
+ return shouldBeRejected(check(3, false, {}, '', []), 'rejected by the impl');
+}).then(function() {
+ return shouldBeRejected(check2(), 'no arguments');
+}).then(function() {
+ return shouldBeResolved(check2({}, '', '', ''), 'valid arguments');
+}).then(function() {
+ return shouldBeResolved(check2({}, ''), 'valid arguments');
+}).then(function() {
+ return shouldBeRejected(check2(3, ''), 'type error(Dictionary)');
+}).then(function() {
+ return shouldBeResolved(check2({}, '', {}, 3), 'convert(String...)');
+}).then(function() {
+ var x = {
+ toString: function() {
+ throw Error('Thrown from toString');
+ }
+ };
+ return shouldBeRejected(check2({}, '', '', x), 'conversion error(String...)');
+}).then(function() {
+ return shouldBeRejected(check3(-1), 'range error(octet)');
+}).then(undefined, function(e) {
+ testFailed('An exception is thrown from a method');
+ debug(e);
+}).then(finishJSTest, finishJSTest);
+</script>
« no previous file with comments | « no previous file | LayoutTests/fast/js/Promise-bindings-check-exception-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698