Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / chromium / postmessage-cross-process.html
blob64ccfe2f087e48b510beceba6dfb81b8270f1ddc
1 <!DOCTYPE html>
2 <title>Service Worker: postMessage across processes</title>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script src="../resources/test-helpers.js"></script>
6 <script>
7 if (window.testRunner) {
8 testRunner.setCanOpenWindows();
11 function open_url_in_new_window(url) {
12 var a = document.createElement('a');
13 a.href = url;
14 // rel=noreferrer causes chrome to open the link in a new renderer process.
15 a.setAttribute('rel', 'noreferrer');
16 a.target = '_blank';
17 a.click();
20 async_test(function(t) {
21 var scope = 'resources/simple.html';
22 var registration;
23 service_worker_unregister_and_register(
24 t, 'resources/postmessage-cross-process-worker.js', scope)
25 .then(function(r) {
26 registration = r;
27 return wait_for_state(t, r.installing, 'activated');
29 .then(function() {
30 var worker = registration.active;
31 open_url_in_new_window(
32 'resources/postmessage-cross-process-helper.html');
33 var messageChannel = new MessageChannel();
34 messageChannel.port1.onmessage = t.step_func(onMessage);
35 worker.postMessage({resultport: messageChannel.port2},
36 [messageChannel.port2]);
38 .catch(unreached_rejection(t));
40 var expected = [
41 'Acking value: 1',
42 'Acking value: 2',
45 function onMessage(e) {
46 var result = e.data;
47 assert_array_equals(result, expected,
48 'Worker should ack values posted by new window in order.');
49 t.done();
51 }, 'postMessage MessagePorts from client to SW in a different process');
52 </script>