OLD | NEW |
1 // This helper will setup a small test framework that will use TESTS and run | 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. | 2 // them sequentially and call self.postMessage('quit') when done. |
3 // This helper also exposes |client|, |postMessage()|, |runNextTestOrQuit()|, | 3 // This helper also exposes |client|, |postMessage()|, |runNextTestOrQuit()|, |
4 // |synthesizeNotificationClick()| and |initialize()|. | 4 // |synthesizeNotificationClick()| and |initialize()|. |
5 importScripts('sw-test-helpers.js'); | 5 importScripts('sw-test-helpers.js'); |
6 | 6 |
7 var TESTS = [ | 7 var TESTS = [ |
8 function testWithNoNotificationClick() { | 8 function testWithNoNotificationClick() { |
9 client.focus().catch(function() { | 9 client.focus().catch(function() { |
10 self.postMessage('focus() outside of a notificationclick event faile
d'); | 10 self.postMessage('focus() outside of a notificationclick event faile
d'); |
11 }).then(runNextTestOrQuit); | 11 }).then(runNextTestOrQuit); |
12 }, | 12 }, |
13 | 13 |
14 function testInStackOutOfWaitUntil() { | 14 function testInStackOutOfWaitUntil() { |
15 synthesizeNotificationClick().then(function() { | 15 synthesizeNotificationClick().then(function() { |
16 client.focus().then(function() { | 16 client.focus().then(function() { |
17 self.postMessage('focus() in notificationclick outside of waitUn
til but in stack succeeded'); | 17 self.postMessage('focus() in notificationclick outside of waitUn
til but in stack succeeded'); |
18 }).then(runNextTestOrQuit); | 18 }).then(runNextTestOrQuit); |
19 }); | 19 }); |
20 }, | 20 }, |
21 | 21 |
22 function testOutOfStackOutOfWaitUntil() { | 22 function testOutOfStackOutOfWaitUntil() { |
23 synthesizeNotificationClick().then(function() { | 23 synthesizeNotificationClick().then(function() { |
24 self.clients.getAll().then(function() { | 24 self.clients.matchAll().then(function() { |
25 client.focus().catch(function() { | 25 client.focus().catch(function() { |
26 self.postMessage('focus() in notificationclick outside of wa
itUntil not in stack failed'); | 26 self.postMessage('focus() in notificationclick outside of wa
itUntil not in stack failed'); |
27 }).then(runNextTestOrQuit); | 27 }).then(runNextTestOrQuit); |
28 }); | 28 }); |
29 }); | 29 }); |
30 }, | 30 }, |
31 | 31 |
32 function testInWaitUntilAsync() { | 32 function testInWaitUntilAsync() { |
33 synthesizeNotificationClick().then(function(e) { | 33 synthesizeNotificationClick().then(function(e) { |
34 e.waitUntil(self.clients.getAll().then(function() { | 34 e.waitUntil(self.clients.matchAll().then(function() { |
35 return client.focus().then(function() { | 35 return client.focus().then(function() { |
36 self.postMessage('focus() in notificationclick\'s waitUntil
suceeded'); | 36 self.postMessage('focus() in notificationclick\'s waitUntil
suceeded'); |
37 }).then(runNextTestOrQuit); | 37 }).then(runNextTestOrQuit); |
38 })); | 38 })); |
39 }); | 39 }); |
40 }, | 40 }, |
41 | 41 |
42 function testDoubleCallInWaitUntilAsync() { | 42 function testDoubleCallInWaitUntilAsync() { |
43 synthesizeNotificationClick().then(function(e) { | 43 synthesizeNotificationClick().then(function(e) { |
44 e.waitUntil(self.clients.getAll().then(function() { | 44 e.waitUntil(self.clients.matchAll().then(function() { |
45 return client.focus().then(function() { | 45 return client.focus().then(function() { |
46 return client.focus(); | 46 return client.focus(); |
47 }).catch(function() { | 47 }).catch(function() { |
48 self.postMessage('focus() called twice failed'); | 48 self.postMessage('focus() called twice failed'); |
49 }).then(runNextTestOrQuit); | 49 }).then(runNextTestOrQuit); |
50 })); | 50 })); |
51 }); | 51 }); |
52 }, | 52 }, |
53 | 53 |
54 function testWaitUntilTimeout() { | 54 function testWaitUntilTimeout() { |
(...skipping 26 matching lines...) Expand all Loading... |
81 self.onmessage = function(e) { | 81 self.onmessage = function(e) { |
82 if (e.data == 'start') { | 82 if (e.data == 'start') { |
83 initialize().then(runNextTestOrQuit); | 83 initialize().then(runNextTestOrQuit); |
84 } else { | 84 } else { |
85 initialize().then(function() { | 85 initialize().then(function() { |
86 self.postMessage('received unexpected message'); | 86 self.postMessage('received unexpected message'); |
87 self.postMessage('quit'); | 87 self.postMessage('quit'); |
88 }); | 88 }); |
89 } | 89 } |
90 }; | 90 }; |
OLD | NEW |