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..3c5cf25c672d61f8e3186ad239942d72d9207306 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/importScripts.html |
@@ -0,0 +1,52 @@ |
+<!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}); |
+ }) |
+ .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) |
+ .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> |