Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <meta charset="utf-8"> | 2 <meta charset="utf-8"> |
| 3 <title>Background Sync API: Verifies that the one-shot sync API works | 3 <title>Background Sync API: Verifies that the one-shot sync API works |
| 4 correctly.</title> | 4 correctly.</title> |
| 5 <script src="../resources/testharness.js"></script> | 5 <script src="../resources/testharness.js"></script> |
| 6 <script src="../resources/testharness-helpers.js"></script> | 6 <script src="../resources/testharness-helpers.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 <script src="resources/test-helpers.js"></script> | |
| 10 <script> | 9 <script> |
| 11 | 10 |
| 12 promise_test(function(t) { | 11 promise_test(function(t) { |
| 13 var url = 'resources/empty_worker.js'; | 12 var url = 'resources/empty_worker.js'; |
| 14 var scope = 'resources/scope/background_sync/oneshot.html'; | 13 var scope = 'resources/scope/background_sync/oneshot.html'; |
| 15 var sync_manager; | 14 var sync_manager; |
| 16 var sync_registration; | 15 var sync_registration; |
| 17 | 16 |
| 18 // One-shot syncs can only be registered from a controlled document. This | 17 // One-shot syncs can only be registered from a controlled document. This |
|
jkarlin
2015/11/13 01:32:18
This comment needs to be updated as they can also
iclelland
2015/11/13 15:26:19
Yeah, that's an old comment. Fixed.
| |
| 19 // test creates a frame, after the service worker is active, in order to use | 18 // test creates a frame, after the service worker is active, in order to use |
| 20 // its service worker registration. | 19 // its service worker registration. |
| 21 return service_worker_unregister_and_register(t, url, scope) | 20 return service_worker_unregister_and_register(t, url, scope) |
| 22 .then(function(sw_registration_page) { | 21 .then(function(sw_registration_page) { |
| 23 return wait_for_state(t, sw_registration_page.installing, 'activated'); | 22 return wait_for_state(t, sw_registration_page.installing, 'activated'); |
| 24 }) | 23 }) |
| 25 .then(function() { | 24 .then(function() { |
| 26 return with_iframe(scope) | 25 return with_iframe(scope) |
| 27 }) | 26 }) |
| 28 .then(function(frame) { | 27 .then(function(frame) { |
| 29 var w = frame.contentWindow; | 28 var w = frame.contentWindow; |
| 30 return w.navigator.serviceWorker.getRegistration(scope); | 29 return w.navigator.serviceWorker.getRegistration(scope); |
| 31 }) | 30 }) |
| 32 .then(function(sw_registration_frame) { | 31 .then(function(sw_registration_frame) { |
| 33 sync_manager = sw_registration_frame.sync; | 32 sync_manager = sw_registration_frame.sync; |
| 34 return clear_registered_syncs(sync_manager); | 33 return sync_manager.getTags(); |
| 35 }) | 34 }) |
| 36 .then(function() { return sync_manager.getRegistrations(); }) | 35 .then(function(tags) { |
| 37 .then(function(registrations) { | 36 assert_equals(tags.length, 0, 'One-shot syncs should be ' + |
| 38 assert_equals(registrations.length, 0, 'One-shot syncs should be ' + | |
| 39 'cleared at the start of the test.'); | 37 'cleared at the start of the test.'); |
| 40 return sync_manager.register({tag: 'abcde'}); | 38 return sync_manager.register('abcde'); |
| 41 }) | 39 }) |
| 42 .then(function(registration) { | 40 .then(function() { |
| 43 sync_registration = registration; | |
| 44 assert_class_string(sync_registration, 'SyncRegistration', 'One-' + | |
| 45 'shot sync registrations should have the correct ' + | |
| 46 'class name.'); | |
| 47 assert_equals('abcde', registration.tag, 'Sync registration tag ' + | |
| 48 'returned should match the tag registered.'); | |
| 49 return service_worker_unregister(t, scope); | 41 return service_worker_unregister(t, scope); |
| 50 }); | 42 }); |
| 51 }, 'Background Sync API should allow one-shot syncs to be registered from ' + | 43 }, 'Background Sync API should allow one-shot syncs to be registered from ' + |
| 52 'the Document scope'); | 44 'the Document scope'); |
| 53 | 45 |
| 54 promise_test(function(t) { | 46 promise_test(function(t) { |
| 55 var url = 'resources/empty_worker.js'; | 47 var url = 'resources/empty_worker.js'; |
| 56 var scope = 'resources/scope/background_sync/oneshot-uncontrolled.html'; | 48 var scope = 'resources/scope/background_sync/oneshot-uncontrolled.html'; |
| 57 var sync_manager; | 49 var sync_manager; |
| 58 var sync_registration; | 50 var sync_registration; |
| 59 | 51 |
| 60 // One-shot syncs can also be registered from uncontrolled documents. This | 52 // One-shot syncs can also be registered from uncontrolled documents. This |
| 61 // test creates a frame, after the service worker is active, in order to use | 53 // test creates a frame, after the service worker is active, in order to use |
| 62 // its service worker registration. | 54 // its service worker registration. |
| 63 return service_worker_unregister_and_register(t, url, scope) | 55 return service_worker_unregister_and_register(t, url, scope) |
| 64 .then(function(sw_registration) { | 56 .then(function(sw_registration) { |
| 65 sync_manager = sw_registration.sync; | 57 sync_manager = sw_registration.sync; |
| 66 return wait_for_state(t, sw_registration.installing, 'activated'); | 58 return wait_for_state(t, sw_registration.installing, 'activated'); |
| 67 }) | 59 }) |
| 68 .then(function() { return clear_registered_syncs(sync_manager); }) | 60 .then(function() { return sync_manager.getTags(); }) |
| 69 .then(function() { return sync_manager.getRegistrations(); }) | 61 .then(function(tags) { |
| 70 .then(function(registrations) { | 62 assert_equals(tags.length, 0, 'One-shot syncs should be ' + |
| 71 assert_equals(registrations.length, 0, 'One-shot syncs should be ' + | |
| 72 'cleared at the start of the test.'); | 63 'cleared at the start of the test.'); |
| 73 return sync_manager.register({tag: 'abcde'}); | 64 return sync_manager.register('abcde'); |
| 74 }) | 65 }) |
| 75 .then(function(registration) { | 66 .then(function() { |
| 76 sync_registration = registration; | |
| 77 assert_class_string(sync_registration, 'SyncRegistration', 'One-' + | |
| 78 'shot sync registrations should have the correct ' + | |
| 79 'class name.'); | |
| 80 assert_equals('abcde', registration.tag, 'Sync registration tag ' + | |
| 81 'returned should match the tag registered.'); | |
| 82 return service_worker_unregister(t, scope); | 67 return service_worker_unregister(t, scope); |
| 83 }) | 68 }) |
| 84 .then(function() { return service_worker_unregister(t, scope); }) | |
| 85 }, 'Background Sync API should allow one-shot syncs to be registered ' + | 69 }, 'Background Sync API should allow one-shot syncs to be registered ' + |
| 86 'with window clients not currently controlled by service worker'); | 70 'with window clients not currently controlled by service worker'); |
| 87 </script> | 71 </script> |
| OLD | NEW |