OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <meta charset="utf-8"> | |
3 <title>Tests for importScripts</title> | |
4 <script src="../resources/testharness.js"></script> | |
5 <script src="../resources/testharnessreport.js"></script> | |
6 <script src="resources/test-helpers.js"></script> | |
7 <body> | |
8 <script> | |
9 function post_and_wait_for_reply(worker, message) { | |
10 return new Promise(resolve => { | |
11 navigator.serviceWorker.onmessage = e => { resolve(e.data); }; | |
12 worker.postMessage(message); | |
13 }); | |
14 } | |
15 | |
16 // This test registers a worker that imports a script multiple times. The | |
17 // script should be stored on the first import and thereafter that stored | |
18 // script should be loaded. The worker asserts that the stored script was | |
19 // loaded; if the assert fails then registration fails. | |
20 promise_test(t => { | |
21 const scope = 'resources/duplicate-import'; | |
22 return service_worker_unregister(t, scope) | |
23 .then(() => { | |
24 return navigator.serviceWorker.register('resources/duplicate-import-wo rker.js', {scope: scope}); | |
horo
2017/01/10 07:09:27
Wrap at 80 columns
falken
2017/01/10 08:17:46
Done.
| |
25 }) | |
26 .then(r => { add_completion_callback(() => r.unregister()); }); | |
27 }, 'import the same script URL multiple times'); | |
28 | |
29 // This test registers a worker that calls importScripts at various stages of | |
30 // service worker lifetime. The worker asserts that the scripts are imported | |
31 // successfully and responds to a message with OK if so. | |
32 promise_test(t => { | |
33 const scope = 'resources/import-scripts'; | |
34 let registration; | |
35 return service_worker_unregister_and_register(t, 'resources/import-scripts-w orker.js', scope) | |
horo
2017/01/10 07:09:27
ditto
falken
2017/01/10 08:17:46
Done.
| |
36 .then(r => { | |
37 registration = r; | |
38 add_completion_callback(() => { registration.unregister(); }); | |
39 return wait_for_state(t, registration.installing, 'activated'); | |
40 }) | |
41 .then(() => { | |
42 return post_and_wait_for_reply(registration.active, 'ping'); | |
43 }) | |
44 .then(data => { | |
45 assert_equals(data, "OK"); | |
46 return registration.unregister(); | |
47 }); | |
48 }, 'call importScript at various stages of service worker lifetime'); | |
49 </script> | |
50 </body> | |
OLD | NEW |