| OLD | NEW |
| 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 pushData = new FutureData(); | 7 var pushData = new FutureData(); |
| 8 | 8 |
| 9 // Sends data back to the test. This must be in response to an earlier | 9 // Sends data back to the test. This must be in response to an earlier |
| 10 // request, but it's ok to respond asynchronously. The request blocks until | 10 // request, but it's ok to respond asynchronously. The request blocks until |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 // Notification permission has been coalesced with Push permission. After | 55 // Notification permission has been coalesced with Push permission. After |
| 56 // this is granted, Push API registration can succeed. | 56 // this is granted, Push API registration can succeed. |
| 57 function requestNotificationPermission() { | 57 function requestNotificationPermission() { |
| 58 Notification.requestPermission(function(permission) { | 58 Notification.requestPermission(function(permission) { |
| 59 sendResultToTest('permission status - ' + permission); | 59 sendResultToTest('permission status - ' + permission); |
| 60 }); | 60 }); |
| 61 } | 61 } |
| 62 | 62 |
| 63 function registerServiceWorker() { | 63 function registerServiceWorker() { |
| 64 // The base dir used to resolve service_worker.js and the scope depends on |
| 65 // whether this script is included from an html file in ./, subscope1/, or |
| 66 // subscope2/. |
| 64 navigator.serviceWorker.register('service_worker.js', {scope: './'}).then( | 67 navigator.serviceWorker.register('service_worker.js', {scope: './'}).then( |
| 65 function(swRegistration) { | 68 function(swRegistration) { |
| 66 sendResultToTest('ok - service worker registered'); | 69 sendResultToTest('ok - service worker registered'); |
| 67 }, sendErrorToTest); | 70 }, sendErrorToTest); |
| 68 } | 71 } |
| 69 | 72 |
| 70 function unregisterServiceWorker() { | 73 function unregisterServiceWorker() { |
| 71 navigator.serviceWorker.getRegistration().then(function(swRegistration) { | 74 navigator.serviceWorker.getRegistration().then(function(swRegistration) { |
| 72 swRegistration.unregister().then(function(result) { | 75 swRegistration.unregister().then(function(result) { |
| 73 sendResultToTest('service worker unregistration status: ' + result); | 76 sendResultToTest('service worker unregistration status: ' + result); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 sendResultToTest('false - is not controlled'); | 115 sendResultToTest('false - is not controlled'); |
| 113 } | 116 } |
| 114 } | 117 } |
| 115 | 118 |
| 116 addEventListener('message', function(event) { | 119 addEventListener('message', function(event) { |
| 117 var message = JSON.parse(event.data); | 120 var message = JSON.parse(event.data); |
| 118 if (message.type == 'push') { | 121 if (message.type == 'push') { |
| 119 pushData.set(message.data); | 122 pushData.set(message.data); |
| 120 } | 123 } |
| 121 }, false); | 124 }, false); |
| OLD | NEW |