| 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 cc817eefd1af48b656097e659a0c9915447375c4..a61a2bc59cfc040c8a0745cbe12344b8f77dd744 100644
|
| --- a/chrome/test/data/push_messaging/push_test.js
|
| +++ b/chrome/test/data/push_messaging/push_test.js
|
| @@ -59,6 +59,30 @@ ResultQueue.prototype.popImmediately = function() {
|
| sendResultToTest(this.queue.length ? this.queue.pop() : null);
|
| };
|
|
|
| +// Waits for the given ServiceWorkerRegistration to become ready.
|
| +// Shim for https://github.com/w3c/ServiceWorker/issues/770.
|
| +function swRegistrationReady(reg) {
|
| + return new Promise((resolve, reject) => {
|
| + if (reg.active) {
|
| + resolve();
|
| + return;
|
| + }
|
| +
|
| + if (!reg.installing && !reg.waiting) {
|
| + reject(Error('Install failed'));
|
| + return;
|
| + }
|
| +
|
| + (reg.installing || reg.waiting).addEventListener('statechange', function() {
|
| + if (this.state == 'redundant') {
|
| + reject(Error('Install failed'));
|
| + } else if (this.state == 'activated') {
|
| + resolve();
|
| + }
|
| + });
|
| + });
|
| +}
|
| +
|
| // Notification permission has been coalesced with Push permission. After
|
| // this is granted, Push API subscription can succeed.
|
| function requestNotificationPermission() {
|
| @@ -85,6 +109,14 @@ function unregisterServiceWorker() {
|
| }).catch(sendErrorToTest);
|
| }
|
|
|
| +function replaceServiceWorker() {
|
| + navigator.serviceWorker.register('service_worker_with_skipWaiting_claim.js', {
|
| + scope: './'
|
| + }).then(swRegistrationReady).then(() => {
|
| + sendResultToTest('ok - service worker replaced');
|
| + }).catch(sendErrorToTest);
|
| +}
|
| +
|
| function removeManifest() {
|
| var element = document.querySelector('link[rel="manifest"]');
|
| if (element) {
|
| @@ -195,11 +227,28 @@ function unsubscribePush() {
|
| sendResultToTest('unsubscribe result: ' + result);
|
| }, function(error) {
|
| sendResultToTest('unsubscribe error: ' + error.message);
|
| - })
|
| + });
|
| })
|
| });
|
| }
|
|
|
| +function storePushSubscription() {
|
| + navigator.serviceWorker.ready.then(swRegistration => {
|
| + swRegistration.pushManager.getSubscription().then(pushSubscription => {
|
| + window.storedPushSubscription = pushSubscription;
|
| + sendResultToTest('ok - stored');
|
| + }, sendErrorToTest);
|
| + }, sendErrorToTest);
|
| +}
|
| +
|
| +function unsubscribeStoredPushSubscription() {
|
| + window.storedPushSubscription.unsubscribe().then(function(result) {
|
| + sendResultToTest('unsubscribe result: ' + result);
|
| + }, function(error) {
|
| + sendResultToTest('unsubscribe error: ' + error.message);
|
| + });
|
| +}
|
| +
|
| function hasSubscription() {
|
| navigator.serviceWorker.ready.then(function(swRegistration) {
|
| return swRegistration.pushManager.getSubscription();
|
|
|