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> | 9 <script> |
10 | 10 |
11 promise_test(function(t) { | 11 promise_test(function(t) { |
12 var url = 'resources/empty_worker.js'; | 12 var url = 'resources/empty_worker.js'; |
13 var scope = 'resources/scope/background_sync/oneshot.html'; | 13 var scope = 'resources/scope/background_sync/oneshot.html'; |
14 var sync_manager; | 14 var sync_manager; |
15 var sync_registration; | 15 var sync_registration; |
16 | 16 |
17 // This test verifies that one-shot syncs can be registered from service- | 17 // This test verifies that registration of one-shots fails from an iframe. |
18 // worker-controlled documents. It creates a frame, after the service worker | |
19 // is active, in order to use its service worker registration. | |
20 return service_worker_unregister_and_register(t, url, scope) | 18 return service_worker_unregister_and_register(t, url, scope) |
21 .then(function(sw_registration_page) { | 19 .then(function(sw_registration_page) { |
22 return wait_for_state(t, sw_registration_page.installing, 'activated'); | 20 return wait_for_state(t, sw_registration_page.installing, 'activated'); |
23 }) | 21 }) |
24 .then(function() { | 22 .then(function() { |
25 return with_iframe(scope) | 23 return with_iframe(scope) |
26 }) | 24 }) |
27 .then(function(frame) { | 25 .then(function(frame) { |
28 var w = frame.contentWindow; | 26 var w = frame.contentWindow; |
29 return w.navigator.serviceWorker.getRegistration(scope); | 27 return w.navigator.serviceWorker.getRegistration(scope); |
30 }) | 28 }) |
31 .then(function(sw_registration_frame) { | 29 .then(function(sw_registration_frame) { |
32 sync_manager = sw_registration_frame.sync; | 30 sync_manager = sw_registration_frame.sync; |
33 return sync_manager.getTags(); | 31 return sync_manager.getTags(); |
34 }) | 32 }) |
35 .then(function(tags) { | 33 .then(function(tags) { |
36 assert_equals(tags.length, 0, 'One-shot syncs should be ' + | 34 assert_equals(tags.length, 0, 'One-shot syncs should be ' + |
37 'cleared at the start of the test.'); | 35 'cleared at the start of the test.'); |
38 return sync_manager.register('abcde'); | 36 return sync_manager.register('abcde'); |
39 }) | 37 }) |
40 .then(function() { | 38 .then(function() { |
41 return service_worker_unregister(t, scope); | 39 assert_unreached('iframes should not be able to register syncs'); |
| 40 }, function(e) { |
| 41 assert_equals(e.name, 'AbortError'); |
| 42 assert_equals(e.message, 'Registration failed - not called from a main f
rame.'); |
| 43 service_worker_unregister(t, scope); |
42 }); | 44 }); |
43 }, 'Background Sync API should allow one-shot syncs to be registered from ' + | 45 }, 'Background Sync should not allow registration from an iframe'); |
44 'the Document scope'); | |
45 | 46 |
46 promise_test(function(t) { | 47 promise_test(function(t) { |
47 var url = 'resources/empty_worker.js'; | 48 var url = 'resources/empty_worker.js'; |
48 var scope = 'resources/scope/background_sync/oneshot-uncontrolled.html'; | 49 var scope = 'resources/scope/background_sync/oneshot-uncontrolled.html'; |
49 var sync_manager; | 50 var sync_manager; |
50 var sync_registration; | 51 var sync_registration; |
51 | 52 |
52 // This test verifies that one-shot syncs can be registered from uncontrolled | 53 // This test verifies that one-shot syncs can be registered from uncontrolled |
53 // documents. | 54 // documents. |
54 return service_worker_unregister_and_register(t, url, scope) | 55 return service_worker_unregister_and_register(t, url, scope) |
55 .then(function(sw_registration) { | 56 .then(function(sw_registration) { |
56 sync_manager = sw_registration.sync; | 57 sync_manager = sw_registration.sync; |
57 return wait_for_state(t, sw_registration.installing, 'activated'); | 58 return wait_for_state(t, sw_registration.installing, 'activated'); |
58 }) | 59 }) |
59 .then(function() { return sync_manager.getTags(); }) | 60 .then(function() { return sync_manager.getTags(); }) |
60 .then(function(tags) { | 61 .then(function(tags) { |
61 assert_equals(tags.length, 0, 'One-shot syncs should be ' + | 62 assert_equals(tags.length, 0, 'One-shot syncs should be ' + |
62 'cleared at the start of the test.'); | 63 'cleared at the start of the test.'); |
63 return sync_manager.register('abcde'); | 64 return sync_manager.register('abcde'); |
64 }) | 65 }) |
65 .then(function() { | 66 .then(function() { |
66 return service_worker_unregister(t, scope); | 67 return service_worker_unregister(t, scope); |
67 }) | 68 }) |
68 }, 'Background Sync API should allow one-shot syncs to be registered ' + | 69 }, 'Background Sync API should allow one-shot syncs to be registered ' + |
69 'with window clients not currently controlled by service worker'); | 70 'from an uncontrolled main-frame document'); |
70 </script> | 71 </script> |
OLD | NEW |