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

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

Issue 673783003: BrowserTest for delivering push message to service worker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PushIntegrationTest2
Patch Set: Minor cleanups. Created 6 years, 2 months 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
« no previous file with comments | « chrome/test/data/push_messaging/service_worker.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/push_messaging/test.html
diff --git a/chrome/test/data/push_messaging/test.html b/chrome/test/data/push_messaging/test.html
index 407695698f89695224c755778a9469741c1da770..71375423686f98574242a7a7659bce0cf5523eb2 100644
--- a/chrome/test/data/push_messaging/test.html
+++ b/chrome/test/data/push_messaging/test.html
@@ -3,6 +3,8 @@
<head>
<title>Push API Test</title>
<script>
+ var lastMessageFromServiceWorker = null;
+
function sendResultToTest(result) {
console.log(result);
if (window.domAutomationController) {
@@ -15,20 +17,62 @@
}
function registerServiceWorker() {
- navigator.serviceWorker.register('service_worker.js').then(function(swRegistration) {
- console.log(swRegistration);
- sendResultToTest('ok');
- }, sendErrorToTest);
+ navigator.serviceWorker.register('service_worker.js').then(
+ function(swRegistration) {
+ console.log(swRegistration);
+ sendResultToTest('ok - service worker registered');
+ }, sendErrorToTest);
}
function registerPush(senderId) {
navigator.serviceWorker.ready.then(function() {
navigator.push.register(senderId).then(function(pushRegistration) {
- sendResultToTest(pushRegistration.pushEndpoint + ' - ' + pushRegistration.pushRegistrationId);
+ sendResultToTest(pushRegistration.pushEndpoint + ' - ' +
+ pushRegistration.pushRegistrationId);
}, sendErrorToTest);
}, sendErrorToTest);
}
+
+ function doPostMessage() {
+ navigator.serviceWorker.controller.postMessage('Message from page.');
+ }
+
+ addEventListener('message', function(event) {
+ console.log(event);
+ console.log(event.data);
+ lastMessageFromServiceWorker = event.data;
+ }, false);
+
+ function isControlled() {
+ if (navigator.serviceWorker.controller) {
+ sendResultToTest('true - is controlled');
+ } else {
+ sendResultToTest('false - is not controlled');
+ }
+ }
+
+ function getLastMessageFromServiceWorker(loops) {
+ loops = loops || 0;
+ if (!lastMessageFromServiceWorker && loops < 10) {
fgorski 2014/10/23 16:29:51 Isn't there a way to implement asynchronous test c
Michael van Ouwerkerk 2014/10/23 16:39:52 Well, domAutomationController.send must be called
+ setTimeout(function() {
+ getLastMessageFromServiceWorker(loops + 1);
+ }, 0);
+ return;
+ }
+ sendResultToTest(lastMessageFromServiceWorker);
+ lastMessageFromServiceWorker = null;
+ }
</script>
</head>
- <body>Push API Test</body>
+ <body>
+ <h1>Push API Test</h1>
fgorski 2014/10/23 16:29:51 What do yo need this for?
Michael van Ouwerkerk 2014/10/23 16:39:52 It's for manually stepping through the test. Some
+ <div>
+ <button onclick="registerServiceWorker();">registerServiceWorker()</button>
+ <button onclick="registerPush();">registerPush()</button>
+ <button onclick="isControlled();">isControlled()</button>
+ <button onclick="doPostMessage();">doPostMessage()</button>
+ <button onclick="getLastMessageFromServiceWorker();">
+ getLastMessageFromServiceWorker()</button>
+ </div>
+ </body>
</html>
« no previous file with comments | « chrome/test/data/push_messaging/service_worker.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698