Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: chrome/test/data/push_messaging/push_test.js

Issue 1770763003: Revert of Partial implementation of subscription restrictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
20 var pushSubscriptionOptions = { 10 var pushSubscriptionOptions = {
21 userVisibleOnly: true 11 userVisibleOnly: true
22 }; 12 };
23 13
24 // Sends data back to the test. This must be in response to an earlier 14 // Sends data back to the test. This must be in response to an earlier
25 // request, but it's ok to respond asynchronously. The request blocks until 15 // request, but it's ok to respond asynchronously. The request blocks until
26 // the response is sent. 16 // the response is sent.
27 function sendResultToTest(result) { 17 function sendResultToTest(result) {
28 console.log('sendResultToTest: ' + result); 18 console.log('sendResultToTest: ' + result);
29 if (window.domAutomationController) { 19 if (window.domAutomationController) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 function swapManifestNoSenderId() { 99 function swapManifestNoSenderId() {
110 var element = document.querySelector('link[rel="manifest"]'); 100 var element = document.querySelector('link[rel="manifest"]');
111 if (element) { 101 if (element) {
112 element.href = 'manifest_no_sender_id.json'; 102 element.href = 'manifest_no_sender_id.json';
113 sendResultToTest('sender id removed from manifest'); 103 sendResultToTest('sender id removed from manifest');
114 } else { 104 } else {
115 sendResultToTest('unable to find manifest element'); 105 sendResultToTest('unable to find manifest element');
116 } 106 }
117 } 107 }
118 108
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
132 function subscribePush() { 109 function subscribePush() {
133 navigator.serviceWorker.ready.then(function(swRegistration) { 110 navigator.serviceWorker.ready.then(function(swRegistration) {
134 pushSubscriptionOptions.applicationServerKey = applicationServerKey.buffer;
135 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) 111 return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
136 .then(function(subscription) { 112 .then(function(subscription) {
137 pushSubscription = subscription; 113 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;
152 sendResultToTest(subscription.endpoint); 114 sendResultToTest(subscription.endpoint);
153 }); 115 });
154 }).catch(sendErrorToTest); 116 }).catch(sendErrorToTest);
155 } 117 }
156 118
157 function GetP256dh() { 119 function GetP256dh() {
158 navigator.serviceWorker.ready.then(function(swRegistration) { 120 navigator.serviceWorker.ready.then(function(swRegistration) {
159 return swRegistration.pushManager.getSubscription() 121 return swRegistration.pushManager.getSubscription()
160 .then(function(subscription) { 122 .then(function(subscription) {
161 sendResultToTest(btoa(String.fromCharCode.apply(null, 123 sendResultToTest(btoa(String.fromCharCode.apply(null,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 sendResultToTest(subscription ? 'true - subscribed' 163 sendResultToTest(subscription ? 'true - subscribed'
202 : 'false - not subscribed'); 164 : 'false - not subscribed');
203 }).catch(sendErrorToTest); 165 }).catch(sendErrorToTest);
204 } 166 }
205 167
206 navigator.serviceWorker.addEventListener('message', function(event) { 168 navigator.serviceWorker.addEventListener('message', function(event) {
207 var message = JSON.parse(event.data); 169 var message = JSON.parse(event.data);
208 if (message.type == 'push') 170 if (message.type == 'push')
209 resultQueue.push(message.data); 171 resultQueue.push(message.data);
210 }, false); 172 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698