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>
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
)
15 return wait_for_state(t
, r
.installing
, 'activated');
18 return new Promise(function(resolve
, reject
) {
19 var w
= new SharedWorker(shared_worker
);
20 w
.port
.onmessage = function(e
) {
25 .then(function(data
) {
26 assert_equals(data
, 'intercepted by service worker');
27 service_worker_unregister_and_done(t
, scope
);
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
)
38 return wait_for_state(t
, r
.installing
, 'activated');
41 return new Promise(function(resolve
, reject
) {
42 var w
= new SharedWorker(shared_worker
);
43 w
.port
.onmessage = function(e
) {
48 .then(function(data
) {
49 assert_equals(data
, 'worker loading intercepted by service worker');
50 service_worker_unregister_and_done(t
, scope
);
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
)
61 return wait_for_state(t
, r
.installing
, 'activated');
64 return new Promise(function(resolve
, reject
) {
65 var w
= new SharedWorker(shared_worker
);
66 w
.port
.onmessage = function(e
) {
71 .then(function(data
) {
72 assert_equals(data
, 'worker loading intercepted by service worker');
73 service_worker_unregister_and_done(t
, scope
);
75 }, 'Verify importScripts from SharedWorker is controlled by a Service Worker');