Index: LayoutTests/http/tests/serviceworker/resources/notificationclick-can-focus.js |
diff --git a/LayoutTests/http/tests/serviceworker/resources/notificationclick-can-focus.js b/LayoutTests/http/tests/serviceworker/resources/notificationclick-can-focus.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a7d712a54669d6a0d37447e63eff7999d15855f8 |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/resources/notificationclick-can-focus.js |
@@ -0,0 +1,42 @@ |
+var client = null; |
+ |
+function initializeClient() { |
+ return self.clients.getAll().then(function(clients) { |
+ client = clients[0]; |
+ }); |
+} |
+ |
+function testWithClick() { |
+ var notification = new Notification('My Notification'); |
+ notification.addEventListener('show', function() { |
+ client.postMessage('click'); |
+ }); |
+ |
+ notification.addEventListener('click', function() { |
+ client.focus().catch(function() { |
+ client.postMessage('focus() outside of a notificationclick failed'); |
+ client.postMessage('quit'); |
+ }); |
+ }); |
+ |
+ notification.addEventListener('error', function() { |
+ client.postMessage('quit'); |
+ }); |
+ |
+ client.postMessage('quit'); |
+} |
+ |
+function testWithNoClick() { |
+ client.focus().catch(function() { |
+ client.postMessage('focus() outside of a notificationclick failed'); |
+ testWithClick(); |
+ }); |
+} |
+ |
+self.onmessage = function(e) { |
+ switch(e.data) { |
+ case "start": |
+ initializeClient().then(testWithNoClick); |
+ break; |
+ } |
+} |