Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / chromium / resources / postmessage-cross-process-helper.html
blob89804fd0ce5e9dcf940d127514431c407e30e2c2
1 <!DOCTYPE html>
2 <script src="../../resources/test-helpers.js"></script>
3 <script>
4 if (window.testRunner) {
5 // waitUntilDone here is necessary to make sure content_shell doesn't exit as
6 // soon as this file is loaded.
7 testRunner.waitUntilDone();
10 var worker;
12 navigator.serviceWorker.getRegistration('simple.html')
13 .then(function(registration) {
14 worker = registration.active;
15 var messageChannel = new MessageChannel();
16 messageChannel.port1.onmessage = on_message;
17 worker.postMessage({port: messageChannel.port2}, [messageChannel.port2]);
18 messageChannel.port1.postMessage({value: 1});
19 messageChannel.port1.postMessage({value: 2});
20 messageChannel.port1.postMessage({done: true});
21 });
23 var result = [];
25 function on_message(e) {
26 var message = e.data;
27 if (message === 'quit') {
28 worker.postMessage({done: result});
29 } else {
30 result.push(message);
33 </script>