Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js |
| diff --git a/LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js b/LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js |
| index 1d3a5f576840015fc44df81b7e357ab7c5e76b51..399b48da8899ad2cb97db8d31d6b014f4535b779 100644 |
| --- a/LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js |
| +++ b/LayoutTests/http/tests/serviceworker/resources/worker-test-harness.js |
| @@ -84,3 +84,27 @@ function promise_test(func, name, properties) { |
| throw value; |
| })); |
| } |
| + |
| +// Returns a promise that fulfills after the provided |promise| is fulfilled. |
| +// The |test| succeeds only if |promise| throws an exception matching |code|. |
| +// The optional |description| describes the test being performed. |
| +// E.g.: |
| +// assert_promise_throws( |
| +// new Promise(...), // something that should throw an exception. |
| +// 'NotFoundError', |
| +// 'Should throw NotFoundError.'); |
| +function assert_promise_throws(promise, code, description) { |
| + return promise.then( |
| + function() { |
| + throw 'assert_promise_throws: ' + description + ' Promise did now throw.'; |
|
jsbell
2014/08/27 22:28:23
Typo: now -> not
asanka
2014/08/28 00:02:56
Done.
|
| + }, |
| + function(e) { |
| + if (code in self) { |
| + // If |code| is a JavaScript error exposed in the global object, then |
| + // require that the thrown exception be of that type. |
| + assert_class_string(e, code, description); |
|
jsbell
2014/08/27 21:56:47
This doesn't work - the Error subclasses like Type
asanka
2014/08/28 00:02:56
Ah. Hack removed. We are now calling assert_promis
|
| + } else { |
| + assert_throws(code, function() { throw e; }, description); |
| + } |
| + }); |
| +} |