OLD | NEW |
(Empty) | |
| 1 if (this.document === undefined) { |
| 2 importScripts("/resources/testharness.js"); |
| 3 importScripts("../resources/utils.js"); |
| 4 } |
| 5 |
| 6 function checkFetchResponse(url, method, desc) { |
| 7 if (!desc) { |
| 8 var cut = (url.length >= 40) ? "[...]" : ""; |
| 9 cut += " (" + method + ")" |
| 10 desc = "Fetching " + url.substring(0, 40) + cut + " is OK" |
| 11 } |
| 12 promise_test(function(test) { |
| 13 return fetch(url, { method: method }).then(function(resp) { |
| 14 assert_equals(resp.status, 200, "HTTP status is 200"); |
| 15 assert_equals(resp.type, "basic", "response type is basic"); |
| 16 assert_equals(resp.headers.get("Content-Type"), "text/html;charset=utf-8",
"Content-Type is " + resp.headers.get("Content-Type")); |
| 17 return resp.text(); |
| 18 }) |
| 19 }, desc); |
| 20 } |
| 21 |
| 22 checkFetchResponse("about:blank", "GET"); |
| 23 checkFetchResponse("about:blank", "PUT"); |
| 24 checkFetchResponse("about:blank", "POST"); |
| 25 |
| 26 function checkKoUrl(url, desc) { |
| 27 if (!desc) |
| 28 desc = "Fetching " + url.substring(0, 45) + " is KO" |
| 29 promise_test(function(test) { |
| 30 var promise = fetch(url); |
| 31 return promise_rejects(test, new TypeError(), promise); |
| 32 }, desc); |
| 33 } |
| 34 |
| 35 checkKoUrl("about:invalid.com"); |
| 36 checkKoUrl("about:config"); |
| 37 checkKoUrl("about:unicorn"); |
| 38 |
| 39 done(); |
OLD | NEW |