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>
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
.setPermission('notifications', 'granted', location
.origin
, location
.origin
);
13 var t
= async_test('WindowClient.focus() behaved as expected');
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');
21 .then(function() { return with_iframe(scope
); })
22 .then(function(frame
) {
23 var w
= frame
.contentWindow
;
24 w
.navigator
.serviceWorker
.onmessage
= t
.step_func(onMessage
);
25 w
.navigator
.serviceWorker
.controller
.postMessage('start');
27 .catch(unreached_rejection(t
));
31 'focus() can\'t focus a window without a user interaction',
32 'focus() error is InvalidAccessError',
34 'focus() result: [object WindowClient]',
35 ' visibilityState: visible',
38 ' frameType is the same',
41 'focus() result: [object WindowClient]',
42 ' visibilityState: visible',
45 ' frameType is the same',
48 'focus() result: [object WindowClient]',
49 ' visibilityState: visible',
52 ' frameType is the same',
55 'focus() result: [object WindowClient]',
56 ' visibilityState: visible',
59 ' frameType is the same',
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;
67 expected
[29] = 'focused clients: 3';
70 function onMessage(e
) {
73 if (typeof(message
) === 'object') {
74 if (message
.type
!== 'click')
76 if (window
.testRunner
)
77 testRunner
.simulateWebNotificationClick(message
.title
);
81 if (message
=== 'quit') {
82 assert_array_equals(result
, expected
,
83 'Worker should post back expected messages.');
84 service_worker_unregister_and_done(t
, scope
);