Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / chromium / windowclient-focus.html
blob0c0e6cfd7b1ad9a940416af52a1574b55de53f5c
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.setPermission('notifications', 'granted', location.origin, location.origin);
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');
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));
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 ' visibilityState: visible',
36 ' focused: true',
37 ' url is the same',
38 ' frameType is the same',
39 'focused clients: 1',
40 'focus() succeeded',
41 'focus() result: [object WindowClient]',
42 ' visibilityState: visible',
43 ' focused: true',
44 ' url is the same',
45 ' frameType is the same',
46 'focused clients: 2',
47 'focus() succeeded',
48 'focus() result: [object WindowClient]',
49 ' visibilityState: visible',
50 ' focused: true',
51 ' url is the same',
52 ' frameType is the same',
53 'focused clients: 2',
54 'focus() succeeded',
55 'focus() result: [object WindowClient]',
56 ' visibilityState: visible',
57 ' focused: true',
58 ' url is the same',
59 ' frameType is the same',
60 'focused clients: 1',
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[29] = 'focused clients: 3';
70 function onMessage(e) {
71 var message = e.data;
73 if (typeof(message) === 'object') {
74 if (message.type !== 'click')
75 return;
76 if (window.testRunner)
77 testRunner.simulateWebNotificationClick(message.title);
78 return;
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);
85 } else {
86 result.push(message);
89 });
90 </script>