Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/resources/wait-for-activate-worker.js |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/resources/wait-for-activate-worker.js b/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/resources/wait-for-activate-worker.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3df437aacb5115be428860e42f8b3d19adbffc6c |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/resources/wait-for-activate-worker.js |
| @@ -0,0 +1,40 @@ |
| +// This worker remains in the installing phase so that the |
| +// navigation preload API can be tested when there is no |
| +// active worker. |
| +importScripts('../../../resources/testharness.js'); |
| +importScripts('helpers.js'); |
| + |
| +function expect_rejection(promise) { |
|
falken
2016/11/24 07:10:00
Ideally I'd use the harness's promise_rejects but
|
| + return promise.then( |
| + () => { return Promise.reject('unexpected fulfillment'); }, |
| + err => { assert_equals('InvalidStateError', err.name); }); |
| +} |
| + |
| +function test_before_activation() { |
| + const np = self.registration.navigationPreload; |
| + return expect_rejection(np.enable()) |
| + .then(() => expect_rejection(np.disable())) |
| + .then(() => expect_rejection(np.setHeaderValue('hi'))) |
| + .then(() => np.getState()) |
| + .then(state => expect_state(state, false, 'true', |
| + 'state should be the default')) |
| + .then(() => 'PASS') |
| + .catch(err => 'FAIL: ' + err); |
| +} |
| + |
| +var resolve_done_promise; |
| +var done_promise = new Promise(resolve => { resolve_done_promise = resolve; }); |
| + |
| +// Run the test once the page messages this worker. |
| +self.addEventListener('message', e => { |
| + e.waitUntil(test_before_activation() |
| + .then(result => { |
| + e.source.postMessage(result); |
| + resolve_done_promise(); |
| + })); |
| + }); |
| + |
| +// Don't become the active worker until the test is done. |
| +self.addEventListener('install', e => { |
| + e.waitUntil(done_promise); |
| + }); |