Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/importScripts.html

Issue 2602853002: Eliminate network fallback from ServiceWorkerContextRequestHandler. (Closed)
Patch Set: rm class Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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>

Powered by Google App Engine
This is Rietveld 408576698