| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 var pushData = new FutureData(); | 7 var pushData = new FutureData(); |
| 8 | 8 |
| 9 // Sends data back to the test. This must be in response to an earlier | 9 // Sends data back to the test. This must be in response to an earlier |
| 10 // request, but it's ok to respond asynchronously. The request blocks until | 10 // request, but it's ok to respond asynchronously. The request blocks until |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 sendResultToTest('manifest removed'); | 85 sendResultToTest('manifest removed'); |
| 86 } else { | 86 } else { |
| 87 sendResultToTest('unable to find manifest element'); | 87 sendResultToTest('unable to find manifest element'); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 function registerPush() { | 91 function registerPush() { |
| 92 navigator.serviceWorker.ready.then(function(swRegistration) { | 92 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 93 return swRegistration.pushManager.register() | 93 return swRegistration.pushManager.register() |
| 94 .then(function(pushRegistration) { | 94 .then(function(pushRegistration) { |
| 95 // TODO: Cleanup once the final API is exposed. | 95 sendResultToTest(pushRegistration.endpoint + ' - ' + |
| 96 var endpoint = pushRegistration.endpoint || | 96 pushRegistration.registrationId); |
| 97 pushRegistration.pushEndpoint; | |
| 98 var registrationId = pushRegistration.registrationId || | |
| 99 pushRegistration.pushRegistrationId; | |
| 100 sendResultToTest(endpoint + ' - ' + registrationId); | |
| 101 }); | 97 }); |
| 102 }).catch(sendErrorToTest); | 98 }).catch(sendErrorToTest); |
| 103 } | 99 } |
| 104 | 100 |
| 105 function hasPermission() { | 101 function hasPermission() { |
| 106 navigator.serviceWorker.ready.then(function(swRegistration) { | 102 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 107 return swRegistration.pushManager.hasPermission() | 103 return swRegistration.pushManager.hasPermission() |
| 108 .then(function(permission) { | 104 .then(function(permission) { |
| 109 sendResultToTest('permission status - ' + permission); | 105 sendResultToTest('permission status - ' + permission); |
| 110 }); | 106 }); |
| 111 }).catch(sendErrorToTest); | 107 }).catch(sendErrorToTest); |
| 112 } | 108 } |
| 113 | 109 |
| 114 function isControlled() { | 110 function isControlled() { |
| 115 if (navigator.serviceWorker.controller) { | 111 if (navigator.serviceWorker.controller) { |
| 116 sendResultToTest('true - is controlled'); | 112 sendResultToTest('true - is controlled'); |
| 117 } else { | 113 } else { |
| 118 sendResultToTest('false - is not controlled'); | 114 sendResultToTest('false - is not controlled'); |
| 119 } | 115 } |
| 120 } | 116 } |
| 121 | 117 |
| 122 addEventListener('message', function(event) { | 118 addEventListener('message', function(event) { |
| 123 var message = JSON.parse(event.data); | 119 var message = JSON.parse(event.data); |
| 124 if (message.type == 'push') { | 120 if (message.type == 'push') { |
| 125 pushData.set(message.data); | 121 pushData.set(message.data); |
| 126 } | 122 } |
| 127 }, false); | 123 }, false); |
| OLD | NEW |