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

Unified Diff: chrome/test/data/push_messaging/push_test.js

Issue 1816123002: Add testing for subscription from service workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed rebase added duplicate code Created 4 years, 9 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
Index: chrome/test/data/push_messaging/push_test.js
diff --git a/chrome/test/data/push_messaging/push_test.js b/chrome/test/data/push_messaging/push_test.js
index 73a307e52b4d3fa6084dd087fd94d2e02b814b77..44f1c32971980c6a6a3d68d5a96fb05a9dbc45a8 100644
--- a/chrome/test/data/push_messaging/push_test.js
+++ b/chrome/test/data/push_messaging/push_test.js
@@ -5,7 +5,6 @@
'use strict';
var resultQueue = new ResultQueue();
-var pushSubscription = null;
// NIST P-256 public key made available to tests. Must be an uncompressed
// point in accordance with SEC1 2.3.3.
@@ -123,7 +122,6 @@ function subscribePushWithoutKey() {
return swRegistration.pushManager.subscribe(
pushSubscriptionOptions)
.then(function(subscription) {
- pushSubscription = subscription;
sendResultToTest(subscription.endpoint);
});
}).catch(sendErrorToTest);
@@ -134,7 +132,6 @@ function subscribePush() {
pushSubscriptionOptions.applicationServerKey = applicationServerKey.buffer;
return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
.then(function(subscription) {
- pushSubscription = subscription;
sendResultToTest(subscription.endpoint);
});
}).catch(sendErrorToTest);
@@ -148,12 +145,29 @@ function subscribePushBadKey() {
invalidApplicationServerKey.buffer;
return swRegistration.pushManager.subscribe(pushSubscriptionOptions)
.then(function(subscription) {
- pushSubscription = subscription;
sendResultToTest(subscription.endpoint);
});
}).catch(sendErrorToTest);
}
+function workerSubscribePush() {
+ // Send the message to the worker for it to subscribe
+ navigator.serviceWorker.controller.postMessage({command: 'workerSubscribe'});
+}
+
+function workerSubscribePermissionFail() {
Michael van Ouwerkerk 2016/03/22 11:31:37 This function appears to be unused.
harkness 2016/03/24 16:56:23 Removed. It was duplicate testing anyway.
+ // Attempt to subscribe with invalid useVisibleOnly flag
Michael van Ouwerkerk 2016/03/22 11:31:37 Is |useVisibleOnly| an intentional misspelling the
harkness 2016/03/24 16:56:23 Acknowledged.
+ navigator.serviceWorker.controller.postMessage(
+ {command: 'workerSubscribePermissionFail'});
+}
+
+function workerSubscribePushNoKey() {
+ // The worker will try to subscribe without providing a key. This should
+ // succeed if the worker was previously subscribed and fail otherwise.
+ navigator.serviceWorker.controller.postMessage(
+ {command: 'workerSubscribeNoKey'});
+}
+
function GetP256dh() {
navigator.serviceWorker.ready.then(function(swRegistration) {
return swRegistration.pushManager.getSubscription()
@@ -182,15 +196,23 @@ function isControlled() {
}
function unsubscribePush() {
- if (!pushSubscription) {
- sendResultToTest('unsubscribe error: no subscription');
- return;
- }
-
- pushSubscription.unsubscribe().then(function(result) {
- sendResultToTest('unsubscribe result: ' + result);
- }, function(error) {
- sendResultToTest('unsubscribe error: ' + error.name + ': ' + error.message);
+ navigator.serviceWorker.ready.then(function(swRegistration) {
harkness 2016/03/21 15:05:02 Previously unsubscribe used a variable that was se
+ if (!swRegistration) {
+ sendResultToTest('unsubscribe result: false');
+ return;
+ }
+ swRegistration.pushManager.getSubscription().then(function(pushSubscription)
+ {
+ if (!pushSubscription) {
+ sendResultToTest('unsubscribe result: false');
+ return;
+ }
+ pushSubscription.unsubscribe().then(function(result) {
+ sendResultToTest('unsubscribe result: ' + result);
+ }, function(error) {
+ sendResultToTest('unsubscribe error: ' + error.message);
+ })
+ })
});
}
@@ -207,4 +229,6 @@ navigator.serviceWorker.addEventListener('message', function(event) {
var message = JSON.parse(event.data);
if (message.type == 'push')
resultQueue.push(message.data);
+ else
+ sendResultToTest(message.data);
}, false);

Powered by Google App Engine
This is Rietveld 408576698