OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: notificationclick can open new WindowClient</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 if (window.testRunner) |
| 8 testRunner.grantWebNotificationPermission(location.origin, true); |
| 9 if (window.internals) |
| 10 internals.overrideWindowInteractionTimeout(1); |
| 11 |
| 12 var t = async_test('notificationclick can open new WindowClient'); |
| 13 t.step(function() { |
| 14 var scope = 'resources/blank.html' |
| 15 service_worker_unregister_and_register( |
| 16 t, 'resources/notificationclick-can-openwindow.js', scope) |
| 17 .then(function(registration) { |
| 18 return wait_for_state(t, registration.installing, 'activated'); |
| 19 }) |
| 20 .then(function() { return with_iframe(scope); }) |
| 21 .then(function(frame) { |
| 22 var w = frame.contentWindow; |
| 23 w.onmessage = t.step_func(onMessage); |
| 24 w.navigator.serviceWorker.controller.postMessage('start'); |
| 25 }) |
| 26 .catch(unreached_rejection(t)); |
| 27 |
| 28 var result = []; |
| 29 var expected = ['openWindow() outside of a Notification click event failed', |
| 30 'openWindow() in Notification click event succeeded', |
| 31 'openWindow() called twice failed', |
| 32 'openWindow() in notificationclick outside of waitUntil but
in stack succeeded', |
| 33 'openWindow() in notificationclick outside of waitUntil not
in stack failed', |
| 34 'openWindow() in notificationclick\'s waitUntil suceeded', |
| 35 'openWindow() called twice failed', |
| 36 'openWindow() failed after timeout', |
| 37 'openWindow() failed because a window was focused before']; |
| 38 |
| 39 function onMessage(e) { |
| 40 var message = e.data; |
| 41 |
| 42 if (typeof(message) === 'object') { |
| 43 if (message.type !== 'click') |
| 44 return; |
| 45 if (window.testRunner) |
| 46 testRunner.simulateWebNotificationClick(message.title); |
| 47 return; |
| 48 } |
| 49 |
| 50 if (message === 'quit') { |
| 51 assert_array_equals(result, expected, |
| 52 'Worker should post back expected messages.'); |
| 53 service_worker_unregister_and_done(t, scope); |
| 54 } else { |
| 55 result.push(message); |
| 56 } |
| 57 } |
| 58 }); |
| 59 </script> |
OLD | NEW |