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

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: 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 30 matching lines...) Expand all
41 function requestNotificationPermission() { 41 function requestNotificationPermission() {
42 Notification.requestPermission(function(permission) { 42 Notification.requestPermission(function(permission) {
43 sendResultToTest('permission status - ' + permission); 43 sendResultToTest('permission status - ' + permission);
44 }); 44 });
45 } 45 }
46 46
47 function registerServiceWorker() { 47 function registerServiceWorker() {
48 // The base dir used to resolve service_worker.js and the scope depends on 48 // The base dir used to resolve service_worker.js and the scope depends on
49 // whether this script is included from an html file in ./, subscope1/, or 49 // whether this script is included from an html file in ./, subscope1/, or
50 // subscope2/. 50 // subscope2/.
51 navigator.serviceWorker.register('service_worker.js', {scope: './'}).then( 51 navigator.serviceWorker.register('service_worker.js', {
52 function(swRegistration) { 52 scope: './'
53 sendResultToTest('ok - service worker registered'); 53 }).then(swRegistrationReady).then(() => {
54 }, sendErrorToTest); 54 sendResultToTest('ok - service worker registered');
55 }).catch(sendErrorToTest);
55 } 56 }
56 57
57 function unregisterServiceWorker() { 58 function unregisterServiceWorker() {
58 navigator.serviceWorker.getRegistration().then(function(swRegistration) { 59 navigator.serviceWorker.getRegistration().then(function(swRegistration) {
59 swRegistration.unregister().then(function(result) { 60 swRegistration.unregister().then(function(result) {
60 sendResultToTest('service worker unregistration status: ' + result); 61 sendResultToTest('service worker unregistration status: ' + result);
61 }) 62 })
62 }).catch(sendErrorToTest); 63 }).catch(sendErrorToTest);
63 } 64 }
64 65
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 }).catch(sendErrorToTest); 199 }).catch(sendErrorToTest);
199 } 200 }
200 201
201 navigator.serviceWorker.addEventListener('message', function(event) { 202 navigator.serviceWorker.addEventListener('message', function(event) {
202 var message = JSON.parse(event.data); 203 var message = JSON.parse(event.data);
203 if (message.type == 'push') 204 if (message.type == 'push')
204 resultQueue.push(message.data); 205 resultQueue.push(message.data);
205 else 206 else
206 sendResultToTest(message.data); 207 sendResultToTest(message.data);
207 }, false); 208 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698