Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-openwindow.js |
| diff --git a/LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-openwindow.js b/LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-openwindow.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5e65f3cf3f82b674881fdb5d8166b98488861912 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-openwindow.js |
| @@ -0,0 +1,119 @@ |
| +var client = null; |
| + |
| +function initialize() { |
| + return self.clients.getAll().then(function(clients) { |
| + client = clients[0]; |
| + }); |
| +} |
| + |
| +function synthesizeNotificationClick() { |
| + var promise = new Promise(function(resolver) { |
| + var title = "fake notification"; |
| + registration.showNotification(title).then(function() { |
| + client.postMessage({type: 'click', title: title}); |
| + }); |
| + |
| + var handler = function(e) { |
| + resolver(e); |
| + e.notification.close(); |
| + self.removeEventListener('notificationclick', handler); |
| + }; |
| + |
| + self.addEventListener('notificationclick', handler); |
| + }); |
| + |
| + return promise; |
| +} |
| + |
| +var CURRENT_TEST = -1; |
| +var TESTS = [ |
| + function testWithNoNotificationClick() { |
| + clients.openWindow('/foo.html').catch(function() { |
| + client.postMessage('openWindow() outside of a notificationclick event failed'); |
| + }).then(runNextTestOrQuit); |
| + }, |
| + |
| + function testInStackOutOfWaitUntil() { |
| + synthesizeNotificationClick().then(function() { |
| + clients.openWindow('/foo.html').then(function() { |
| + client.postMessage('openWindow() in notificationclick outside of waitUntil but in stack succeeded'); |
| + }).then(runNextTestOrQuit); |
| + }); |
| + }, |
| + |
| + function testOutOfStackOutOfWaitUntil() { |
| + synthesizeNotificationClick().then(function() { |
| + self.clients.getAll().then(function() { |
| + clients.openWindow('/foo.html').catch(function() { |
| + client.postMessage('openWindow() in notificationclick outside of waitUntil not in stack failed'); |
| + }).then(runNextTestOrQuit); |
| + }); |
| + }); |
| + }, |
| + |
| + function testInWaitUntilAsyncAndDoubleCall() { |
| + synthesizeNotificationClick().then(function(e) { |
| + e.waitUntil(self.clients.getAll().then(function() { |
| + return clients.openWindow('/foo.html').then(function() { |
| + client.postMessage('openWindow() in notificationclick\'s waitUntil suceeded'); |
| + }).then(runNextTestOrQuit); |
| + })); |
| + }); |
| + }, |
| + |
| + function testDoubleCallInWaitUntilAsync() { |
| + synthesizeNotificationClick().then(function(e) { |
| + e.waitUntil(self.clients.getAll().then(function() { |
| + return clients.openWindow('/foo.html').then(function() { |
| + return clients.openWindow('/foo.html'); |
| + }).catch(function() { |
| + client.postMessage('openWindow() 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 clients.openWindow('/foo.html').catch(function() { |
| + client.postMessage('openWindow() failed after timeout'); |
| + }).then(runNextTestOrQuit); |
| + })); |
| + }); |
| + }, |
| + |
| + function testFocusWindowOpenWindowCombo() { |
| + synthesizeNotificationClick().then(function(e) { |
| + e.waitUntil(client.focus().then(function() { |
| + clients.openWindow().catch(function() { |
| + client.postMessage('openWindow() failed because a window was focused before'); |
| + }).then(runNextTestOrQuit); |
| + })); |
| + }); |
| + }, |
| +]; |
| + |
| +function runNextTestOrQuit() { |
|
dominicc (has gone to gerrit)
2015/02/13 03:45:11
You could put this, the thing that starts it, and
mlamouri (slow - plz ping)
2015/02/13 10:18:09
I have two other CLs testing .focus() and .openWin
|
| + ++CURRENT_TEST; |
| + if (CURRENT_TEST >= TESTS.length) { |
| + client.postMessage('quit'); |
| + return; |
| + } |
| + TESTS[CURRENT_TEST](); |
| +} |
| + |
| +self.onmessage = function(e) { |
| + switch(e.data) { |
| + case "start": |
| + initialize().then(runNextTestOrQuit); |
| + break; |
| + } |
| +} |