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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/registration-tests.js

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

Powered by Google App Engine
This is Rietveld 408576698