OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <meta charset="utf-8"> | 2 <meta charset="utf-8"> |
3 <title>Service Worker: Registration for iframe</title> | 3 <title>Service Worker: Registration for iframe</title> |
4 <script src="/resources/testharness.js"></script> | 4 <script src="/resources/testharness.js"></script> |
5 <script src="/resources/testharnessreport.js"></script> | 5 <script src="/resources/testharnessreport.js"></script> |
6 <script src="resources/test-helpers.sub.js"></script> | 6 <script src="resources/test-helpers.sub.js"></script> |
7 <script> | 7 <script> |
8 | 8 |
9 // Set script url and scope url relative to the iframe's document's url. Assert | 9 // Set script url and scope url relative to the iframe's document's url. Assert |
10 // the implementation parses the urls against the iframe's document's url. | 10 // the implementation parses the urls against the iframe's document's url. |
11 async_test(function(t) { | 11 async_test(function(t) { |
12 var url = 'resources/blank.html'; | 12 const url = 'resources/blank.html'; |
13 var scope = 'registration-for-iframe-from-parent-frame'; | 13 const iframe_scope = 'registration-with-valid-scope'; |
14 var expected_scope = normalizeURL('resources/' + scope); | 14 const scope = normalizeURL('resources/' + iframe_scope); |
15 var script = 'empty-worker.js'; | 15 const iframe_script = 'empty-worker.js'; |
16 var expected_script = normalizeURL('resources/' + script); | 16 const script = normalizeURL('resources/' + iframe_script); |
17 var frame; | 17 var frame; |
18 var registration; | 18 var registration; |
19 | 19 |
20 service_worker_unregister(t, scope) | 20 service_worker_unregister(t, scope) |
21 .then(function() { return with_iframe(url); }) | 21 .then(function() { return with_iframe(url); }) |
22 .then(function(f) { | 22 .then(function(f) { |
23 frame = f; | 23 frame = f; |
24 return frame.contentWindow.navigator.serviceWorker.register( | 24 return frame.contentWindow.navigator.serviceWorker.register( |
25 script, | 25 iframe_script, |
26 { scope: scope }); | 26 { scope: iframe_scope }); |
27 }) | 27 }) |
28 .then(function(r) { | 28 .then(function(r) { |
29 registration = r; | 29 registration = r; |
30 return wait_for_state(t, r.installing, 'activated'); | 30 return wait_for_state(t, r.installing, 'activated'); |
31 }) | 31 }) |
32 .then(function() { | 32 .then(function() { |
33 assert_equals(registration.scope, expected_scope, | 33 assert_equals(registration.scope, scope, |
34 'registration\'s scope must be parsed against the ' + | 34 'registration\'s scope must be parsed against the ' + |
35 '"relevant global object"'); | 35 '"relevant global object"'); |
36 assert_equals(registration.active.scriptURL, expected_script, | 36 assert_equals(registration.active.scriptURL, script, |
37 'worker\'s scriptURL must be parsed against the ' + | 37 'worker\'s scriptURL must be parsed against the ' + |
38 '"relevant global object"'); | 38 '"relevant global object"'); |
| 39 return registration.unregister(); |
| 40 }) |
| 41 .then(function() { |
39 frame.remove(); | 42 frame.remove(); |
40 return service_worker_unregister_and_done(t, scope); | 43 t.done(); |
41 }) | 44 }) |
42 .catch(unreached_rejection(t)); | 45 .catch(unreached_rejection(t)); |
43 }, 'register method should use the "relevant global object" to parse its ' + | 46 }, 'register method should use the "relevant global object" to parse its ' + |
44 'scriptURL and scope - normal case'); | 47 'scriptURL and scope - normal case'); |
45 | 48 |
46 // Set script url and scope url relative to the parent frame's document's url. | 49 // Set script url and scope url relative to the parent frame's document's url. |
47 // Assert the implementation throws a TypeError exception. | 50 // Assert the implementation throws a TypeError exception. |
48 async_test(function(t) { | 51 async_test(function(t) { |
49 var url = 'resources/blank.html'; | 52 const url = 'resources/blank.html'; |
50 var scope = 'resources/registration-for-iframe-from-parent-frame'; | 53 const iframe_scope = 'resources/registration-with-scope-to-non-existing-url'; |
51 var script = 'resources/empty-worker.js'; | 54 const scope = normalizeURL('resources/' + iframe_scope); |
| 55 const script = 'resources/empty-worker.js'; |
52 var frame; | 56 var frame; |
53 var registration; | 57 var registration; |
54 | 58 |
55 service_worker_unregister(t, scope) | 59 service_worker_unregister(t, scope) |
56 .then(function() { return with_iframe(url); }) | 60 .then(function() { return with_iframe(url); }) |
57 .then(function(f) { | 61 .then(function(f) { |
58 frame = f; | 62 frame = f; |
59 return frame.contentWindow.navigator.serviceWorker.register( | 63 return frame.contentWindow.navigator.serviceWorker.register( |
60 script, | 64 script, |
61 { scope: scope }); | 65 { scope: iframe_scope }); |
62 }) | 66 }) |
63 .then( | 67 .then( |
64 function() { | 68 function() { |
65 assert_unreached('register() should reject'); | 69 assert_unreached('register() should reject'); |
66 }, | 70 }, |
67 function(e) { | 71 function(e) { |
68 assert_equals(e.name, 'TypeError', | 72 assert_equals(e.name, 'TypeError', |
69 'register method with scriptURL and scope parsed to ' + | 73 'register method with scriptURL and scope parsed to ' + |
70 'nonexistent location should reject with TypeError'); | 74 'nonexistent location should reject with TypeError'); |
71 frame.remove(); | 75 frame.remove(); |
72 return service_worker_unregister_and_done(t, scope); | 76 t.done(); |
73 }) | 77 }) |
74 .catch(unreached_rejection(t)); | 78 .catch(unreached_rejection(t)); |
75 }, 'register method should use the "relevant global object" to parse its ' + | 79 }, 'register method should use the "relevant global object" to parse its ' + |
76 'scriptURL and scope - error case'); | 80 'scriptURL and scope - error case'); |
77 | 81 |
78 // Set the scope url to a non-subdirectory of the script url. Assert the | 82 // Set the scope url to a non-subdirectory of the script url. Assert the |
79 // implementation throws a SecurityError exception. | 83 // implementation throws a SecurityError exception. |
80 async_test(function(t) { | 84 async_test(function(t) { |
81 var url = 'resources/blank.html'; | 85 const url = 'resources/blank.html'; |
82 var scope = '../registration-for-iframe-from-parent-frame'; | 86 const scope = 'registration-with-disallowed-scope'; |
83 var script = 'empty-worker.js'; | 87 const iframe_scope = '../' + scope; |
| 88 const script = 'empty-worker.js'; |
84 var frame; | 89 var frame; |
85 var registration; | 90 var registration; |
86 | 91 |
87 service_worker_unregister(t, scope) | 92 service_worker_unregister(t, scope) |
88 .then(function() { return with_iframe(url); }) | 93 .then(function() { return with_iframe(url); }) |
89 .then(function(f) { | 94 .then(function(f) { |
90 frame = f; | 95 frame = f; |
91 return frame.contentWindow.navigator.serviceWorker.register( | 96 return frame.contentWindow.navigator.serviceWorker.register( |
92 script, | 97 script, |
93 { scope: scope }); | 98 { scope: iframe_scope }); |
94 }) | 99 }) |
95 .then( | 100 .then( |
96 function() { | 101 function() { |
97 assert_unreached('register() should reject'); | 102 assert_unreached('register() should reject'); |
98 }, | 103 }, |
99 function(e) { | 104 function(e) { |
100 assert_equals(e.name, 'SecurityError', | 105 assert_equals(e.name, 'SecurityError', |
101 'The scope set to a non-subdirectory of the scriptURL ' + | 106 'The scope set to a non-subdirectory of the scriptURL ' + |
102 'should reject with SecurityError'); | 107 'should reject with SecurityError'); |
103 frame.remove(); | 108 frame.remove(); |
104 return service_worker_unregister_and_done(t, scope); | 109 t.done(); |
105 }) | 110 }) |
106 .catch(unreached_rejection(t)); | 111 .catch(unreached_rejection(t)); |
107 }, 'A scope url should start with the given script url'); | 112 }, 'A scope url should start with the given script url'); |
108 | 113 |
109 </script> | 114 </script> |
OLD | NEW |