| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title> | 2 <title> |
| 3 Tests stashed message ports when the service worker is killed. | 3 Tests stashed message ports when the service worker is killed. |
| 4 </title> | 4 </title> |
| 5 <script src="../../../resources/testharness.js"></script> | 5 <script src="../../../resources/testharness.js"></script> |
| 6 <script src="../../../resources/testharnessreport.js"></script> | 6 <script src="../../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/test-helpers.js"></script> | 7 <script src="../resources/test-helpers.js"></script> |
| 8 <script> | 8 <script> |
| 9 var worker = 'resources/stashed-ports-echo-worker.js'; | 9 var worker = 'resources/stashed-ports-echo-worker.js'; |
| 10 var scope = 'resources/'; | 10 var scope = 'resources/'; |
| 11 | 11 |
| 12 // Helper method that waits for a reply on a port, and resolves a promise with | 12 // Helper method that waits for a reply on a port, and resolves a promise with |
| 13 // the reply. | 13 // the reply. |
| 14 function wait_for_reply(test, port) { | 14 function wait_for_reply(test, port) { |
| 15 return new Promise(function(resolve) { | 15 return new Promise(function(resolve) { |
| 16 var resolved = false; | 16 var resolved = false; |
| 17 port.onmessage = test.step_func(function(event) { | 17 port.onmessage = test.step_func(function(event) { |
| 18 assert_false(resolved); | 18 assert_false(resolved); |
| 19 resolved = true; | 19 resolved = true; |
| 20 resolve(event.data); | 20 resolve(event.data); |
| 21 }); | 21 }); |
| 22 }); | 22 }); |
| 23 } | 23 } |
| 24 | 24 |
| 25 test(function(test) { | 25 test(function(test) { |
| 26 assert_exists(window, 'internals'); | 26 assert_true(window.internals instanceof Object); |
| 27 test.done(); | 27 test.done(); |
| 28 }, 'internals.terminateServiceWorker is required for the following tests.'); | 28 }, 'internals.terminateServiceWorker is required for the following tests.'); |
| 29 | 29 |
| 30 promise_test(function(test) { | 30 promise_test(function(test) { |
| 31 var sw; | 31 var sw; |
| 32 var channel = new MessageChannel(); | 32 var channel = new MessageChannel(); |
| 33 var portName = 'foobarname'; | 33 var portName = 'foobarname'; |
| 34 return service_worker_unregister_and_register(test, worker, scope + 'basic') | 34 return service_worker_unregister_and_register(test, worker, scope + 'basic') |
| 35 .then(function(registration) { | 35 .then(function(registration) { |
| 36 sw = registration.installing; | 36 sw = registration.installing; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 53 channel.port1.postMessage('second ping'); | 53 channel.port1.postMessage('second ping'); |
| 54 return wait_for_reply(test, channel.port1); | 54 return wait_for_reply(test, channel.port1); |
| 55 }) | 55 }) |
| 56 .then(test.step_func(function(reply) { | 56 .then(test.step_func(function(reply) { |
| 57 assert_equals(reply.data, 'second ping'); | 57 assert_equals(reply.data, 'second ping'); |
| 58 assert_equals(reply.name, portName); | 58 assert_equals(reply.name, portName); |
| 59 })); | 59 })); |
| 60 }, 'Messages can be send when the service worker has been terminated'); | 60 }, 'Messages can be send when the service worker has been terminated'); |
| 61 | 61 |
| 62 </script> | 62 </script> |
| OLD | NEW |