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/permissions-helper.js"></script> | 5 <script src="../resources/permissions-helper.js"></script> |
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 <script> | 9 <script> |
10 | 10 |
11 promise_test(function(t) { | 11 promise_test(function(t) { |
12 var url = 'resources/empty_worker.js'; | 12 const url = 'resources/empty_worker.js'; |
13 var scope = 'resources/scope/background_sync/oneshot.html'; | 13 const iframe_scope = 'oneshot.html'; |
| 14 const scope = 'resources/scope/background_sync/' + iframe_scope; |
14 var sync_manager; | 15 var sync_manager; |
15 var sync_registration; | |
16 | 16 |
17 // This test verifies that registration of one-shots fails from an iframe. | 17 // This test verifies that registration of one-shots fails from an iframe. |
18 return PermissionsHelper.setPermission('background-sync', 'granted') | 18 return PermissionsHelper.setPermission('background-sync', 'granted') |
19 .then(function() { | 19 .then(function() { |
20 return service_worker_unregister_and_register(t, url, scope); | 20 return service_worker_unregister_and_register(t, url, scope); |
21 }) | 21 }) |
22 .then(function(sw_registration_page) { | 22 .then(function(sw_registration_page) { |
23 return wait_for_state(t, sw_registration_page.installing, 'activated'); | 23 return wait_for_state(t, sw_registration_page.installing, 'activated'); |
24 }) | 24 }) |
25 .then(function() { | 25 .then(function() { |
26 return with_iframe(scope) | 26 return with_iframe(scope) |
27 }) | 27 }) |
28 .then(function(frame) { | 28 .then(function(frame) { |
29 var w = frame.contentWindow; | 29 var w = frame.contentWindow; |
30 return w.navigator.serviceWorker.getRegistration(scope); | 30 return w.navigator.serviceWorker.getRegistration(iframe_scope); |
31 }) | 31 }) |
32 .then(function(sw_registration_frame) { | 32 .then(function(sw_registration_frame) { |
33 sync_manager = sw_registration_frame.sync; | 33 sync_manager = sw_registration_frame.sync; |
34 return sync_manager.getTags(); | 34 return sync_manager.getTags(); |
35 }) | 35 }) |
36 .then(function(tags) { | 36 .then(function(tags) { |
37 assert_equals(tags.length, 0, 'One-shot syncs should be ' + | 37 assert_equals(tags.length, 0, 'One-shot syncs should be ' + |
38 'cleared at the start of the test.'); | 38 'cleared at the start of the test.'); |
39 return sync_manager.register('iframe-oneshot'); | 39 return sync_manager.register('iframe-oneshot'); |
40 }) | 40 }) |
41 .then(function() { | 41 .then(function() { |
42 return service_worker_unregister(t, scope); | 42 return service_worker_unregister(t, scope); |
43 }); | 43 }); |
44 }, 'Background Sync API should allow one-shot syncs to be registered ' + | 44 }, 'Background Sync API should allow one-shot syncs to be registered ' + |
45 'from an iframe'); | 45 'from an iframe'); |
46 | 46 |
47 promise_test(function(t) { | 47 promise_test(function(t) { |
48 var url = 'resources/empty_worker.js'; | 48 const url = 'resources/empty_worker.js'; |
49 var scope = 'resources/scope/background_sync/oneshot-uncontrolled.html'; | 49 const scope = 'resources/scope/background_sync/oneshot-uncontrolled.html'; |
50 var sync_manager; | 50 var sync_manager; |
51 var sync_registration; | |
52 | 51 |
53 // This test verifies that one-shot syncs can be registered from uncontrolled | 52 // This test verifies that one-shot syncs can be registered from uncontrolled |
54 // documents. | 53 // documents. |
55 return PermissionsHelper.setPermission('background-sync', 'granted') | 54 return PermissionsHelper.setPermission('background-sync', 'granted') |
56 .then(function() { | 55 .then(function() { |
57 return service_worker_unregister_and_register(t, url, scope); | 56 return service_worker_unregister_and_register(t, url, scope); |
58 }) | 57 }) |
59 .then(function(sw_registration) { | 58 .then(function(sw_registration) { |
60 sync_manager = sw_registration.sync; | 59 sync_manager = sw_registration.sync; |
61 return wait_for_state(t, sw_registration.installing, 'activated'); | 60 return wait_for_state(t, sw_registration.installing, 'activated'); |
62 }) | 61 }) |
63 .then(function() { return sync_manager.getTags(); }) | 62 .then(function() { return sync_manager.getTags(); }) |
64 .then(function(tags) { | 63 .then(function(tags) { |
65 assert_equals(tags.length, 0, 'One-shot syncs should be ' + | 64 assert_equals(tags.length, 0, 'One-shot syncs should be ' + |
66 'cleared at the start of the test.'); | 65 'cleared at the start of the test.'); |
67 return sync_manager.register('abcde'); | 66 return sync_manager.register('abcde'); |
68 }) | 67 }) |
69 .then(function() { | 68 .then(function() { |
70 return service_worker_unregister(t, scope); | 69 return service_worker_unregister(t, scope); |
71 }) | 70 }) |
72 }, 'Background Sync API should allow one-shot syncs to be registered ' + | 71 }, 'Background Sync API should allow one-shot syncs to be registered ' + |
73 'from an uncontrolled main-frame document'); | 72 'from an uncontrolled main-frame document'); |
74 </script> | 73 </script> |
OLD | NEW |