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

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

Issue 1153193013: Parameterize PushMessagingBrowserTest to work with bubbles & infobars (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ready for review Created 5 years, 6 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 var resultQueue = new ResultQueue(); 7 var resultQueue = new ResultQueue();
8 var pushSubscription = null; 8 var pushSubscription = null;
9 var lastPermissionRequestResult = '';
9 10
10 var pushSubscriptionOptions = { 11 var pushSubscriptionOptions = {
11 userVisibleOnly: true 12 userVisibleOnly: true
12 }; 13 };
13 14
14 // Sends data back to the test. This must be in response to an earlier 15 // Sends data back to the test. This must be in response to an earlier
15 // request, but it's ok to respond asynchronously. The request blocks until 16 // request, but it's ok to respond asynchronously. The request blocks until
16 // the response is sent. 17 // the response is sent.
17 function sendResultToTest(result) { 18 function sendResultToTest(result) {
18 console.log('sendResultToTest: ' + result); 19 console.log('sendResultToTest: ' + result);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // Called by native. Immediately sends the next data item to the test if it is 58 // Called by native. Immediately sends the next data item to the test if it is
58 // available, otherwise sends null. 59 // available, otherwise sends null.
59 ResultQueue.prototype.popImmediately = function() { 60 ResultQueue.prototype.popImmediately = function() {
60 sendResultToTest(this.queue.length ? this.queue.pop() : null); 61 sendResultToTest(this.queue.length ? this.queue.pop() : null);
61 }; 62 };
62 63
63 // Notification permission has been coalesced with Push permission. After 64 // Notification permission has been coalesced with Push permission. After
64 // this is granted, Push API subscription can succeed. 65 // this is granted, Push API subscription can succeed.
65 function requestNotificationPermission() { 66 function requestNotificationPermission() {
66 Notification.requestPermission(function(permission) { 67 Notification.requestPermission(function(permission) {
67 sendResultToTest('permission status - ' + permission); 68 lastPermissionRequestResult = permission;
johnme 2015/06/02 14:12:38 What's the purpose of this change? Note that sendR
68 }); 69 });
69 } 70 }
70 71
72 // The result of requesting permission in requestNotificationPermission() will
73 // be sent back. If the permission request has not yet completed, try again
74 // after a timeout.
75 function getLastPermissionRequestResult(timeout) {
76 if (lastPermissionRequestResult === '')
77 window.setTimeout(getLastPermissionRequestResult, timeout);
78 else
79 sendResultToTest('permission status - ' + lastPermissionRequestResult);
80 }
81
71 function registerServiceWorker() { 82 function registerServiceWorker() {
72 // The base dir used to resolve service_worker.js and the scope depends on 83 // The base dir used to resolve service_worker.js and the scope depends on
73 // whether this script is included from an html file in ./, subscope1/, or 84 // whether this script is included from an html file in ./, subscope1/, or
74 // subscope2/. 85 // subscope2/.
75 navigator.serviceWorker.register('service_worker.js', {scope: './'}).then( 86 navigator.serviceWorker.register('service_worker.js', {scope: './'}).then(
76 function(swRegistration) { 87 function(swRegistration) {
77 sendResultToTest('ok - service worker registered'); 88 sendResultToTest('ok - service worker registered');
78 }, sendErrorToTest); 89 }, sendErrorToTest);
79 } 90 }
80 91
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 sendResultToTest(subscription ? 'true - subscribed' 154 sendResultToTest(subscription ? 'true - subscribed'
144 : 'false - not subscribed'); 155 : 'false - not subscribed');
145 }).catch(sendErrorToTest); 156 }).catch(sendErrorToTest);
146 } 157 }
147 158
148 addEventListener('message', function(event) { 159 addEventListener('message', function(event) {
149 var message = JSON.parse(event.data); 160 var message = JSON.parse(event.data);
150 if (message.type == 'push') 161 if (message.type == 'push')
151 resultQueue.push(message.data); 162 resultQueue.push(message.data);
152 }, false); 163 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698