Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / shared-worker-controlled.html
blobd7daa03252dde7f27ef63b7e36f162913dfad1dc
1 <!DOCTYPE html>
2 <title>Service Worker: controlling a SharedWorker</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/test-helpers.js"></script>
6 <body>
7 <script>
8 promise_test(function(t) {
9 var shared_worker = 'resources/shared-worker-controlled.js';
10 var service_worker = 'resources/simple-intercept-worker.js';
11 var scope = shared_worker;
13 return service_worker_unregister_and_register(t, service_worker, scope)
14 .then(function(r) {
15 return wait_for_state(t, r.installing, 'activated');
17 .then(function() {
18 return new Promise(function(resolve, reject) {
19 var w = new SharedWorker(shared_worker);
20 w.port.onmessage = function(e) {
21 resolve(e.data);
23 });
25 .then(function(data) {
26 assert_equals(data, 'intercepted by service worker');
27 service_worker_unregister_and_done(t, scope);
28 });
29 }, 'Verify subresource loads in SharedWorker are controlled by a Service Worker');
31 promise_test(function(t) {
32 var shared_worker = 'resources/dummy-shared-worker.js';
33 var service_worker = 'resources/dummy-shared-worker-interceptor.js';
34 var scope = shared_worker;
36 return service_worker_unregister_and_register(t, service_worker, scope)
37 .then(function(r) {
38 return wait_for_state(t, r.installing, 'activated');
40 .then(function() {
41 return new Promise(function(resolve, reject) {
42 var w = new SharedWorker(shared_worker);
43 w.port.onmessage = function(e) {
44 resolve(e.data);
46 });
48 .then(function(data) {
49 assert_equals(data, 'worker loading intercepted by service worker');
50 service_worker_unregister_and_done(t, scope);
51 });
52 }, 'Verify SharedWorker construction is controlled by a Service Worker');
54 promise_test(function(t) {
55 var shared_worker = 'resources/shared-worker-import.js';
56 var service_worker = 'resources/dummy-shared-worker-interceptor.js';
57 var scope = shared_worker;
59 return service_worker_unregister_and_register(t, service_worker, scope)
60 .then(function(r) {
61 return wait_for_state(t, r.installing, 'activated');
63 .then(function() {
64 return new Promise(function(resolve, reject) {
65 var w = new SharedWorker(shared_worker);
66 w.port.onmessage = function(e) {
67 resolve(e.data);
69 });
71 .then(function(data) {
72 assert_equals(data, 'worker loading intercepted by service worker');
73 service_worker_unregister_and_done(t, scope);
74 });
75 }, 'Verify importScripts from SharedWorker is controlled by a Service Worker');
76 </script>
77 </body>