<!DOCTYPE html>
<html>
<head>
<title>unsubscribe must resolve with true iff it is called on an active subscription</title>
<link rel="manifest" href="resources/push_manifest.json">
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
<script src="../notifications/resources/test-helpers.js"></script>
<script src="resources/test-helpers.js"></script>
</head>
<body>
<script>
// This test uses the test runner. If running manually, grant permission when prompted.
async_test(function(test) {
if (window.testRunner)
testRunner.setPermission('push-messaging', 'granted', location.origin, location.origin);
var script = 'resources/instrumentation-service-worker.js';
var scope = 'resources/scope/' + location.pathname;
var port;
getActiveServiceWorkerWithMessagePort(test, script, scope)
.then(function(workerInfo) {
port = workerInfo.port;
return subscribeAndUnsubscribePush(workerInfo.registration);
})
.then(function() {
return runCommandInServiceWorker(port, 'getSubscription');
})
.then(function(data) {
assert_equals(data.endpoint, null,
'There must be no subscription after unsubscribing in the document.');
return runCommandInServiceWorker(port, 'subscribe');
})
.then(function(data) {
assert_equals(typeof data.endpoint, 'string',
'There must be a subscription after subscribing');
return runCommandInServiceWorker(port, 'unsubscribe');
})
.then(function(data) {
assert_true(data.unsubscribeResult,
'Calling unsubscribe on an active subscription must resolve with true.');
return runCommandInServiceWorker(port, 'unsubscribe');
})
.then(function(data) {
assert_false(data.unsubscribeResult,
'Calling unsubscribe on a deactivated subscription must resolve with false.');
return runCommandInServiceWorker(port, 'getSubscription');
})
.then(function(data) {
assert_equals(data.endpoint, null,
'There must be no subscription after unsubscribing in the service worker.');
test.done();
})
.catch(unreached_rejection(test));
}, 'unsubscribe must resolve with true iff it is called on an active subscription');
</script>
</body>
</html>