OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/common/utils.js"); |
| 3 importScripts("/resources/testharness.js"); |
| 4 importScripts("../resources/utils.js"); |
| 5 importScripts("/common/get-host-info.sub.js") |
| 6 } |
| 7 |
| 8 function corsNoPreflight(desc, baseURL, method, headerName, headerValue) { |
| 9 |
| 10 var uuid_token = token(); |
| 11 var url = baseURL + dirname(location.pathname) + RESOURCES_DIR + "preflight.py
"; |
| 12 var urlParameters = "?token=" + uuid_token + "&max_age=0"; |
| 13 var requestInit = {"mode": "cors", "method": method, "headers":{}}; |
| 14 if (headerName) |
| 15 requestInit["headers"][headerName] = headerValue; |
| 16 |
| 17 promise_test(function(test) { |
| 18 return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(func
tion(resp) { |
| 19 assert_equals(resp.status, 200, "Clean stash response's status is 200"); |
| 20 return fetch(url + urlParameters, requestInit).then(function(resp) { |
| 21 assert_equals(resp.status, 200, "Response's status is 200"); |
| 22 assert_equals(resp.headers.get("x-did-preflight"), "0", "No preflight re
quest has been made"); |
| 23 }); |
| 24 }); |
| 25 }, desc); |
| 26 } |
| 27 |
| 28 var host_info = get_host_info(); |
| 29 |
| 30 corsNoPreflight("Cross domain basic usage [GET]", host_info.HTTP_REMOTE_ORIGIN,
"GET"); |
| 31 corsNoPreflight("Same domain different port [GET]", host_info.HTTP_ORIGIN_WITH_D
IFFERENT_PORT, "GET"); |
| 32 corsNoPreflight("Cross domain different port [GET]", host_info.HTTP_REMOTE_ORIGI
N_WITH_DIFFERENT_PORT, "GET"); |
| 33 corsNoPreflight("Cross domain different protocol [GET]", host_info.HTTPS_REMOTE_
ORIGIN, "GET"); |
| 34 corsNoPreflight("Same domain different protocol different port [GET]", host_info
.HTTPS_ORIGIN, "GET"); |
| 35 corsNoPreflight("Cross domain [POST]", host_info.HTTP_REMOTE_ORIGIN, "POST"); |
| 36 corsNoPreflight("Cross domain [HEAD]", host_info.HTTP_REMOTE_ORIGIN, "HEAD"); |
| 37 corsNoPreflight("Cross domain [GET] [Accept: */*]", host_info.HTTP_REMOTE_ORIGIN
, "GET" , "Accept", "*/*"); |
| 38 corsNoPreflight("Cross domain [GET] [Accept-Language: fr]", host_info.HTTP_REMOT
E_ORIGIN, "GET" , "Accept-Language", "fr"); |
| 39 corsNoPreflight("Cross domain [GET] [Content-Language: fr]", host_info.HTTP_REMO
TE_ORIGIN, "GET" , "Content-Language", "fr"); |
| 40 corsNoPreflight("Cross domain [GET] [Content-Type: application/x-www-form-urlenc
oded]", host_info.HTTP_REMOTE_ORIGIN, "GET" , "Content-Type", "application/x-www
-form-urlencoded"); |
| 41 corsNoPreflight("Cross domain [GET] [Content-Type: multipart/form-data]", host_i
nfo.HTTP_REMOTE_ORIGIN, "GET" , "Content-Type", "multipart/form-data"); |
| 42 corsNoPreflight("Cross domain [GET] [Content-Type: text/plain]", host_info.HTTP_
REMOTE_ORIGIN, "GET" , "Content-Type", "text/plain"); |
| 43 corsNoPreflight("Cross domain [GET] [Content-Type: text/plain;charset=utf-8]", h
ost_info.HTTP_REMOTE_ORIGIN, "GET" , "Content-Type", "text/plain;charset=utf-8")
; |
| 44 corsNoPreflight("Cross domain [GET] [Content-Type: Text/Plain;charset=utf-8]", h
ost_info.HTTP_REMOTE_ORIGIN, "GET" , "Content-Type", "Text/Plain;charset=utf-8")
; |
| 45 |
| 46 done(); |
OLD | NEW |