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

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

Issue 2415873002: Import w3c tests for the service workers (Closed)
Patch Set: Rebase Created 4 years, 2 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 <title>Service Worker: Registration</title>
3 <script src="/resources/testharness.js"></script>
4 <script src="resources/testharness-helpers.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <script src="resources/test-helpers.sub.js"></script>
7 <script>
8
9 promise_test(function(t) {
10 var script = 'resources/registration-worker.js';
11 var scope = 'resources/registration/normal';
12 return navigator.serviceWorker.register(script, {scope: scope})
13 .then(function(registration) {
14 assert_true(registration instanceof ServiceWorkerRegistration,
15 'Successfully registered.');
16 service_worker_unregister_and_done(t, scope);
17 })
18 }, 'Registering normal scope');
19
20 promise_test(function(t) {
21 var script = 'resources/registration-worker.js';
22 var scope = 'resources/registration/scope-with-fragment#ref';
23 return navigator.serviceWorker.register(script, {scope: scope})
24 .then(function(registration) {
25 assert_true(
26 registration instanceof ServiceWorkerRegistration,
27 'Successfully registered.');
28 assert_equals(
29 registration.scope,
30 normalizeURL('resources/registration/scope-with-fragment'),
31 'A fragment should be removed from scope')
32 service_worker_unregister_and_done(t, scope);
33 })
34 }, 'Registering scope with fragment');
35
36 promise_test(function(t) {
37 var script = 'resources/registration-worker.js';
38 var scope = 'resources/';
39 return navigator.serviceWorker.register(script, {scope: scope})
40 .then(function(registration) {
41 assert_true(registration instanceof ServiceWorkerRegistration,
42 'Successfully registered.');
43 service_worker_unregister_and_done(t, scope);
44 })
45 }, 'Registering same scope as the script directory');
46
47 promise_test(function(t) {
48 var script = 'resources/registration-worker.js';
49 var scope = 'resources';
50 return assert_promise_rejects(
51 navigator.serviceWorker.register(script, {scope: scope}),
52 'SecurityError',
53 'Registering same scope as the script directory without the last ' +
54 'slash should fail with SecurityError.');
55 }, 'Registering same scope as the script directory without the last slash');
56
57 promise_test(function(t) {
58 var script = 'resources/registration-worker.js';
59 var scope = 'different-directory/';
60 return assert_promise_rejects(
61 navigator.serviceWorker.register(script, {scope: scope}),
62 'SecurityError',
63 'Registration scope outside the script directory should fail ' +
64 'with SecurityError.');
65 }, 'Registration scope outside the script directory');
66
67 promise_test(function(t) {
68 var script = 'resources/registration-worker.js';
69 var scope = 'http://example.com/';
70 return assert_promise_rejects(
71 navigator.serviceWorker.register(script, {scope: scope}),
72 'SecurityError',
73 'Registration scope outside domain should fail with SecurityError.');
74 }, 'Registering scope outside domain');
75
76 promise_test(function(t) {
77 var script = 'http://example.com/worker.js';
78 var scope = 'http://example.com/scope/';
79 return assert_promise_rejects(
80 navigator.serviceWorker.register(script, {scope: scope}),
81 'SecurityError',
82 'Registration script outside domain should fail with SecurityError.');
83 }, 'Registering script outside domain');
84
85 promise_test(function(t) {
86 var script = 'resources/no-such-worker.js';
87 var scope = 'resources/scope/no-such-worker';
88 return assert_promise_rejects(
89 navigator.serviceWorker.register(script, {scope: scope}),
90 new TypeError(),
91 'Registration of non-existent script should fail.');
92 }, 'Registering non-existent script');
93
94 promise_test(function(t) {
95 var script = 'resources/invalid-chunked-encoding.py';
96 var scope = 'resources/scope/invalid-chunked-encoding/';
97 return assert_promise_rejects(
98 navigator.serviceWorker.register(script, {scope: scope}),
99 new TypeError(),
100 'Registration of invalid chunked encoding script should fail.');
101 }, 'Registering invalid chunked encoding script');
102
103 promise_test(function(t) {
104 var script = 'resources/invalid-chunked-encoding-with-flush.py';
105 var scope = 'resources/scope/invalid-chunked-encoding-with-flush/';
106 return assert_promise_rejects(
107 navigator.serviceWorker.register(script, {scope: scope}),
108 new TypeError(),
109 'Registration of invalid chunked encoding script should fail.');
110 }, 'Registering invalid chunked encoding script with flush');
111
112 promise_test(function(t) {
113 var script = 'resources/mime-type-worker.py';
114 var scope = 'resources/scope/no-mime-type-worker/';
115 return assert_promise_rejects(
116 navigator.serviceWorker.register(script, {scope: scope}),
117 'SecurityError',
118 'Registration of no MIME type script should fail.');
119 }, 'Registering script with no MIME type');
120
121 promise_test(function(t) {
122 var script = 'resources/mime-type-worker.py?mime=text/plain';
123 var scope = 'resources/scope/bad-mime-type-worker/';
124 return assert_promise_rejects(
125 navigator.serviceWorker.register(script, {scope: scope}),
126 'SecurityError',
127 'Registration of plain text script should fail.');
128 }, 'Registering script with bad MIME type');
129
130 promise_test(function(t) {
131 var script = 'resources/redirect.py?Redirect=' +
132 encodeURIComponent('/resources/registration-worker.js');
133 var scope = 'resources/scope/redirect/';
134 return assert_promise_rejects(
135 navigator.serviceWorker.register(script, {scope: scope}),
136 'SecurityError',
137 'Registration of redirected script should fail.');
138 }, 'Registering redirected script');
139
140 promise_test(function(t) {
141 var script = 'resources/malformed-worker.py?parse-error';
142 var scope = 'resources/scope/parse-error';
143 return assert_promise_rejects(
144 navigator.serviceWorker.register(script, {scope: scope}),
145 new TypeError(),
146 'Registration of script including parse error should fail.');
147 }, 'Registering script including parse error');
148
149 promise_test(function(t) {
150 var script = 'resources/malformed-worker.py?undefined-error';
151 var scope = 'resources/scope/undefined-error';
152 return assert_promise_rejects(
153 navigator.serviceWorker.register(script, {scope: scope}),
154 new TypeError(),
155 'Registration of script including undefined error should fail.');
156 }, 'Registering script including undefined error');
157
158 promise_test(function(t) {
159 var script = 'resources/malformed-worker.py?uncaught-exception';
160 var scope = 'resources/scope/uncaught-exception';
161 return assert_promise_rejects(
162 navigator.serviceWorker.register(script, {scope: scope}),
163 new TypeError(),
164 'Registration of script including uncaught exception should fail.');
165 }, 'Registering script including uncaught exception');
166
167 promise_test(function(t) {
168 var script = 'resources/malformed-worker.py?caught-exception';
169 var scope = 'resources/scope/caught-exception';
170 return navigator.serviceWorker.register(script, {scope: scope})
171 .then(function(registration) {
172 assert_true(registration instanceof ServiceWorkerRegistration,
173 'Successfully registered.');
174 service_worker_unregister_and_done(t, scope);
175 })
176 }, 'Registering script including caught exception');
177
178 promise_test(function(t) {
179 var script = 'resources/malformed-worker.py?import-malformed-script';
180 var scope = 'resources/scope/import-malformed-script';
181 return assert_promise_rejects(
182 navigator.serviceWorker.register(script, {scope: scope}),
183 new TypeError(),
184 'Registration of script importing malformed script should fail.');
185 }, 'Registering script importing malformed script');
186
187 promise_test(function(t) {
188 var script = 'resources/malformed-worker.py?import-no-such-script';
189 var scope = 'resources/scope/import-no-such-script';
190 return assert_promise_rejects(
191 navigator.serviceWorker.register(script, {scope: scope}),
192 new TypeError(),
193 'Registration of script importing non-existent script should fail.');
194 }, 'Registering script importing non-existent script');
195
196 promise_test(function(t) {
197 // URL-encoded full-width 'scope'.
198 var name = '%ef%bd%93%ef%bd%83%ef%bd%8f%ef%bd%90%ef%bd%85';
199 var script = 'resources/empty-worker.js';
200 var scope = 'resources/' + name + '/escaped-multibyte-character-scope';
201 return navigator.serviceWorker.register(script, {scope: scope})
202 .then(function(registration) {
203 assert_equals(
204 registration.scope,
205 normalizeURL(scope),
206 'URL-encoded multibyte characters should be available.');
207 service_worker_unregister_and_done(t, scope);
208 });
209 }, 'Scope including URL-encoded multibyte characters');
210
211 promise_test(function(t) {
212 // Non-URL-encoded full-width "scope".
213 var name = String.fromCodePoint(0xff53, 0xff43, 0xff4f, 0xff50, 0xff45);
214 var script = 'resources/empty-worker.js';
215 var scope = 'resources/' + name + '/non-escaped-multibyte-character-scope';
216 return navigator.serviceWorker.register(script, {scope: scope})
217 .then(function(registration) {
218 assert_equals(
219 registration.scope,
220 normalizeURL(scope),
221 'Non-URL-encoded multibyte characters should be available.');
222 service_worker_unregister_and_done(t, scope);
223 });
224 }, 'Scope including non-escaped multibyte characters');
225
226 promise_test(function(t) {
227 var script = 'resources%2fempty-worker.js';
228 var scope = 'resources/scope/encoded-slash-in-script-url';
229 return assert_promise_rejects(
230 navigator.serviceWorker.register(script, {scope: scope}),
231 new TypeError(),
232 'URL-encoded slash in the script URL should be rejected.');
233 }, 'Script URL including URL-encoded slash');
234
235 promise_test(function(t) {
236 var script = 'resources/empty-worker.js';
237 var scope = 'resources/scope%2fencoded-slash-in-scope';
238 return assert_promise_rejects(
239 navigator.serviceWorker.register(script, {scope: scope}),
240 new TypeError(),
241 'URL-encoded slash in the scope should be rejected.');
242 }, 'Scope including URL-encoded slash');
243
244 promise_test(function(t) {
245 var script = 'resources%5cempty-worker.js';
246 var scope = 'resources/scope/encoded-slash-in-script-url';
247 return assert_promise_rejects(
248 navigator.serviceWorker.register(script, {scope: scope}),
249 new TypeError(),
250 'URL-encoded backslash in the script URL should be rejected.');
251 }, 'Script URL including URL-encoded backslash');
252
253 promise_test(function(t) {
254 var script = 'resources/empty-worker.js';
255 var scope = 'resources/scope%5cencoded-slash-in-scope';
256 return assert_promise_rejects(
257 navigator.serviceWorker.register(script, {scope: scope}),
258 new TypeError(),
259 'URL-encoded backslash in the scope should be rejected.');
260 }, 'Scope including URL-encoded backslash');
261
262 promise_test(function(t) {
263 var script = 'resources/././empty-worker.js';
264 var scope = 'resources/scope/parent-reference-in-script-url';
265 return navigator.serviceWorker.register(script, {scope: scope})
266 .then(function(registration) {
267 assert_equals(
268 registration.installing.scriptURL,
269 normalizeURL('resources/empty-worker.js'),
270 'Script URL including self-reference should be normalized.');
271 service_worker_unregister_and_done(t, scope);
272 });
273 }, 'Script URL including self-reference');
274
275 promise_test(function(t) {
276 var script = 'resources/empty-worker.js';
277 var scope = 'resources/././scope/self-reference-in-scope';
278 return navigator.serviceWorker.register(script, {scope: scope})
279 .then(function(registration) {
280 assert_equals(
281 registration.scope,
282 normalizeURL('resources/scope/self-reference-in-scope'),
283 'Scope including self-reference should be normalized.');
284 service_worker_unregister_and_done(t, scope);
285 });
286 }, 'Scope including self-reference');
287
288 promise_test(function(t) {
289 var script = 'resources/../resources/empty-worker.js';
290 var scope = 'resources/scope/parent-reference-in-script-url';
291 return navigator.serviceWorker.register(script, {scope: scope})
292 .then(function(registration) {
293 assert_equals(
294 registration.installing.scriptURL,
295 normalizeURL('resources/empty-worker.js'),
296 'Script URL including parent-reference should be normalized.');
297 service_worker_unregister_and_done(t, scope);
298 });
299 }, 'Script URL including parent-reference');
300
301 promise_test(function(t) {
302 var script = 'resources/empty-worker.js';
303 var scope = 'resources/../resources/scope/parent-reference-in-scope';
304 return navigator.serviceWorker.register(script, {scope: scope})
305 .then(function(registration) {
306 assert_equals(
307 registration.scope,
308 normalizeURL('resources/scope/parent-reference-in-scope'),
309 'Scope including parent-reference should be normalized.');
310 service_worker_unregister_and_done(t, scope);
311 });
312 }, 'Scope including parent-reference');
313
314 promise_test(function(t) {
315 var script = 'resources/empty-worker.js';
316 var scope = 'resources/../scope/parent-reference-in-scope';
317 return assert_promise_rejects(
318 navigator.serviceWorker.register(script, {scope: scope}),
319 'SecurityError',
320 'Scope not under the script directory should be rejected.');
321 }, 'Scope including parent-reference and not under the script directory');
322
323 promise_test(function(t) {
324 var script = 'resources////empty-worker.js';
325 var scope = 'resources/scope/consecutive-slashes-in-script-url';
326 return assert_promise_rejects(
327 navigator.serviceWorker.register(script, {scope: scope}),
328 'SecurityError',
329 'Consecutive slashes in the script url should not be unified.');
330 }, 'Script URL including consecutive slashes');
331
332 promise_test(function(t) {
333 var script = 'resources/empty-worker.js';
334 var scope = 'resources/scope////consecutive-slashes-in-scope';
335 return navigator.serviceWorker.register(script, {scope: scope})
336 .then(function(registration) {
337 // Although consecutive slashes in the scope are not unified, the
338 // scope is under the script directory and registration should
339 // succeed.
340 assert_equals(
341 registration.scope,
342 normalizeURL(scope),
343 'Should successfully be registered.');
344 service_worker_unregister_and_done(t, scope);
345 })
346 }, 'Scope including consecutive slashes');
347
348 promise_test(function(t) {
349 var script = 'filesystem:' + normalizeURL('resources/empty-worker.js');
350 var scope = 'resources/scope/filesystem-script-url';
351 return assert_promise_rejects(
352 navigator.serviceWorker.register(script, {scope: scope}),
353 'SecurityError',
354 'Registering a script which has same-origin filesystem: URL should ' +
355 'fail with SecurityError.');
356 }, 'Script URL is same-origin filesystem: URL');
357
358 promise_test(function(t) {
359 var script = 'resources/empty-worker.js';
360 var scope = 'filesystem:' + normalizeURL('resources/scope/filesystem-scope-u rl');
361 return assert_promise_rejects(
362 navigator.serviceWorker.register(script, {scope: scope}),
363 'SecurityError',
364 'Registering with the scope that has same-origin filesystem: URL ' +
365 'should fail with SecurityError.');
366 }, 'Scope URL is same-origin filesystem: URL');
367
368 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698