1 // This helper will setup a small test framework that will use TESTS and run
2 // them sequentially and call self.postMessage('quit') when done.
3 // This helper also exposes |client|, |postMessage()|, |runNextTestOrQuit()|,
4 // |synthesizeNotificationClick()| and |initialize()|.
5 importScripts('sw-test-helpers.js');
8 function testWithNoNotificationClick() {
9 clients.openWindow('/foo.html').catch(function() {
10 self.postMessage('openWindow() outside of a notificationclick event failed');
11 }).then(runNextTestOrQuit);
14 function testInStackOutOfWaitUntil() {
15 synthesizeNotificationClick().then(function() {
16 clients.openWindow('/foo.html').then(function() {
17 self.postMessage('openWindow() in notificationclick outside of waitUntil but in stack succeeded');
18 }).then(runNextTestOrQuit);
22 function testOutOfStackOutOfWaitUntil() {
23 synthesizeNotificationClick().then(function() {
24 self.clients.matchAll().then(function() {
25 clients.openWindow('/foo.html').catch(function() {
26 self.postMessage('openWindow() in notificationclick outside of waitUntil not in stack failed');
27 }).then(runNextTestOrQuit);
32 function testInWaitUntilAsyncAndDoubleCall() {
33 synthesizeNotificationClick().then(function(e) {
34 e.waitUntil(self.clients.matchAll().then(function() {
35 return clients.openWindow('/foo.html').then(function() {
36 self.postMessage('openWindow() in notificationclick\'s waitUntil suceeded');
37 }).then(runNextTestOrQuit);
42 function testDoubleCallInWaitUntilAsync() {
43 synthesizeNotificationClick().then(function(e) {
44 e.waitUntil(self.clients.matchAll().then(function() {
45 return clients.openWindow('/foo.html').then(function() {
46 return clients.openWindow('/foo.html');
48 self.postMessage('openWindow() called twice failed');
49 }).then(runNextTestOrQuit);
55 function testWaitUntilTimeout() {
56 var p = new Promise(function(resolve) {
57 setTimeout(function() {
62 synthesizeNotificationClick().then(function(e) {
63 e.waitUntil(p.then(function() {
64 return clients.openWindow('/foo.html').catch(function() {
65 self.postMessage('openWindow() failed after timeout');
66 }).then(runNextTestOrQuit);
71 function testFocusWindowOpenWindowCombo() {
72 synthesizeNotificationClick().then(function(e) {
73 e.waitUntil(client.focus().then(function() {
74 clients.openWindow().catch(function() {
75 self.postMessage('openWindow() failed because a window was focused before');
76 }).then(runNextTestOrQuit);
82 self.onmessage = function(e) {
83 if (e.data == 'start') {
84 initialize().then(runNextTestOrQuit);
86 initialize().then(function() {
87 self.postMessage('received unexpected message');
88 self.postMessage('quit');