Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/registration-iframe.https.html

Issue 2691903005: ServiceWorker: Change base URL for parsing script URL and scope URL (Closed)
Patch Set: Address comments on tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 9 // Set script url and scope url relative to the iframe's document's url. Assert
10 // 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 var url = 'resources/blank.html';
13 var scope = 'resources/registration-for-iframe-from-calling-frame'; 13 var scope = 'registration-for-iframe-from-parent-frame';
14 var parsed_scope = normalizeURL(scope); 14 var expected_scope = normalizeURL('resources/' + scope);
15 var script = 'resources/empty-worker.js'; 15 var script = 'empty-worker.js';
16 var parsed_script = normalizeURL(script); 16 var expected_script = normalizeURL('resources/' + 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 script,
26 { scope: scope }); 26 { scope: 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( 33 assert_equals(registration.scope, expected_scope,
34 registration.scope, parsed_scope, 34 'registration\'s scope must be parsed against the ' +
35 'registration\'s scope must be the scope parsed against calling ' + 35 '"relevant global object"');
36 'document\'s url'); 36 assert_equals(registration.active.scriptURL, expected_script,
37 assert_equals( 37 'worker\'s scriptURL must be parsed against the ' +
38 registration.active.scriptURL, parsed_script, 38 '"relevant global object"');
39 'worker\'s script must be the url parsed against calling ' +
40 'document\'s url');
41 frame.remove(); 39 frame.remove();
42 return service_worker_unregister_and_done(t, scope); 40 return service_worker_unregister_and_done(t, scope);
43 }) 41 })
44 .catch(unreached_rejection(t)); 42 .catch(unreached_rejection(t));
45 }, 'Subframe\'s container\'s register method should use calling frame\'s ' + 43 }, 'register method should use the "relevant global object" to parse its ' +
46 'document\'s url as a base url for parsing its script url and scope url ' + 44 'scriptURL and scope - normal case');
47 '- normal case');
48 45
49 // Set script url and scope url relative to the iframe's document's url. 46 // Set script url and scope url relative to the parent frame's document's url.
50 // Assert the implementation throws a NetworkError exception. 47 // Assert the implementation throws a TypeError exception.
51 async_test(function(t) { 48 async_test(function(t) {
52 var url = 'resources/blank.html'; 49 var url = 'resources/blank.html';
53 var scope = 'registration-for-iframe-from-calling-frame'; 50 var scope = 'resources/registration-for-iframe-from-parent-frame';
54 var script = 'empty-worker.js'; 51 var script = 'resources/empty-worker.js';
55 var frame; 52 var frame;
56 var registration; 53 var registration;
57 54
58 service_worker_unregister(t, scope) 55 service_worker_unregister(t, scope)
59 .then(function() { return with_iframe(url); }) 56 .then(function() { return with_iframe(url); })
60 .then(function(f) { 57 .then(function(f) {
61 frame = f; 58 frame = f;
62 return frame.contentWindow.navigator.serviceWorker.register( 59 return frame.contentWindow.navigator.serviceWorker.register(
63 script, 60 script,
64 { scope: scope }); 61 { scope: scope });
65 }) 62 })
66 .then( 63 .then(
67 function() { 64 function() {
68 assert_unreached('register() should reject'); 65 assert_unreached('register() should reject');
69 }, 66 },
70 function(e) { 67 function(e) {
71 assert_equals(e.name, 'TypeError'); 68 assert_equals(e.name, 'TypeError',
69 'register method with scriptURL and scope parsed to ' +
70 'nonexistent location should reject with TypeError');
72 frame.remove(); 71 frame.remove();
73 return service_worker_unregister_and_done(t, scope); 72 return service_worker_unregister_and_done(t, scope);
74 }) 73 })
75 .catch(unreached_rejection(t)); 74 .catch(unreached_rejection(t));
76 }, 'Subframe\'s container\'s register method should use calling frame\'s ' + 75 }, 'register method should use the "relevant global object" to parse its ' +
77 'document\'s url as a base url for parsing its script url and scope url ' + 76 'scriptURL and scope - error case');
78 '- error case');
79 77
80 // Set the scope url to a non-subdirectory of the script url. 78 // Set the scope url to a non-subdirectory of the script url. Assert the
81 // Assert the implementation throws a SecurityError exception. 79 // implementation throws a SecurityError exception.
82 async_test(function(t) { 80 async_test(function(t) {
83 var url = 'resources/blank.html'; 81 var url = 'resources/blank.html';
84 var scope = 'registration-for-iframe-from-calling-frame'; 82 var scope = '../registration-for-iframe-from-parent-frame';
85 var script = 'resources/empty-worker.js'; 83 var script = 'empty-worker.js';
86 var frame; 84 var frame;
87 var registration; 85 var registration;
88 86
89 service_worker_unregister(t, scope) 87 service_worker_unregister(t, scope)
90 .then(function() { return with_iframe(url); }) 88 .then(function() { return with_iframe(url); })
91 .then(function(f) { 89 .then(function(f) {
92 frame = f; 90 frame = f;
93 return frame.contentWindow.navigator.serviceWorker.register( 91 return frame.contentWindow.navigator.serviceWorker.register(
94 script, 92 script,
95 { scope: scope }); 93 { scope: scope });
96 }) 94 })
97 .then( 95 .then(
98 function() { 96 function() {
99 assert_unreached('register() should reject'); 97 assert_unreached('register() should reject');
100 }, 98 },
101 function(e) { 99 function(e) {
102 assert_equals(e.name, 'SecurityError'); 100 assert_equals(e.name, 'SecurityError',
101 'The scope set to a non-subdirectory of the scriptURL ' +
102 'should reject with SecurityError');
103 frame.remove(); 103 frame.remove();
104 return service_worker_unregister_and_done(t, scope); 104 return service_worker_unregister_and_done(t, scope);
105 }) 105 })
106 .catch(unreached_rejection(t)); 106 .catch(unreached_rejection(t));
107 }, 'A scope url should start with the given script url'); 107 }, 'A scope url should start with the given script url');
108
108 </script> 109 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698