Chromium Code Reviews| 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 // The ResultQueue is a mechanism for passing messages back to the test | 7 // The ResultQueue is a mechanism for passing messages back to the test |
| 8 // framework. | 8 // framework. |
| 9 var resultQueue = new ResultQueue(); | 9 var resultQueue = new ResultQueue(); |
| 10 | 10 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 return swRegistration.pushManager.subscribe({ | 112 return swRegistration.pushManager.subscribe({ |
| 113 userVisibleOnly: true, | 113 userVisibleOnly: true, |
| 114 applicationServerKey: kApplicationServerKey.buffer | 114 applicationServerKey: kApplicationServerKey.buffer |
| 115 }) | 115 }) |
| 116 .then(function(subscription) { | 116 .then(function(subscription) { |
| 117 sendResultToTest(subscription.endpoint); | 117 sendResultToTest(subscription.endpoint); |
| 118 }); | 118 }); |
| 119 }).catch(sendErrorToTest); | 119 }).catch(sendErrorToTest); |
| 120 } | 120 } |
| 121 | 121 |
| 122 function documentSubscribePushWithNumber() { | |
|
harkness
2016/11/02 18:48:12
nit NumericKey ?
awdf
2016/11/03 14:10:11
Done.
| |
| 123 navigator.serviceWorker.ready.then(function(swRegistration) { | |
| 124 return swRegistration.pushManager.subscribe({ | |
| 125 userVisibleOnly: true, | |
| 126 applicationServerKey: new TextEncoder().encode('1234567890') | |
| 127 }) | |
| 128 .then(function(subscription) { | |
| 129 sendResultToTest(subscription.endpoint); | |
| 130 }); | |
| 131 }).catch(sendErrorToTest); | |
| 132 } | |
| 133 | |
| 122 function workerSubscribePush() { | 134 function workerSubscribePush() { |
| 123 // Send the message to the worker for it to subscribe | 135 // Send the message to the worker for it to subscribe |
| 124 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'}); | 136 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'}); |
| 125 } | 137 } |
| 126 | 138 |
| 127 function workerSubscribePushNoKey() { | 139 function workerSubscribePushNoKey() { |
| 128 // The worker will try to subscribe without providing a key. This should | 140 // The worker will try to subscribe without providing a key. This should |
| 129 // succeed if the worker was previously subscribed and fail otherwise. | 141 // succeed if the worker was previously subscribed and fail otherwise. |
|
harkness
2016/11/02 18:48:12
Can you update this comment please to include info
awdf
2016/11/03 14:10:11
Done.
| |
| 130 navigator.serviceWorker.controller.postMessage( | 142 navigator.serviceWorker.controller.postMessage( |
| 131 {command: 'workerSubscribeNoKey'}); | 143 {command: 'workerSubscribeNoKey'}); |
| 132 } | 144 } |
| 133 | 145 |
| 146 function workerSubscribePushWithNumber() { | |
| 147 // Send the message to the worker for it to subscribe | |
| 148 navigator.serviceWorker.controller.postMessage( | |
| 149 {command: 'workerSubscribeWithNumber'}); | |
| 150 } | |
| 151 | |
| 134 function GetP256dh() { | 152 function GetP256dh() { |
| 135 navigator.serviceWorker.ready.then(function(swRegistration) { | 153 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 136 return swRegistration.pushManager.getSubscription() | 154 return swRegistration.pushManager.getSubscription() |
| 137 .then(function(subscription) { | 155 .then(function(subscription) { |
| 138 sendResultToTest(btoa(String.fromCharCode.apply(null, | 156 sendResultToTest(btoa(String.fromCharCode.apply(null, |
| 139 new Uint8Array(subscription.getKey('p256dh'))))); | 157 new Uint8Array(subscription.getKey('p256dh'))))); |
| 140 }); | 158 }); |
| 141 }).catch(sendErrorToTest); | 159 }).catch(sendErrorToTest); |
| 142 } | 160 } |
| 143 | 161 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 }).catch(sendErrorToTest); | 223 }).catch(sendErrorToTest); |
| 206 } | 224 } |
| 207 | 225 |
| 208 navigator.serviceWorker.addEventListener('message', function(event) { | 226 navigator.serviceWorker.addEventListener('message', function(event) { |
| 209 var message = JSON.parse(event.data); | 227 var message = JSON.parse(event.data); |
| 210 if (message.type == 'push') | 228 if (message.type == 'push') |
| 211 resultQueue.push(message.data); | 229 resultQueue.push(message.data); |
| 212 else | 230 else |
| 213 sendResultToTest(message.data); | 231 sendResultToTest(message.data); |
| 214 }, false); | 232 }, false); |
| OLD | NEW |