Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/chromium/stashed-ports.html |
| diff --git a/LayoutTests/http/tests/serviceworker/chromium/stashed-ports.html b/LayoutTests/http/tests/serviceworker/chromium/stashed-ports.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..47d28569bec8df517024819fe977ffcadb3fd526 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/chromium/stashed-ports.html |
| @@ -0,0 +1,68 @@ |
| +<!DOCTYPE html> |
| +<title> |
| + Tests stashed message ports when the service worker is killed. |
| +</title> |
| +<script src="../../../resources/testharness.js"></script> |
| +<script src="../../../resources/testharnessreport.js"></script> |
| +<script src="../resources/test-helpers.js"></script> |
| +<script> |
| +var worker = 'resources/stashed-port-worker.js'; |
| +var scope = 'resources/'; |
| + |
| +// Helper method that waits for a reply on a port, and resolves a promise with |
| +// the reply. |
| +function wait_for_reply(test, port) { |
| + return new Promise(function(resolve) { |
| + var resolved = false; |
| + port.onmessage = test.step_func(function(event) { |
| + assert_false(resolved); |
| + resolved = true; |
| + resolve(event.data); |
| + }); |
| + }); |
| +} |
| + |
| +function delay(ms) { |
|
scheib
2015/05/06 22:36:18
unused
Marijn Kruisselbrink
2015/05/13 02:46:02
Done.
|
| + return new Promise(function(resolve) { |
| + window.setTimeout(resolve, ms); |
| + }); |
| +} |
| + |
| +test(function(test) { |
| + assert_exists(window, 'internals'); |
| + test.done(); |
| + }, 'internals.terminateServiceWorker is required for the following tests.'); |
| + |
| +promise_test(function(test) { |
| + var sw; |
| + var channel = new MessageChannel(); |
| + var portName = 'foobarname'; |
| + return service_worker_unregister_and_register(test, worker, scope + 'basic') |
| + .then(function(registration) { |
| + sw = registration.installing; |
| + sw.postMessage({name: portName, port: channel.port2}, [channel.port2]); |
| + channel.port1.postMessage('first ping'); |
| + return wait_for_reply(test, channel.port1); |
| + }) |
| + .then(test.step_func(function(reply) { |
| + assert_equals(reply.data, 'first ping'); |
| + assert_equals(reply.name, portName); |
| + channel.port1.postMessage('ping pong'); |
| + return wait_for_reply(test, channel.port1); |
| + })) |
| + .then(test.step_func(function(reply) { |
| + assert_equals(reply.data, 'ping pong'); |
| + assert_equals(reply.name, portName); |
| + return internals.terminateServiceWorker(sw); |
| + })) |
| + .then(function() { |
| + channel.port1.postMessage('second ping'); |
| + return wait_for_reply(test, channel.port1); |
| + }) |
| + .then(test.step_func(function(reply) { |
| + assert_equals(reply.data, 'second ping'); |
| + assert_equals(reply.name, portName); |
| + })); |
| + }, 'Messages can be send when the service worker has been terminated'); |
| + |
| +</script> |