Commit 325ed8bd authored by mek@chromium.org's avatar mek@chromium.org

Move promise_test and assert_promise_rejects out of worker-test-harness.

These methods have nothing to do with service worker based tests, and are just
as useful in normal testharness based tests, so move them to a separate file.

Additionally rename worker-test-harness.js to worker-testharness.js for consistency.

Review URL: https://codereview.chromium.org/647493002

git-svn-id: svn://svn.chromium.org/blink/trunk@183557 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 57ffedcd
importScripts('../../serviceworker/resources/worker-test-harness.js');
importScripts('../../serviceworker/resources/worker-testharness.js');
importScripts('../../resources/testharness-helpers.js');
promise_test(function(test) {
return navigator.geofencing.registerRegion(
......
/*
* testharness-helpers contains various useful extensions to testharness.js to
* allow them to be used across multiple tests before they have been
* upstreamed. This file is intended to be usable from both document and worker
* environments, so code should for example not rely on the DOM.
*/
// '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 reject.';
},
function(e) {
if (code !== undefined) {
assert_throws(code, function() { throw e; }, description);
}
});
}
importScripts('../../resources/interfaces.js');
importScripts('../../resources/worker-test-harness.js');
importScripts('../../resources/worker-testharness.js');
test(function() {
assert_throws({name: 'InvalidAccessError'}, function() {
......
importScripts('../../resources/worker-test-harness.js');
importScripts('../../resources/worker-testharness.js');
test(function() {
assert_false(
......
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
importScripts('../../resources/testharness-helpers.js');
var test_cache_list =
['', 'example', 'Another cache name', 'A', 'a', 'ex ample'];
......
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
importScripts('../../resources/testharness-helpers.js');
promise_test(function(t) {
var cache_name = 'cache-storage/foo';
......
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
this.addEventListener('fetch', function(event) {
event.respondWith(new Response('ERROR'));
......
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
importScripts('../../resources/testharness-helpers.js');
importScripts('test-helpers.js');
promise_test(function() {
......
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
importScripts('test-helpers.js');
async_test(function(t) {
......
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
test(function() {
function size(headers) {
......
importScripts('interfaces.js');
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
test(function() {
var EVENT_HANDLER = 'object';
......
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
importScripts('../../resources/testharness-helpers.js');
importScripts('test-helpers.js');
var URL = 'https://www.example.com/test.html';
......
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
importScripts('../../resources/testharness-helpers.js');
promise_test(function() {
var response = new Response('test string');
......
importScripts('worker-test-harness.js');
importScripts('worker-testharness.js');
function size(headers) {
var count = 0;
......
......@@ -72,41 +72,3 @@ importScripts('/resources/testharness.js');
}
});
})();
// '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);
}
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment