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