Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <title>Service Worker: Clients.get</title> | |
| 3 <script src="../resources/testharness.js"></script> | |
| 4 <script src="../resources/testharnessreport.js"></script> | |
| 5 <script src="../resources/get-host-info.js"></script> | |
| 6 <script src="resources/test-helpers.js"></script> | |
| 7 <script> | |
| 8 var scope = 'resources/clients-get-frame.html'; | |
| 9 var client_ids = []; | |
| 10 var frame; | |
| 11 promise_test(function(t) { | |
| 12 return service_worker_unregister_and_register( | |
| 13 t, 'resources/clients-get-worker.js', scope) | |
| 14 .then(function(registration) { | |
| 15 add_completion_callback(function() { registration.unregister(); }); | |
| 16 return wait_for_state(t, registration.installing, 'activated'); | |
| 17 }) | |
| 18 .then(function() { | |
| 19 return with_iframe(scope + '#1'); | |
| 20 }) | |
| 21 .then(function(frame1) { | |
| 22 add_completion_callback(function() { frame1.remove(); }); | |
| 23 frame1.focus(); | |
| 24 return wait_for_clientId(); | |
| 25 }) | |
| 26 .then(function(client_id) { | |
| 27 client_ids.push(client_id); | |
| 28 return with_iframe(scope + '#2'); | |
| 29 }) | |
| 30 .then(function(frame2) { | |
| 31 frame = frame2; | |
| 32 add_completion_callback(function() { frame2.remove(); }); | |
| 33 return wait_for_clientId(); | |
| 34 }) | |
| 35 .then(function(client_id) { | |
| 36 client_ids.push(client_id, 'invalid-id'); | |
| 37 var channel = new MessageChannel(); | |
| 38 channel.port1.onmessage = t.step_func(on_message); | |
|
nhiroki
2016/02/19 05:18:31
This test may finish before |on_message| is fired.
jungkees
2016/02/19 16:31:43
That's right. I'm working on this. Actually having
jungkees
2016/02/22 05:23:56
It was not an error in this test case. GetCallback
jungkees
2016/02/22 14:05:09
Promisified the block and fixed the renderer crash
| |
| 39 frame.contentWindow.navigator.serviceWorker.controller.postMessage( | |
| 40 {port: channel.port2, clientIds: client_ids}, [channel.port2]); | |
| 41 }); | |
| 42 }, 'Test Clients.get()'); | |
| 43 | |
| 44 function wait_for_clientId() { | |
| 45 return new Promise(function(resolve, reject) { | |
| 46 function get_client_id(e) { | |
| 47 window.removeEventListener('message', get_client_id); | |
| 48 resolve(e.data.clientId); | |
| 49 } | |
| 50 window.addEventListener('message', get_client_id, false); | |
| 51 }); | |
| 52 } | |
| 53 | |
| 54 var expected = [ | |
| 55 /* visibilityState, focused, url, frameType */ | |
| 56 ['visible', true, normalizeURL(scope) + '#1', 'nested'], | |
| 57 ['visible', false, normalizeURL(scope) + '#2', 'nested'], | |
| 58 undefined | |
| 59 ]; | |
| 60 | |
| 61 function on_message(e) { | |
| 62 assert_equals(e.data.length, 3); | |
| 63 assert_array_equals(e.data[0], expected[0]); | |
| 64 assert_array_equals(e.data[1], expected[1]); | |
| 65 assert_equals(e.data[2], expected[2]); | |
| 66 } | |
| 67 </script> | |
| OLD | NEW |