Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/importScripts.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/importScripts.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/importScripts.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a3d071679a8c2f6611463f14ff3b7777e04db402 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/importScripts.html |
| @@ -0,0 +1,50 @@ |
| +<!DOCTYPE html> |
| +<meta charset="utf-8"> |
| +<title>Tests for importScripts</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="resources/test-helpers.js"></script> |
| +<body> |
| +<script> |
| +function post_and_wait_for_reply(worker, message) { |
| + return new Promise(resolve => { |
| + navigator.serviceWorker.onmessage = e => { resolve(e.data); }; |
| + worker.postMessage(message); |
| + }); |
| +} |
| + |
| +// This test registers a worker that imports a script multiple times. The |
| +// script should be stored on the first import and thereafter that stored |
| +// script should be loaded. The worker asserts that the stored script was |
| +// loaded; if the assert fails then registration fails. |
| +promise_test(t => { |
| + const scope = 'resources/duplicate-import'; |
| + return service_worker_unregister(t, scope) |
| + .then(() => { |
| + return navigator.serviceWorker.register('resources/duplicate-import-worker.js', {scope: scope}); |
|
horo
2017/01/10 07:09:27
Wrap at 80 columns
falken
2017/01/10 08:17:46
Done.
|
| + }) |
| + .then(r => { add_completion_callback(() => r.unregister()); }); |
| + }, 'import the same script URL multiple times'); |
| + |
| +// This test registers a worker that calls importScripts at various stages of |
| +// service worker lifetime. The worker asserts that the scripts are imported |
| +// successfully and responds to a message with OK if so. |
| +promise_test(t => { |
| + const scope = 'resources/import-scripts'; |
| + let registration; |
| + return service_worker_unregister_and_register(t, 'resources/import-scripts-worker.js', scope) |
|
horo
2017/01/10 07:09:27
ditto
falken
2017/01/10 08:17:46
Done.
|
| + .then(r => { |
| + registration = r; |
| + add_completion_callback(() => { registration.unregister(); }); |
| + return wait_for_state(t, registration.installing, 'activated'); |
| + }) |
| + .then(() => { |
| + return post_and_wait_for_reply(registration.active, 'ping'); |
| + }) |
| + .then(data => { |
| + assert_equals(data, "OK"); |
| + return registration.unregister(); |
| + }); |
| + }, 'call importScript at various stages of service worker lifetime'); |
| +</script> |
| +</body> |