| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 sendResultToTest('service worker unregistration status: ' + result); | 76 sendResultToTest('service worker unregistration status: ' + result); |
| 77 }) | 77 }) |
| 78 }).catch(sendErrorToTest); | 78 }).catch(sendErrorToTest); |
| 79 } | 79 } |
| 80 | 80 |
| 81 function removeManifest() { | 81 function removeManifest() { |
| 82 var element = document.querySelector('link[rel="manifest"]'); | 82 var element = document.querySelector('link[rel="manifest"]'); |
| 83 if (element) { | 83 if (element) { |
| 84 element.parentNode.removeChild(element); | 84 element.parentNode.removeChild(element); |
| 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 function registerPush() { | 91 function registerPush() { |
| 91 navigator.serviceWorker.ready.then(function(swRegistration) { | 92 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 92 // TODO(mvanouwerkerk): Cleanup once the final API is exposed. | 93 return swRegistration.pushManager.register() |
| 93 var pushManager = swRegistration.pushManager || navigator.push; | 94 .then(function(pushRegistration) { |
| 94 return pushManager.register().then(function(pushRegistration) { | 95 // TODO: Cleanup once the final API is exposed. |
| 95 sendResultToTest(pushRegistration.pushEndpoint + ' - ' + | 96 var endpoint = pushRegistration.endpoint || |
| 96 pushRegistration.pushRegistrationId); | 97 pushRegistration.pushEndpoint; |
| 97 }); | 98 var registrationId = pushRegistration.registrationId || |
| 99 pushRegistration.pushRegistrationId; |
| 100 sendResultToTest(endpoint + ' - ' + registrationId); |
| 101 }); |
| 98 }).catch(sendErrorToTest); | 102 }).catch(sendErrorToTest); |
| 99 } | 103 } |
| 100 | 104 |
| 101 function hasPermission() { | 105 function hasPermission() { |
| 102 navigator.serviceWorker.ready.then(function(swRegistration) { | 106 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 103 // TODO(mvanouwerkerk): Cleanup once the final API is exposed. | 107 return swRegistration.pushManager.hasPermission() |
| 104 var pushManager = swRegistration.pushManager || navigator.push; | 108 .then(function(permission) { |
| 105 return pushManager.hasPermission().then(function(permission) { | 109 sendResultToTest('permission status - ' + permission); |
| 106 sendResultToTest('permission status - ' + permission); | 110 }); |
| 107 }); | |
| 108 }).catch(sendErrorToTest); | 111 }).catch(sendErrorToTest); |
| 109 } | 112 } |
| 110 | 113 |
| 111 function isControlled() { | 114 function isControlled() { |
| 112 if (navigator.serviceWorker.controller) { | 115 if (navigator.serviceWorker.controller) { |
| 113 sendResultToTest('true - is controlled'); | 116 sendResultToTest('true - is controlled'); |
| 114 } else { | 117 } else { |
| 115 sendResultToTest('false - is not controlled'); | 118 sendResultToTest('false - is not controlled'); |
| 116 } | 119 } |
| 117 } | 120 } |
| 118 | 121 |
| 119 addEventListener('message', function(event) { | 122 addEventListener('message', function(event) { |
| 120 var message = JSON.parse(event.data); | 123 var message = JSON.parse(event.data); |
| 121 if (message.type == 'push') { | 124 if (message.type == 'push') { |
| 122 pushData.set(message.data); | 125 pushData.set(message.data); |
| 123 } | 126 } |
| 124 }, false); | 127 }, false); |
| OLD | NEW |