Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / chromium / service-worker-allowed.html
blob1ab415256ed115ae40451091895f5ac141382a2e
1 <!DOCTYPE html>
2 <!-- FIXME: Move this test out of chromium/ when PHP is no longer needed
3 to set the Service-Worker-Allowed header (crbug.com/347864).
4 -->
5 <title>Service Worker: Service-Worker-Allowed header</title>
6 <script src="../../resources/testharness.js"></script>
7 <script src="../../resources/testharness-helpers.js"></script>
8 <script src="../../resources/testharnessreport.js"></script>
9 <script src="../../resources/get-host-info.js"></script>
10 <script src="../resources/test-helpers.js"></script>
11 <script>
13 var host_info = get_host_info();
15 promise_test(function(t) {
16 var script = 'resources/service-worker-allowed-worker.php' +
17 '?ServiceWorkerAllowed=/allowed-path';
18 var scope = '/allowed-path';
19 return navigator.serviceWorker.register(script, {scope: scope})
20 .then(function(registration) {
21 assert_true(
22 registration instanceof ServiceWorkerRegistration,
23 'Successfully registered.');
24 assert_equals(
25 registration.scope,
26 normalizeURL(scope),
27 'Registering within Service-Worker-Allowed path should pass');
28 service_worker_unregister_and_done(t, scope);
30 }, 'Registering within Service-Worker-Allowed path');
32 promise_test(function(t) {
33 var script = 'resources/service-worker-allowed-worker.php' +
34 '?ServiceWorkerAllowed=../allowed-path-with-parent';
35 var scope = 'allowed-path-with-parent';
36 return navigator.serviceWorker.register(script, {scope: scope})
37 .then(function(registration) {
38 assert_true(
39 registration instanceof ServiceWorkerRegistration,
40 'Successfully registered.');
41 assert_equals(
42 registration.scope,
43 normalizeURL(scope),
44 'Registering within Service-Worker-Allowed path with parent ' +
45 'reference should pass');
46 service_worker_unregister_and_done(t, scope);
48 }, 'Registering within Service-Worker-Allowed path with parent reference');
50 promise_test(function(t) {
51 var script = 'resources/service-worker-allowed-worker.php' +
52 '?ServiceWorkerAllowed=/allowed-path';
53 var scope = '/disallowed-path';
54 return assert_promise_rejects(
55 navigator.serviceWorker.register(script, {scope: scope}),
56 'SecurityError',
57 'Registering outside Service-Worker-Allowed path should fail');
58 }, 'Registering outside Service-Worker-Allowed path');
60 promise_test(function(t) {
61 var script = 'resources/service-worker-allowed-worker.php' +
62 '?ServiceWorkerAllowed=../allowed-path-with-parent';
63 var scope = '/allowed-path-with-parent';
64 return assert_promise_rejects(
65 navigator.serviceWorker.register(script, {scope: scope}),
66 'SecurityError',
67 'Registering outside Service-Worker-Allowed path with parent ' +
68 'reference should fail');
69 }, 'Registering outside Service-Worker-Allowed path with parent reference');
71 promise_test(function(t) {
72 var script = host_info.HTTPS_REMOTE_ORIGIN +
73 '/serviceworker/chromium/resources/' +
74 'service-worker-allowed-worker.php' +
75 '?ServiceWorkerAllowed=' +
76 host_info.HTTP_REMOTE_ORIGIN + '/cross-origin/';
77 var scope = '/cross-origin/';
78 return assert_promise_rejects(
79 navigator.serviceWorker.register(script, {scope: scope}),
80 'SecurityError',
81 'Registering cross-origin Service-Worker-Allowed should fail');
82 }, 'Registering cross-origin Service-Worker-Allowed');
84 </script>