| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test PushRegistration.unregister()</title> | 4 <title>Test PushRegistration.unregister()</title> |
| 5 <link rel="manifest" href="resources/push_manifest.json"> | 5 <link rel="manifest" href="resources/push_manifest.json"> |
| 6 <script src="../resources/testharness.js"></script> | 6 <script src="../resources/testharness.js"></script> |
| 7 <script src="../resources/testharnessreport.js"></script> | 7 <script src="../resources/testharnessreport.js"></script> |
| 8 <script src="../serviceworker/resources/test-helpers.js"></script> | 8 <script src="../serviceworker/resources/test-helpers.js"></script> |
| 9 </head> | 9 </head> |
| 10 <body> | 10 <body> |
| 11 <script> | 11 <script> |
| 12 async_test(function(test) { | 12 async_test(function(test) { |
| 13 var workerUrl = 'resources/empty_worker.js'; | 13 var workerUrl = 'resources/empty_worker.js'; |
| 14 var workerScope = 'resources/scope/' + location.pathname; | 14 var workerScope = 'resources/scope/' + location.pathname; |
| 15 var swRegistration; | 15 var swRegistration; |
| 16 var pushRegistration; |
| 16 service_worker_unregister_and_register(test, workerUrl, workerScope) | 17 service_worker_unregister_and_register(test, workerUrl, workerScope) |
| 17 .then(function(serviceWorkerRegistration) { | 18 .then(function(serviceWorkerRegistration) { |
| 18 swRegistration = serviceWorkerRegistration; | 19 swRegistration = serviceWorkerRegistration; |
| 19 return wait_for_state(test, swRegistration.installing, 'activated'); | 20 return wait_for_state(test, swRegistration.installing, 'activated'); |
| 20 }) | 21 }) |
| 21 .then(function() { | 22 .then(function() { |
| 22 // If running manually, grant permission when prompted. | 23 // If running manually, grant permission when prompted. |
| 23 if (self.testRunner) | 24 if (self.testRunner) |
| 24 testRunner.setPushMessagingPermission(location.origin, true); | 25 testRunner.setPushMessagingPermission(location.origin, true); |
| 25 return swRegistration.pushManager.register(); | 26 return swRegistration.pushManager.register(); |
| 26 }) | 27 }) |
| 27 .then(function(pushRegistration) { | 28 .then(function(registration) { |
| 29 pushRegistration = registration; |
| 28 assert_inherits(pushRegistration, 'unregister', | 30 assert_inherits(pushRegistration, 'unregister', |
| 29 'unregister() should be exposed on the PushRegistrat
ion object'); | 31 'unregister() should be exposed on the PushRegistrat
ion object'); |
| 30 assert_equals(typeof(pushRegistration.unregister), 'function', | 32 assert_equals(typeof(pushRegistration.unregister), 'function', |
| 31 'PushRegistration.unregister() is a function.'); | 33 'PushRegistration.unregister() is a function.'); |
| 32 return pushRegistration.unregister(); | 34 return pushRegistration.unregister(); |
| 33 }) | 35 }) |
| 34 .then(function(unregistration_result) { | 36 .then(function(unregistration_result) { |
| 35 assert_true(unregistration_result, | 37 assert_true(unregistration_result, |
| 36 'Unregistering a registered PushRegistration should succ
eed.'); | 38 "unregister() called when correctly registered should be
fulfilled with true"); |
| 37 // FIXME: we should add another call to unregister(). It should then | 39 return pushRegistration.unregister(); |
| 38 // fail. | 40 }) |
| 39 // FIXME: we should check that there is no more push registration | 41 .then(function(unregistration_result) { |
| 40 // object available if we query the registrations. | 42 assert_false(unregistration_result, |
| 43 "unregister() called a second time should be fulfilled
with false"); |
| 44 return swRegistration.pushManager.getRegistration(); |
| 45 }) |
| 46 .then(function(pushRegistration) { |
| 47 assert_equals(pushRegistration, null, |
| 48 "After unregistration, there is no more PushRegistrati
on."); |
| 41 return service_worker_unregister_and_done(test, workerScope); | 49 return service_worker_unregister_and_done(test, workerScope); |
| 42 }) | 50 }) |
| 43 .catch(unreached_rejection(test)); | 51 .catch(unreached_rejection(test)); |
| 44 }, 'unregister() succeeds if called after a successful registration'); | 52 }); |
| 45 </script> | 53 </script> |
| 46 </body> | 54 </body> |
| 47 </html> | 55 </html> |
| OLD | NEW |