OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("../resources/utils.js"); |
| 4 importScripts("/common/get-host-info.sub.js"); |
| 5 } |
| 6 |
| 7 function cors(desc, origin) { |
| 8 var url = origin + dirname(location.pathname); |
| 9 var urlParameters = "?pipe=header(Access-Control-Allow-Origin,*)"; |
| 10 |
| 11 promise_test(function(test) { |
| 12 return fetch(url + RESOURCES_DIR + "top.txt" + urlParameters, {"mode": "no-c
ors"} ).then(function(resp) { |
| 13 assert_equals(resp.status, 0, "Opaque filter: status is 0"); |
| 14 assert_equals(resp.statusText, "", "Opaque filter: statusText is \"\""); |
| 15 assert_equals(resp.type , "opaque", "Opaque filter: response's type is opa
que"); |
| 16 return resp.text().then(function(value) { |
| 17 assert_equals(value, "", "Opaque response should have an empty body"); |
| 18 }); |
| 19 }); |
| 20 }, desc + " [no-cors mode]"); |
| 21 |
| 22 promise_test(function(test) { |
| 23 return promise_rejects(test, new TypeError(), fetch(url + RESOURCES_DIR + "t
op.txt", {"mode": "cors"})); |
| 24 }, desc + " [server forbid CORS]"); |
| 25 |
| 26 promise_test(function(test) { |
| 27 return fetch(url + RESOURCES_DIR + "top.txt" + urlParameters, {"mode": "cors
"} ).then(function(resp) { |
| 28 assert_equals(resp.status, 200, "Fetch's response's status is 200"); |
| 29 assert_equals(resp.type , "cors", "CORS response's type is cors"); |
| 30 }); |
| 31 }, desc + " [cors mode]"); |
| 32 } |
| 33 |
| 34 var host_info = get_host_info(); |
| 35 |
| 36 cors("Same domain different port", host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT); |
| 37 cors("Same domain different protocol different port", host_info.HTTPS_ORIGIN); |
| 38 cors("Cross domain basic usage", host_info.HTTP_REMOTE_ORIGIN); |
| 39 cors("Cross domain different port", host_info.HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_
PORT); |
| 40 cors("Cross domain different protocol", host_info.HTTPS_REMOTE_ORIGIN); |
| 41 |
| 42 done(); |
OLD | NEW |