OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Tests that postMessage works during and after terminating a service worke
r</title> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="../../resources/testharness-helpers.js"></script> |
| 6 <script src="../resources/test-helpers.js"></script> |
| 7 <script> |
| 8 function send_ping(worker) { |
| 9 return new Promise(function(resolve) { |
| 10 var channel = new MessageChannel(); |
| 11 channel.port1.onmessage = function(message) { |
| 12 resolve(message.data); |
| 13 }; |
| 14 worker.postMessage({port: channel.port2}, [channel.port2]); |
| 15 }); |
| 16 } |
| 17 |
| 18 promise_test(function(test) { |
| 19 var worker = 'resources/ping-worker.js'; |
| 20 var scope = 'resources/blank.html'; |
| 21 var sw; |
| 22 return service_worker_unregister_and_register(test, worker, scope) |
| 23 .then(function(registration) { |
| 24 return wait_for_update(test, registration); |
| 25 }) |
| 26 .then(function(worker) { |
| 27 sw = worker; |
| 28 return send_ping(sw); |
| 29 }) |
| 30 .then(function(reply) { |
| 31 assert_equals(reply, 0); |
| 32 return internals.terminateServiceWorker(sw); |
| 33 }) |
| 34 .then(function() { |
| 35 return send_ping(sw); |
| 36 }) |
| 37 .then(function(reply) { |
| 38 assert_equals(reply, 0); |
| 39 return send_ping(sw); |
| 40 }) |
| 41 .then(function(reply) { |
| 42 assert_equals(reply, 1); |
| 43 return service_worker_unregister_and_done(test, scope); |
| 44 }); |
| 45 }, 'postMessage to a terminated service worker.'); |
| 46 </script> |
OLD | NEW |