OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Background Sync API: Verifies that the one-shot sync API works correc
tly.</title> |
| 5 <script src="../resources/testharness.js"></script> |
| 6 <script src="../resources/testharnessreport.js"></script> |
| 7 <script src="../serviceworker/resources/test-helpers.js"></script> |
| 8 </head> |
| 9 <body> |
| 10 <script> |
| 11 // Tests that the Background Sync One-Shot API works as expected from the |
| 12 // Document scope |
| 13 async_test(function(t) { |
| 14 var sync_manager; |
| 15 var sync_registration; |
| 16 |
| 17 service_worker_unregister_and_register(t, 'resources/empty_worker.js',
'resources/scope/background_sync/oneshot.html').then(function(swreg) { |
| 18 sync_manager = swreg.sync; |
| 19 return wait_for_state(t, swreg.installing, 'activated'); |
| 20 }).then(function() { |
| 21 // Get any existing registrations |
| 22 return sync_manager.getRegistrations(); |
| 23 }).then(function(registrations) { |
| 24 // Clear them all out |
| 25 var promises = []; |
| 26 for (registration of registrations) { |
| 27 promises.push(registration.unregister()); |
| 28 } |
| 29 return Promise.all(promises); |
| 30 }).then(function() { |
| 31 // Ensure that there are none left |
| 32 return sync_manager.getRegistrations(); |
| 33 }).then(function(registrations) { |
| 34 assert_equals(registrations.length, 0); |
| 35 }).then(function() { |
| 36 // Register a new one |
| 37 return sync_manager.register({tag: "abcde"}); |
| 38 }).then(function(registration) { |
| 39 sync_registration = registration; |
| 40 assert_class_string(sync_registration, 'SyncRegistration'); |
| 41 assert_equals("abcde", registration.tag); |
| 42 return sync_manager.getRegistrations(); |
| 43 }).then(function(registrations) { |
| 44 assert_equals(1, registrations.length); |
| 45 }).then(function() { |
| 46 // Unregister it |
| 47 return sync_registration.unregister(); |
| 48 }).then(function() { |
| 49 // Ensure that they are all gone |
| 50 return sync_manager.getRegistrations(); |
| 51 }).then(function(registrations) { |
| 52 assert_equals(0, registrations.length); |
| 53 }).then(function() { |
| 54 t.done(); |
| 55 }).catch(unreached_rejection(t)); |
| 56 }, 'SyncManager should be allow one-shot syncs to be registered and unregi
stered.'); |
| 57 </script> |
| 58 </body> |
| 59 </html> |
OLD | NEW |