OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: WindowClient.focus() tests (using testRunner)</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 // This test is using testRunner to grant itself the notification permission and |
| 8 // to simulate a click on a notification. A couple of changes would allow it to |
| 9 // be run as a manual test by other browser vendors. |
| 10 if (window.testRunner) |
| 11 testRunner.grantWebNotificationPermission(location.origin, true); |
| 12 |
| 13 var t = async_test('WindowClient.focus() behaved as expected'); |
| 14 t.step(function() { |
| 15 var scope = 'resources/windowclient-focus.html' |
| 16 service_worker_unregister_and_register( |
| 17 t, 'resources/windowclient-focus.js', scope) |
| 18 .then(function(registration) { |
| 19 return wait_for_state(t, registration.installing, 'activated'); |
| 20 }) |
| 21 .then(function() { return with_iframe(scope); }) |
| 22 .then(function(frame) { |
| 23 var w = frame.contentWindow; |
| 24 w.onmessage = t.step_func(onMessage); |
| 25 w.navigator.serviceWorker.controller.postMessage('start'); |
| 26 }) |
| 27 .catch(unreached_rejection(t)); |
| 28 |
| 29 var result = []; |
| 30 var expected = [ |
| 31 'focus() can\'t focus a window without a user interaction', |
| 32 'focus() error is InvalidAccessError', |
| 33 'focus() succeeded', |
| 34 'focus() result: [object WindowClient]', |
| 35 ' url: ' + location.origin + '/serviceworker/chromium/resources/windowcl
ient-focus.html', |
| 36 ' visibilityState: visible', |
| 37 ' focused: true', |
| 38 ' frameType: nested', |
| 39 'focused clients: 1', |
| 40 'focus() succeeded', |
| 41 'focus() result: [object WindowClient]', |
| 42 ' url: ' + location.origin + '/serviceworker/chromium/resources/windowcl
ient-focus.html?1', |
| 43 ' visibilityState: visible', |
| 44 ' focused: true', |
| 45 ' frameType: nested', |
| 46 'focused clients: 2', |
| 47 'focus() succeeded', |
| 48 'focus() result: [object WindowClient]', |
| 49 ' url: ' + location.origin + '/serviceworker/chromium/resources/windowcl
ient-focus.html?2', |
| 50 ' visibilityState: visible', |
| 51 ' focused: true', |
| 52 ' frameType: nested', |
| 53 'focused clients: 2', |
| 54 'focus() succeeded', |
| 55 'focus() result: [object WindowClient]', |
| 56 ' url: ' + location.origin + '/serviceworker/chromium/resources/windowcl
ient-focus.html?3', |
| 57 ' visibilityState: visible', |
| 58 ' focused: true', |
| 59 ' frameType: top-level', |
| 60 'focused clients: 1', |
| 61 ]; |
| 62 |
| 63 // On Mac, focusing and LayoutTests are no friend. This is amending the |
| 64 // above |expected| array to match Mac's expectations. |
| 65 var isMac = navigator.platform.indexOf('Mac') == 0; |
| 66 if (isMac) { |
| 67 expected[27] = ' focused: false'; |
| 68 expected[29] = 'focused clients: 3'; |
| 69 } |
| 70 |
| 71 function onMessage(e) { |
| 72 var message = e.data; |
| 73 |
| 74 if (typeof(message) === 'object') { |
| 75 if (message.type !== 'click') |
| 76 return; |
| 77 if (window.testRunner) |
| 78 testRunner.simulateWebNotificationClick(message.title); |
| 79 return; |
| 80 } |
| 81 |
| 82 if (message === 'quit') { |
| 83 assert_array_equals(result, expected, |
| 84 'Worker should post back expected messages.'); |
| 85 service_worker_unregister_and_done(t, scope); |
| 86 } else { |
| 87 result.push(message); |
| 88 } |
| 89 } |
| 90 }); |
| 91 </script> |
OLD | NEW |