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

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: Rebase, address review comments. 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 dd4315029c577a9b2d66afe66913b219c17f6cfd..7328271eb5e93155fc319717207abcfcbaa3fa32 100644
--- a/chrome/test/data/push_messaging/test.html
+++ b/chrome/test/data/push_messaging/test.html
@@ -4,8 +4,13 @@
<title>Push API Test</title>
<link rel="manifest" href="manifest.json">
<script>
+ var pushData = new FutureData();
+
+ // Sends data back to the test. This must be in response to an earlier
+ // request, but it's ok to respond asynchronously. The request blocks until
+ // the response is sent.
function sendResultToTest(result) {
- console.log(result);
+ console.log('sendResultToTest: ' + result);
if (window.domAutomationController) {
domAutomationController.send('' + result);
}
@@ -15,11 +20,39 @@
sendResultToTest(error.name + ' - ' + error.message);
}
+ // A container for a single piece of data. The data does not have to be
+ // available yet when the getter is called, as all responses to the test are
+ // asynchronous.
+ function FutureData() {
+ this.data = null;
+ this.waiting = false;
+ }
+
+ // Sends the data to the test if it is available. Otherwise sets the
+ // |waiting| flag.
+ FutureData.prototype.get = function() {
+ if (this.data) {
Peter Beverloo 2014/10/27 15:20:49 Maybe strict check on === null? Also, isn't the pu
Michael van Ouwerkerk 2014/10/27 15:27:18 Something for a later patch, perhaps? For its curr
+ sendResultToTest(this.data);
+ } else {
+ this.waiting = true;
+ }
+ };
+
+ // Sets a new data value. If the |waiting| flag is on, it is turned off and
+ // the data is sent to the test.
+ FutureData.prototype.set = function(data) {
+ this.data = data;
+ if (this.waiting) {
+ sendResultToTest(data);
+ this.waiting = false;
+ }
+ };
+
function registerServiceWorker() {
- navigator.serviceWorker.register('service_worker.js', {scope: './'}).then(function(swRegistration) {
- console.log(swRegistration);
- sendResultToTest('ok');
- }, sendErrorToTest);
+ navigator.serviceWorker.register('service_worker.js', {scope: './'}).then(
+ function(swRegistration) {
+ sendResultToTest('ok - service worker registered');
+ }, sendErrorToTest);
}
function registerPush() {
@@ -29,7 +62,24 @@
}, sendErrorToTest);
}, sendErrorToTest);
}
+
+ function isControlled() {
Peter Beverloo 2014/10/27 15:20:49 This is not being used.
Michael van Ouwerkerk 2014/10/27 15:27:18 It is, see push_messaging_browsertest.cc
+ if (navigator.serviceWorker.controller) {
+ sendResultToTest('true - is controlled');
+ } else {
+ sendResultToTest('false - is not controlled');
+ }
+ }
+
+ addEventListener('message', function(event) {
+ var message = JSON.parse(event.data);
+ if (message.type == 'push') {
+ pushData.set(message.data);
+ }
+ }, false);
</script>
</head>
- <body>Push API Test</body>
+ <body>
+ <h1>Push API Test</h1>
+ </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