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

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: More formatting 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() {
116 navigator.serviceWorker.ready.then(function(swRegistration) {
117 var invalidApplicationServerKey = new Uint8Array(300);
118 invalidApplicationServerKey.fill('0x05', 1, 300);
119 pushSubscriptionOptions.applicationServerKey =
120 invalidApplicationServerKey.buffer;
121 return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
122 .then(function(subscription) {
123 sendResultToTest(subscription.endpoint);
124 });
125 }).catch(sendErrorToTest);
126 }
127
128 function workerSubscribePush() { 115 function workerSubscribePush() {
129 // Send the message to the worker for it to subscribe 116 // Send the message to the worker for it to subscribe
130 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'}); 117 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'});
131 } 118 }
132 119
133 function workerSubscribePushNoKey() { 120 function workerSubscribePushNoKey() {
134 // The worker will try to subscribe without providing a key. This should 121 // The worker will try to subscribe without providing a key. This should
135 // succeed if the worker was previously subscribed and fail otherwise. 122 // succeed if the worker was previously subscribed and fail otherwise.
136 navigator.serviceWorker.controller.postMessage( 123 navigator.serviceWorker.controller.postMessage(
137 {command: 'workerSubscribeNoKey'}); 124 {command: 'workerSubscribeNoKey'});
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 }).catch(sendErrorToTest); 198 }).catch(sendErrorToTest);
212 } 199 }
213 200
214 navigator.serviceWorker.addEventListener('message', function(event) { 201 navigator.serviceWorker.addEventListener('message', function(event) {
215 var message = JSON.parse(event.data); 202 var message = JSON.parse(event.data);
216 if (message.type == 'push') 203 if (message.type == 'push')
217 resultQueue.push(message.data); 204 resultQueue.push(message.data);
218 else 205 else
219 sendResultToTest(message.data); 206 sendResultToTest(message.data);
220 }, false); 207 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698