| OLD | NEW |
| 1 /*global self*/ | 1 /*global self*/ |
| 2 /*jshint latedef: nofunc*/ | 2 /*jshint latedef: nofunc*/ |
| 3 /* | 3 /* |
| 4 Distributed under both the W3C Test Suite License [1] and the W3C | 4 Distributed under both the W3C Test Suite License [1] and the W3C |
| 5 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the | 5 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the |
| 6 policies and contribution forms [3]. | 6 policies and contribution forms [3]. |
| 7 | 7 |
| 8 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license | 8 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license |
| 9 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license | 9 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license |
| 10 [3] http://www.w3.org/2004/10/27-testcases | 10 [3] http://www.w3.org/2004/10/27-testcases |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 return test_obj; | 520 return test_obj; |
| 521 } | 521 } |
| 522 | 522 |
| 523 function promise_test(func, name, properties) { | 523 function promise_test(func, name, properties) { |
| 524 var test = async_test(name, properties); | 524 var test = async_test(name, properties); |
| 525 // If there is no promise tests queue make one. | 525 // If there is no promise tests queue make one. |
| 526 if (!tests.promise_tests) { | 526 if (!tests.promise_tests) { |
| 527 tests.promise_tests = Promise.resolve(); | 527 tests.promise_tests = Promise.resolve(); |
| 528 } | 528 } |
| 529 tests.promise_tests = tests.promise_tests.then(function() { | 529 tests.promise_tests = tests.promise_tests.then(function() { |
| 530 var donePromise = new Promise(function(resolve) { |
| 531 test.add_cleanup(resolve); |
| 532 }); |
| 530 var promise = test.step(func, test, test); | 533 var promise = test.step(func, test, test); |
| 531 test.step(function() { | 534 test.step(function() { |
| 532 assert_not_equals(promise, undefined); | 535 assert_not_equals(promise, undefined); |
| 533 }); | 536 }); |
| 534 return Promise.resolve(promise) | 537 Promise.resolve(promise).then( |
| 535 .then( | |
| 536 function() { | 538 function() { |
| 537 test.done(); | 539 test.done(); |
| 538 }) | 540 }) |
| 539 .catch(test.step_func( | 541 .catch(test.step_func( |
| 540 function(value) { | 542 function(value) { |
| 541 if (value instanceof AssertionError) { | 543 if (value instanceof AssertionError) { |
| 542 throw value; | 544 throw value; |
| 543 } | 545 } |
| 544 assert(false, "promise_test", null, | 546 assert(false, "promise_test", null, |
| 545 "Unhandled rejection with value: ${value}", {valu
e:value}); | 547 "Unhandled rejection with value: ${value}", {valu
e:value}); |
| 546 })); | 548 })); |
| 549 return donePromise; |
| 547 }); | 550 }); |
| 548 } | 551 } |
| 549 | 552 |
| 550 function promise_rejects(test, expected, promise, description) { | 553 function promise_rejects(test, expected, promise, description) { |
| 551 return promise.then(test.unreached_func("Should have rejected: " + descr
iption)).catch(function(e) { | 554 return promise.then(test.unreached_func("Should have rejected: " + descr
iption)).catch(function(e) { |
| 552 assert_throws(expected, function() { throw e }, description); | 555 assert_throws(expected, function() { throw e }, description); |
| 553 }); | 556 }); |
| 554 } | 557 } |
| 555 | 558 |
| 556 /** | 559 /** |
| (...skipping 2129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2686 } | 2689 } |
| 2687 }; | 2690 }; |
| 2688 | 2691 |
| 2689 addEventListener("error", error_handler, false); | 2692 addEventListener("error", error_handler, false); |
| 2690 addEventListener("unhandledrejection", function(e){ error_handler(e.reason);
}, false); | 2693 addEventListener("unhandledrejection", function(e){ error_handler(e.reason);
}, false); |
| 2691 | 2694 |
| 2692 test_environment.on_tests_ready(); | 2695 test_environment.on_tests_ready(); |
| 2693 | 2696 |
| 2694 })(); | 2697 })(); |
| 2695 // vim: set expandtab shiftwidth=4 tabstop=4: | 2698 // vim: set expandtab shiftwidth=4 tabstop=4: |
| OLD | NEW |