Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/chromium/postmessage-after-terminate.html |
| diff --git a/LayoutTests/http/tests/serviceworker/chromium/postmessage-after-terminate.html b/LayoutTests/http/tests/serviceworker/chromium/postmessage-after-terminate.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f663e6496daf54265326f49f777ce6fdf4e414c5 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/chromium/postmessage-after-terminate.html |
| @@ -0,0 +1,52 @@ |
| +<!DOCTYPE html> |
| +<title>Tests that postMessage works during and after terminating a service worker</title> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script src="../../resources/testharness-helpers.js"></script> |
| +<script src="../resources/test-helpers.js"></script> |
| +<script> |
| +var properties = {timeout: 2500}; |
| + |
| +function sendPing(worker) { |
| + return new Promise(function(resolve) { |
| + var channel = new MessageChannel(); |
|
dominicc (has gone to gerrit)
2014/11/17 02:25:26
Could you indent this slightly differently, follow
Marijn Kruisselbrink
2014/11/17 23:18:44
Done (at least I think so).
|
| + channel.port1.onmessage = function(message) { |
| + resolve(message.data); |
| + }; |
| + worker.postMessage({port: channel.port2}, [channel.port2]); |
| + }); |
| +} |
| + |
| +function delay(ms) { |
| + return new Promise(function(resolve) { |
| + window.setTimeout(resolve, ms); |
| + }); |
| +} |
| + |
| +promise_test(function(test) { |
| + var worker = 'resources/ping-worker.js'; |
| + var scope = 'resources/blank.html'; |
| + var sw; |
| + return service_worker_unregister_and_register(test, worker, scope) |
| + .then(function(registration) { |
| + return wait_for_update(test, registration); |
| + }).then(function(worker) { |
| + sw = worker; |
| + return sendPing(sw); |
| + }).then(function(reply) { |
| + assert_equals(reply, 1); |
| + return internals.terminateServiceWorker(sw); |
|
dominicc (has gone to gerrit)
2014/11/17 02:25:25
What if the Service Worker terminated itself, perh
Marijn Kruisselbrink
2014/11/17 23:18:44
I suppose I could change the test to have the work
|
| + }).then(function() { |
| + //return delay(500); |
|
Marijn Kruisselbrink
2014/11/04 23:11:54
This test currently only passes when this delay is
dominicc (has gone to gerrit)
2014/11/17 02:25:25
Let's not add a test that is known to be broken. O
Marijn Kruisselbrink
2014/11/17 23:18:44
Well, the test is not broken, it just doesn't curr
|
| + }).then(function() { |
| + return sendPing(sw); |
| + }).then(function(reply) { |
| + assert_equals(reply, 1); |
| + return sendPing(sw); |
|
dominicc (has gone to gerrit)
2014/11/17 02:25:25
Are two subsequent pings necessary?
Marijn Kruisselbrink
2014/11/17 23:18:44
Not really, just a simple sanity check to make sur
|
| + }).then(function(reply) { |
| + assert_equals(reply, 2); |
| + return service_worker_unregister_and_done(test, scope); |
| + }); |
| + }, 'Terminate terminates the worker.', properties); |
|
dominicc (has gone to gerrit)
2014/11/17 02:25:25
Is the test really about that? It's about postMess
Marijn Kruisselbrink
2014/11/17 23:18:44
Well, it's more about both. I started writing this
|
| + |
| +</script> |