Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html |
| diff --git a/LayoutTests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html b/LayoutTests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b4cff8054d59fee417ffb4c8d17092b4d9e145a7 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html |
| @@ -0,0 +1,36 @@ |
| +<!DOCTYPE html> |
| +<script src="test-helpers.js"></script> |
| +<script> |
| +if (window.testRunner) { |
| + // waitUntilDone here is necesary to make sure content_shell doesn't exist as |
|
jsbell
2014/11/18 00:24:14
typo: "exist" -> "exit"
|
| + // soon as this file is loaded. |
| + testRunner.waitUntilDone(); |
| +} |
| + |
| +var worker; |
| + |
| +navigator.serviceWorker.getRegistration('simple.html') |
| + .then(function(registration) { |
| + return get_newest_worker(registration); |
| + }) |
| + .then(function(sw) { |
| + worker = sw; |
| + var messageChannel = new MessageChannel(); |
| + messageChannel.port1.onmessage = onMessage; |
| + sw.postMessage({port: messageChannel.port2}, [messageChannel.port2]); |
| + messageChannel.port1.postMessage({value: 1}); |
| + messageChannel.port1.postMessage({value: 2}); |
| + messageChannel.port1.postMessage({done: true}); |
| + }); |
| + |
| +var result = []; |
| + |
| +function onMessage(e) { |
| + var message = e.data; |
| + if (message === 'quit') { |
| + worker.postMessage({done: result}); |
| + } else { |
| + result.push(message); |
| + } |
| +}; |
| +</script> |