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

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

Powered by Google App Engine
This is Rietveld 408576698