Chromium Code Reviews| 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); |