Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / push_messaging / unsubscribe-in-service-worker.html
blob458afaca39efb8be0af54c9648aedf1cca1503f7
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>unsubscribe must resolve with true iff it is called on an active subscription</title>
5 <link rel="manifest" href="resources/push_manifest.json">
6 <script src="../resources/testharness.js"></script>
7 <script src="../resources/testharnessreport.js"></script>
8 <script src="../serviceworker/resources/test-helpers.js"></script>
9 <script src="../notifications/resources/test-helpers.js"></script>
10 <script src="resources/test-helpers.js"></script>
11 </head>
12 <body>
13 <script>
14 // This test uses the test runner. If running manually, grant permission when prompted.
15 async_test(function(test) {
16 if (window.testRunner)
17 testRunner.setPermission('push-messaging', 'granted', location.origin, location.origin);
19 var script = 'resources/instrumentation-service-worker.js';
20 var scope = 'resources/scope/' + location.pathname;
21 var port;
23 getActiveServiceWorkerWithMessagePort(test, script, scope)
24 .then(function(workerInfo) {
25 port = workerInfo.port;
26 return subscribeAndUnsubscribePush(workerInfo.registration);
28 .then(function() {
29 return runCommandInServiceWorker(port, 'getSubscription');
31 .then(function(data) {
32 assert_equals(data.endpoint, null,
33 'There must be no subscription after unsubscribing in the document.');
34 return runCommandInServiceWorker(port, 'subscribe');
36 .then(function(data) {
37 assert_equals(typeof data.endpoint, 'string',
38 'There must be a subscription after subscribing');
39 return runCommandInServiceWorker(port, 'unsubscribe');
41 .then(function(data) {
42 assert_true(data.unsubscribeResult,
43 'Calling unsubscribe on an active subscription must resolve with true.');
44 return runCommandInServiceWorker(port, 'unsubscribe');
46 .then(function(data) {
47 assert_false(data.unsubscribeResult,
48 'Calling unsubscribe on a deactivated subscription must resolve with false.');
49 return runCommandInServiceWorker(port, 'getSubscription');
51 .then(function(data) {
52 assert_equals(data.endpoint, null,
53 'There must be no subscription after unsubscribing in the service worker.');
54 test.done();
56 .catch(unreached_rejection(test));
57 }, 'unsubscribe must resolve with true iff it is called on an active subscription');
58 </script>
59 </body>
60 </html>