| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <title>ServiceWorkerGlobalScope: postMessage</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 | |
| 8 promise_test(function(t) { | |
| 9 var script = 'resources/postmessage-loopback-worker.js'; | |
| 10 var scope = 'resources/scope/postmessage-loopback'; | |
| 11 var registration; | |
| 12 | |
| 13 return service_worker_unregister_and_register(t, script, scope) | |
| 14 .then(function(r) { | |
| 15 registration = r; | |
| 16 return wait_for_state(t, registration.installing, 'activated'); | |
| 17 }) | |
| 18 .then(function() { | |
| 19 var channel = new MessageChannel(); | |
| 20 var saw_message = new Promise(function(resolve) { | |
| 21 channel.port1.onmessage = function(event) { | |
| 22 resolve(event.data); | |
| 23 }; | |
| 24 }); | |
| 25 registration.active.postMessage({port: channel.port2}, | |
| 26 [channel.port2]); | |
| 27 return saw_message; | |
| 28 }) | |
| 29 .then(function(result) { | |
| 30 assert_equals(result, 'OK'); | |
| 31 return service_worker_unregister_and_done(t, scope); | |
| 32 }); | |
| 33 }, 'Post loopback messages'); | |
| 34 | |
| 35 promise_test(function(t) { | |
| 36 var script1 = 'resources/postmessage-ping-worker.js'; | |
| 37 var script2 = 'resources/postmessage-pong-worker.js'; | |
| 38 var scope = 'resources/scope/postmessage-pingpong'; | |
| 39 var registration; | |
| 40 var frame; | |
| 41 | |
| 42 return service_worker_unregister_and_register(t, script1, scope) | |
| 43 .then(function(r) { | |
| 44 registration = r; | |
| 45 return wait_for_state(t, registration.installing, 'activated'); | |
| 46 }) | |
| 47 .then(function() { | |
| 48 // A controlled frame is necessary for keeping a waiting worker. | |
| 49 return with_iframe(scope); | |
| 50 }) | |
| 51 .then(function(f) { | |
| 52 frame = f; | |
| 53 return navigator.serviceWorker.register(script2, {scope: scope}); | |
| 54 }) | |
| 55 .then(function(r) { | |
| 56 return wait_for_state(t, r.installing, 'installed'); | |
| 57 }) | |
| 58 .then(function() { | |
| 59 var channel = new MessageChannel(); | |
| 60 var saw_message = new Promise(function(resolve) { | |
| 61 channel.port1.onmessage = function(event) { | |
| 62 resolve(event.data); | |
| 63 }; | |
| 64 }); | |
| 65 registration.active.postMessage({port: channel.port2}, | |
| 66 [channel.port2]); | |
| 67 return saw_message; | |
| 68 }) | |
| 69 .then(function(result) { | |
| 70 assert_equals(result, 'OK'); | |
| 71 frame.remove(); | |
| 72 return service_worker_unregister_and_done(t, scope); | |
| 73 }); | |
| 74 }, 'Post messages among service workers'); | |
| 75 | |
| 76 </script> | |
| OLD | NEW |