Index: LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-focus.js |
diff --git a/LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-focus.js b/LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-focus.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5158ff5965fb60ddc6f8781ff3497a5385e07eb0 |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-focus.js |
@@ -0,0 +1,120 @@ |
+var client = null; |
+ |
+function initialize() { |
+ return self.clients.getAll().then(function(clients) { |
+ client = clients[0]; |
+ }); |
+} |
+ |
+function synthesizeNotificationClick() { |
+ var promise = new Promise(function(resolver) { |
dominicc (has gone to gerrit)
2015/02/13 03:45:11
resolver -> resolve?
mlamouri (slow - plz ping)
2015/02/13 10:18:08
Done.
|
+ var title = "fake notification"; |
+ |
+ registration.showNotification(title).then(function() { |
+ client.postMessage({type: 'click', title: title}); |
+ }); |
+ |
+ var handler = function(e) { |
+ self.removeEventListener('notificationclick', handler); |
+ e.notification.close(); |
+ |
+ resolver(e); |
+ }; |
+ |
+ self.addEventListener('notificationclick', handler); |
+ }); |
+ |
+ return promise; |
+} |
+ |
+var CURRENT_TEST = -1; |
dominicc (has gone to gerrit)
2015/02/13 03:45:11
Why ALL_CAPS for this? It's just a variable!
mlamouri (slow - plz ping)
2015/02/13 10:18:09
This is discrimination! :o
|
+var TESTS = [ |
+ function testWithNoNotificationClick() { |
+ client.focus().catch(function() { |
+ client.postMessage('focus() outside of a notificationclick event failed'); |
+ }).then(runNextTestOrQuit); |
+ }, |
+ |
+ function testInStackOutOfWaitUntil() { |
+ synthesizeNotificationClick().then(function() { |
+ client.focus().then(function() { |
+ client.postMessage('focus() in notificationclick outside of waitUntil but in stack succeeded'); |
+ }).then(runNextTestOrQuit); |
+ }); |
+ }, |
+ |
+ function testOutOfStackOutOfWaitUntil() { |
+ synthesizeNotificationClick().then(function() { |
+ self.clients.getAll().then(function() { |
+ client.focus().catch(function() { |
+ client.postMessage('focus() in notificationclick outside of waitUntil not in stack failed'); |
+ }).then(runNextTestOrQuit); |
+ }); |
+ }); |
+ }, |
+ |
+ function testInWaitUntilAsync() { |
+ synthesizeNotificationClick().then(function(e) { |
+ e.waitUntil(self.clients.getAll().then(function() { |
+ return client.focus().then(function() { |
+ client.postMessage('focus() in notificationclick\'s waitUntil suceeded'); |
+ }).then(runNextTestOrQuit); |
+ })); |
+ }); |
+ }, |
+ |
+ function testDoubleCallInWaitUntilAsync() { |
+ synthesizeNotificationClick().then(function(e) { |
+ e.waitUntil(self.clients.getAll().then(function() { |
+ return client.focus().then(function() { |
+ return client.focus(); |
+ }).catch(function() { |
+ client.postMessage('focus() called twice failed'); |
+ }).then(runNextTestOrQuit); |
+ })); |
+ }); |
+ }, |
+ |
+ function testWaitUntilTimeout() { |
+ var p = new Promise(function(resolve) { |
+ setTimeout(function() { |
+ resolve(); |
+ }, 2000); |
+ }); |
+ |
+ synthesizeNotificationClick().then(function(e) { |
+ e.waitUntil(p.then(function() { |
+ return client.focus().catch(function() { |
+ client.postMessage('focus() failed after timeout'); |
+ }).then(runNextTestOrQuit); |
+ })); |
+ }); |
+ }, |
+ |
+ function testFocusWindowOpenWindowCombo() { |
+ synthesizeNotificationClick().then(function(e) { |
+ e.waitUntil(clients.openWindow('/foo.html').then(function() { |
+ client.focus().catch(function() { |
+ client.postMessage('focus() failed because a window was opened before'); |
+ }).then(runNextTestOrQuit); |
+ })); |
+ }); |
+ }, |
+]; |
+ |
+function runNextTestOrQuit() { |
+ ++CURRENT_TEST; |
+ if (CURRENT_TEST >= TESTS.length) { |
+ client.postMessage('quit'); |
+ return; |
+ } |
+ TESTS[CURRENT_TEST](); |
+} |
+ |
+self.onmessage = function(e) { |
+ switch(e.data) { |
dominicc (has gone to gerrit)
2015/02/13 03:45:11
Maybe "if" is more succinct?
mlamouri (slow - plz ping)
2015/02/13 10:18:08
Done. It's also sending an error message and a "qu
mlamouri (slow - plz ping)
2015/02/13 10:18:09
Done. It's also sending an error message and a "qu
|
+ case "start": |
+ initialize().then(runNextTestOrQuit); |
+ break; |
+ } |
+} |