OLD | NEW |
| (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 }); | |
OLD | NEW |