Chromium Code Reviews| Index: LayoutTests/http/tests/resources/testharness-helpers.js |
| diff --git a/LayoutTests/http/tests/resources/testharness-helpers.js b/LayoutTests/http/tests/resources/testharness-helpers.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0bcfa0dcb4cd171f11858332c2131e232940f01b |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/resources/testharness-helpers.js |
| @@ -0,0 +1,43 @@ |
| +/* |
| + * testharness-helpers contains various useful extensions to testharness.js to |
| + * allow them to be used accross multiple tests before they have been |
|
jsbell
2014/10/09 18:46:06
typo: accross -> across
|
| + * upstreamed. |
| + */ |
| + |
| +// 'promise_test' is a new kind of testharness test that handles some |
| +// boilerplate for testing with promises. |
| +function promise_test(func, name, properties) { |
| + properties = properties || {}; |
| + var test = async_test(name, properties); |
| + Promise.resolve(test.step(func, test, test)) |
| + .then(function() { test.done(); }) |
| + .catch(test.step_func(function(value) { |
| + throw value; |
| + })); |
| +} |
| + |
| +// Returns a promise that fulfills after the provided |promise| is fulfilled. |
| +// The |test| succeeds only if |promise| rejects with an exception matching |
| +// |code|. Accepted values for |code| follow those accepted for assert_throws(). |
| +// The optional |description| describes the test being performed. |
| +// E.g.: |
| +// assert_promise_rejects( |
| +// new Promise(...), // something that should throw an exception. |
| +// 'NotFoundError', |
| +// 'Should throw NotFoundError.'); |
| +// |
| +// assert_promise_rejects( |
| +// new Promise(...), |
| +// new TypeError(), |
| +// 'Should throw TypeError'); |
| +function assert_promise_rejects(promise, code, description) { |
| + return promise.then( |
| + function() { |
| + throw 'assert_promise_rejects: ' + description + ' Promise did not throw.'; |
| + }, |
| + function(e) { |
| + if (code !== undefined) { |
| + assert_throws(code, function() { throw e; }, description); |
| + } |
| + }); |
| +} |