OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("../resources/utils.js"); |
| 4 } |
| 5 |
| 6 function corsFilter(corsUrl, headerName, headerValue, isFiltered) { |
| 7 var url = corsUrl + "?pipe=header(" + headerName + "," + encodeURIComponent(he
aderValue) +")|header(Access-Control-Allow-Origin,*)"; |
| 8 promise_test(function(test) { |
| 9 return fetch(url).then(function(resp) { |
| 10 assert_equals(resp.status, 200, "Fetch success with code 200"); |
| 11 assert_equals(resp.type , "cors", "CORS fetch's response has cors type"); |
| 12 if (!isFiltered) { |
| 13 assert_equals(resp.headers.get(headerName), headerValue, |
| 14 headerName + " header should be included in response with value: " + h
eaderValue); |
| 15 } else { |
| 16 assert_false(resp.headers.has(headerName), "UA should exclude " + header
Name + " header from response"); |
| 17 } |
| 18 test.done(); |
| 19 }); |
| 20 }, "CORS filter on " + headerName + " header"); |
| 21 } |
| 22 |
| 23 function corsExposeFilter(corsUrl, headerName, headerValue, isForbidden) { |
| 24 var url = corsUrl + "?pipe=header(" + headerName + "," + encodeURIComponent(he
aderValue) +")|" + |
| 25 "header(Access-Control-Allow-Origin,*)" + |
| 26 "header(Access-Control-Expose-Headers," + headerName
+ ")"; |
| 27 |
| 28 promise_test(function(test) { |
| 29 return fetch(url).then(function(resp) { |
| 30 assert_equals(resp.status, 200, "Fetch success with code 200"); |
| 31 assert_equals(resp.type , "cors", "CORS fetch's response has cors type"); |
| 32 if (!isForbidden) { |
| 33 assert_equals(resp.headers.get(headerName), headerValue, |
| 34 headerName + " header should be included in response with value: " + h
eaderValue); |
| 35 } else { |
| 36 assert_false(resp.headers.has(headerName), "UA should exclude " + header
Name + " header from response"); |
| 37 } |
| 38 test.done(); |
| 39 }); |
| 40 }, "CORS filter on " + headerName + " header, header is exposed"); |
| 41 } |
| 42 |
| 43 var url = "http://{{host}}:{{ports[http][1]}}" + dirname(location.pathname) + RE
SOURCES_DIR + "top.txt"; |
| 44 |
| 45 corsFilter(url, "Cache-Control", "no-cache", false); |
| 46 corsFilter(url, "Content-Language", "fr", false); |
| 47 corsFilter(url, "Content-Type", "text/html", false); |
| 48 corsFilter(url, "Expires","04 May 1988 22:22:22 GMT" , false); |
| 49 corsFilter(url, "Last-Modified", "04 May 1988 22:22:22 GMT", false); |
| 50 corsFilter(url, "Pragma", "no-cache", false); |
| 51 |
| 52 corsFilter(url, "Age", "27", true); |
| 53 corsFilter(url, "Server", "wptServe" , true); |
| 54 corsFilter(url, "Warning", "Mind the gap" , true); |
| 55 corsFilter(url, "Content-Length", "0" , true); |
| 56 corsFilter(url, "Set-Cookie", "name=value" , true); |
| 57 corsFilter(url, "Set-Cookie2", "name=value" , true); |
| 58 |
| 59 corsExposeFilter(url, "Age", "27", false); |
| 60 corsExposeFilter(url, "Server", "wptServe" , false); |
| 61 corsExposeFilter(url, "Warning", "Mind the gap" , false); |
| 62 corsExposeFilter(url, "Content-Length", "0" , false); |
| 63 corsExposeFilter(url, "Set-Cookie", "name=value" , true); |
| 64 corsExposeFilter(url, "Set-Cookie2", "name=value" , true); |
| 65 |
| 66 done(); |
OLD | NEW |