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

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: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
93 let pushSubscriptionOptions = {
94 userVisibleOnly: true
95 };
97 return swRegistration.pushManager.subscribe( 96 return swRegistration.pushManager.subscribe(
98 pushSubscriptionOptions) 97 pushSubscriptionOptions)
Peter Beverloo 2016/10/31 17:30:20 I see failing tests. Is it possible that subscribi
Peter Beverloo 2016/10/31 17:30:20 nit: consider inlining the dictionary
awdf 2016/10/31 17:35:02 Huh, that's weird, I thought they might but I'm pr
awdf 2016/10/31 18:35:40 Done.
99 .then(function(subscription) { 98 .then(function(subscription) {
100 sendResultToTest(subscription.endpoint); 99 sendResultToTest(subscription.endpoint);
101 }); 100 });
102 }).catch(sendErrorToTest); 101 }).catch(sendErrorToTest);
103 } 102 }
104 103
105 function documentSubscribePush() { 104 function documentSubscribePush() {
106 navigator.serviceWorker.ready.then(function(swRegistration) { 105 navigator.serviceWorker.ready.then(function(swRegistration) {
107 pushSubscriptionOptions.applicationServerKey = kApplicationServerKey.buffer; 106 let pushSubscriptionOptions = {
awdf 2016/10/31 18:35:40 ah did you prefer this one not inlined actually? i
107 userVisibleOnly: true,
108 applicationServerKey: kApplicationServerKey.buffer
109 };
108 return swRegistration.pushManager.subscribe(pushSubscriptionOptions) 110 return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
109 .then(function(subscription) { 111 .then(function(subscription) {
110 sendResultToTest(subscription.endpoint); 112 sendResultToTest(subscription.endpoint);
111 }); 113 });
112 }).catch(sendErrorToTest); 114 }).catch(sendErrorToTest);
113 } 115 }
114 116
115 function workerSubscribePush() { 117 function workerSubscribePush() {
116 // Send the message to the worker for it to subscribe 118 // Send the message to the worker for it to subscribe
117 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'}); 119 navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'});
(...skipping 11 matching lines...) Expand all
129 return swRegistration.pushManager.getSubscription() 131 return swRegistration.pushManager.getSubscription()
130 .then(function(subscription) { 132 .then(function(subscription) {
131 sendResultToTest(btoa(String.fromCharCode.apply(null, 133 sendResultToTest(btoa(String.fromCharCode.apply(null,
132 new Uint8Array(subscription.getKey('p256dh'))))); 134 new Uint8Array(subscription.getKey('p256dh')))));
133 }); 135 });
134 }).catch(sendErrorToTest); 136 }).catch(sendErrorToTest);
135 } 137 }
136 138
137 function permissionState() { 139 function permissionState() {
138 navigator.serviceWorker.ready.then(function(swRegistration) { 140 navigator.serviceWorker.ready.then(function(swRegistration) {
141 let pushSubscriptionOptions = {
142 userVisibleOnly: true
143 };
139 return swRegistration.pushManager.permissionState(pushSubscriptionOptions) 144 return swRegistration.pushManager.permissionState(pushSubscriptionOptions)
Peter Beverloo 2016/10/31 17:30:20 nit: consider inlining the dictionary
awdf 2016/10/31 18:35:40 Done.
140 .then(function(permission) { 145 .then(function(permission) {
141 sendResultToTest('permission status - ' + permission); 146 sendResultToTest('permission status - ' + permission);
142 }); 147 });
143 }).catch(sendErrorToTest); 148 }).catch(sendErrorToTest);
144 } 149 }
145 150
146 function isControlled() { 151 function isControlled() {
147 if (navigator.serviceWorker.controller) { 152 if (navigator.serviceWorker.controller) {
148 sendResultToTest('true - is controlled'); 153 sendResultToTest('true - is controlled');
149 } else { 154 } else {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 }).catch(sendErrorToTest); 203 }).catch(sendErrorToTest);
199 } 204 }
200 205
201 navigator.serviceWorker.addEventListener('message', function(event) { 206 navigator.serviceWorker.addEventListener('message', function(event) {
202 var message = JSON.parse(event.data); 207 var message = JSON.parse(event.data);
203 if (message.type == 'push') 208 if (message.type == 'push')
204 resultQueue.push(message.data); 209 resultQueue.push(message.data);
205 else 210 else
206 sendResultToTest(message.data); 211 sendResultToTest(message.data);
207 }, false); 212 }, false);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698