2 <title>ServiceWorkerGlobalScope: postMessage
</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 script
= 'resources/postmessage-loopback-worker.js';
10 var scope
= 'resources/scope/postmessage-loopback';
13 return service_worker_unregister_and_register(t
, script
, scope
)
16 return wait_for_state(t
, registration
.installing
, 'activated');
19 var channel
= new MessageChannel();
20 var saw_message
= new Promise(function(resolve
) {
21 channel
.port1
.onmessage = function(event
) {
25 registration
.active
.postMessage({port
: channel
.port2
},
29 .then(function(result
) {
30 assert_equals(result
, 'OK');
31 return service_worker_unregister_and_done(t
, scope
);
33 }, 'Post loopback messages');
35 promise_test(function(t
) {
36 var script1
= 'resources/postmessage-ping-worker.js';
37 var script2
= 'resources/postmessage-pong-worker.js';
38 var scope
= 'resources/scope/postmessage-pingpong';
42 return service_worker_unregister_and_register(t
, script1
, scope
)
45 return wait_for_state(t
, registration
.installing
, 'activated');
48 // A controlled frame is necessary for keeping a waiting worker.
49 return with_iframe(scope
);
53 return navigator
.serviceWorker
.register(script2
, {scope
: scope
});
56 return wait_for_state(t
, r
.installing
, 'installed');
59 var channel
= new MessageChannel();
60 var saw_message
= new Promise(function(resolve
) {
61 channel
.port1
.onmessage = function(event
) {
65 registration
.active
.postMessage({port
: channel
.port2
},
69 .then(function(result
) {
70 assert_equals(result
, 'OK');
72 return service_worker_unregister_and_done(t
, scope
);
74 }, 'Post messages among service workers');