Chromium Code Reviews| Index: chrome/test/data/push_messaging/service_worker.js |
| diff --git a/chrome/test/data/push_messaging/service_worker.js b/chrome/test/data/push_messaging/service_worker.js |
| index a338fdc12b67916945a433b11fde0aa64f25debb..e43019335b6c7127a9c424d91a5fa7f009a3c542 100644 |
| --- a/chrome/test/data/push_messaging/service_worker.js |
| +++ b/chrome/test/data/push_messaging/service_worker.js |
| @@ -2,6 +2,19 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +// NIST P-256 public key made available to tests. Must be an uncompressed |
| +// point in accordance with SEC1 2.3.3 |
| +var applicationServerKey = new Uint8Array([ |
|
Michael van Ouwerkerk
2016/03/22 11:31:37
To avoid duplication of this inscrutable thing you
harkness
2016/03/24 16:56:23
Done.
|
| + 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, 0x10, 0xC1, |
| + 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, 0xC9, 0xC6, 0xBB, 0xBF, |
| + 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52, |
| + 0x21, 0xD3, 0x71, 0x90, 0x13, 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1, |
| + 0x7F, 0xF2, 0x76, 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xFD |
| +]); |
| +var pushSubscriptionOptions = { |
| + userVisibleOnly: true |
| +}; |
| + |
| // The "onpush" event currently understands two values as message payload |
| // data coming from the test. Any other input is passed through to the |
| // document unchanged. |
| @@ -38,6 +51,31 @@ this.onpush = function(event) { |
| })); |
| }; |
| +self.addEventListener('message', function handler (event) { |
| + if (event.data.command == 'workerSubscribe') { |
| + pushSubscriptionOptions.applicationServerKey = applicationServerKey.buffer; |
| + } else if (event.data.command == 'workerSubscribePermissionFail') { |
| + pushSubscriptionOptions.applicationServerKey = applicationServerKey.buffer; |
| + pushSubscriptionOptions.userVisibleOnly = false; |
| + } else if (event.data.command == 'workerSubscribeNoKey') { |
| + // Nothing to set up |
| + } else { |
| + sendMessageToClients('message', 'error - unknown message request'); |
| + return; |
| + } |
| + |
| + self.registration.pushManager.subscribe(pushSubscriptionOptions) |
| + .then(function(subscription) { |
| + sendMessageToClients('message', subscription.endpoint); |
| + }, function(error) { |
| + sendErrorToClients(error); |
| + }); |
| +}); |
| + |
| +function sendErrorToClients(error) { |
| + sendMessageToClients('error', error.name + ' - ' + error.message); |
| +} |
| + |
| function sendMessageToClients(type, data) { |
| var message = JSON.stringify({ |
| 'type': type, |