| 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 // NIST P-256 public key made available to tests. Must be an uncompressed |
| 11 // point in accordance with SEC1 2.3.3. |
| 12 var applicationServerKey = new Uint8Array([ |
| 13 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36, 0x10, 0xC1, |
| 14 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48, 0xC9, 0xC6, 0xBB, 0xBF, |
| 15 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B, 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52, |
| 16 0x21, 0xD3, 0x71, 0x90, 0x13, 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1, |
| 17 0x7F, 0xF2, 0x76, 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xFD |
| 18 ]); |
| 19 |
| 10 var pushSubscriptionOptions = { | 20 var pushSubscriptionOptions = { |
| 11 userVisibleOnly: true | 21 userVisibleOnly: true |
| 12 }; | 22 }; |
| 13 | 23 |
| 14 // Sends data back to the test. This must be in response to an earlier | 24 // Sends data back to the test. This must be in response to an earlier |
| 15 // request, but it's ok to respond asynchronously. The request blocks until | 25 // request, but it's ok to respond asynchronously. The request blocks until |
| 16 // the response is sent. | 26 // the response is sent. |
| 17 function sendResultToTest(result) { | 27 function sendResultToTest(result) { |
| 18 console.log('sendResultToTest: ' + result); | 28 console.log('sendResultToTest: ' + result); |
| 19 if (window.domAutomationController) { | 29 if (window.domAutomationController) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 function swapManifestNoSenderId() { | 109 function swapManifestNoSenderId() { |
| 100 var element = document.querySelector('link[rel="manifest"]'); | 110 var element = document.querySelector('link[rel="manifest"]'); |
| 101 if (element) { | 111 if (element) { |
| 102 element.href = 'manifest_no_sender_id.json'; | 112 element.href = 'manifest_no_sender_id.json'; |
| 103 sendResultToTest('sender id removed from manifest'); | 113 sendResultToTest('sender id removed from manifest'); |
| 104 } else { | 114 } else { |
| 105 sendResultToTest('unable to find manifest element'); | 115 sendResultToTest('unable to find manifest element'); |
| 106 } | 116 } |
| 107 } | 117 } |
| 108 | 118 |
| 119 // This is the old style of push subscriptions which we are phasing away |
| 120 // from, where the subscription used a sender ID instead of public key. |
| 121 function subscribePushWithoutKey() { |
| 122 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 123 return swRegistration.pushManager.subscribe( |
| 124 pushSubscriptionOptions) |
| 125 .then(function(subscription) { |
| 126 pushSubscription = subscription; |
| 127 sendResultToTest(subscription.endpoint); |
| 128 }); |
| 129 }).catch(sendErrorToTest); |
| 130 } |
| 131 |
| 109 function subscribePush() { | 132 function subscribePush() { |
| 110 navigator.serviceWorker.ready.then(function(swRegistration) { | 133 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 134 pushSubscriptionOptions.applicationServerKey = applicationServerKey.buffer; |
| 111 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) | 135 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) |
| 112 .then(function(subscription) { | 136 .then(function(subscription) { |
| 113 pushSubscription = subscription; | 137 pushSubscription = subscription; |
| 138 sendResultToTest(subscription.endpoint); |
| 139 }); |
| 140 }).catch(sendErrorToTest); |
| 141 } |
| 142 |
| 143 function subscribePushBadKey() { |
| 144 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 145 var invalidApplicationServerKey = Uint8Array.from(applicationServerKey); |
| 146 invalidApplicationServerKey[0] = 0x05; |
| 147 pushSubscriptionOptions.applicationServerKey = |
| 148 invalidApplicationServerKey.buffer; |
| 149 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) |
| 150 .then(function(subscription) { |
| 151 pushSubscription = subscription; |
| 114 sendResultToTest(subscription.endpoint); | 152 sendResultToTest(subscription.endpoint); |
| 115 }); | 153 }); |
| 116 }).catch(sendErrorToTest); | 154 }).catch(sendErrorToTest); |
| 117 } | 155 } |
| 118 | 156 |
| 119 function GetP256dh() { | 157 function GetP256dh() { |
| 120 navigator.serviceWorker.ready.then(function(swRegistration) { | 158 navigator.serviceWorker.ready.then(function(swRegistration) { |
| 121 return swRegistration.pushManager.getSubscription() | 159 return swRegistration.pushManager.getSubscription() |
| 122 .then(function(subscription) { | 160 .then(function(subscription) { |
| 123 sendResultToTest(btoa(String.fromCharCode.apply(null, | 161 sendResultToTest(btoa(String.fromCharCode.apply(null, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 sendResultToTest(subscription ? 'true - subscribed' | 201 sendResultToTest(subscription ? 'true - subscribed' |
| 164 : 'false - not subscribed'); | 202 : 'false - not subscribed'); |
| 165 }).catch(sendErrorToTest); | 203 }).catch(sendErrorToTest); |
| 166 } | 204 } |
| 167 | 205 |
| 168 navigator.serviceWorker.addEventListener('message', function(event) { | 206 navigator.serviceWorker.addEventListener('message', function(event) { |
| 169 var message = JSON.parse(event.data); | 207 var message = JSON.parse(event.data); |
| 170 if (message.type == 'push') | 208 if (message.type == 'push') |
| 171 resultQueue.push(message.data); | 209 resultQueue.push(message.data); |
| 172 }, false); | 210 }, false); |
| OLD | NEW |