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

Unified Diff: chrome/test/data/push_messaging/push_messaging_test_android.html

Issue 1485743002: Push API: test that default notification is shown on Android when needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PushMessagingInstrumentationTest
Patch Set: Tweak for build error. Created 5 years 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 side-by-side diff with in-line comments
Download patch
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>

Powered by Google App Engine
This is Rietveld 408576698