Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/resources/wait-for-activate-worker.js

Issue 2735443002: Refactor ServiceWorker tests for inclusion in WPT (Closed)
Patch Set: Upstream service worker nav. preload tests to WPT Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // This worker remains in the installing phase so that the
2 // navigation preload API can be tested when there is no
3 // active worker.
4 importScripts('../../../resources/testharness.js');
5 importScripts('helpers.js');
6
7 function expect_rejection(promise) {
8 return promise.then(
9 () => { return Promise.reject('unexpected fulfillment'); },
10 err => { assert_equals('InvalidStateError', err.name); });
11 }
12
13 function test_before_activation() {
14 const np = self.registration.navigationPreload;
15 return expect_rejection(np.enable())
16 .then(() => expect_rejection(np.disable()))
17 .then(() => expect_rejection(np.setHeaderValue('hi')))
18 .then(() => np.getState())
19 .then(state => expect_navigation_preload_state(
20 state, false, 'true', 'state should be the default'))
21 .then(() => 'PASS')
22 .catch(err => 'FAIL: ' + err);
23 }
24
25 var resolve_done_promise;
26 var done_promise = new Promise(resolve => { resolve_done_promise = resolve; });
27
28 // Run the test once the page messages this worker.
29 self.addEventListener('message', e => {
30 e.waitUntil(test_before_activation()
31 .then(result => {
32 e.source.postMessage(result);
33 resolve_done_promise();
34 }));
35 });
36
37 // Don't become the active worker until the test is done.
38 self.addEventListener('install', e => {
39 e.waitUntil(done_promise);
40 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698