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

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

Issue 672383003: [ServiceWorker] Don't allow registration of the ServiceWorker scope outside the script directory. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Service Worker: Registration</title> 2 <title>Service Worker: Registration</title>
3 <script src="../resources/testharness.js"></script> 3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharness-helpers.js"></script> 4 <script src="../resources/testharness-helpers.js"></script>
5 <script src="../resources/testharnessreport.js"></script> 5 <script src="../resources/testharnessreport.js"></script>
6 <script src="resources/test-helpers.js"></script> 6 <script src="resources/test-helpers.js"></script>
7 <script> 7 <script>
8 8
9 promise_test(function(t) { 9 promise_test(function(t) {
10 var script = 'resources/registration-worker.js'; 10 var script = 'resources/registration-worker.js';
11 var scope = '/registration/'; 11 var scope = 'resources/registration/';
12 return navigator.serviceWorker.register(script, {scope: scope}) 12 return navigator.serviceWorker.register(script, {scope: scope})
13 .then(function(registration) { 13 .then(function(registration) {
14 assert_true(registration instanceof ServiceWorkerRegistration, 14 assert_true(registration instanceof ServiceWorkerRegistration,
15 'Successfully registered.'); 15 'Successfully registered.');
16 service_worker_unregister_and_done(t, scope); 16 service_worker_unregister_and_done(t, scope);
17 }) 17 })
18 }, 'Registering normal pattern'); 18 }, 'Registering normal pattern');
19 19
20 promise_test(function(t) { 20 promise_test(function(t) {
21 var script = 'resources/registration-worker.js'; 21 var script = 'resources/registration-worker.js';
22 var scope = 'resources/';
23 return navigator.serviceWorker.register(script, {scope: scope})
24 .then(function(registration) {
25 assert_true(registration instanceof ServiceWorkerRegistration,
26 'Successfully registered.');
27 service_worker_unregister_and_done(t, scope);
28 })
29 }, 'Registering same scope as the script directory');
30
31 promise_test(function(t) {
32 var script = 'resources/registration-worker.js';
33 var scope = 'resources';
34 return assert_promise_rejects(
35 navigator.serviceWorker.register(script, {scope: scope}),
36 'SecurityError',
37 'Registering same scope as the script directory without the last ' +
38 'slash should fail with SecurityError.');
39 }, 'Registering same scope as the script directory without the last slash');
40
41 promise_test(function(t) {
42 var script = 'resources/registration-worker.js';
43 var scope = 'different-directory/';
44 return assert_promise_rejects(
45 navigator.serviceWorker.register(script, {scope: scope}),
46 'SecurityError',
47 'Registration scope outside the script directory should fail ' +
48 'with SecurityError.');
49 }, 'Registration scope outside the script directory');
50
51 promise_test(function(t) {
52 var script = 'resources/registration-worker.js';
22 var scope = 'http://example.com/'; 53 var scope = 'http://example.com/';
23 return assert_promise_rejects( 54 return assert_promise_rejects(
24 navigator.serviceWorker.register(script, {scope: scope}), 55 navigator.serviceWorker.register(script, {scope: scope}),
25 'SecurityError', 56 'SecurityError',
26 'Registration scope outside domain should fail with SecurityError.'); 57 'Registration scope outside domain should fail with SecurityError.');
27 }, 'Registering scope outside domain'); 58 }, 'Registering scope outside domain');
28 59
29 promise_test(function(t) { 60 promise_test(function(t) {
30 var script = 'http://example.com/worker.js'; 61 var script = 'http://example.com/worker.js';
62 var scope = 'http://example.com/scope/';
31 return assert_promise_rejects( 63 return assert_promise_rejects(
32 navigator.serviceWorker.register(script), 64 navigator.serviceWorker.register(script, {scope: scope}),
33 'SecurityError', 65 'SecurityError',
34 'Registration script outside domain should fail with SecurityError.'); 66 'Registration script outside domain should fail with SecurityError.');
35 }, 'Registering script outside domain'); 67 }, 'Registering script outside domain');
36 68
37 promise_test(function(t) { 69 promise_test(function(t) {
38 var script = 'no-such-worker.js'; 70 var script = 'resources/no-such-worker.js';
71 var scope = 'resources/scope/no-such-worker';
39 return assert_promise_rejects( 72 return assert_promise_rejects(
40 navigator.serviceWorker.register(script), 73 navigator.serviceWorker.register(script, {scope: scope}),
41 'NetworkError', 74 'NetworkError',
42 'Registration of non-existent script should fail.'); 75 'Registration of non-existent script should fail.');
43 }, 'Registering non-existent script'); 76 }, 'Registering non-existent script');
44 77
45 promise_test(function(t) { 78 promise_test(function(t) {
46 var script = 'resources/invalid-chunked-encoding.php'; 79 var script = 'resources/invalid-chunked-encoding.php';
80 var scope = 'resources/scope/invalid-chunked-encoding/';
47 return assert_promise_rejects( 81 return assert_promise_rejects(
48 navigator.serviceWorker.register(script), 82 navigator.serviceWorker.register(script, {scope: scope}),
49 'NetworkError', 83 'NetworkError',
50 'Registration of invalid chunked encoding script should fail.'); 84 'Registration of invalid chunked encoding script should fail.');
51 }, 'Registering invalid chunked encoding script'); 85 }, 'Registering invalid chunked encoding script');
52 86
53 promise_test(function(t) { 87 promise_test(function(t) {
54 var script = 'resources/invalid-chunked-encoding-with-flush.php'; 88 var script = 'resources/invalid-chunked-encoding-with-flush.php';
89 var scope = 'resources/scope/invalid-chunked-encoding-with-flush/';
55 return assert_promise_rejects( 90 return assert_promise_rejects(
56 navigator.serviceWorker.register(script), 91 navigator.serviceWorker.register(script, {scope: scope}),
57 'NetworkError', 92 'NetworkError',
58 'Registration of invalid chunked encoding script should fail.'); 93 'Registration of invalid chunked encoding script should fail.');
59 }, 'Registering invalid chunked encoding script with flush'); 94 }, 'Registering invalid chunked encoding script with flush');
60 95
61 promise_test(function(t) { 96 promise_test(function(t) {
62 var script = 'resources/plain-text-worker.php'; 97 var script = 'resources/plain-text-worker.php';
98 var scope = 'resources/scope/plain-text-worker/';
63 return assert_promise_rejects( 99 return assert_promise_rejects(
64 navigator.serviceWorker.register(script), 100 navigator.serviceWorker.register(script, {scope: scope}),
65 'SecurityError', 101 'SecurityError',
66 'Registration of plain text script should fail.'); 102 'Registration of plain text script should fail.');
67 }, 'Registering script without correct MIME type'); 103 }, 'Registering script without correct MIME type');
68 104
69 promise_test(function(t) { 105 promise_test(function(t) {
70 var script = 'resources/redirect.php?Redirect=' + 106 var script = 'resources/redirect.php?Redirect=' +
71 encodeURIComponent('/resources/registration-worker.js'); 107 encodeURIComponent('/resources/registration-worker.js');
108 var scope = 'resources/sope/redirect/';
72 return assert_promise_rejects( 109 return assert_promise_rejects(
73 navigator.serviceWorker.register(script), 110 navigator.serviceWorker.register(script, {scope: scope}),
74 'SecurityError', 111 'SecurityError',
75 'Registration of redirected script should fail.'); 112 'Registration of redirected script should fail.');
76 }, 'Registering redirected script'); 113 }, 'Registering redirected script');
77 114
78 </script> 115 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698