OLD | NEW |
| (Empty) |
1 if (self.importScripts) { | |
2 importScripts('../resources/fetch-test-helpers.js'); | |
3 importScripts('../resources/fetch-access-control-util.js'); | |
4 } | |
5 | |
6 // Tests for CORS preflight fetch (simple methods). | |
7 // Spec: https://fetch.spec.whatwg.org/#cors-preflight-fetch | |
8 | |
9 var TEST_TARGETS = []; | |
10 | |
11 ['GET', 'POST'].forEach(function(method) { | |
12 var checkMethod = checkJsonpMethod.bind(this, method); | |
13 TEST_TARGETS.push( | |
14 // Tests for Access-Control-Allow-Headers header. | |
15 [OTHER_BASE_URL + 'mode=cors&method=' + method + '&headers=CUSTOM', | |
16 [fetchRejected]], | |
17 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
18 '&headers=CUSTOM&ACAOrigin=*', | |
19 [fetchRejected]], | |
20 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
21 '&headers=CUSTOM&ACAOrigin=' + BASE_ORIGIN, | |
22 [fetchRejected]], | |
23 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
24 '&headers=CUSTOM&ACAOrigin=*&ACAHeaders=x-serviceworker-test', | |
25 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
26 [checkMethod, hasCustomHeader]], | |
27 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
28 '&headers=CUSTOM&ACAOrigin=' + BASE_ORIGIN + | |
29 '&ACAHeaders=x-serviceworker-test', | |
30 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
31 [checkMethod, hasCustomHeader]], | |
32 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
33 '&headers=CUSTOM&ACAOrigin=*&ACAHeaders=x-serviceworker-test&ACEHeaders=C
ontent-Length, X-ServiceWorker-ServerHeader', | |
34 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
35 [checkMethod, hasCustomHeader]], | |
36 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
37 '&headers=CUSTOM&ACAOrigin=' + BASE_ORIGIN + | |
38 '&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWor
ker-ServerHeader', | |
39 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
40 [checkMethod, hasCustomHeader]], | |
41 | |
42 // Test that Access-Control-Allow-Headers is checked in | |
43 // CORS preflight fetch. | |
44 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
45 '&headers=CUSTOM&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-serviceworker-tes
t&PreflightTest=200', | |
46 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
47 [checkMethod, hasCustomHeader]], | |
48 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
49 '&headers=CUSTOM&ACAOrigin=*&PACAOrigin=*&ACAHeaders=x-serviceworker-test
&PreflightTest=200', | |
50 [fetchRejected]], | |
51 | |
52 // Test that CORS check is done in both preflight and main fetch. | |
53 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
54 '&headers=CUSTOM&ACAOrigin=*&PACAHeaders=x-serviceworker-test&PreflightTe
st=200', | |
55 [fetchRejected]], | |
56 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
57 '&headers=CUSTOM&PACAOrigin=*&PACAHeaders=x-serviceworker-test&PreflightT
est=200', | |
58 [fetchRejected]], | |
59 | |
60 // Test that Access-Control-Expose-Headers of CORS preflight is ignored. | |
61 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
62 '&headers=CUSTOM&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-serviceworker-tes
t&PACEHeaders=Content-Length, X-ServiceWorker-ServerHeader&PreflightTest=200', | |
63 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
64 [checkMethod, hasCustomHeader]], | |
65 | |
66 // Test that CORS preflight with Status 2XX succeeds. | |
67 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
68 '&headers=CUSTOM&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-serviceworker-tes
t&PreflightTest=201', | |
69 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
70 [checkMethod, hasCustomHeader]], | |
71 | |
72 // Test that CORS preflight with Status other than 2XX fails. | |
73 // https://crbug.com/452394 | |
74 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
75 '&headers=CUSTOM&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-serviceworker-tes
t&PreflightTest=301', | |
76 [fetchRejected]], | |
77 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
78 '&headers=CUSTOM&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-serviceworker-tes
t&PreflightTest=401', | |
79 [fetchRejected]], | |
80 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
81 '&headers=CUSTOM&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-serviceworker-tes
t&PreflightTest=500', | |
82 [fetchRejected]], | |
83 | |
84 // Test CORS preflight with multiple request headers. | |
85 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
86 '&headers=CUSTOM2&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-servicEworker-u,
x-servicEworker-ua, x-servicewOrker-test, x-sErviceworker-s, x-sErviceworker-v&
PreflightTest=200', | |
87 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
88 [checkMethod, hasCustomHeader2]], | |
89 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
90 '&headers=CUSTOM2&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-servicewOrker-te
st&PreflightTest=200', | |
91 [fetchRejected]], | |
92 | |
93 // Test request headers sent in CORS preflight requests. | |
94 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
95 '&headers=CUSTOM&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-serviceworker-tes
t&PACRMethod=' + method + | |
96 '&PACRHeaders=x-serviceworker-test&PreflightTest=200', | |
97 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
98 [checkMethod, hasCustomHeader]], | |
99 // Test Access-Control-Request-Headers is sorted https://crbug.com/452391 | |
100 | |
101 [OTHER_BASE_URL + 'mode=cors&method=' + method + | |
102 '&headers=CUSTOM2&ACAOrigin=*&PACAOrigin=*&PACAHeaders=x-servicEworker-u,
x-servicEworker-ua, x-servicewOrker-test, x-sErviceworker-s, x-sErviceworker-v&
PACRMethod=' + method + | |
103 '&PACRHeaders=x-serviceworker-s, x-serviceworker-test, x-serviceworker-u,
x-serviceworker-ua, x-serviceworker-v&PreflightTest=200', | |
104 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
105 [checkMethod, hasCustomHeader2]]); | |
106 }); | |
107 | |
108 if (self.importScripts) { | |
109 executeTests(TEST_TARGETS); | |
110 done(); | |
111 } | |
OLD | NEW |