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

Unified 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: cleanup up 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/serviceworker/resources/notificationclick-can-openwindow.js
diff --git a/LayoutTests/http/tests/serviceworker/resources/notificationclick-can-openwindow.js b/LayoutTests/http/tests/serviceworker/resources/notificationclick-can-openwindow.js
new file mode 100644
index 0000000000000000000000000000000000000000..e310f27643cddd9bafacd155a7834ab3c2d665db
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/resources/notificationclick-can-openwindow.js
@@ -0,0 +1,146 @@
+var client = null;
+
+function initializeClient() {
+ return self.clients.getAll().then(function(clients) {
+ client = clients[0];
+ });
+}
+
+function afterWindowFocus() {
+ var title = 'afterWindowFocus';
+ registration.showNotification(title).then(function() {
+ client.postMessage({type: 'click', title: title});
+ });
+
+ var handler = function (e) {
+ e.waitUntil(client.focus().then(function() {
+ clients.openWindow().catch(function() {
+ client.postMessage('openWindow() failed because a window was focused before');
+ client.postMessage('quit');
+ });
+ }));
+ self.removeEventListener('notificationclick', handler);
+ };
+
+ self.addEventListener('notificationclick', handler);
+}
+
+function testTimeout() {
+ var title = 'testTimeout';
+ registration.showNotification(title).then(function() {
+ client.postMessage({type: 'click', title: title});
+ });
+
+ var p = new Promise(function(resolve) {
+ setTimeout(function() {
+ resolve();
+ }, 2000);
+ });
+
+ var handler = function (e) {
+ e.waitUntil(p.then(function() {
+ return clients.openWindow('/foo.html').catch(function() {
+ client.postMessage('openWindow() failed after timeout');
+ afterWindowFocus();
+ });
+ }));
+ self.removeEventListener('notificationclick', handler);
+ };
+
+ self.addEventListener('notificationclick', handler);
+}
+
+function testWithSWNotificationClick3() {
+ var title = 'testWithSWNotificationClick3';
+ registration.showNotification(title).then(function() {
+ client.postMessage({type: 'click', title: title});
+ });
+
+ var handler = function (e) {
+ e.waitUntil(self.clients.getAll().then(function() {
+ return clients.openWindow('/foo.html').then(function() {
+ client.postMessage('openWindow() in notificationclick\'s waitUntil suceeded');
+ return clients.openWindow('/foo.html');
+ }).catch(function() {
+ client.postMessage('openWindow() called twice failed');
+ testTimeout();
+ });
+ }));
+ self.removeEventListener('notificationclick', handler);
+ };
+
+ self.addEventListener('notificationclick', handler);
+}
+
+function testWithSWNotificationClick2() {
+ var title = 'testWithSWNotificationClick2';
+ registration.showNotification(title).then(function() {
+ client.postMessage({type: 'click', title: title});
+ });
+
+ var handler = function (e) {
+ self.clients.getAll().then(function() {
+ clients.openWindow('/foo.html').catch(function() {
+ client.postMessage('openWindow() in notificationclick outside of waitUntil not in stack failed');
+ }).then(testWithSWNotificationClick3);
+ });
+ self.removeEventListener('notificationclick', handler);
+ };
+
+ self.addEventListener('notificationclick', handler);
+}
+
+function testWithSWNotificationClick1() {
+ var title = 'testWithSWNotificationClick1';
+ registration.showNotification(title).then(function() {
+ client.postMessage({type: 'click', title: title});
+ });
+
+ var handler = function(e) {
+ clients.openWindow('/foo.html').then(function() {
+ client.postMessage('openWindow() in notificationclick outside of waitUntil but in stack succeeded');
+ }).then(testWithSWNotificationClick2);
+ self.removeEventListener('notificationclick', handler);
+ };
+
+ self.addEventListener('notificationclick', handler);
+}
+
+function testWithNotificationClick() {
+ var notification = new Notification('My Notification');
+ notification.addEventListener('show', function() {
+ client.postMessage({type: 'click', title: 'My Notification'});
+ });
+
+ notification.addEventListener('click', function() {
+ clients.openWindow('/foo.html').then(function() {
+ client.postMessage('openWindow() in Notification click event succeeded');
+ }).then(function() {
+ clients.openWindow('/foo.html').catch(function() {
+ client.postMessage('openWindow() called twice failed');
+ notification.close();
+ testWithSWNotificationClick1();
+ });
+ });
+ });
+
+ notification.addEventListener('error', function() {
+ client.postMessage('failed');
+ client.postMessage('quit');
+ });
+}
+
+function testWithNoClick() {
+ clients.openWindow('/foo.html').catch(function() {
+ client.postMessage('openWindow() outside of a Notification click event failed');
+ testWithNotificationClick();
+ });
+}
+
+self.onmessage = function(e) {
+ switch(e.data) {
+ case "start":
+ initializeClient().then(testWithNoClick);
+ break;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698