chromium/third_party/blink/web_tests/http/tests/serviceworker/resources/postmessage-cross-process-helper.html

<!DOCTYPE html>
<script src="../resources/test-helpers.js"></script>
<script>
if (window.testRunner) {
  // waitUntilDone here is necessary to make sure content_shell doesn't exit as
  // soon as this file is loaded.
  testRunner.waitUntilDone();
}

var worker;

navigator.serviceWorker.getRegistration('simple.html')
  .then(function(registration) {
      worker = registration.active;
      var messageChannel = new MessageChannel();
      messageChannel.port1.onmessage = on_message;
      worker.postMessage({port: messageChannel.port2}, [messageChannel.port2]);
      messageChannel.port1.postMessage({value: 1});
      messageChannel.port1.postMessage({value: 2});
      messageChannel.port1.postMessage({done: true});
  });

var result = [];

function on_message(e) {
  var message = e.data;
  if (message === 'quit') {
    worker.postMessage({done: result});
  } else {
    result.push(message);
  }
}
</script>