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( |
| 25 'resources/duplicate-import-worker.js', {scope: scope}); |
| 26 }) |
| 27 .then(r => { add_completion_callback(() => r.unregister()); }); |
| 28 }, 'import the same script URL multiple times'); |
| 29 |
| 30 // This test registers a worker that calls importScripts at various stages of |
| 31 // service worker lifetime. The worker asserts that the scripts are imported |
| 32 // successfully and responds to a message with OK if so. |
| 33 promise_test(t => { |
| 34 const scope = 'resources/import-scripts'; |
| 35 let registration; |
| 36 return service_worker_unregister_and_register( |
| 37 t, 'resources/import-scripts-worker.js', scope) |
| 38 .then(r => { |
| 39 registration = r; |
| 40 add_completion_callback(() => { registration.unregister(); }); |
| 41 return wait_for_state(t, registration.installing, 'activated'); |
| 42 }) |
| 43 .then(() => { |
| 44 return post_and_wait_for_reply(registration.active, 'ping'); |
| 45 }) |
| 46 .then(data => { |
| 47 assert_equals(data, "OK"); |
| 48 return registration.unregister(); |
| 49 }); |
| 50 }, 'call importScript at various stages of service worker lifetime'); |
| 51 </script> |
| 52 </body> |
OLD | NEW |