Chromium Code Reviews| Index: chrome/test/data/push_messaging/push_messaging_test_android.html |
| diff --git a/chrome/test/data/push_messaging/push_messaging_test_android.html b/chrome/test/data/push_messaging/push_messaging_test_android.html |
| index 158c27191a411966b72c2d8f8bb62d29a6eaf75c..906d25b3dfe750ab7e74fe04c6056207ac3b8ccd 100644 |
| --- a/chrome/test/data/push_messaging/push_messaging_test_android.html |
| +++ b/chrome/test/data/push_messaging/push_messaging_test_android.html |
| @@ -12,8 +12,8 @@ |
| // PushMessagingTest observes changes to the tab title as an asynchronous |
| // response mechanism from JavaScript to Java. |
| // TODO(mvanouwerkerk): Use DomAutomationController - crbug.com/562487 |
| - function respondToTest(result) { |
| - document.title = result; |
| + function sendToTest(message) { |
| + document.title = message; |
|
johnme
2015/12/08 17:12:31
Please add some error handling for the case where
Michael van Ouwerkerk
2015/12/09 15:02:52
Done.
|
| } |
| function subscribePush() { |
| @@ -21,8 +21,36 @@ |
| 'push_messaging_test_worker_android.js', location.pathname) |
| .then(registration => |
| registration.pushManager.subscribe({ userVisibleOnly: true })) |
| - .then(subscription => respondToTest('subscribe ok')) |
| - .catch(error => respondToTest('subscribe fail: ' + error)); |
| + .then(subscription => { |
| + setupMessageHandler(); |
| + sendToTest('subscribe ok'); |
| + }) |
|
johnme
2015/12/08 17:12:31
Nit: this indentation feels a little odd. How abou
Michael van Ouwerkerk
2015/12/09 15:02:52
I've done something like that.
|
| + .catch(error => sendToTest('subscribe fail: ' + error)); |
| + } |
| + |
| + // Sets whether the service worker should show a notification when it |
| + // receives a push message or not. |
| + function setNotifyOnPush(notify) { |
|
johnme
2015/12/08 17:12:31
Can you add a "Called by test" comment, as otherwi
Michael van Ouwerkerk
2015/12/09 15:02:52
Done.
|
| + sendToServiceWorker('setNotifyOnPush', notify); |
| + } |
| + |
| + // Sends a message of type |type| with a data payload of |data| to the |
| + // service worker. |
| + function sendToServiceWorker(type, data) { |
| + navigator.serviceWorker.ready |
| + .then(registration => { |
| + registration.active.postMessage( |
| + JSON.stringify({'type': type, 'data': data})); |
| + }); |
| + } |
| + |
| + // The data for messages of type sendToTest will be passed to the test. |
| + function setupMessageHandler() { |
| + messagePort.addEventListener('message', event => { |
| + var message = JSON.parse(event.data); |
| + if (message.type == 'sendToTest') |
| + sendToTest(message.data); |
| + }); |
| } |
| </script> |
| </body> |