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) { | |
jsbell
2014/11/18 00:24:14
Since this is validating chrome-specific behavior
Marijn Kruisselbrink
2014/11/18 01:16:13
Yeah, I guess this is kind of on the edge between
Marijn Kruisselbrink
2014/11/20 20:41:12
And I've convinced myself that even though the tes
| |
8 testRunner.setCanOpenWindows(); | |
9 } | |
10 | |
11 async_test(function(t) { | |
12 var scope = 'resources/simple.html'; | |
13 var registration; | |
14 service_worker_unregister_and_register( | |
15 t, 'resources/postmessage-cross-process-worker.js', scope) | |
16 .then(function(r) { | |
17 registration = r; | |
18 return wait_for_activated(t, registration); | |
19 }) | |
20 .then(function() { | |
21 return get_newest_worker(registration); | |
22 }) | |
23 .then(function(worker) { | |
24 var a = document.createElement('a'); | |
jsbell
2014/11/18 00:24:14
Maybe factor this out into a helper function?
Marijn Kruisselbrink
2014/11/18 01:16:13
Done.
| |
25 a.href = 'resources/postmessage-cross-process-helper.html'; | |
26 a.setAttribute('rel', 'noreferrer'); | |
jsbell
2014/11/18 00:24:14
I assume this is the magic that effectively forces
Marijn Kruisselbrink
2014/11/18 01:16:13
Yes.
| |
27 a.target = '_blank'; | |
28 a.click(); | |
29 | |
30 var messageChannel = new MessageChannel(); | |
31 messageChannel.port1.onmessage = t.step_func(onMessage); | |
32 worker.postMessage({resultport: messageChannel.port2}, [messageChannel .port2]); | |
jsbell
2014/11/18 00:24:14
wrap at 80 columns
Marijn Kruisselbrink
2014/11/18 01:16:13
Done.
| |
33 }) | |
34 .catch(unreached_rejection(t)); | |
35 | |
36 var expected = [ | |
37 'Acking value: 1', | |
38 'Acking value: 2', | |
39 ]; | |
40 | |
41 function onMessage(e) { | |
42 var result = e.data; | |
43 assert_array_equals(result, expected, | |
44 'Worker should post back expected values.'); | |
jsbell
2014/11/18 00:24:14
Can you explain more than the assertion already do
Marijn Kruisselbrink
2014/11/18 01:16:13
Done.
| |
45 t.done(); | |
46 } | |
47 }, 'postMessage MessagePorts from client to SW in a different process'); | |
48 </script> | |
OLD | NEW |