Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / push_messaging / get-subscription-in-document.html
blob484d0e973d7ba52c975f7107835f62c9f9d9c6fb
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>getSubscription must return the details of the active subscription if there is one</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 </head>
10 <body>
11 <script>
12 async_test(function(test) {
13 var workerUrl = 'resources/empty_worker.js';
14 var workerScope = 'resources/scope/' + location.pathname;
15 var swRegistration = null;
16 service_worker_unregister_and_register(test, workerUrl, workerScope)
17 .then(function(serviceWorkerRegistration) {
18 swRegistration = serviceWorkerRegistration;
19 return wait_for_state(test, swRegistration.installing, 'activated');
21 .then(function() {
22 // If running manually, grant permission when prompted.
23 if (self.testRunner)
24 testRunner.setPermission('push-messaging', 'granted', location.origin, location.origin);
26 assert_inherits(swRegistration.pushManager, 'getSubscription',
27 'getSubscription() should be exposed on the PushManager object');
28 assert_equals(typeof(swRegistration.pushManager.getSubscription), 'function',
29 'PushManager.getSubscription() is a function.');
31 return swRegistration.pushManager.getSubscription();
33 .then(function(pushSubscription) {
34 assert_equals(pushSubscription, null,
35 "pushSubscription should be null if there is no active push registration.")
36 return swRegistration.pushManager.subscribe();
38 .then(function(pushSubscription) {
39 previousPushSubscription = pushSubscription;
40 return swRegistration.pushManager.getSubscription();
42 .then(function(pushSubscription) {
43 assert_equals(previousPushSubscription.endpoint, pushSubscription.endpoint,
44 "Both subscription objects should have the same endpoint.");
45 return pushSubscription.unsubscribe();
47 .then(function(unsubscribed) {
48 assert_true(unsubscribed, "unsubscription was successful");
49 return swRegistration.pushManager.getSubscription();
51 .then(function(pushSubscription) {
52 assert_equals(pushSubscription, null,
53 "pushSubscription should be null after unsubscribing.")
54 return swRegistration.pushManager.subscribe();
56 .then(function(pushSubscription) {
57 assert_not_equals(pushSubscription, null,
58 "Subscription should have succeeded.");
59 return service_worker_unregister(test, workerScope);
61 .then(function() {
62 return swRegistration.pushManager.getSubscription();
64 .then(function(pushSubscription) {
65 assert_equals(pushSubscription, null,
66 "After unregistration of SW, there should be no push subscription.");
67 return service_worker_unregister_and_done(test, workerScope);
69 .catch(unreached_rejection(test));
70 }, 'getSubscription must return the details of the active subscription if there is one');
71 </script>
72 </body>
73 </html>