Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / chromium / clients-openwindow.html
blob9b54a261f4af046d02497cfb5c5a7feada41c600
1 <!DOCTYPE html>
2 <title>Service Worker: clients.openWindow() 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('clients.openWindow() behaved as expected');
14 t.step(function() {
15 var scope = 'resources/blank.html'
16 service_worker_unregister_and_register(
17 t, 'resources/clients-openwindow.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 = ['openWindow() can\'t open a window without a user interaction',
31 'openWindow() error is InvalidAccessError',
32 'openWindow() can open cross origin windows',
33 'openWindow() result: null',
34 'openWindow() can open not controlled windows',
35 'openWindow() result: [object WindowClient]',
36 'openWindow() can open controlled windows',
37 'openWindow() result: [object WindowClient]',
38 ' url: ' + location.origin + '/serviceworker/chromium/resources/blank.html',
39 ' visibilityState: visible',
40 ' focused: true',
41 ' frameType: top-level',
42 'openWindow() can open about:blank',
43 'openWindow() result: null',
44 'openWindow() can open about:crash',
45 'openWindow() result: null',
46 'openWindow() can not open an invalid url',
47 'openWindow() error is: TypeError',
48 'openWindow() can not open view-source scheme',
49 'openWindow() can not open file scheme',
50 'openWindow() error is: SecurityError',
53 // LayoutTests on Mac do not open focused windows.
54 var isMac = navigator.platform.indexOf('Mac') == 0;
55 if (isMac)
56 expected[10] = ' focused: false';
58 function onMessage(e) {
59 var message = e.data;
61 if (typeof(message) === 'object') {
62 if (message.type !== 'click')
63 return;
64 if (window.testRunner)
65 testRunner.simulateWebNotificationClick(message.title);
66 return;
69 if (message === 'quit') {
70 assert_array_equals(result, expected,
71 'Worker should post back expected messages.');
72 service_worker_unregister_and_done(t, scope);
73 } else {
74 result.push(message);
77 });
78 </script>