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

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

Issue 2460223004: Fix potential bug in push_test.js - do not cache subscription options (Closed)
Patch Set: oops, remove duplicated line Created 4 years, 1 month 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
11 var pushSubscriptionOptions = {
12 userVisibleOnly: true
13 };
14
15 // Waits for the given ServiceWorkerRegistration to become ready. 11 // Waits for the given ServiceWorkerRegistration to become ready.
16 // Shim for https://github.com/w3c/ServiceWorker/issues/770. 12 // Shim for https://github.com/w3c/ServiceWorker/issues/770.
17 function swRegistrationReady(reg) { 13 function swRegistrationReady(reg) {
18 return new Promise((resolve, reject) => { 14 return new Promise((resolve, reject) => {
19 if (reg.active) { 15 if (reg.active) {
20 resolve(); 16 resolve();
21 return; 17 return;
22 } 18 }
23 19
24 if (!reg.installing && !reg.waiting) { 20 if (!reg.installing && !reg.waiting) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 sendResultToTest('sender id removed from manifest'); 83 sendResultToTest('sender id removed from manifest');
88 } else { 84 } else {
89 sendResultToTest('unable to find manifest element'); 85 sendResultToTest('unable to find manifest element');
90 } 86 }
91 } 87 }
92 88
93 // This is the old style of push subscriptions which we are phasing away 89 // This is the old style of push subscriptions which we are phasing away
94 // from, where the subscription used a sender ID instead of public key. 90 // from, where the subscription used a sender ID instead of public key.
95 function documentSubscribePushWithoutKey() { 91 function documentSubscribePushWithoutKey() {
96 navigator.serviceWorker.ready.then(function(swRegistration) { 92 navigator.serviceWorker.ready.then(function(swRegistration) {
97 return swRegistration.pushManager.subscribe( 93 return swRegistration.pushManager.subscribe({userVisibleOnly: true})
98 pushSubscriptionOptions)
99 .then(function(subscription) { 94 .then(function(subscription) {
100 sendResultToTest(subscription.endpoint); 95 sendResultToTest(subscription.endpoint);
101 }); 96 });
97 }).catch(sendErrorToTest);
98 }
99
100 function documentSubscribePushWithEmptyOptions() {
101 navigator.serviceWorker.ready.then(function(swRegistration) {
102 return swRegistration.pushManager.subscribe(
103 {} /* pushSubscriptionOptions */)
Peter Beverloo 2016/10/31 18:39:56 nit: no need to pass anything here, it defaults to
104 .then(function(subscription) {
105 sendResultToTest(subscription.endpoint);
106 });
102 }).catch(sendErrorToTest); 107 }).catch(sendErrorToTest);
103 } 108 }
104 109
105 function documentSubscribePush() { 110 function documentSubscribePush() {
106 navigator.serviceWorker.ready.then(function(swRegistration) { 111 navigator.serviceWorker.ready.then(function(swRegistration) {
107 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; 112 return swRegistration.pushManager.subscribe({
108 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) 113 userVisibleOnly: true,
114 applicationServerKey: kApplicationServerKey.buffer
115 })
109 .then(function(subscription) { 116 .then(function(subscription) {
110 sendResultToTest(subscription.endpoint); 117 sendResultToTest(subscription.endpoint);
111 }); 118 });
112 }).catch(sendErrorToTest); 119 }).catch(sendErrorToTest);
113 } 120 }
114 121
115 function workerSubscribePush() { 122 function workerSubscribePush() {
116 // Send the message to the worker for it to subscribe 123 // Send the message to the worker for it to subscribe
117 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'}); 124 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'});
118 } 125 }
(...skipping 10 matching lines...) Expand all
129 return swRegistration.pushManager.getSubscription() 136 return swRegistration.pushManager.getSubscription()
130 .then(function(subscription) { 137 .then(function(subscription) {
131 sendResultToTest(btoa(String.fromCharCode.apply(null, 138 sendResultToTest(btoa(String.fromCharCode.apply(null,
132 new Uint8Array(subscription.getKey('p256dh'))))); 139 new Uint8Array(subscription.getKey('p256dh')))));
133 }); 140 });
134 }).catch(sendErrorToTest); 141 }).catch(sendErrorToTest);
135 } 142 }
136 143
137 function permissionState() { 144 function permissionState() {
138 navigator.serviceWorker.ready.then(function(swRegistration) { 145 navigator.serviceWorker.ready.then(function(swRegistration) {
139 return swRegistration.pushManager.permissionState(pushSubscriptionOptions) 146 return swRegistration.pushManager.permissionState({userVisibleOnly: true})
140 .then(function(permission) { 147 .then(function(permission) {
141 sendResultToTest('permission status - ' + permission); 148 sendResultToTest('permission status - ' + permission);
142 }); 149 });
143 }).catch(sendErrorToTest); 150 }).catch(sendErrorToTest);
144 } 151 }
145 152
146 function isControlled() { 153 function isControlled() {
147 if (navigator.serviceWorker.controller) { 154 if (navigator.serviceWorker.controller) {
148 sendResultToTest('true - is controlled'); 155 sendResultToTest('true - is controlled');
149 } else { 156 } else {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 }).catch(sendErrorToTest); 205 }).catch(sendErrorToTest);
199 } 206 }
200 207
201 navigator.serviceWorker.addEventListener('message', function(event) { 208 navigator.serviceWorker.addEventListener('message', function(event) {
202 var message = JSON.parse(event.data); 209 var message = JSON.parse(event.data);
203 if (message.type == 'push') 210 if (message.type == 'push')
204 resultQueue.push(message.data); 211 resultQueue.push(message.data);
205 else 212 else
206 sendResultToTest(message.data); 213 sendResultToTest(message.data);
207 }, false); 214 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698