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 resultQueue = new ResultQueue(); | 7 var resultQueue = new ResultQueue(); |
8 var pushSubscription = null; | 8 var pushSubscription = null; |
9 | 9 |
10 // Sends data back to the test. This must be in response to an earlier | 10 // Sends data back to the test. This must be in response to an earlier |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } else { | 90 } else { |
91 sendResultToTest('unable to find manifest element'); | 91 sendResultToTest('unable to find manifest element'); |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 function subscribePush() { | 95 function subscribePush() { |
96 navigator.serviceWorker.ready.then(function(swRegistration) { | 96 navigator.serviceWorker.ready.then(function(swRegistration) { |
97 return swRegistration.pushManager.subscribe() | 97 return swRegistration.pushManager.subscribe() |
98 .then(function(subscription) { | 98 .then(function(subscription) { |
99 pushSubscription = subscription; | 99 pushSubscription = subscription; |
100 sendResultToTest( | 100 sendResultToTest(subscription.endpoint); |
101 subscription.endpoint + ' - ' + subscription.subscriptionId); | |
102 }); | 101 }); |
103 }).catch(sendErrorToTest); | 102 }).catch(sendErrorToTest); |
104 } | 103 } |
105 | 104 |
106 function permissionState() { | 105 function permissionState() { |
107 navigator.serviceWorker.ready.then(function(swRegistration) { | 106 navigator.serviceWorker.ready.then(function(swRegistration) { |
108 return swRegistration.pushManager.permissionState() | 107 return swRegistration.pushManager.permissionState() |
109 .then(function(permission) { | 108 .then(function(permission) { |
110 sendResultToTest('permission status - ' + permission); | 109 sendResultToTest('permission status - ' + permission); |
111 }); | 110 }); |
(...skipping 28 matching lines...) Expand all Loading... |
140 sendResultToTest(subscription ? 'true - subscribed' | 139 sendResultToTest(subscription ? 'true - subscribed' |
141 : 'false - not subscribed'); | 140 : 'false - not subscribed'); |
142 }).catch(sendErrorToTest); | 141 }).catch(sendErrorToTest); |
143 } | 142 } |
144 | 143 |
145 addEventListener('message', function(event) { | 144 addEventListener('message', function(event) { |
146 var message = JSON.parse(event.data); | 145 var message = JSON.parse(event.data); |
147 if (message.type == 'push') | 146 if (message.type == 'push') |
148 resultQueue.push(message.data); | 147 resultQueue.push(message.data); |
149 }, false); | 148 }, false); |
OLD | NEW |