Chromium Code Reviews| 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 // Set script url and scope url relative to the calling frame's document's url. | 8 |
| 9 // Assert the implementation parses the urls against the calling frame's | |
| 10 // document's url. | |
|
falken
2017/02/24 06:49:27
I actually liked these comments explaining each te
jungkees
2017/02/24 12:25:26
Okay. I thought it was a bit redundant to the test
| |
| 11 async_test(function(t) { | 9 async_test(function(t) { |
| 12 var url = 'resources/blank.html'; | 10 var url = 'resources/blank.html'; |
| 13 var scope = 'resources/registration-for-iframe-from-calling-frame'; | 11 var scope = 'registration-for-iframe-from-parent-frame'; |
| 14 var parsed_scope = normalizeURL(scope); | 12 var expected_scope = normalizeURL('resources/' + scope); |
| 15 var script = 'resources/empty-worker.js'; | 13 var script = 'empty-worker.js'; |
| 16 var parsed_script = normalizeURL(script); | 14 var expected_script = normalizeURL('resources/' + script); |
| 17 var frame; | 15 var frame; |
| 18 var registration; | 16 var registration; |
| 19 | 17 |
| 20 service_worker_unregister(t, scope) | 18 service_worker_unregister(t, scope) |
| 21 .then(function() { return with_iframe(url); }) | 19 .then(function() { return with_iframe(url); }) |
| 22 .then(function(f) { | 20 .then(function(f) { |
| 23 frame = f; | 21 frame = f; |
| 24 return frame.contentWindow.navigator.serviceWorker.register( | 22 return frame.contentWindow.navigator.serviceWorker.register( |
| 25 script, | 23 script, |
| 26 { scope: scope }); | 24 { scope: scope }); |
| 27 }) | 25 }) |
| 28 .then(function(r) { | 26 .then(function(r) { |
| 29 registration = r; | 27 registration = r; |
| 30 return wait_for_state(t, r.installing, 'activated'); | 28 return wait_for_state(t, r.installing, 'activated'); |
| 31 }) | 29 }) |
| 32 .then(function() { | 30 .then(function() { |
| 33 assert_equals( | 31 assert_equals( |
| 34 registration.scope, parsed_scope, | 32 registration.scope, expected_scope, |
| 35 'registration\'s scope must be the scope parsed against calling ' + | 33 'registration\'s scope must be parsed against relevant global'); |
| 36 'document\'s url'); | |
| 37 assert_equals( | 34 assert_equals( |
| 38 registration.active.scriptURL, parsed_script, | 35 registration.active.scriptURL, expected_script, |
| 39 'worker\'s script must be the url parsed against calling ' + | 36 'worker\'s scriptURL must be parsed against relevant global'); |
| 40 'document\'s url'); | |
| 41 frame.remove(); | 37 frame.remove(); |
| 42 return service_worker_unregister_and_done(t, scope); | 38 return service_worker_unregister_and_done(t, scope); |
| 43 }) | 39 }) |
| 44 .catch(unreached_rejection(t)); | 40 .catch(unreached_rejection(t)); |
| 45 }, 'Subframe\'s container\'s register method should use calling frame\'s ' + | 41 }, 'register method should use relevant global to parse its scriptURL and ' + |
| 46 'document\'s url as a base url for parsing its script url and scope url ' + | 42 'scope - normal case'); |
|
falken
2017/02/24 06:49:27
maybe s/relevant global/the "relevant global objec
jungkees
2017/02/24 12:25:26
Yes. Addressed.
| |
| 47 '- normal case'); | |
| 48 | 43 |
| 49 // Set script url and scope url relative to the iframe's document's url. | |
| 50 // Assert the implementation throws a NetworkError exception. | |
| 51 async_test(function(t) { | 44 async_test(function(t) { |
| 52 var url = 'resources/blank.html'; | 45 var url = 'resources/blank.html'; |
| 53 var scope = 'registration-for-iframe-from-calling-frame'; | 46 var scope = 'resources/registration-for-iframe-from-parent-frame'; |
| 54 var script = 'empty-worker.js'; | 47 var script = 'resources/empty-worker.js'; |
| 55 var frame; | 48 var frame; |
| 56 var registration; | 49 var registration; |
| 57 | 50 |
| 58 service_worker_unregister(t, scope) | 51 service_worker_unregister(t, scope) |
| 59 .then(function() { return with_iframe(url); }) | 52 .then(function() { return with_iframe(url); }) |
| 60 .then(function(f) { | 53 .then(function(f) { |
| 61 frame = f; | 54 frame = f; |
| 62 return frame.contentWindow.navigator.serviceWorker.register( | 55 return frame.contentWindow.navigator.serviceWorker.register( |
| 63 script, | 56 script, |
| 64 { scope: scope }); | 57 { scope: scope }); |
| 65 }) | 58 }) |
| 66 .then( | 59 .then( |
| 67 function() { | 60 function() { |
| 68 assert_unreached('register() should reject'); | 61 assert_unreached('register() should reject'); |
| 69 }, | 62 }, |
| 70 function(e) { | 63 function(e) { |
| 71 assert_equals(e.name, 'TypeError'); | 64 assert_equals(e.name, 'TypeError', |
| 65 'register method with scriptURL and scope parsed to ' + | |
| 66 'nonexistent location should reject with TypeError'); | |
| 72 frame.remove(); | 67 frame.remove(); |
| 73 return service_worker_unregister_and_done(t, scope); | 68 return service_worker_unregister_and_done(t, scope); |
| 74 }) | 69 }) |
| 75 .catch(unreached_rejection(t)); | 70 .catch(unreached_rejection(t)); |
| 76 }, 'Subframe\'s container\'s register method should use calling frame\'s ' + | 71 }, 'register method should use relevant global to parse its scriptURL and ' + |
| 77 'document\'s url as a base url for parsing its script url and scope url ' + | 72 'scope - error case'); |
|
falken
2017/02/24 06:49:27
ditto
jungkees
2017/02/24 12:25:26
Done.
| |
| 78 '- error case'); | |
| 79 | 73 |
| 80 // Set the scope url to a non-subdirectory of the script url. | |
| 81 // Assert the implementation throws a SecurityError exception. | |
| 82 async_test(function(t) { | 74 async_test(function(t) { |
| 83 var url = 'resources/blank.html'; | 75 var url = 'resources/blank.html'; |
| 84 var scope = 'registration-for-iframe-from-calling-frame'; | 76 var scope = '../registration-for-iframe-from-parent-frame'; |
| 85 var script = 'resources/empty-worker.js'; | 77 var script = 'empty-worker.js'; |
| 86 var frame; | 78 var frame; |
| 87 var registration; | 79 var registration; |
| 88 | 80 |
| 89 service_worker_unregister(t, scope) | 81 service_worker_unregister(t, scope) |
| 90 .then(function() { return with_iframe(url); }) | 82 .then(function() { return with_iframe(url); }) |
| 91 .then(function(f) { | 83 .then(function(f) { |
| 92 frame = f; | 84 frame = f; |
| 93 return frame.contentWindow.navigator.serviceWorker.register( | 85 return frame.contentWindow.navigator.serviceWorker.register( |
| 94 script, | 86 script, |
| 95 { scope: scope }); | 87 { scope: scope }); |
| 96 }) | 88 }) |
| 97 .then( | 89 .then( |
| 98 function() { | 90 function() { |
| 99 assert_unreached('register() should reject'); | 91 assert_unreached('register() should reject'); |
| 100 }, | 92 }, |
| 101 function(e) { | 93 function(e) { |
| 102 assert_equals(e.name, 'SecurityError'); | 94 assert_equals(e.name, 'SecurityError', |
| 95 'The scope set to a non-subdirectory of the scriptURL ' + | |
| 96 'should reject with SecurityError'); | |
| 103 frame.remove(); | 97 frame.remove(); |
| 104 return service_worker_unregister_and_done(t, scope); | 98 return service_worker_unregister_and_done(t, scope); |
| 105 }) | 99 }) |
| 106 .catch(unreached_rejection(t)); | 100 .catch(unreached_rejection(t)); |
| 107 }, 'A scope url should start with the given script url'); | 101 }, 'A scope url should start with the given script url'); |
| 102 | |
| 108 </script> | 103 </script> |
| OLD | NEW |