Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/notificationclick-can-openwindow.js

Issue 896043004: Tests for WaitUntilObserver and focus/openining windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sw_client_focus_cleanup
Patch Set: review comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 var client = null;
2
3 function initializeClient() {
4 return self.clients.getAll().then(function(clients) {
5 client = clients[0];
6 });
7 }
8
9 function afterWindowFocus() {
10 var title = 'afterWindowFocus';
11 registration.showNotification(title).then(function() {
12 client.postMessage({type: 'click', title: title});
13 });
14
15 var handler = function (e) {
16 e.waitUntil(client.focus().then(function() {
17 clients.openWindow().catch(function() {
18 client.postMessage('openWindow() failed because a window was foc used before');
19 client.postMessage('quit');
20 });
21 }));
22 self.removeEventListener('notificationclick', handler);
23 };
24
25 self.addEventListener('notificationclick', handler);
26 }
27
28 function testTimeout() {
29 var title = 'testTimeout';
30 registration.showNotification(title).then(function() {
31 client.postMessage({type: 'click', title: title});
32 });
33
34 var p = new Promise(function(resolve) {
35 setTimeout(function() {
36 resolve();
37 }, 2000);
38 });
39
40 var handler = function (e) {
41 e.waitUntil(p.then(function() {
42 return clients.openWindow('/foo.html').catch(function() {
43 client.postMessage('openWindow() failed after timeout');
44 afterWindowFocus();
45 });
46 }));
47 self.removeEventListener('notificationclick', handler);
48 };
49
50 self.addEventListener('notificationclick', handler);
51 }
52
53 function testWithSWNotificationClick3() {
54 var title = 'testWithSWNotificationClick3';
55 registration.showNotification(title).then(function() {
56 client.postMessage({type: 'click', title: title});
57 });
58
59 var handler = function (e) {
60 e.waitUntil(self.clients.getAll().then(function() {
61 return clients.openWindow('/foo.html').then(function() {
62 client.postMessage('openWindow() in notificationclick\'s waitUnt il suceeded');
63 return clients.openWindow('/foo.html');
64 }).catch(function() {
65 client.postMessage('openWindow() called twice failed');
66 testTimeout();
67 });
68 }));
69 self.removeEventListener('notificationclick', handler);
70 };
71
72 self.addEventListener('notificationclick', handler);
73 }
74
75 function testWithSWNotificationClick2() {
76 var title = 'testWithSWNotificationClick2';
77 registration.showNotification(title).then(function() {
78 client.postMessage({type: 'click', title: title});
79 });
80
81 var handler = function (e) {
82 self.clients.getAll().then(function() {
83 clients.openWindow('/foo.html').catch(function() {
84 client.postMessage('openWindow() in notificationclick outside of waitUntil not in stack failed');
85 }).then(testWithSWNotificationClick3);
86 });
87 self.removeEventListener('notificationclick', handler);
88 };
89
90 self.addEventListener('notificationclick', handler);
91 }
92
93 function testWithSWNotificationClick1() {
94 var title = 'testWithSWNotificationClick1';
95 registration.showNotification(title).then(function() {
96 client.postMessage({type: 'click', title: title});
97 });
98
99 var handler = function(e) {
100 clients.openWindow('/foo.html').then(function() {
101 client.postMessage('openWindow() in notificationclick outside of wai tUntil but in stack succeeded');
102 }).then(testWithSWNotificationClick2);
103 self.removeEventListener('notificationclick', handler);
104 };
105
106 self.addEventListener('notificationclick', handler);
107 }
108
109 function testWithNotificationClick() {
110 var notification = new Notification('My Notification');
111 notification.addEventListener('show', function() {
112 client.postMessage({type: 'click', title: 'My Notification'});
113 });
114
115 notification.addEventListener('click', function() {
116 clients.openWindow('/foo.html').then(function() {
117 client.postMessage('openWindow() in Notification click event succeed ed');
118 }).then(function() {
119 clients.openWindow('/foo.html').catch(function() {
120 client.postMessage('openWindow() called twice failed');
121 notification.close();
122 testWithSWNotificationClick1();
123 });
124 });
125 });
126
127 notification.addEventListener('error', function() {
128 client.postMessage('failed');
129 client.postMessage('quit');
130 });
131 }
132
133 function testWithNoClick() {
134 clients.openWindow('/foo.html').catch(function() {
135 client.postMessage('openWindow() outside of a Notification click event f ailed');
136 testWithNotificationClick();
137 });
138 }
139
140 self.onmessage = function(e) {
141 switch(e.data) {
142 case "start":
143 initializeClient().then(testWithNoClick);
144 break;
145 }
146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698