| OLD | NEW |
| 1 if (self.importScripts) { | 1 if (self.importScripts) { |
| 2 importScripts('../resources/fetch-test-helpers.js'); | 2 importScripts('../resources/fetch-test-helpers.js'); |
| 3 importScripts('/serviceworker/resources/fetch-access-control-util.js'); | 3 importScripts('/serviceworker/resources/fetch-access-control-util.js'); |
| 4 } | 4 } |
| 5 | 5 |
| 6 // Tests for CORS preflight fetch. |
| 7 // Spec: https://fetch.spec.whatwg.org/#cors-preflight-fetch |
| 8 |
| 6 var TEST_TARGETS = [ | 9 var TEST_TARGETS = [ |
| 7 // CORS test | |
| 8 [OTHER_BASE_URL + 'method=GET&headers=CUSTOM', | |
| 9 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], | |
| 10 onlyOnServiceWorkerProxiedTest([methodIsGET, noCustomHeader, authCheck2])], | |
| 11 [OTHER_BASE_URL + 'method=POST&headers=CUSTOM', | |
| 12 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], | |
| 13 onlyOnServiceWorkerProxiedTest([methodIsPOST, noCustomHeader])], | |
| 14 [OTHER_BASE_URL + 'method=PUT&headers=CUSTOM', | |
| 15 [fetchError]], | |
| 16 [OTHER_BASE_URL + 'method=XXX&headers=CUSTOM', | |
| 17 [fetchError]], | |
| 18 | |
| 19 [OTHER_BASE_URL + 'mode=same-origin&method=GET', [fetchRejected]], | |
| 20 [OTHER_BASE_URL + 'mode=same-origin&method=POST', [fetchRejected]], | |
| 21 [OTHER_BASE_URL + 'mode=same-origin&method=PUT', [fetchRejected]], | |
| 22 [OTHER_BASE_URL + 'mode=same-origin&method=XXX', [fetchRejected]], | |
| 23 | |
| 24 [OTHER_BASE_URL + 'mode=no-cors&method=GET&headers=CUSTOM', | |
| 25 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], | |
| 26 onlyOnServiceWorkerProxiedTest([methodIsGET, noCustomHeader, authCheck2])], | |
| 27 [OTHER_BASE_URL + 'mode=no-cors&method=POST&headers=CUSTOM', | |
| 28 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], | |
| 29 onlyOnServiceWorkerProxiedTest([methodIsPOST, noCustomHeader])], | |
| 30 [OTHER_BASE_URL + 'mode=no-cors&method=PUT&headers=CUSTOM', | |
| 31 [fetchError]], | |
| 32 [OTHER_BASE_URL + 'mode=no-cors&method=XXX&headers=CUSTOM', | |
| 33 [fetchError]], | |
| 34 | |
| 35 // method=GET | 10 // method=GET |
| 36 | 11 |
| 37 // CORS check | |
| 38 // https://fetch.spec.whatwg.org/#concept-cors-check | |
| 39 // Tests for Access-Control-Allow-Origin header. | |
| 40 [OTHER_BASE_URL + 'mode=cors&method=GET', | |
| 41 [fetchRejected]], | |
| 42 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=*', | |
| 43 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 44 [methodIsGET, authCheckNone]], | |
| 45 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=' + BASE_ORIGIN, | |
| 46 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 47 [methodIsGET]], | |
| 48 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=' + BASE_ORIGIN + | |
| 49 ',http://www.example.com', | |
| 50 [fetchRejected]], | |
| 51 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://www.example.com', | |
| 52 [fetchRejected]], | |
| 53 | |
| 54 // CORS filtered response | |
| 55 // https://fetch.spec.whatwg.org/#concept-filtered-response-cors | |
| 56 // Tests for Access-Control-Expose-Headers header. | |
| 57 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=X-ServiceWorker
-ServerHeader', | |
| 58 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], | |
| 59 [methodIsGET]], | |
| 60 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=' + BASE_ORIGIN + | |
| 61 '&ACEHeaders=X-ServiceWorker-ServerHeader', | |
| 62 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], | |
| 63 [methodIsGET]], | |
| 64 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=Content-Length,
X-ServiceWorker-ServerHeader', | |
| 65 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
| 66 [methodIsGET]], | |
| 67 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=' + BASE_ORIGIN + | |
| 68 '&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', | |
| 69 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
| 70 [methodIsGET]], | |
| 71 | |
| 72 // CORS preflight fetch | |
| 73 // https://fetch.spec.whatwg.org/#cors-preflight-fetch | |
| 74 // Tests for Access-Control-Allow-Headers header. | 12 // Tests for Access-Control-Allow-Headers header. |
| 75 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM', | 13 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM', |
| 76 [fetchRejected]], | 14 [fetchRejected]], |
| 77 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*', | 15 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*', |
| 78 [fetchRejected]], | 16 [fetchRejected]], |
| 79 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=' + | 17 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=' + |
| 80 BASE_ORIGIN, | 18 BASE_ORIGIN, |
| 81 [fetchRejected]], | 19 [fetchRejected]], |
| 82 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&ACAHeaders=
x-serviceworker-test', | 20 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&ACAHeaders=
x-serviceworker-test', |
| 83 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | 21 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&PACAOrigin=
*&PACAHeaders=x-serviceworker-test&PreflightTest=200&PACRMethod=GET&PACRHeaders=
x-serviceworker-test', | 76 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&PACAOrigin=
*&PACAHeaders=x-serviceworker-test&PreflightTest=200&PACRMethod=GET&PACRHeaders=
x-serviceworker-test', |
| 139 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | 77 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 140 [methodIsGET, hasCustomHeader]], | 78 [methodIsGET, hasCustomHeader]], |
| 141 // Test Access-Control-Request-Headers is sorted https://crbug.com/452391 | 79 // Test Access-Control-Request-Headers is sorted https://crbug.com/452391 |
| 142 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM2&ACAOrigin=*&PACAOrigin
=*&PACAHeaders=x-servicEworker-u, x-servicEworker-ua, x-servicewOrker-test, x-sE
rviceworker-s, x-sErviceworker-v&PreflightTest=200&PACRMethod=GET&PACRHeaders=x-
serviceworker-s, x-serviceworker-test, x-serviceworker-u, x-serviceworker-ua, x-
serviceworker-v', | 80 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM2&ACAOrigin=*&PACAOrigin
=*&PACAHeaders=x-servicEworker-u, x-servicEworker-ua, x-servicewOrker-test, x-sE
rviceworker-s, x-sErviceworker-v&PreflightTest=200&PACRMethod=GET&PACRHeaders=x-
serviceworker-s, x-serviceworker-test, x-serviceworker-u, x-serviceworker-ua, x-
serviceworker-v', |
| 143 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | 81 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 144 [methodIsGET, hasCustomHeader2]], | 82 [methodIsGET, hasCustomHeader2]], |
| 145 | 83 |
| 146 // method=POST | 84 // method=POST |
| 147 | 85 |
| 148 // CORS check | |
| 149 // https://fetch.spec.whatwg.org/#concept-cors-check | |
| 150 // Tests for Access-Control-Allow-Origin header. | |
| 151 [OTHER_BASE_URL + 'mode=cors&method=POST', | |
| 152 [fetchRejected]], | |
| 153 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=*', | |
| 154 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 155 [methodIsPOST]], | |
| 156 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=' + BASE_ORIGIN, | |
| 157 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 158 [methodIsPOST]], | |
| 159 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=' + BASE_ORIGIN + | |
| 160 ',http://www.example.com', | |
| 161 [fetchRejected]], | |
| 162 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://www.example.com', | |
| 163 [fetchRejected]], | |
| 164 | |
| 165 // CORS filtered response | |
| 166 // https://fetch.spec.whatwg.org/#concept-filtered-response-cors | |
| 167 // Tests for Access-Control-Expose-Headers header. | |
| 168 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders=X-ServiceWorke
r-ServerHeader', | |
| 169 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], | |
| 170 [methodIsPOST]], | |
| 171 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=' + BASE_ORIGIN + | |
| 172 '&ACEHeaders=X-ServiceWorker-ServerHeader', | |
| 173 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], | |
| 174 [methodIsPOST]], | |
| 175 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders=Content-Length
, X-ServiceWorker-ServerHeader', | |
| 176 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
| 177 [methodIsPOST]], | |
| 178 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=' + BASE_ORIGIN + | |
| 179 '&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', | |
| 180 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
| 181 [methodIsPOST]], | |
| 182 | |
| 183 // CORS preflight fetch | |
| 184 // https://fetch.spec.whatwg.org/#cors-preflight-fetch | |
| 185 // Tests for Access-Control-Allow-Headers header. | 86 // Tests for Access-Control-Allow-Headers header. |
| 186 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM', | 87 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM', |
| 187 [fetchRejected]], | 88 [fetchRejected]], |
| 188 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*', | 89 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*', |
| 189 [fetchRejected]], | 90 [fetchRejected]], |
| 190 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeaders
=x-serviceworker-test', | 91 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeaders
=x-serviceworker-test', |
| 191 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | 92 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 192 [methodIsPOST, hasCustomHeader]], | 93 [methodIsPOST, hasCustomHeader]], |
| 193 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeaders
=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', | 94 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeaders
=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
| 194 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | 95 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 // Test Access-Control-Request-Headers is sorted https://crbug.com/452391 | 390 // Test Access-Control-Request-Headers is sorted https://crbug.com/452391 |
| 490 [OTHER_BASE_URL + 'mode=cors&method=XXX&headers=CUSTOM2&ACAOrigin=*&PACAOrigin
=*&PACAMethods=XXX&PACAHeaders=x-servicEworker-u, x-servicEworker-ua, x-servicew
Orker-test, x-sErviceworker-s, x-sErviceworker-v&PreflightTest=200&PACRMethod=XX
X&PACRHeaders=x-serviceworker-s, x-serviceworker-test, x-serviceworker-u, x-serv
iceworker-ua, x-serviceworker-v', | 391 [OTHER_BASE_URL + 'mode=cors&method=XXX&headers=CUSTOM2&ACAOrigin=*&PACAOrigin
=*&PACAMethods=XXX&PACAHeaders=x-servicEworker-u, x-servicEworker-ua, x-servicew
Orker-test, x-sErviceworker-s, x-sErviceworker-v&PreflightTest=200&PACRMethod=XX
X&PACRHeaders=x-serviceworker-s, x-serviceworker-test, x-serviceworker-u, x-serv
iceworker-ua, x-serviceworker-v', |
| 491 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | 392 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 492 [methodIsXXX, hasCustomHeader2]], | 393 [methodIsXXX, hasCustomHeader2]], |
| 493 ]; | 394 ]; |
| 494 | 395 |
| 495 if (self.importScripts) { | 396 if (self.importScripts) { |
| 496 executeTests(TEST_TARGETS); | 397 executeTests(TEST_TARGETS); |
| 497 done(); | 398 done(); |
| 498 } | 399 } |
| OLD | NEW |