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 var saw_message = new Promise(function(resolve) { |
| 39 channel.port1.onmessage = resolve; |
| 40 }); |
| 41 frame.contentWindow.navigator.serviceWorker.controller.postMessage( |
| 42 {port: channel.port2, clientIds: client_ids}, [channel.port2]); |
| 43 return saw_message; |
| 44 }) |
| 45 .then(function(e) { |
| 46 assert_equals(e.data.length, 3); |
| 47 assert_array_equals(e.data[0], expected[0]); |
| 48 assert_array_equals(e.data[1], expected[1]); |
| 49 assert_equals(e.data[2], expected[2]); |
| 50 }); |
| 51 }, 'Test Clients.get()'); |
| 52 |
| 53 function wait_for_clientId() { |
| 54 return new Promise(function(resolve, reject) { |
| 55 function get_client_id(e) { |
| 56 window.removeEventListener('message', get_client_id); |
| 57 resolve(e.data.clientId); |
| 58 } |
| 59 window.addEventListener('message', get_client_id, false); |
| 60 }); |
| 61 } |
| 62 |
| 63 var expected = [ |
| 64 /* visibilityState, focused, url, frameType */ |
| 65 ['visible', true, normalizeURL(scope) + '#1', 'nested'], |
| 66 ['visible', false, normalizeURL(scope) + '#2', 'nested'], |
| 67 undefined |
| 68 ]; |
| 69 </script> |
OLD | NEW |