Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / chromium / resources / notificationclick-can-openwindow.js
blobcaf3d8a6ad61d84300160b7801a7e8f07e9f99ae
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');
7 var TESTS = [
8     function testWithNoNotificationClick() {
9         clients.openWindow('/foo.html').catch(function() {
10             self.postMessage('openWindow() outside of a notificationclick event failed');
11         }).then(runNextTestOrQuit);
12     },
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);
19         });
20     },
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);
28             });
29         });
30     },
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);
38             }));
39         });
40     },
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');
47                 }).catch(function() {
48                     self.postMessage('openWindow() called twice failed');
49                 }).then(runNextTestOrQuit);
50             }));
51         });
52     },
55     function testWaitUntilTimeout() {
56         var p = new Promise(function(resolve) {
57             setTimeout(function() {
58                 resolve();
59             }, 2000);
60         });
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);
67             }));
68         });
69     },
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);
77             }));
78         });
79     },
82 self.onmessage = function(e) {
83     if (e.data == 'start') {
84         initialize().then(runNextTestOrQuit);
85     } else {
86         initialize().then(function() {
87             self.postMessage('received unexpected message');
88             self.postMessage('quit');
89         });
90     }