OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: postMessage to Client</title> | 2 <title>Service Worker: notificationclick can focus WindowClient</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 Client'); | 7 if (window.testRunner) |
| 8 testRunner.grantWebNotificationPermission(location.origin, true); |
| 9 |
| 10 var t = async_test('notificationclick can focus WindowClient'); |
8 t.step(function() { | 11 t.step(function() { |
9 var scope = 'resources/blank.html' | 12 var scope = 'resources/blank.html' |
10 service_worker_unregister_and_register( | 13 service_worker_unregister_and_register( |
11 t, 'resources/postmessage-to-client-worker.js', scope) | 14 t, 'resources/notificationclick-can-focus.js', scope) |
12 .then(function(registration) { | 15 .then(function(registration) { |
13 return wait_for_state(t, registration.installing, 'activated'); | 16 return wait_for_state(t, registration.installing, 'activated'); |
14 }) | 17 }) |
15 .then(function() { return with_iframe(scope); }) | 18 .then(function() { return with_iframe(scope); }) |
16 .then(function(frame) { | 19 .then(function(frame) { |
17 var w = frame.contentWindow; | 20 var w = frame.contentWindow; |
18 w.onmessage = t.step_func(onMessage); | 21 w.onmessage = t.step_func(onMessage); |
19 w.navigator.serviceWorker.controller.postMessage('ping'); | 22 w.navigator.serviceWorker.controller.postMessage('no-click'); |
20 }) | 23 }) |
21 .catch(unreached_rejection(t)); | 24 .catch(unreached_rejection(t)); |
22 | 25 |
23 var result = []; | 26 var result = []; |
24 var expected = ['Sending message via clients']; | 27 var expected = ['focus() outside of a notificationclick failed', |
| 28 ]; |
25 | 29 |
26 function onMessage(e) { | 30 function onMessage(e) { |
27 var message = e.data; | 31 var message = e.data; |
28 if (message === 'quit') { | 32 if (message === 'quit') { |
29 assert_array_equals(result, expected, | 33 assert_array_equals(result, expected, |
30 'Worker should post back expected messages.'); | 34 'Worker should post back expected messages.'); |
31 service_worker_unregister_and_done(t, scope); | 35 service_worker_unregister_and_done(t, scope); |
| 36 } else if (message === 'click') { |
| 37 if (window.testRunner) |
| 38 testRunner.simulateWebNotificationClick('My Notification'); |
32 } else { | 39 } else { |
33 result.push(message); | 40 result.push(message); |
34 } | 41 } |
35 } | 42 } |
36 }); | 43 }); |
37 </script> | 44 </script> |
OLD | NEW |