OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: postMessage to ServiceWorkerClient</title> | 2 <title>Service Worker: ServiceWorkerClient.focus()</title> |
3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src="resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
6 <script> | 6 <script> |
7 var t = async_test('postMessage from ServiceWorker to ServiceWorkerClient'); | 7 var t = async_test('Test ServiceWorkerClient.focus()'); |
8 t.step(function() { | 8 t.step(function() { |
9 var scope = 'resources/blank.html' | 9 var scope = 'resources/blank.html' |
10 service_worker_unregister_and_register( | 10 service_worker_unregister_and_register( |
11 t, 'resources/postmessage-to-client-worker.js', scope) | 11 t, 'resources/client-focus.js', scope) |
12 .then(function(registration) { | 12 .then(function(registration) { |
13 return wait_for_update(t, registration); | 13 return wait_for_update(t, registration); |
14 }) | 14 }) |
15 .then(function(sw) { | 15 .then(function(sw) { |
16 return wait_for_state(t, sw, 'activated'); | 16 return wait_for_state(t, sw, 'activated'); |
17 }) | 17 }) |
18 .then(function() { return with_iframe(scope); }) | 18 .then(function() { return with_iframe(scope); }) |
19 .then(function(frame) { | 19 .then(function(frame) { |
20 var w = frame.contentWindow; | 20 var w = frame.contentWindow; |
21 w.onmessage = t.step_func(onMessage); | 21 w.onmessage = t.step_func(onMessage); |
22 w.navigator.serviceWorker.controller.postMessage('ping'); | 22 w.navigator.serviceWorker.controller.postMessage('ping'); |
23 }) | 23 }) |
24 .catch(unreached_rejection(t)); | 24 .catch(unreached_rejection(t)); |
25 | 25 |
26 var result = []; | 26 var result = []; |
27 var expected = ['Sending message via clients']; | 27 var expected = ['focus() is present', 'focus() succeeded with true']; |
28 | 28 |
29 function onMessage(e) { | 29 function onMessage(e) { |
30 var message = e.data; | 30 var message = e.data; |
31 if (message === 'quit') { | 31 if (message === 'quit') { |
32 assert_array_equals(result, expected, | 32 assert_array_equals(result, expected, |
33 'Worker should post back expected messages.'); | 33 'Worker should post back expected messages.'); |
34 service_worker_unregister_and_done(t, scope); | 34 service_worker_unregister_and_done(t, scope); |
35 } else { | 35 } else { |
36 result.push(message); | 36 result.push(message); |
37 } | 37 } |
38 } | 38 } |
39 }); | 39 }); |
40 </script> | 40 </script> |
OLD | NEW |