OLD | NEW |
---|---|
(Empty) | |
1 var client = null; | |
2 | |
3 function initialize() { | |
4 return self.clients.getAll().then(function(clients) { | |
5 client = clients[0]; | |
6 }); | |
7 } | |
8 | |
9 function synthesizeNotificationClick() { | |
10 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.
| |
11 var title = "fake notification"; | |
12 | |
13 registration.showNotification(title).then(function() { | |
14 client.postMessage({type: 'click', title: title}); | |
15 }); | |
16 | |
17 var handler = function(e) { | |
18 self.removeEventListener('notificationclick', handler); | |
19 e.notification.close(); | |
20 | |
21 resolver(e); | |
22 }; | |
23 | |
24 self.addEventListener('notificationclick', handler); | |
25 }); | |
26 | |
27 return promise; | |
28 } | |
29 | |
30 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
| |
31 var TESTS = [ | |
32 function testWithNoNotificationClick() { | |
33 client.focus().catch(function() { | |
34 client.postMessage('focus() outside of a notificationclick event fai led'); | |
35 }).then(runNextTestOrQuit); | |
36 }, | |
37 | |
38 function testInStackOutOfWaitUntil() { | |
39 synthesizeNotificationClick().then(function() { | |
40 client.focus().then(function() { | |
41 client.postMessage('focus() in notificationclick outside of wait Until but in stack succeeded'); | |
42 }).then(runNextTestOrQuit); | |
43 }); | |
44 }, | |
45 | |
46 function testOutOfStackOutOfWaitUntil() { | |
47 synthesizeNotificationClick().then(function() { | |
48 self.clients.getAll().then(function() { | |
49 client.focus().catch(function() { | |
50 client.postMessage('focus() in notificationclick outside of waitUntil not in stack failed'); | |
51 }).then(runNextTestOrQuit); | |
52 }); | |
53 }); | |
54 }, | |
55 | |
56 function testInWaitUntilAsync() { | |
57 synthesizeNotificationClick().then(function(e) { | |
58 e.waitUntil(self.clients.getAll().then(function() { | |
59 return client.focus().then(function() { | |
60 client.postMessage('focus() in notificationclick\'s waitUnti l suceeded'); | |
61 }).then(runNextTestOrQuit); | |
62 })); | |
63 }); | |
64 }, | |
65 | |
66 function testDoubleCallInWaitUntilAsync() { | |
67 synthesizeNotificationClick().then(function(e) { | |
68 e.waitUntil(self.clients.getAll().then(function() { | |
69 return client.focus().then(function() { | |
70 return client.focus(); | |
71 }).catch(function() { | |
72 client.postMessage('focus() called twice failed'); | |
73 }).then(runNextTestOrQuit); | |
74 })); | |
75 }); | |
76 }, | |
77 | |
78 function testWaitUntilTimeout() { | |
79 var p = new Promise(function(resolve) { | |
80 setTimeout(function() { | |
81 resolve(); | |
82 }, 2000); | |
83 }); | |
84 | |
85 synthesizeNotificationClick().then(function(e) { | |
86 e.waitUntil(p.then(function() { | |
87 return client.focus().catch(function() { | |
88 client.postMessage('focus() failed after timeout'); | |
89 }).then(runNextTestOrQuit); | |
90 })); | |
91 }); | |
92 }, | |
93 | |
94 function testFocusWindowOpenWindowCombo() { | |
95 synthesizeNotificationClick().then(function(e) { | |
96 e.waitUntil(clients.openWindow('/foo.html').then(function() { | |
97 client.focus().catch(function() { | |
98 client.postMessage('focus() failed because a window was open ed before'); | |
99 }).then(runNextTestOrQuit); | |
100 })); | |
101 }); | |
102 }, | |
103 ]; | |
104 | |
105 function runNextTestOrQuit() { | |
106 ++CURRENT_TEST; | |
107 if (CURRENT_TEST >= TESTS.length) { | |
108 client.postMessage('quit'); | |
109 return; | |
110 } | |
111 TESTS[CURRENT_TEST](); | |
112 } | |
113 | |
114 self.onmessage = function(e) { | |
115 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
| |
116 case "start": | |
117 initialize().then(runNextTestOrQuit); | |
118 break; | |
119 } | |
120 } | |
OLD | NEW |