Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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(); | |
| 9 } | |
| 10 | |
| 11 function openUrlInNewWindow(url) { | |
|
falken
2014/11/20 02:29:12
In Service Worker test style <http://www.chromium.
Marijn Kruisselbrink
2014/11/20 20:41:12
Done.
Marijn Kruisselbrink
2014/11/20 20:41:12
Done.
| |
| 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(); | |
| 18 } | |
| 19 | |
| 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_activated(t, registration); | |
| 28 }) | |
| 29 .then(function() { | |
| 30 return get_newest_worker(registration); | |
|
falken
2014/11/20 02:29:12
You can just use registration.active directly. No
Marijn Kruisselbrink
2014/11/20 20:41:12
Done.
| |
| 31 }) | |
| 32 .then(function(worker) { | |
| 33 openUrlInNewWindow('resources/postmessage-cross-process-helper.html'); | |
| 34 var messageChannel = new MessageChannel(); | |
| 35 messageChannel.port1.onmessage = t.step_func(onMessage); | |
| 36 worker.postMessage({resultport: messageChannel.port2}, | |
| 37 [messageChannel.port2]); | |
| 38 }) | |
| 39 .catch(unreached_rejection(t)); | |
| 40 | |
| 41 var expected = [ | |
| 42 'Acking value: 1', | |
| 43 'Acking value: 2', | |
| 44 ]; | |
| 45 | |
| 46 function onMessage(e) { | |
| 47 var result = e.data; | |
| 48 assert_array_equals(result, expected, | |
| 49 'Worker should ack values posted by new window in order.'); | |
| 50 t.done(); | |
| 51 } | |
| 52 }, 'postMessage MessagePorts from client to SW in a different process'); | |
| 53 </script> | |
| OLD | NEW |