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

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

Issue 2411733002: Check the format of an applicationServerKey when used to register a push subscription. (Closed)
Patch Set: Removed unneeded file Created 4 years, 2 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 // 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 function documentSubscribePush() { 105 function documentSubscribePush() {
106 navigator.serviceWorker.ready.then(function(swRegistration) { 106 navigator.serviceWorker.ready.then(function(swRegistration) {
107 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; 107 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer;
108 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) 108 return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
109 .then(function(subscription) { 109 .then(function(subscription) {
110 sendResultToTest(subscription.endpoint); 110 sendResultToTest(subscription.endpoint);
111 }); 111 });
112 }).catch(sendErrorToTest); 112 }).catch(sendErrorToTest);
113 } 113 }
114 114
115 function documentSubscribePushBadKey() { 115 function documentSubscribePushLongKey() {
116 navigator.serviceWorker.ready.then(function(swRegistration) { 116 navigator.serviceWorker.ready.then(function(swRegistration) {
117 var invalidApplicationServerKey = new Uint8Array(300); 117 var invalidApplicationServerKey = new Uint8Array(300);
118 invalidApplicationServerKey.fill('0x05', 1, 300); 118 invalidApplicationServerKey.fill('0x05', 1, 300);
119 pushSubscriptionOptions.applicationServerKey = 119 pushSubscriptionOptions.applicationServerKey =
120 invalidApplicationServerKey.buffer; 120 invalidApplicationServerKey.buffer;
121 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) 121 return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
122 .then(function(subscription) { 122 .then(function(subscription) {
123 sendResultToTest(subscription.endpoint); 123 sendResultToTest(subscription.endpoint);
124 }); 124 });
125 }).catch(sendErrorToTest); 125 }).catch(sendErrorToTest);
126 } 126 }
127 127
128 function documentSubscribePushShortKey() {
129 navigator.serviceWorker.ready.then(function(swRegistration) {
130 pushSubscriptionOptions.applicationServerKey = new Uint8Array().buffer;
131 return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
132 .then(function(subscription) {
133 sendResultToTest(subscription.endpoint);
134 });
135 }).catch(sendErrorToTest);
136 }
137 function documentSubscribePushNonNumericKey() {
138 navigator.serviceWorker.ready.then(function(swRegistration) {
139 const invalidApplicationServerKey = Uint8Array.from("01234a56789");
140 pushSubscriptionOptions.applicationServerKey =
141 invalidApplicationServerKey.buffer;
142 return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
143 .then(function(subscription) {
144 sendResultToTest(subscription.endpoint);
145 });
146 }).catch(sendErrorToTest);
147 }
148
149 function documentSubscribePushValidSenderId() {
150 navigator.serviceWorker.ready.then(function(swRegistration) {
151 let validApplicationServerKey = "123456789";
152 pushSubscriptionOptions.applicationServerKey =
153 validApplicationServerKey.buffer;
154 return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
155 .then(function(subscription) {
156 sendResultToTest(subscription.endpoint);
157 });
158 }).catch(sendErrorToTest);
159 }
160
128 function workerSubscribePush() { 161 function workerSubscribePush() {
129 // Send the message to the worker for it to subscribe 162 // Send the message to the worker for it to subscribe
130 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'}); 163 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'});
131 } 164 }
132 165
133 function workerSubscribePushNoKey() { 166 function workerSubscribePushNoKey() {
134 // The worker will try to subscribe without providing a key. This should 167 // The worker will try to subscribe without providing a key. This should
135 // succeed if the worker was previously subscribed and fail otherwise. 168 // succeed if the worker was previously subscribed and fail otherwise.
136 navigator.serviceWorker.controller.postMessage( 169 navigator.serviceWorker.controller.postMessage(
137 {command: 'workerSubscribeNoKey'}); 170 {command: 'workerSubscribeNoKey'});
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 }).catch(sendErrorToTest); 244 }).catch(sendErrorToTest);
212 } 245 }
213 246
214 navigator.serviceWorker.addEventListener('message', function(event) { 247 navigator.serviceWorker.addEventListener('message', function(event) {
215 var message = JSON.parse(event.data); 248 var message = JSON.parse(event.data);
216 if (message.type == 'push') 249 if (message.type == 'push')
217 resultQueue.push(message.data); 250 resultQueue.push(message.data);
218 else 251 else
219 sendResultToTest(message.data); 252 sendResultToTest(message.data);
220 }, false); 253 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698