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

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: rebase 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 .then(function(subscription) {
104 sendResultToTest(subscription.endpoint);
105 });
102 }).catch(sendErrorToTest); 106 }).catch(sendErrorToTest);
103 } 107 }
104 108
105 function documentSubscribePush() { 109 function documentSubscribePush() {
106 navigator.serviceWorker.ready.then(function(swRegistration) { 110 navigator.serviceWorker.ready.then(function(swRegistration) {
107 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; 111 return swRegistration.pushManager.subscribe({
108 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) 112 userVisibleOnly: true,
113 applicationServerKey: kApplicationServerKey.buffer
114 })
109 .then(function(subscription) { 115 .then(function(subscription) {
110 sendResultToTest(subscription.endpoint); 116 sendResultToTest(subscription.endpoint);
111 }); 117 });
112 }).catch(sendErrorToTest); 118 }).catch(sendErrorToTest);
113 } 119 }
114 120
115 function workerSubscribePush() { 121 function workerSubscribePush() {
116 // Send the message to the worker for it to subscribe 122 // Send the message to the worker for it to subscribe
117 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'}); 123 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'});
118 } 124 }
(...skipping 10 matching lines...) Expand all
129 return swRegistration.pushManager.getSubscription() 135 return swRegistration.pushManager.getSubscription()
130 .then(function(subscription) { 136 .then(function(subscription) {
131 sendResultToTest(btoa(String.fromCharCode.apply(null, 137 sendResultToTest(btoa(String.fromCharCode.apply(null,
132 new Uint8Array(subscription.getKey('p256dh'))))); 138 new Uint8Array(subscription.getKey('p256dh')))));
133 }); 139 });
134 }).catch(sendErrorToTest); 140 }).catch(sendErrorToTest);
135 } 141 }
136 142
137 function permissionState() { 143 function permissionState() {
138 navigator.serviceWorker.ready.then(function(swRegistration) { 144 navigator.serviceWorker.ready.then(function(swRegistration) {
139 return swRegistration.pushManager.permissionState(pushSubscriptionOptions) 145 return swRegistration.pushManager.permissionState({userVisibleOnly: true})
140 .then(function(permission) { 146 .then(function(permission) {
141 sendResultToTest('permission status - ' + permission); 147 sendResultToTest('permission status - ' + permission);
142 }); 148 });
143 }).catch(sendErrorToTest); 149 }).catch(sendErrorToTest);
144 } 150 }
145 151
146 function isControlled() { 152 function isControlled() {
147 if (navigator.serviceWorker.controller) { 153 if (navigator.serviceWorker.controller) {
148 sendResultToTest('true - is controlled'); 154 sendResultToTest('true - is controlled');
149 } else { 155 } else {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 }).catch(sendErrorToTest); 204 }).catch(sendErrorToTest);
199 } 205 }
200 206
201 navigator.serviceWorker.addEventListener('message', function(event) { 207 navigator.serviceWorker.addEventListener('message', function(event) {
202 var message = JSON.parse(event.data); 208 var message = JSON.parse(event.data);
203 if (message.type == 'push') 209 if (message.type == 'push')
204 resultQueue.push(message.data); 210 resultQueue.push(message.data);
205 else 211 else
206 sendResultToTest(message.data); 212 sendResultToTest(message.data);
207 }, false); 213 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698