| 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 var TEST_TARGETS = [ | |
| 7 // Redirect: same origin -> same origin | |
| 8 [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 9 '&mode=same-origin&method=GET', | |
| 10 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
| 11 [methodIsGET, authCheck1]], | |
| 12 | |
| 13 // https://fetch.spec.whatwg.org/#concept-http-fetch | |
| 14 // Step 4, Case 301/302/303/307/308: | |
| 15 // Step 2: If location is null, return response. | |
| 16 [REDIRECT_URL + 'noLocation' + | |
| 17 '&mode=same-origin&method=GET&NoRedirectTest=true', | |
| 18 [fetchResolved, hasBody, typeBasic], | |
| 19 [checkJsonpNoRedirect]], | |
| 20 // Step 5: If locationURL is failure, return a network error. | |
| 21 [REDIRECT_URL + 'http://' + | |
| 22 '&mode=same-origin&method=GET', | |
| 23 [fetchRejected]], | |
| 24 | |
| 25 [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 26 '&mode=same-origin&method=GET&headers=CUSTOM', | |
| 27 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
| 28 [methodIsGET, hasCustomHeader, authCheck1]], | |
| 29 // Chrome changes the method from POST to GET when it recieves 301 redirect | |
| 30 // response. See a note in http://tools.ietf.org/html/rfc7231#section-6.4.2 | |
| 31 [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 32 '&mode=same-origin&method=POST&Status=301', | |
| 33 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
| 34 [methodIsGET, authCheck1]], | |
| 35 // Chrome changes the method from POST to GET when it recieves 302 redirect | |
| 36 // response. See a note in http://tools.ietf.org/html/rfc7231#section-6.4.3 | |
| 37 [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 38 '&mode=same-origin&method=POST', | |
| 39 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
| 40 [methodIsGET, authCheck1]], | |
| 41 // GET method must be used for 303 redirect. | |
| 42 [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 43 '&mode=same-origin&method=POST&Status=303', | |
| 44 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
| 45 [methodIsGET, authCheck1]], | |
| 46 // The 307 redirect response doesn't change the method. | |
| 47 [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 48 '&mode=same-origin&method=POST&Status=307', | |
| 49 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
| 50 [methodIsPOST, authCheck1]], | |
| 51 // The 308 redirect response doesn't change the method. | |
| 52 // FIXME: currently this and following 308 tests are disabled because they | |
| 53 // fail on try bots, probably due to Apache/PHP versions. | |
| 54 // https://crbug.com/451938 | |
| 55 // [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 56 // '&mode=same-origin&method=POST&Status=308', | |
| 57 // [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
| 58 // [methodIsPOST, authCheck1]], | |
| 59 | |
| 60 // Do not redirect for other status even if Location header exists. | |
| 61 [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 62 '&mode=same-origin&method=POST&Status=201&NoRedirectTest=true', | |
| 63 [fetchResolved, hasBody, typeBasic], | |
| 64 [checkJsonpNoRedirect]], | |
| 65 | |
| 66 [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 67 '&mode=same-origin&method=PUT', | |
| 68 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
| 69 [methodIsPUT, authCheck1]], | |
| 70 | |
| 71 [REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 72 '&mode=cors&method=GET&headers=CUSTOM', | |
| 73 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], | |
| 74 [methodIsGET, hasCustomHeader, authCheck1]], | |
| 75 | |
| 76 // Redirect: same origin -> other origin | |
| 77 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL) + | |
| 78 '&mode=same-origin&method=GET', | |
| 79 [fetchRejected]], | |
| 80 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL) + | |
| 81 '&mode=same-origin&method=POST', | |
| 82 [fetchRejected]], | |
| 83 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL) + | |
| 84 '&mode=same-origin&method=PUT', | |
| 85 [fetchRejected]], | |
| 86 | |
| 87 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL) + | |
| 88 '&mode=cors&method=GET', | |
| 89 [fetchRejected]], | |
| 90 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL) + | |
| 91 '&mode=cors&method=PUT', | |
| 92 [fetchRejected]], | |
| 93 | |
| 94 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + '&ACAOrigin=*') + | |
| 95 '&mode=cors&method=GET', | |
| 96 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 97 [methodIsGET, authCheckNone]], | |
| 98 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + '&ACAOrigin=*') + | |
| 99 '&mode=cors&method=PUT', | |
| 100 [fetchRejected]], | |
| 101 [REDIRECT_URL + | |
| 102 encodeURIComponent(OTHER_BASE_URL + '&ACAOrigin=*&ACAMethods=PUT') + | |
| 103 '&mode=cors&method=PUT', | |
| 104 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 105 [methodIsPUT, noCustomHeader, authCheckNone]], | |
| 106 | |
| 107 // Status code tests for mode="cors" | |
| 108 // The 301 redirect response MAY change the request method from POST to GET. | |
| 109 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + '&ACAOrigin=*') + | |
| 110 '&mode=cors&method=POST&Status=301', | |
| 111 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 112 [methodIsGET]], | |
| 113 // The 302 redirect response MAY change the request method from POST to GET. | |
| 114 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + '&ACAOrigin=*') + | |
| 115 '&mode=cors&method=POST&Status=302', | |
| 116 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 117 [methodIsGET]], | |
| 118 // GET method must be used for 303 redirect. | |
| 119 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + '&ACAOrigin=*') + | |
| 120 '&mode=cors&method=POST&Status=303', | |
| 121 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 122 [methodIsGET]], | |
| 123 // The 307 redirect response MUST NOT change the method. | |
| 124 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + '&ACAOrigin=*') + | |
| 125 '&mode=cors&method=POST&Status=307', | |
| 126 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 127 [methodIsPOST]], | |
| 128 // The 308 redirect response MUST NOT change the method. | |
| 129 // FIXME: disabled due to https://crbug.com/451938 | |
| 130 // [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + '&ACAOrigin=*') + | |
| 131 // '&mode=cors&method=POST&Status=308', | |
| 132 // [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 133 // [methodIsPOST]], | |
| 134 | |
| 135 // Server header | |
| 136 [REDIRECT_URL + | |
| 137 encodeURIComponent( | |
| 138 OTHER_BASE_URL + | |
| 139 '&ACAOrigin=' + BASE_ORIGIN + | |
| 140 '&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader') + | |
| 141 '&mode=cors&method=GET', | |
| 142 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], | |
| 143 [methodIsGET, authCheckNone]], | |
| 144 | |
| 145 // Redirect: other origin -> same origin | |
| 146 [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 147 '&mode=same-origin&method=GET', | |
| 148 [fetchRejected]], | |
| 149 [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 150 '&mode=same-origin&method=POST', | |
| 151 [fetchRejected]], | |
| 152 | |
| 153 [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 154 '&mode=cors&method=GET', | |
| 155 [fetchRejected]], | |
| 156 [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL) + | |
| 157 '&mode=cors&method=GET&ACAOrigin=*', | |
| 158 [fetchRejected]], | |
| 159 [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL + 'ACAOrigin=*') + | |
| 160 '&mode=cors&method=GET&ACAOrigin=*', | |
| 161 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 162 [methodIsGET, authCheckNone]], | |
| 163 | |
| 164 // Status code tests for mode="cors" | |
| 165 // The 301 redirect response MAY change the request method from POST to GET. | |
| 166 [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL + 'ACAOrigin=*') + | |
| 167 '&mode=cors&method=post&ACAOrigin=*&Status=301', | |
| 168 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 169 [methodIsGET]], | |
| 170 // The 302 redirect response MAY change the request method from POST to GET. | |
| 171 [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL + 'ACAOrigin=*') + | |
| 172 '&mode=cors&method=post&ACAOrigin=*&Status=302', | |
| 173 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 174 [methodIsGET]], | |
| 175 // GET method must be used for 303 redirect. | |
| 176 [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL + 'ACAOrigin=*') + | |
| 177 '&mode=cors&method=post&ACAOrigin=*&Status=303', | |
| 178 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 179 [methodIsGET]], | |
| 180 // The 307 redirect response MUST NOT change the method. | |
| 181 [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL + 'ACAOrigin=*') + | |
| 182 '&mode=cors&method=post&ACAOrigin=*&Status=307', | |
| 183 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 184 [methodIsPOST]], | |
| 185 // The 308 redirect response MUST NOT change the method. | |
| 186 // FIXME: disabled due to https://crbug.com/451938 | |
| 187 // [OTHER_REDIRECT_URL + encodeURIComponent(BASE_URL + 'ACAOrigin=*') + | |
| 188 // '&mode=cors&method=post&ACAOrigin=*&Status=308', | |
| 189 // [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 190 // [methodIsPOST]], | |
| 191 | |
| 192 // Once CORS preflight flag is set, redirecting to the cross-origin is not | |
| 193 // allowed. | |
| 194 // Custom method | |
| 195 [OTHER_REDIRECT_URL + | |
| 196 encodeURIComponent(BASE_URL + 'ACAOrigin=*&ACAMethods=PUT') + | |
| 197 '&mode=cors&method=PUT&ACAOrigin=*&ACAMethods=PUT', | |
| 198 [fetchRejected]], | |
| 199 // Custom header | |
| 200 [OTHER_REDIRECT_URL + | |
| 201 encodeURIComponent( | |
| 202 BASE_URL + | |
| 203 'ACAOrigin=' + BASE_ORIGIN + '&ACAHeaders=x-serviceworker-test') + | |
| 204 '&mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*', | |
| 205 [fetchRejected]], | |
| 206 | |
| 207 // Redirect: other origin -> other origin | |
| 208 [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL) + | |
| 209 '&mode=same-origin&method=GET', | |
| 210 [fetchRejected]], | |
| 211 [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL) + | |
| 212 '&mode=cors&method=GET', | |
| 213 [fetchRejected]], | |
| 214 [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL) + | |
| 215 '&mode=cors&method=GET&ACAOrigin=*', | |
| 216 [fetchRejected]], | |
| 217 [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*') + | |
| 218 '&mode=cors&method=GET&ACAOrigin=*', | |
| 219 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 220 [methodIsGET, authCheckNone]], | |
| 221 [OTHER_REDIRECT_URL + | |
| 222 encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=' + BASE_ORIGIN + '') + | |
| 223 '&mode=cors&method=GET&ACAOrigin=*', | |
| 224 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 225 [methodIsGET, authCheckNone]], | |
| 226 [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*') + | |
| 227 '&mode=cors&method=GET&ACAOrigin=' + BASE_ORIGIN + '', | |
| 228 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 229 [methodIsGET, authCheckNone]], | |
| 230 [OTHER_REDIRECT_URL + | |
| 231 encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=' + BASE_ORIGIN + '') + | |
| 232 '&mode=cors&method=GET&ACAOrigin=' + BASE_ORIGIN + '', | |
| 233 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 234 [methodIsGET, authCheckNone]], | |
| 235 | |
| 236 // Status code tests for mode="cors" | |
| 237 // The 301 redirect response MAY change the request method from POST to GET. | |
| 238 [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*') + | |
| 239 '&mode=cors&method=POST&ACAOrigin=*&Status=301', | |
| 240 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 241 [methodIsGET]], | |
| 242 // The 302 redirect response MAY change the request method from POST to GET. | |
| 243 [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*') + | |
| 244 '&mode=cors&method=POST&ACAOrigin=*&Status=302', | |
| 245 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 246 [methodIsGET]], | |
| 247 // GET method must be used for 303 redirect. | |
| 248 [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*') + | |
| 249 '&mode=cors&method=POST&ACAOrigin=*&Status=303', | |
| 250 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 251 [methodIsGET]], | |
| 252 // The 307 redirect response MUST NOT change the method. | |
| 253 [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*') + | |
| 254 '&mode=cors&method=POST&ACAOrigin=*&Status=307', | |
| 255 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 256 [methodIsPOST]], | |
| 257 // The 308 redirect response MUST NOT change the method. | |
| 258 // FIXME: disabled due to https://crbug.com/451938 | |
| 259 // [OTHER_REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*') + | |
| 260 // '&mode=cors&method=POST&ACAOrigin=*&Status=308', | |
| 261 // [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], | |
| 262 // [methodIsPOST]], | |
| 263 | |
| 264 // Server header | |
| 265 [OTHER_REDIRECT_URL + | |
| 266 encodeURIComponent(OTHER_BASE_URL + | |
| 267 'ACAOrigin=*&ACEHeaders=X-ServiceWorker-ServerHeader') + | |
| 268 '&mode=cors&method=GET&ACAOrigin=*', | |
| 269 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], | |
| 270 [methodIsGET, authCheckNone]], | |
| 271 | |
| 272 // Once CORS preflight flag is set, redirecting to the cross-origin is not | |
| 273 // allowed. | |
| 274 // Custom method | |
| 275 [OTHER_REDIRECT_URL + | |
| 276 encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*&ACAMethods=PUT') + | |
| 277 '&mode=cors&method=PUT&ACAOrigin=*&ACAMethods=PUT', | |
| 278 [fetchRejected]], | |
| 279 // Custom header | |
| 280 [OTHER_REDIRECT_URL + | |
| 281 encodeURIComponent( | |
| 282 OTHER_BASE_URL + | |
| 283 'ACAOrigin=' + BASE_ORIGIN + '&ACAHeaders=x-serviceworker-test') + | |
| 284 '&mode=cors&method=GET&headers=CUSTOM' + | |
| 285 '&ACAOrigin=' + BASE_ORIGIN + '&ACAHeaders=x-serviceworker-test', | |
| 286 [fetchRejected]], | |
| 287 ]; | |
| 288 | |
| 289 if (self.importScripts) { | |
| 290 executeTests(TEST_TARGETS); | |
| 291 done(); | |
| 292 } | |
| OLD | NEW |