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).
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>
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
) {
22 registration
instanceof ServiceWorkerRegistration
,
23 'Successfully registered.');
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
) {
39 registration
instanceof ServiceWorkerRegistration
,
40 'Successfully registered.');
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
}),
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
}),
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
}),
81 'Registering cross-origin Service-Worker-Allowed should fail');
82 }, 'Registering cross-origin Service-Worker-Allowed');