if (this.document === undefined) { importScripts("/resources/testharness.js"); importScripts("../resources/utils.js"); } var unicorn = ''; function checkFetchResponse(url, data, mime, desc) { if (!desc) { var cut = (url.length >= 45) ? "[...]" : ""; desc = "Fetching " + url.substring(0, 45) + cut + " is OK" } promise_test(function(test) { return fetch(url).then(function(resp) { assert_equals(resp.status, 200, "HTTP status is 200"); assert_equals(resp.type, "basic", "response type is basic"); assert_equals(resp.headers.get("Content-Type"), mime, "Content-Type is " + resp.headers.get("Content-Type")); return resp.text(); }).then(function(bodyAsText) { assert_equals(bodyAsText, data, "Response's body is " + data); }) }, desc); } checkFetchResponse("about:blank", "", "text/html;charset=utf-8"); checkFetchResponse("about:unicorn", unicorn, "image/svg+xml"); function checkKoUrl(url, desc) { if (!desc) desc = "Fetching " + url.substring(0, 45) + " is KO" promise_test(function(test) { var promise = fetch(url); return promise_rejects(test, new TypeError(), promise); }, desc); } checkKoUrl("about:invalid.com"); checkKoUrl("about:config"); done();