| 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
|
| index 8fed59fb90b60e51f48a8679f6e70b7b04f417c2..bcc37391b4774d4e8cb5c4cfd26147149a76494e 100644
|
| --- a/LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-openwindow.js
|
| +++ b/LayoutTests/http/tests/serviceworker/chromium/resources/notificationclick-can-openwindow.js
|
| @@ -1,42 +1,20 @@
|
| -var client = null;
|
| +// This helper will setup a small test framework that will use TESTS and run
|
| +// them iteratively and call self.postMessage('quit') when done.
|
| +// This helper also exposes |client|, |postMessage()|, |runNextTestOrQuit()|,
|
| +// |synthesizeNotificationClick()| and |initialize()|.
|
| +importScripts('sw-test-helpers.js');
|
|
|
| -function initialize() {
|
| - return self.clients.getAll().then(function(clients) {
|
| - client = clients[0];
|
| - });
|
| -}
|
| -
|
| -function synthesizeNotificationClick() {
|
| - var promise = new Promise(function(resolve) {
|
| - var title = "fake notification";
|
| - registration.showNotification(title).then(function() {
|
| - client.postMessage({type: 'click', title: title});
|
| - });
|
| -
|
| - var handler = function(e) {
|
| - resolve(e);
|
| - e.notification.close();
|
| - self.removeEventListener('notificationclick', handler);
|
| - };
|
| -
|
| - self.addEventListener('notificationclick', handler);
|
| - });
|
| -
|
| - return promise;
|
| -}
|
| -
|
| -var currentTest = -1;
|
| var TESTS = [
|
| function testWithNoNotificationClick() {
|
| clients.openWindow('/foo.html').catch(function() {
|
| - client.postMessage('openWindow() outside of a notificationclick event failed');
|
| + self.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');
|
| + self.postMessage('openWindow() in notificationclick outside of waitUntil but in stack succeeded');
|
| }).then(runNextTestOrQuit);
|
| });
|
| },
|
| @@ -45,7 +23,7 @@ var TESTS = [
|
| 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');
|
| + self.postMessage('openWindow() in notificationclick outside of waitUntil not in stack failed');
|
| }).then(runNextTestOrQuit);
|
| });
|
| });
|
| @@ -55,7 +33,7 @@ var TESTS = [
|
| 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');
|
| + self.postMessage('openWindow() in notificationclick\'s waitUntil suceeded');
|
| }).then(runNextTestOrQuit);
|
| }));
|
| });
|
| @@ -67,7 +45,7 @@ var TESTS = [
|
| return clients.openWindow('/foo.html').then(function() {
|
| return clients.openWindow('/foo.html');
|
| }).catch(function() {
|
| - client.postMessage('openWindow() called twice failed');
|
| + self.postMessage('openWindow() called twice failed');
|
| }).then(runNextTestOrQuit);
|
| }));
|
| });
|
| @@ -84,7 +62,7 @@ var TESTS = [
|
| synthesizeNotificationClick().then(function(e) {
|
| e.waitUntil(p.then(function() {
|
| return clients.openWindow('/foo.html').catch(function() {
|
| - client.postMessage('openWindow() failed after timeout');
|
| + self.postMessage('openWindow() failed after timeout');
|
| }).then(runNextTestOrQuit);
|
| }));
|
| });
|
| @@ -94,29 +72,20 @@ var TESTS = [
|
| synthesizeNotificationClick().then(function(e) {
|
| e.waitUntil(client.focus().then(function() {
|
| clients.openWindow().catch(function() {
|
| - client.postMessage('openWindow() failed because a window was focused before');
|
| + self.postMessage('openWindow() failed because a window was focused before');
|
| }).then(runNextTestOrQuit);
|
| }));
|
| });
|
| },
|
| ];
|
|
|
| -function runNextTestOrQuit() {
|
| - ++currentTest;
|
| - if (currentTest >= TESTS.length) {
|
| - client.postMessage('quit');
|
| - return;
|
| - }
|
| - TESTS[currentTest]();
|
| -}
|
| -
|
| self.onmessage = function(e) {
|
| if (e.data == "start") {
|
| initialize().then(runNextTestOrQuit);
|
| } else {
|
| initialize().then(function() {
|
| - client.postMessage('received unexpected message');
|
| - client.postMessage('quit');
|
| + self.postMessage('received unexpected message');
|
| + self.postMessage('quit');
|
| });
|
| }
|
| }
|
|
|