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

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

Issue 2452833004: Fix flaky SW registration in PushMessaging/BudgetManager browser tests (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
(...skipping 26 matching lines...) Expand all
37 function requestNotificationPermission() { 37 function requestNotificationPermission() {
38 Notification.requestPermission(function(permission) { 38 Notification.requestPermission(function(permission) {
39 sendResultToTest('permission status - ' + permission); 39 sendResultToTest('permission status - ' + permission);
40 }); 40 });
41 } 41 }
42 42
43 function registerServiceWorker() { 43 function registerServiceWorker() {
44 // The base dir used to resolve service_worker.js and the scope depends on 44 // The base dir used to resolve service_worker.js and the scope depends on
45 // whether this script is included from an html file in ./, subscope1/, or 45 // whether this script is included from an html file in ./, subscope1/, or
46 // subscope2/. 46 // subscope2/.
47 navigator.serviceWorker.register('service_worker.js', {scope: './'}).then( 47 navigator.serviceWorker.register('service_worker.js', {
48 function(swRegistration) { 48 scope: './'
49 sendResultToTest('ok - service worker registered'); 49 }).then(swRegistrationReady).then(() => {
50 }, sendErrorToTest); 50 sendResultToTest('ok - service worker registered');
51 }).catch(sendErrorToTest);
51 } 52 }
52 53
53 function unregisterServiceWorker() { 54 function unregisterServiceWorker() {
54 navigator.serviceWorker.getRegistration().then(function(swRegistration) { 55 navigator.serviceWorker.getRegistration().then(function(swRegistration) {
55 swRegistration.unregister().then(function(result) { 56 swRegistration.unregister().then(function(result) {
56 sendResultToTest('service worker unregistration status: ' + result); 57 sendResultToTest('service worker unregistration status: ' + result);
57 }) 58 })
58 }).catch(sendErrorToTest); 59 }).catch(sendErrorToTest);
59 } 60 }
60 61
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 }).catch(sendErrorToTest); 205 }).catch(sendErrorToTest);
205 } 206 }
206 207
207 navigator.serviceWorker.addEventListener('message', function(event) { 208 navigator.serviceWorker.addEventListener('message', function(event) {
208 var message = JSON.parse(event.data); 209 var message = JSON.parse(event.data);
209 if (message.type == 'push') 210 if (message.type == 'push')
210 resultQueue.push(message.data); 211 resultQueue.push(message.data);
211 else 212 else
212 sendResultToTest(message.data); 213 sendResultToTest(message.data);
213 }, false); 214 }, false);
OLDNEW
« no previous file with comments | « chrome/test/data/budget_service/service_worker.js ('k') | chrome/test/data/push_messaging/service_worker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698