Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / serviceworker / resources / worker-test-harness.js
index 1d3a5f5..4129f8f 100644 (file)
@@ -84,3 +84,29 @@ 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| 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);
+      }
+    });
+}