OLD | NEW |
1 <?php | 1 <?php |
2 header('Content-Type: application/javascript'); | 2 header('Content-Type: application/javascript'); |
3 $directive = $_GET['directive']; | 3 $directive = $_GET['directive']; |
4 | 4 |
5 if ($directive == 'default') { | 5 if ($directive == 'default') { |
6 header('Content-Security-Policy: default-src \'self\''); | 6 header('Content-Security-Policy: default-src \'self\''); |
7 | 7 |
8 ?> | 8 ?> |
9 importScripts('worker-testharness.js'); | 9 importScripts('worker-testharness.js'); |
10 importScripts('test-helpers.js'); | 10 importScripts('test-helpers.js'); |
| 11 importScripts('../../resources/get-host-info.js'); |
| 12 |
| 13 var host_info = get_host_info(); |
11 | 14 |
12 test(function() { | 15 test(function() { |
13 var import_script_failed = false; | 16 var import_script_failed = false; |
14 try { | 17 try { |
15 importScripts('http://localhost:8000/serviceworker/resources/empty.js'); | 18 importScripts(host_info.HTTP_REMOTE_ORIGIN + |
| 19 '/serviceworker/resources/empty.js'); |
16 } catch(e) { | 20 } catch(e) { |
17 import_script_failed = true; | 21 import_script_failed = true; |
18 } | 22 } |
19 assert_true(import_script_failed, | 23 assert_true(import_script_failed, |
20 'Importing the other origins script should fail.'); | 24 'Importing the other origins script should fail.'); |
21 }, 'importScripts test for default-src'); | 25 }, 'importScripts test for default-src'); |
22 | 26 |
23 async_test(function(t) { | 27 async_test(function(t) { |
24 fetch('http://localhost:8000/serviceworker/resources/fetch-access-control.ph
p?ACAOrigin=*', | 28 fetch(host_info.HTTP_REMOTE_ORIGIN + |
| 29 '/serviceworker/resources/fetch-access-control.php?ACAOrigin=*', |
25 {mode: 'cors'}) | 30 {mode: 'cors'}) |
26 .then(function(response){ | 31 .then(function(response){ |
27 assert_unreached('fetch should fail.'); | 32 assert_unreached('fetch should fail.'); |
28 }, function(){ | 33 }, function(){ |
29 t.done(); | 34 t.done(); |
30 }) | 35 }) |
31 .catch(unreached_rejection(t)); | 36 .catch(unreached_rejection(t)); |
32 }, 'Fetch test for default-src'); | 37 }, 'Fetch test for default-src'); |
33 | 38 |
34 async_test(function(t) { | 39 async_test(function(t) { |
35 var REDIRECT_URL = 'http://127.0.0.1:8000/serviceworker/resources/redirect.p
hp?Redirect='; | 40 var REDIRECT_URL = host_info.HTTP_ORIGIN + |
36 var OTHER_BASE_URL = 'http://localhost:8000/serviceworker/resources/fetch-ac
cess-control.php?' | 41 '/serviceworker/resources/redirect.php?Redirect='; |
| 42 var OTHER_BASE_URL = host_info.HTTP_REMOTE_ORIGIN + |
| 43 '/serviceworker/resources/fetch-access-control.php?' |
37 fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'), | 44 fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'), |
38 {mode: 'cors'}) | 45 {mode: 'cors'}) |
39 .then(function(response){ | 46 .then(function(response){ |
40 assert_unreached('Redirected fetch should fail.'); | 47 assert_unreached('Redirected fetch should fail.'); |
41 }, function(){ | 48 }, function(){ |
42 t.done(); | 49 t.done(); |
43 }) | 50 }) |
44 .catch(unreached_rejection(t)); | 51 .catch(unreached_rejection(t)); |
45 }, 'Redirected fetch test for default-src'); | 52 }, 'Redirected fetch test for default-src'); |
46 | 53 |
47 <?php | 54 <?php |
48 | 55 |
49 } else if ($directive == 'script') { | 56 } else if ($directive == 'script') { |
50 header('Content-Security-Policy: script-src \'self\''); | 57 header('Content-Security-Policy: script-src \'self\''); |
51 | 58 |
52 ?> | 59 ?> |
53 importScripts('worker-testharness.js'); | 60 importScripts('worker-testharness.js'); |
54 importScripts('test-helpers.js'); | 61 importScripts('test-helpers.js'); |
| 62 importScripts('../../resources/get-host-info.js'); |
| 63 |
| 64 var host_info = get_host_info(); |
55 | 65 |
56 test(function() { | 66 test(function() { |
57 var import_script_failed = false; | 67 var import_script_failed = false; |
58 try { | 68 try { |
59 importScripts('http://localhost:8000/serviceworker/resources/empty.js'); | 69 importScripts(host_info.HTTP_REMOTE_ORIGIN + |
| 70 '/serviceworker/resources/empty.js'); |
60 } catch(e) { | 71 } catch(e) { |
61 import_script_failed = true; | 72 import_script_failed = true; |
62 } | 73 } |
63 assert_true(import_script_failed, | 74 assert_true(import_script_failed, |
64 'Importing the other origins script should fail.'); | 75 'Importing the other origins script should fail.'); |
65 }, 'importScripts test for script-src'); | 76 }, 'importScripts test for script-src'); |
66 | 77 |
67 async_test(function(t) { | 78 async_test(function(t) { |
68 fetch('http://localhost:8000/serviceworker/resources/fetch-access-control.ph
p?ACAOrigin=*', | 79 fetch(host_info.HTTP_REMOTE_ORIGIN + |
| 80 '/serviceworker/resources/fetch-access-control.php?ACAOrigin=*', |
69 {mode: 'cors'}) | 81 {mode: 'cors'}) |
70 .then(function(response){ | 82 .then(function(response){ |
71 t.done(); | 83 t.done(); |
72 }, function(){ | 84 }, function(){ |
73 assert_unreached('fetch should not fail.'); | 85 assert_unreached('fetch should not fail.'); |
74 }) | 86 }) |
75 .catch(unreached_rejection(t)); | 87 .catch(unreached_rejection(t)); |
76 }, 'Fetch test for script-src'); | 88 }, 'Fetch test for script-src'); |
77 | 89 |
78 async_test(function(t) { | 90 async_test(function(t) { |
79 var REDIRECT_URL = 'http://127.0.0.1:8000/serviceworker/resources/redirect.p
hp?Redirect='; | 91 var REDIRECT_URL = host_info.HTTP_ORIGIN + |
80 var OTHER_BASE_URL = 'http://localhost:8000/serviceworker/resources/fetch-ac
cess-control.php?' | 92 '/serviceworker/resources/redirect.php?Redirect='; |
| 93 var OTHER_BASE_URL = host_info.HTTP_REMOTE_ORIGIN + |
| 94 '/serviceworker/resources/fetch-access-control.php?' |
81 fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'), | 95 fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'), |
82 {mode: 'cors'}) | 96 {mode: 'cors'}) |
83 .then(function(response){ | 97 .then(function(response){ |
84 t.done(); | 98 t.done(); |
85 }, function(){ | 99 }, function(){ |
86 assert_unreached('Redirected fetch should not fail.'); | 100 assert_unreached('Redirected fetch should not fail.'); |
87 }) | 101 }) |
88 .catch(unreached_rejection(t)); | 102 .catch(unreached_rejection(t)); |
89 }, 'Redirected fetch test for script-src'); | 103 }, 'Redirected fetch test for script-src'); |
90 | 104 |
91 <?php | 105 <?php |
92 | 106 |
93 } else if ($directive == 'connect') { | 107 } else if ($directive == 'connect') { |
94 header('Content-Security-Policy: connect-src \'self\''); | 108 header('Content-Security-Policy: connect-src \'self\''); |
95 | 109 |
96 ?> | 110 ?> |
97 importScripts('worker-testharness.js'); | 111 importScripts('worker-testharness.js'); |
98 importScripts('test-helpers.js'); | 112 importScripts('test-helpers.js'); |
| 113 importScripts('../../resources/get-host-info.js'); |
| 114 |
| 115 var host_info = get_host_info(); |
99 | 116 |
100 test(function() { | 117 test(function() { |
101 var import_script_failed = false; | 118 var import_script_failed = false; |
102 try { | 119 try { |
103 importScripts('http://localhost:8000/serviceworker/resources/empty.js'); | 120 importScripts(host_info.HTTP_REMOTE_ORIGIN + |
| 121 '/serviceworker/resources/empty.js'); |
104 } catch(e) { | 122 } catch(e) { |
105 import_script_failed = true; | 123 import_script_failed = true; |
106 } | 124 } |
107 assert_false(import_script_failed, | 125 assert_false(import_script_failed, |
108 'Importing the other origins script should not fail.'); | 126 'Importing the other origins script should not fail.'); |
109 }, 'importScripts test for connect-src'); | 127 }, 'importScripts test for connect-src'); |
110 | 128 |
111 async_test(function(t) { | 129 async_test(function(t) { |
112 fetch('http://localhost:8000/serviceworker/resources/fetch-access-control.ph
p?ACAOrigin=*', | 130 fetch(host_info.HTTP_REMOTE_ORIGIN + |
| 131 '/serviceworker/resources/fetch-access-control.php?ACAOrigin=*', |
113 {mode: 'cors'}) | 132 {mode: 'cors'}) |
114 .then(function(response){ | 133 .then(function(response){ |
115 assert_unreached('fetch should fail.'); | 134 assert_unreached('fetch should fail.'); |
116 }, function(){ | 135 }, function(){ |
117 t.done(); | 136 t.done(); |
118 }) | 137 }) |
119 .catch(unreached_rejection(t)); | 138 .catch(unreached_rejection(t)); |
120 }, 'Fetch test for connect-src'); | 139 }, 'Fetch test for connect-src'); |
121 | 140 |
122 async_test(function(t) { | 141 async_test(function(t) { |
123 var REDIRECT_URL = 'http://127.0.0.1:8000/serviceworker/resources/redirect.p
hp?Redirect='; | 142 var REDIRECT_URL = host_info.HTTP_ORIGIN + |
124 var OTHER_BASE_URL = 'http://localhost:8000/serviceworker/resources/fetch-ac
cess-control.php?' | 143 '/serviceworker/resources/redirect.php?Redirect='; |
| 144 var OTHER_BASE_URL = host_info.HTTP_REMOTE_ORIGIN + |
| 145 '/serviceworker/resources/fetch-access-control.php?' |
125 fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'), | 146 fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'), |
126 {mode: 'cors'}) | 147 {mode: 'cors'}) |
127 .then(function(response){ | 148 .then(function(response){ |
128 assert_unreached('Redirected fetch should fail.'); | 149 assert_unreached('Redirected fetch should fail.'); |
129 }, function(){ | 150 }, function(){ |
130 t.done(); | 151 t.done(); |
131 }) | 152 }) |
132 .catch(unreached_rejection(t)); | 153 .catch(unreached_rejection(t)); |
133 }, 'Redirected fetch test for connect-src'); | 154 }, 'Redirected fetch test for connect-src'); |
134 | 155 |
135 <?php | 156 <?php |
136 } | 157 } |
137 ?> | 158 ?> |
OLD | NEW |