| OLD | NEW |
| 1 // Test helper that is meant as a mini test framework to be used from a service | 1 // Test helper that is meant as a mini test framework to be used from a service |
| 2 // worker that runs some tests and send results back to its client. | 2 // worker that runs some tests and send results back to its client. |
| 3 // | 3 // |
| 4 // A simple usage of this framework would consist of calling initialize() to | 4 // A simple usage of this framework would consist of calling initialize() to |
| 5 // setup then runNextTestOrQuit() in order to start running the methods defined | 5 // setup then runNextTestOrQuit() in order to start running the methods defined |
| 6 // by TESTS. Then, tests can start sending messages back to the client using | 6 // by TESTS. Then, tests can start sending messages back to the client using |
| 7 // postMessage(). | 7 // postMessage(). |
| 8 // | 8 // |
| 9 // Example: | 9 // Example: |
| 10 // var TESTS = [ | 10 // var TESTS = [ |
| 11 // function simpleTest() { | 11 // function simpleTest() { |
| 12 // self.postMessage('you will receive this first'); | 12 // self.postMessage('you will receive this first'); |
| 13 // }, | 13 // }, |
| 14 // function secondTest() { | 14 // function secondTest() { |
| 15 // self.postMessage('secondTest done!'); | 15 // self.postMessage('secondTest done!'); |
| 16 // runNextTestOrQuit(); | 16 // runNextTestOrQuit(); |
| 17 // } | 17 // } |
| 18 // ]; | 18 // ]; |
| 19 // | 19 // |
| 20 // initialize().runNextTestOrQuit(); | 20 // initialize().runNextTestOrQuit(); |
| 21 // | 21 // |
| 22 // In addition, there is a helper method meant to synthesized notificationclick | 22 // In addition, there is a helper method meant to synthesized notificationclick |
| 23 // events sent to a service worker, see synthesizeNotificationClick. | 23 // events sent to a service worker, see synthesizeNotificationClick. |
| 24 | 24 |
| 25 var client = null; | 25 var client = null; |
| 26 var currentTest = -1; | 26 var currentTest = -1; |
| 27 | 27 |
| 28 self.initialize = function() { | 28 self.initialize = function() { |
| 29 return self.clients.getAll().then(function(clients) { | 29 return self.clients.matchAll().then(function(clients) { |
| 30 client = clients[0]; | 30 client = clients[0]; |
| 31 }); | 31 }); |
| 32 } | 32 } |
| 33 | 33 |
| 34 self.postMessage = function(msg) { | 34 self.postMessage = function(msg) { |
| 35 client.postMessage(msg); | 35 client.postMessage(msg); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Run the next test in TESTS if any. Otherwise sends a 'quit' message. and | 38 // Run the next test in TESTS if any. Otherwise sends a 'quit' message. and |
| 39 // stops. | 39 // stops. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 63 resolve(e); | 63 resolve(e); |
| 64 e.notification.close(); | 64 e.notification.close(); |
| 65 self.removeEventListener('notificationclick', handler); | 65 self.removeEventListener('notificationclick', handler); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 self.addEventListener('notificationclick', handler); | 68 self.addEventListener('notificationclick', handler); |
| 69 }); | 69 }); |
| 70 | 70 |
| 71 return promise; | 71 return promise; |
| 72 } | 72 } |
| OLD | NEW |