| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Test PushManager.getRegistration()</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'); | |
| 20 }) | |
| 21 .then(function() { | |
| 22 // If running manually, grant permission when prompted. | |
| 23 if (self.testRunner) | |
| 24 testRunner.setPushMessagingPermission(location.origin, true); | |
| 25 | |
| 26 assert_inherits(swRegistration.pushManager, 'getRegistration', | |
| 27 'getRegistration() should be exposed on the PushMana
ger object'); | |
| 28 assert_equals(typeof(swRegistration.pushManager.getRegistration), 'f
unction', | |
| 29 'PushManager.getRegistration() is a function.'); | |
| 30 | |
| 31 return swRegistration.pushManager.getRegistration(); | |
| 32 }) | |
| 33 .then(function(pushRegistration) { | |
| 34 assert_equals(pushRegistration, null, | |
| 35 "pushRegistration should be null if there is no active
push registration.") | |
| 36 return swRegistration.pushManager.register(); | |
| 37 }) | |
| 38 .then(function(pushRegistration) { | |
| 39 previousPushRegistration = pushRegistration; | |
| 40 return swRegistration.pushManager.getRegistration(); | |
| 41 }) | |
| 42 .then(function(pushRegistration) { | |
| 43 assert_equals(previousPushRegistration.endPoint, pushRegistration.en
dPoint, | |
| 44 "Both registration objects should have the same endpoi
nt."); | |
| 45 assert_equals(previousPushRegistration.registrationId, pushRegistrat
ion.registrationId, | |
| 46 "Both registration objects should have the same regist
ration id."); | |
| 47 return pushRegistration.unregister(); | |
| 48 }) | |
| 49 .then(function(unregistered) { | |
| 50 assert_true(unregistered, "unregistration was successful"); | |
| 51 return swRegistration.pushManager.getRegistration(); | |
| 52 }) | |
| 53 .then(function(pushRegistration) { | |
| 54 assert_equals(pushRegistration, null, | |
| 55 "pushRegistration should be null after unregistering."
) | |
| 56 return swRegistration.pushManager.register(); | |
| 57 }) | |
| 58 .then(function(pushRegistration) { | |
| 59 assert_not_equals(pushRegistration, null, | |
| 60 "Registration should have succeeded."); | |
| 61 return service_worker_unregister(test, workerScope); | |
| 62 }) | |
| 63 .then(function() { | |
| 64 return swRegistration.pushManager.getRegistration(); | |
| 65 }) | |
| 66 .then(function(pushRegistration) { | |
| 67 assert_equals(pushRegistration, null, | |
| 68 "After unregistration from SW, there should be no regi
stration."); | |
| 69 return service_worker_unregister_and_done(test, workerScope); | |
| 70 }) | |
| 71 .catch(unreached_rejection(test)); | |
| 72 }); | |
| 73 </script> | |
| 74 </body> | |
| 75 </html> | |
| OLD | NEW |