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-for-iframe-from-parent-frame'; |
falken
2017/03/07 05:00:19
let's make it so the three tests don't all use the
jungkees
2017/03/07 07:02:03
Understood your point. Addressed.
| |
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 frame.remove(); | 39 frame.remove(); |
40 return service_worker_unregister_and_done(t, scope); | 40 return service_worker_unregister_and_done(t, scope); |
falken
2017/03/07 05:00:19
Instead of unregister_and_done, how about we just
jungkees
2017/03/07 07:02:03
While testing this proposed change, I noticed that
falken
2017/03/07 07:11:47
Interesting. This could likely be resolved by:
r
jungkees
2017/03/07 07:26:27
Embarrassing ;) I missed that frame remove. The co
| |
41 }) | 41 }) |
42 .catch(unreached_rejection(t)); | 42 .catch(unreached_rejection(t)); |
43 }, 'register method should use the "relevant global object" to parse its ' + | 43 }, 'register method should use the "relevant global object" to parse its ' + |
44 'scriptURL and scope - normal case'); | 44 'scriptURL and scope - normal case'); |
45 | 45 |
46 // Set script url and scope url relative to the parent frame's document's url. | 46 // Set script url and scope url relative to the parent frame's document's url. |
47 // Assert the implementation throws a TypeError exception. | 47 // Assert the implementation throws a TypeError exception. |
48 async_test(function(t) { | 48 async_test(function(t) { |
49 var url = 'resources/blank.html'; | 49 const url = 'resources/blank.html'; |
50 var scope = 'resources/registration-for-iframe-from-parent-frame'; | 50 const iframe_scope = 'resources/registration-for-iframe-from-parent-frame'; |
51 var script = 'resources/empty-worker.js'; | 51 const scope = normalizeURL('resources/' + iframe_scope); |
52 const script = 'resources/empty-worker.js'; | |
52 var frame; | 53 var frame; |
53 var registration; | 54 var registration; |
54 | 55 |
55 service_worker_unregister(t, scope) | 56 service_worker_unregister(t, scope) |
56 .then(function() { return with_iframe(url); }) | 57 .then(function() { return with_iframe(url); }) |
57 .then(function(f) { | 58 .then(function(f) { |
58 frame = f; | 59 frame = f; |
59 return frame.contentWindow.navigator.serviceWorker.register( | 60 return frame.contentWindow.navigator.serviceWorker.register( |
60 script, | 61 script, |
61 { scope: scope }); | 62 { scope: iframe_scope }); |
62 }) | 63 }) |
63 .then( | 64 .then( |
64 function() { | 65 function() { |
65 assert_unreached('register() should reject'); | 66 assert_unreached('register() should reject'); |
66 }, | 67 }, |
67 function(e) { | 68 function(e) { |
68 assert_equals(e.name, 'TypeError', | 69 assert_equals(e.name, 'TypeError', |
69 'register method with scriptURL and scope parsed to ' + | 70 'register method with scriptURL and scope parsed to ' + |
70 'nonexistent location should reject with TypeError'); | 71 'nonexistent location should reject with TypeError'); |
71 frame.remove(); | 72 frame.remove(); |
72 return service_worker_unregister_and_done(t, scope); | 73 return service_worker_unregister_and_done(t, scope); |
falken
2017/03/07 05:00:19
let's just call t.done() since there is no registr
jungkees
2017/03/07 07:02:03
Done.
| |
73 }) | 74 }) |
74 .catch(unreached_rejection(t)); | 75 .catch(unreached_rejection(t)); |
75 }, 'register method should use the "relevant global object" to parse its ' + | 76 }, 'register method should use the "relevant global object" to parse its ' + |
76 'scriptURL and scope - error case'); | 77 'scriptURL and scope - error case'); |
77 | 78 |
78 // Set the scope url to a non-subdirectory of the script url. Assert the | 79 // Set the scope url to a non-subdirectory of the script url. Assert the |
79 // implementation throws a SecurityError exception. | 80 // implementation throws a SecurityError exception. |
80 async_test(function(t) { | 81 async_test(function(t) { |
81 var url = 'resources/blank.html'; | 82 const url = 'resources/blank.html'; |
82 var scope = '../registration-for-iframe-from-parent-frame'; | 83 const scope = 'registration-for-iframe-from-parent-frame'; |
83 var script = 'empty-worker.js'; | 84 const iframe_scope = '../' + scope; |
85 const script = 'empty-worker.js'; | |
84 var frame; | 86 var frame; |
85 var registration; | 87 var registration; |
86 | 88 |
87 service_worker_unregister(t, scope) | 89 service_worker_unregister(t, scope) |
88 .then(function() { return with_iframe(url); }) | 90 .then(function() { return with_iframe(url); }) |
89 .then(function(f) { | 91 .then(function(f) { |
90 frame = f; | 92 frame = f; |
91 return frame.contentWindow.navigator.serviceWorker.register( | 93 return frame.contentWindow.navigator.serviceWorker.register( |
92 script, | 94 script, |
93 { scope: scope }); | 95 { scope: iframe_scope }); |
94 }) | 96 }) |
95 .then( | 97 .then( |
96 function() { | 98 function() { |
97 assert_unreached('register() should reject'); | 99 assert_unreached('register() should reject'); |
98 }, | 100 }, |
99 function(e) { | 101 function(e) { |
100 assert_equals(e.name, 'SecurityError', | 102 assert_equals(e.name, 'SecurityError', |
101 'The scope set to a non-subdirectory of the scriptURL ' + | 103 'The scope set to a non-subdirectory of the scriptURL ' + |
102 'should reject with SecurityError'); | 104 'should reject with SecurityError'); |
103 frame.remove(); | 105 frame.remove(); |
104 return service_worker_unregister_and_done(t, scope); | 106 return service_worker_unregister_and_done(t, scope); |
falken
2017/03/07 05:00:19
let's just call t.done()
jungkees
2017/03/07 07:02:03
Done.
| |
105 }) | 107 }) |
106 .catch(unreached_rejection(t)); | 108 .catch(unreached_rejection(t)); |
107 }, 'A scope url should start with the given script url'); | 109 }, 'A scope url should start with the given script url'); |
108 | 110 |
109 </script> | 111 </script> |
OLD | NEW |