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

Side by Side Diff: LayoutTests/http/tests/serviceworker/registration-iframe.html

Issue 835673006: Use caller's document url to resolve scriptURL/patternURL in registerServiceWorker/getRegistration (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address comments in registration-iframe.html Created 5 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
(Empty)
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>Service Worker: Registration for iframe</title>
4 <script src="../resources/testharness.js"></script>
5 <script src="../resources/testharnessreport.js"></script>
6 <script src="resources/test-helpers.js"></script>
7 <script>
8 // Set script url and scope url relative to the calling frame's document's url.
9 // Assert the implementation parses the urls against the calling frame's
10 // document's url.
11 async_test(function(t) {
12 var url = 'resources/blank.html';
13 var scope = 'resources/registration-for-iframe-from-calling-frame';
14 var parsed_scope = normalizeURL(scope);
15 var script = 'resources/empty-worker.js';
16 var parsed_script = normalizeURL(script);
17 var frame;
18 var registration;
19
20 service_worker_unregister(t, scope)
21 .then(function() { return with_iframe(url); })
22 .then(function(f) {
23 frame = f;
24 return frame.contentWindow.navigator.serviceWorker.register(
25 script,
26 { scope: scope });
27 })
28 .then(function(r) {
29 registration = r;
30 return wait_for_state(t, r.installing, 'activated');
31 })
32 .then(function() {
33 assert_equals(
34 registration.scope, parsed_scope,
35 'registration\'s scope must be the scope parsed against calling ' +
36 'document\'s url');
37 assert_equals(
38 registration.active.scriptURL, parsed_script,
39 'worker\'s script must be the url parsed against calling ' +
40 'document\'s url');
41 unload_iframe(frame);
42 return service_worker_unregister_and_done(t, scope);
43 })
44 .catch(unreached_rejection(t));
45 }, 'Subframe\'s container\'s register method should use calling frame\'s ' +
46 'document\'s url as a base url for parsing its script url and scope url ' +
47 '- normal case');
48
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) {
52 var url = 'resources/blank.html';
53 var scope = 'registration-for-iframe-from-calling-frame';
54 var script = 'empty-worker.js';
55 var frame;
56 var registration;
57
58 service_worker_unregister(t, scope)
59 .then(function() { return with_iframe(url); })
60 .then(function(f) {
61 frame = f;
62 return frame.contentWindow.navigator.serviceWorker.register(
63 script,
64 { scope: scope });
65 })
66 .then(
67 function() {
68 assert_unreached('register() should reject');
69 },
70 function(e) {
71 assert_equals(e.name, 'NetworkError');
72 unload_iframe(frame);
73 return service_worker_unregister_and_done(t, scope);
74 })
75 .catch(unreached_rejection(t));
76 }, 'Subframe\'s container\'s register method should use calling frame\'s ' +
77 'document\'s url as a base url for parsing its script url and scope url ' +
78 '- error case');
79
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) {
83 var url = 'resources/blank.html';
84 var scope = 'registration-for-iframe-from-calling-frame';
85 var script = 'resources/empty-worker.js';
86 var frame;
87 var registration;
88
89 service_worker_unregister(t, scope)
90 .then(function() { return with_iframe(url); })
91 .then(function(f) {
92 frame = f;
93 return frame.contentWindow.navigator.serviceWorker.register(
94 script,
95 { scope: scope });
96 })
97 .then(
98 function() {
99 assert_unreached('register() should reject');
100 },
101 function(e) {
102 assert_equals(e.name, 'SecurityError');
103 unload_iframe(frame);
104 return service_worker_unregister_and_done(t, scope);
105 })
106 .catch(unreached_rejection(t));
107 }, 'A scope url should start with the given script url');
108 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698