Update web-platform-tests to revision dc5cbf088edcdb266541d4e5a76149a2c6e716a0

This commit is contained in:
Ms2ger 2016-09-09 09:40:35 +02:00
parent 1d40075f03
commit 079092dfea
2381 changed files with 90360 additions and 17722 deletions

View file

@ -11,7 +11,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("mode-same-origin.js?pipe=sub"));
fetch_tests_from_worker(new Worker("mode-same-origin.js"));
</script>
</body>
</html>
</html>

View file

@ -11,6 +11,7 @@
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="mode-same-origin.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="mode-same-origin.js"></script>
</body>
</html>
</html>

View file

@ -1,6 +1,7 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
function fetchSameOrigin(url, shouldPass) {
@ -15,10 +16,19 @@ function fetchSameOrigin(url, shouldPass) {
}, "Fetch "+ url + " with same-origin mode");
}
var host_info = get_host_info();
fetchSameOrigin(RESOURCES_DIR + "top.txt", true);
fetchSameOrigin("http://{{host}}:{{ports[http][0]}}/fetch/api/resources/top.txt", true);
fetchSameOrigin("https://{{host}}:{{ports[https][0]}}/fetch/api/resources/top.txt", false);
fetchSameOrigin("http://{{domains[www]}}:{{ports[http][0]}}/fetch/api/resources/top.txt", false);
fetchSameOrigin(host_info.HTTP_ORIGIN + "/fetch/api/resources/top.txt", true);
fetchSameOrigin(host_info.HTTPS_ORIGIN + "/fetch/api/resources/top.txt", false);
fetchSameOrigin(host_info.HTTP_REMOTE_ORIGIN + "/fetch/api/resources/top.txt", false);
var redirPath = dirname(location.pathname) + RESOURCES_DIR + "redirect.py?location=";
fetchSameOrigin(redirPath + RESOURCES_DIR + "top.txt", true);
fetchSameOrigin(redirPath + host_info.HTTP_ORIGIN + "/fetch/api/resources/top.txt", true);
fetchSameOrigin(redirPath + host_info.HTTPS_ORIGIN + "/fetch/api/resources/top.txt", false);
fetchSameOrigin(redirPath + host_info.HTTP_REMOTE_ORIGIN + "/fetch/api/resources/top.txt", false);
done();

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: same-origin mode</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch">
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("referrer.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: same-origin mode</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#basic-fetch">
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="referrer.js"></script>
</body>
</html>

View file

@ -0,0 +1,35 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
function runTest(url, init, expectedReferrer, title) {
promise_test(function(test) {
url += (url.indexOf('?') !== -1 ? '&' : '?') + "headers=referer&cors";
return fetch(url , init).then(function(resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
assert_equals(resp.headers.get("x-request-referer"), expectedReferrer, "Request's referrer is correct");
});
}, title);
}
var fetchedUrl = RESOURCES_DIR + "inspect-headers.py";
var corsFetchedUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "inspect-headers.py";
var redirectUrl = RESOURCES_DIR + "redirect.py?location=" ;
var corsRedirectUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "redirect.py?location=";
runTest(fetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, location.toString(), "origin-when-cross-origin policy on a same-origin URL");
runTest(corsFetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, get_host_info().HTTP_ORIGIN + "/", "origin-when-cross-origin policy on a cross-origin URL");
runTest(redirectUrl + corsFetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, get_host_info().HTTP_ORIGIN + "/", "origin-when-cross-origin policy on a cross-origin URL after same-origin redirection");
runTest(corsRedirectUrl + fetchedUrl, { referrerPolicy: "origin-when-cross-origin"}, get_host_info().HTTP_ORIGIN + "/", "origin-when-cross-origin policy on a same-origin URL after cross-origin redirection");
var referrerUrlWithCredentials = get_host_info().HTTP_ORIGIN.replace("http://", "http://username:password@");
runTest(fetchedUrl, {referrer: referrerUrlWithCredentials}, get_host_info().HTTP_ORIGIN + "/", "Referrer with credentials should be stripped");
var referrerUrlWithFragmentIdentifier = get_host_info().HTTP_ORIGIN + "#fragmentIdentifier";
runTest(fetchedUrl, {referrer: referrerUrlWithFragmentIdentifier}, get_host_info().HTTP_ORIGIN + "/", "Referrer with fragment ID should be stripped");
done();

View file

@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: HEAD method</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("request-head.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: HEAD method</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="request-head.js"></script>
</body>
</html>

View file

@ -0,0 +1,10 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
}
promise_test(function(test) {
var requestInit = {"method": "HEAD", "body": "test"};
return promise_rejects(test, new TypeError(), fetch(".", requestInit));
}, "Fetch with HEAD with body");
done();

View file

@ -3,19 +3,39 @@ if (this.document === undefined) {
importScripts("../resources/utils.js");
}
function checkContentType(contentType, body)
{
if (self.FormData && body instanceof self.FormData) {
assert_true(contentType.startsWith("multipart/form-data;boundary="), "Request should have header content-type starting with multipart/form-data;boundary=, but got " + contentType);
return;
}
var expectedContentType = "text/plain;charset=UTF-8";
if(body === null || body instanceof ArrayBuffer || body.buffer instanceof ArrayBuffer)
expectedContentType = null;
else if (body instanceof Blob)
expectedContentType = body.type ? body.type : null;
assert_equals(contentType , expectedContentType, "Request should have header content-type: " + expectedContentType);
}
function requestHeaders(desc, url, method, body, expectedOrigin, expectedContentLength) {
var urlParameters = "?headers=origin|user-agent|accept-charset|content-length";
var urlParameters = "?headers=origin|user-agent|accept-charset|content-length|content-type";
var requestInit = {"method": method}
if (body)
requestInit["body"] = body;
promise_test(function(test){
if (typeof body === "function")
body = body();
if (body)
requestInit["body"] = body;
return fetch(url + urlParameters, requestInit).then(function(resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
assert_equals(resp.type , "basic", "Response's type is basic");
assert_equals(resp.headers.get("x-request-origin") , expectedOrigin, "Request has header origin: " + expectedOrigin);
assert_equals(resp.headers.get("x-request-content-length") , expectedContentLength, "Request has header content-length: " + expectedContentLength);
assert_true(resp.headers.has("x-request-user-agent"), "Request has header user-agent");
assert_false(resp.headers.has("accept-charset"), "Request has header accept-charset");
assert_equals(resp.headers.get("x-request-origin") , expectedOrigin, "Request should have header origin: " + expectedOrigin);
if (expectedContentLength !== undefined)
assert_equals(resp.headers.get("x-request-content-length") , expectedContentLength, "Request should have header content-length: " + expectedContentLength);
checkContentType(resp.headers.get("x-request-content-type"), body);
});
}, desc);
}
@ -23,12 +43,20 @@ function requestHeaders(desc, url, method, body, expectedOrigin, expectedContent
var url = RESOURCES_DIR + "inspect-headers.py"
requestHeaders("Fetch with GET", url, "GET", null, location.origin, null);
requestHeaders("Fetch with HEAD", url, "HEAD", null, location.origin, "0");
requestHeaders("Fetch with HEAD with body", url, "HEAD", "Request's body", location.origin, "14");
requestHeaders("Fetch with HEAD", url, "HEAD", null, location.origin, null);
requestHeaders("Fetch with PUT without body", url, "POST", null, location.origin, "0");
requestHeaders("Fetch with PUT with body", url, "PUT", "Request's body", location.origin, "14");
requestHeaders("Fetch with POST without body", url, "POST", null, location.origin, "0");
requestHeaders("Fetch with POST with body", url, "POST", "Request's body", location.origin, "14");
requestHeaders("Fetch with POST with text body", url, "POST", "Request's body", location.origin, "14");
requestHeaders("Fetch with POST with FormData body", url, "POST", function() { return new FormData(); }, location.origin);
requestHeaders("Fetch with POST with Blob body", url, "POST", new Blob(["Test"]), location.origin, "4");
requestHeaders("Fetch with POST with ArrayBuffer body", url, "POST", new ArrayBuffer(4), location.origin, "4");
requestHeaders("Fetch with POST with Uint8Array body", url, "POST", new Uint8Array(4), location.origin, "4");
requestHeaders("Fetch with POST with Int8Array body", url, "POST", new Int8Array(4), location.origin, "4");
requestHeaders("Fetch with POST with Float32Array body", url, "POST", new Float32Array(1), location.origin, "4");
requestHeaders("Fetch with POST with Float64Array body", url, "POST", new Float64Array(1), location.origin, "8");
requestHeaders("Fetch with POST with DataView body", url, "POST", new DataView(new ArrayBuffer(8), 0, 4), location.origin, "4");
requestHeaders("Fetch with POST with Blob body with mime type", url, "POST", new Blob(["Test"], { type: "text/maybe" }), location.origin, "4");
requestHeaders("Fetch with Chicken", url, "Chicken", null, location.origin, null);
requestHeaders("Fetch with Chicken with body", url, "Chicken", "Request's body", location.origin, "14");

View file

@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: fetch() respects Request referrer value</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="request-referrer.js"></script>
</body>
</html>

View file

@ -0,0 +1,28 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function testReferrer(referrer, expected) {
promise_test(function(test) {
var url = RESOURCES_DIR + "inspect-headers.py?headers=referer"
var req = new Request(url, { referrer: referrer });
return fetch(req).then(function(resp) {
var actual = resp.headers.get("x-request-referer");
if (expected) {
assert_equals(actual, expected, "request's referer should be: " + expected);
return;
}
if (actual) {
assert_equals(actual, "", "request's referer should be empty");
}
});
});
}
testReferrer("about:client", window.location.href);
var fooURL = new URL("./foo", window.location).href;
testReferrer(fooURL, fooURL);
done();

View file

@ -3,27 +3,25 @@ if (this.document === undefined) {
importScripts("../resources/utils.js");
}
var unicorn = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2361 1572" fill="hotpink"><path d="m1648 1570c-42-12 6-93 55-94 46 0 50-10 46-123-5-122-7-126-119-202-81-55-145-128-175-201-12-30-26-59-31-63s-58-4-119 0c-70 6-131 5-170-2-59-10-84-21-220-93-68-36-72-37-145-31-41 4-100 11-131 17-55 10-57 12-62 47-16 95 3 152 49 152 14 0 29 8 34 19 14 25 13 101-0 101-12 0-60-46-60-58 0-4-17-18-38-31l-38-23-2-115c-1-64 2-124 8-133s24-21 42-25c59-12 128-37 128-46 0-5-4-9-10-9-14 0-28-30-45-95-12-47-13-69-3-124 11-62 10-71-10-109-12-23-22-50-22-60s-7-27-15-37c-18-23-19-18-5 24 8 24 7 50-5 110-10 48-14 96-10 120 8 47-9 72-48 72-40 0-66-26-77-81-6-28-30-88-53-133-23-45-45-88-48-96-4-8-22-20-41-26-26-9-34-17-34-36 0-22 4-24 37-21l37 3-9-33c-12-43-6-47 31-20l30 22 26-20c14-11 39-38 55-61 39-53 63-62 139-49 46 8 64 8 75-2 8-7 15-8 15-4-0 15-14 30-34 37-37 14-6 19 44 7 49-12 53-11 90 15 28 19 48 26 69 23 37-6 29 10-16 28-19 8-32 19-28 24 4 6 15 5 30-2 18-8 35-7 71 5 27 9 58 16 71 16 32 0 29 17-7 35-16 9-30 17-30 20 0 2 22 2 49-2 44-5 52-3 96 31 27 20 54 34 62 32 25-10 14 4-16 19-16 8-39 15-50 15-29 0-26 16 20 87 45 68 96 101 189 123 149 35 239 59 268 71 27 12 36 11 67-4 21-10 41-29 47-45 23-59 39-78 80-101 60-32 141-27 175 12 23 28 25 34 43 178 15 118 36 182 72 224 28 32 35 35 90 35 75 0 125-21 167-68l33-37-17 40c-16 41-65 98-100 117-11 6-42 17-70 24l-50 12 62 1c48 0 72-5 116-28 50-25 55-26 45-8-17 33-98 115-136 139-29 18-51 22-113 22-71 1-80-2-115-30-21-17-86-28-99-128-7-56 0-176 0-176s18-102-6-175c-19-57-81-86-123-20-19 30-43 60-54 67-18 12-18 13 6 59 34 67 38 144 14 260l-20 95 24 35c13 20 40 51 59 70 40 38 41 50 29 252-6 92-9 107-25 111-10 3-19 12-19 20s-7 18-17 20c-32 10-87 15-105 10zm-1228-1255c0-18-2-19-16-8-12 10-13 15-3 21 18 11 18 11 18-13zm743 1151c-12-5-23-14-23-20 0-17 57-69 76-69 21 0 130-65 167-99 47-43 36-101-38-198-30-39-73-148-63-158 2-2 30-5 63-7l60-3 32 60c41 77 38 69 63 145 40 115 41 112-31 166-34 27-79 62-98 79-20 17-43 34-53 38-10 3-22 17-27 30-5 14-13 27-17 29-19 12-90 16-111 7zm-913-440c0-23 28-113 44-145 6-11 32-51 57-90 26-39 50-81 53-95 5-21 22-30 103-59 53-19 102-36 108-38 6-2 18 11 27 30l16 34-92 28c-105 32-126 47-161 122-16 34-35 58-50 63-32 13-40 42-22 85l15 36-37 25c-45 30-62 31-62 4zm-48-843c-41-18-25-52 19-39 21 6 23 10 14 28-9 17-15 19-33 11zm-74-25c-28-6-31-32-4-32 13 0 26 4 29 8 8 13-8 28-25 24zm-78-37c0-9 6-12 15-9 19 7 19 24 0 24-8 0-15-7-15-15zm-50-15c0-5 7-7 15-4 19 7 19 14 0 14-8 0-15-4-15-10z"/></svg>';
function checkFetchResponse(url, data, mime, desc) {
function checkFetchResponse(url, method, desc) {
if (!desc) {
var cut = (url.length >= 45) ? "[...]" : "";
desc = "Fetching " + url.substring(0, 45) + cut + " is OK"
var cut = (url.length >= 40) ? "[...]" : "";
cut += " (" + method + ")"
desc = "Fetching " + url.substring(0, 40) + cut + " is OK"
}
promise_test(function(test) {
return fetch(url).then(function(resp) {
return fetch(url, { method: method }).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"));
assert_equals(resp.headers.get("Content-Type"), "text/html;charset=utf-8", "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");
checkFetchResponse("about:blank", "GET");
checkFetchResponse("about:blank", "PUT");
checkFetchResponse("about:blank", "POST");
function checkKoUrl(url, desc) {
if (!desc)
@ -36,5 +34,6 @@ function checkKoUrl(url, desc) {
checkKoUrl("about:invalid.com");
checkKoUrl("about:config");
checkKoUrl("about:unicorn");
done();

View file

@ -3,12 +3,18 @@ if (this.document === undefined) {
importScripts("../resources/utils.js");
}
function checkFetchResponse(url, data, mime) {
function checkFetchResponse(url, data, mime, fetchMode) {
var cut = (url.length >= 40) ? "[...]" : "";
desc = "Fetching " + url.substring(0, 40) + cut + " is OK"
desc = "Fetching " + url.substring(0, 40) + cut + " is OK";
var init = { };
if (fetchMode) {
init.mode = fetchMode;
desc += " (" + fetchMode + ")";
}
promise_test(function(test) {
return fetch(url).then(function(resp) {
return fetch(url, init).then(function(resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
assert_equals(resp.statusText, "OK", "HTTP statusText is OK");
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();
@ -19,6 +25,8 @@ function checkFetchResponse(url, data, mime) {
}
checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII");
checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", "same-origin");
checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", "cors");
checkFetchResponse("data:text/plain;base64,cmVzcG9uc2UncyBib2R5", "response's body", "text/plain");
checkFetchResponse("data:image/png;base64,cmVzcG9uc2UncyBib2R5",
"response's body",

View file

@ -0,0 +1,69 @@
<!doctype html>
<meta charset=utf-8>
<title>Fetch: Request and Response text() should decode as UTF-8</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://fetch.spec.whatwg.org/#body-mixin" />
<script src="../resources/utils.js"></script>
<script>
function testTextDecoding(body, expectedText, urlParameter, title)
{
var arrayBuffer = stringToArray(body);
promise_test(function(test) {
var request = new Request("", {method: "POST", body: arrayBuffer});
return request.text().then(function(value) {
assert_equals(value, expectedText, "Request.text() should decode data as UTF-8");
});
}, title + " with Request.text()");
promise_test(function(test) {
var response = new Response(arrayBuffer);
return response.text().then(function(value) {
assert_equals(value, expectedText, "Response.text() should decode data as UTF-8");
});
}, title + " with Response.text()");
promise_test(function(test) {
return fetch("../resources/status.py?code=200&type=text%2Fplain%3Bcharset%3DUTF-8&content=" + urlParameter).then(function(response) {
return response.text().then(function(value) {
assert_equals(value, expectedText, "Fetched Response.text() should decode data as UTF-8");
});
});
}, title + " with fetched data (UTF-8 charset)");
promise_test(function(test) {
return fetch("../resources/status.py?code=200&type=text%2Fplain%3Bcharset%3DUTF-16&content=" + urlParameter).then(function(response) {
return response.text().then(function(value) {
assert_equals(value, expectedText, "Fetched Response.text() should decode data as UTF-8");
});
});
}, title + " with fetched data (UTF-16 charset)");
}
var utf8WithBOM = "\xef\xbb\xbf\xe4\xb8\x89\xe6\x9d\x91\xe3\x81\x8b\xe3\x81\xaa\xe5\xad\x90";
var utf8WithBOMAsURLParameter = "%EF%BB%BF%E4%B8%89%E6%9D%91%E3%81%8B%E3%81%AA%E5%AD%90";
var utf8WithoutBOM = "\xe4\xb8\x89\xe6\x9d\x91\xe3\x81\x8b\xe3\x81\xaa\xe5\xad\x90";
var utf8WithoutBOMAsURLParameter = "%E4%B8%89%E6%9D%91%E3%81%8B%E3%81%AA%E5%AD%90";
var utf8Decoded = "三村かな子";
testTextDecoding(utf8WithBOM, utf8Decoded, utf8WithBOMAsURLParameter, "UTF-8 with BOM");
testTextDecoding(utf8WithoutBOM, utf8Decoded, utf8WithoutBOMAsURLParameter, "UTF-8 without BOM");
var utf16BEWithBOM = "\xfe\xff\x4e\x09\x67\x51\x30\x4b\x30\x6a\x5b\x50";
var utf16BEWithBOMAsURLParameter = "%fe%ff%4e%09%67%51%30%4b%30%6a%5b%50";
var utf16BEWithBOMDecodedAsUTF8 = "<22><>N\tgQ0K0j[P";
testTextDecoding(utf16BEWithBOM, utf16BEWithBOMDecodedAsUTF8, utf16BEWithBOMAsURLParameter, "UTF-16BE with BOM decoded as UTF-8");
var utf16LEWithBOM = "\xff\xfe\x09\x4e\x51\x67\x4b\x30\x6a\x30\x50\x5b";
var utf16LEWithBOMAsURLParameter = "%ff%fe%09%4e%51%67%4b%30%6a%30%50%5b";
var utf16LEWithBOMDecodedAsUTF8 = "<22><>\tNQgK0j0P[";
testTextDecoding(utf16LEWithBOM, utf16LEWithBOMDecodedAsUTF8, utf16LEWithBOMAsURLParameter, "UTF-16LE with BOM decoded as UTF-8");
var utf16WithoutBOM = "\xe6\x00\xf8\x00\xe5\x00\x0a\x00\xc6\x30\xb9\x30\xc8\x30\x0a\x00";
var utf16WithoutBOMAsURLParameter = "%E6%00%F8%00%E5%00%0A%00%C6%30%B9%30%C8%30%0A%00";
var utf16WithoutBOMDecoded = "\ufffd\u0000\ufffd\u0000\ufffd\u0000\u000a\u0000\ufffd\u0030\ufffd\u0030\ufffd\u0030\u000a\u0000";
testTextDecoding(utf16WithoutBOM, utf16WithoutBOMDecoded, utf16WithoutBOMAsURLParameter, "UTF-16 without BOM decoded as UTF-8");
</script>

View file

@ -13,7 +13,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-basic.js?pipe=sub"));
fetch_tests_from_worker(new Worker("cors-basic.js"));
</script>
</body>
</html>
</html>

View file

@ -13,6 +13,7 @@
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="cors-basic.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-basic.js"></script>
</body>
</html>
</html>

View file

@ -1,17 +1,11 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js");
}
function cors(desc, scheme, subdomain, port) {
if (!port)
port = location.port;
if (subdomain)
subdomain = subdomain + ".";
else
subdomain = "";
var url = scheme + "://" + subdomain + "{{host}}" + ":" + port + dirname(location.pathname);
function cors(desc, origin) {
var url = origin + dirname(location.pathname);
var urlParameters = "?pipe=header(Access-Control-Allow-Origin,*)";
promise_test(function(test) {
@ -19,13 +13,14 @@ function cors(desc, scheme, subdomain, port) {
assert_equals(resp.status, 0, "Opaque filter: status is 0");
assert_equals(resp.statusText, "", "Opaque filter: statusText is \"\"");
assert_equals(resp.type , "opaque", "Opaque filter: response's type is opaque");
return resp.text().then(function(value) {
assert_equals(value, "", "Opaque response should have an empty body");
});
});
}, desc + " [no-cors mode]");
promise_test(function(test) {
var testedPromise = fetch(url + RESOURCES_DIR + "top.txt", {"mode": "cors"} ).then(function(resp) {
return promise_rejects(test, new TypeError(), testedPromise);
});
return promise_rejects(test, new TypeError(), fetch(url + RESOURCES_DIR + "top.txt", {"mode": "cors"}));
}, desc + " [server forbid CORS]");
promise_test(function(test) {
@ -36,10 +31,12 @@ function cors(desc, scheme, subdomain, port) {
}, desc + " [cors mode]");
}
cors("Same domain different port", "http", undefined, "{{ports[http][1]}}");
cors("Same domain different protocol different port", "https", undefined, "{{ports[https][0]}}");
cors("Cross domain basic usage", "http", "www1");
cors("Cross domain different port", "http", "www1", "{{ports[http][1]}}");
cors("Cross domain different protocol", "https", "www1", "{{ports[https][0]}}");
var host_info = get_host_info();
cors("Same domain different port", host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT);
cors("Same domain different protocol different port", host_info.HTTPS_ORIGIN);
cors("Cross domain basic usage", host_info.HTTP_REMOTE_ORIGIN);
cors("Cross domain different port", host_info.HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT);
cors("Cross domain different protocol", host_info.HTTPS_REMOTE_ORIGIN);
done();

View file

@ -12,7 +12,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-cookies.js?pipe=sub"));
fetch_tests_from_worker(new Worker("cors-cookies.js"));
</script>
</body>
</html>
</html>

View file

@ -12,6 +12,7 @@
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="cors-cookies.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-cookies.js"></script>
</body>
</html>
</html>

View file

@ -1,11 +1,12 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
function corsCookies(desc, domain1, domain2, credentialsMode, cookies) {
var urlSetCookie = "http://" + domain1 + ":{{ports[http][0]}}" + dirname(location.pathname) + RESOURCES_DIR + "top.txt";
var urlCheckCookies = "http://" + domain2 + ":{{ports[http][0]}}" + dirname(location.pathname) + RESOURCES_DIR + "inspect-headers.py?cors&headers=cookie";
function corsCookies(desc, baseURL1, baseURL2, credentialsMode, cookies) {
var urlSetCookie = baseURL1 + dirname(location.pathname) + RESOURCES_DIR + "top.txt";
var urlCheckCookies = baseURL2 + dirname(location.pathname) + RESOURCES_DIR + "inspect-headers.py?cors&headers=cookie";
//enable cors with credentials
var urlParameters = "?pipe=header(Access-Control-Allow-Origin," + location.origin + ")";
urlParameters += "|header(Access-Control-Allow-Credentials,true)";
@ -29,7 +30,7 @@ function corsCookies(desc, domain1, domain2, credentialsMode, cookies) {
}).then(function(resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
assert_false(resp.headers.has("Cookie") , "Cookie header is not exposed in response");
if (credentialsMode === "include" && domain1 === domain2) {
if (credentialsMode === "include" && baseURL1 === baseURL2) {
assert_equals(resp.headers.get("x-request-cookie") , cookies.join("; "), "Request includes cookie(s)");
}
else {
@ -38,21 +39,23 @@ function corsCookies(desc, domain1, domain2, credentialsMode, cookies) {
//clean cookies
return fetch(urlSetCookie + urlCleanParameters, {"credentials": "include"});
}).catch(function(e) {
fetch(urlSetCookie + urlCleanParameters, {"credentials": "include"});
throw e;
return fetch(urlSetCookie + urlCleanParameters, {"credentials": "include"}).then(function(resp) {
throw e;
})
});
}, desc);
}
var local = "{{host}}";
var remote = "www.{{host}}";
var remote1 = "www1.{{host}}";
var local = get_host_info().HTTP_ORIGIN;
var remote = get_host_info().HTTP_REMOTE_ORIGIN;
// FIXME: otherRemote might not be accessible on some test environments.
var otherRemote = local.replace("http://", "http://www.");
corsCookies("Omit mode: no cookie sent", local, local, "omit", ["g=7"]);
corsCookies("Include mode: 1 cookie", remote, remote, "include", ["a=1"]);
corsCookies("Include mode: local cookies are not sent with remote request", local, remote, "include", ["c=3"]);
corsCookies("Include mode: remote cookies are not sent with local request", remote, local, "include", ["d=4"]);
corsCookies("Include mode: remote cookies are not sent with other remote request", remote, remote1, "include", ["e=5"]);
corsCookies("Same-origin mode: cookies are discarded in cors request", remote, remote, "same-origin", ["f=6"]);
corsCookies("Include mode: remote cookies are not sent with other remote request", remote, otherRemote, "include", ["e=5"]);
done();

View file

@ -14,7 +14,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-no-preflight.js?pipe=sub"));
fetch_tests_from_worker(new Worker("cors-no-preflight.js"));
</script>
</body>
</html>
</html>

View file

@ -15,6 +15,7 @@
<body>
<script src="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="cors-no-preflight.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-no-preflight.js"></script>
</body>
</html>
</html>

View file

@ -1,26 +1,21 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("/common/utils.js");
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
function corsNoPreflight(desc, scheme, subdomain, port, method, headerName, headerValue) {
if (!port)
port = location.port;
if (subdomain)
subdomain = subdomain + ".";
else
subdomain = "";
function corsNoPreflight(desc, baseURL, method, headerName, headerValue) {
var uuid_token = token();
var url = scheme + "://" + subdomain + "{{host}}" + ":" + port + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var url = baseURL + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var urlParameters = "?token=" + uuid_token + "&max_age=0";
var requestInit = {"mode": "cors", "method": method, "headers":{}};
if (headerName)
requestInit["headers"][headerName] = headerValue;
promise_test(function(test) {
fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
assert_equals(resp.status, 200, "Clean stash response's status is 200");
return fetch(url + urlParameters, requestInit).then(function(resp) {
assert_equals(resp.status, 200, "Response's status is 200");
@ -29,22 +24,23 @@ function corsNoPreflight(desc, scheme, subdomain, port, method, headerName, head
});
}, desc);
}
var port2 = "{{ports[http][1]}}";
var httpsPort = "{{ports[https][0]}}";
corsNoPreflight("Cross domain basic usage [GET]", "http", "www1", undefined, "GET");
corsNoPreflight("Same domain different port [GET]", "http", undefined, port2, "GET");
corsNoPreflight("Cross domain different port [GET]", "http", "www1", port2, "GET");
corsNoPreflight("Cross domain different protocol [GET]", "https", "www1", httpsPort, "GET");
corsNoPreflight("Same domain different protocol different port [GET]", "https", undefined, httpsPort, "GET");
corsNoPreflight("Cross domain [POST]", "http", "www1", undefined, "POST");
corsNoPreflight("Cross domain [HEAD]", "http", "www1", undefined, "HEAD");
corsNoPreflight("Cross domain [GET] [Accept: */*]", "http", "www1", undefined, "GET" , "Accept", "*/*");
corsNoPreflight("Cross domain [GET] [Accept-Language: fr]", "http", "www1", undefined, "GET" , "Accept-Language", "fr");
corsNoPreflight("Cross domain [GET] [Content-Language: fr]", "http", "www1", undefined, "GET" , "Content-Language", "fr");
corsNoPreflight("Cross domain [GET] [Content-Type: application/x-www-form-urlencoded]", "http", "www1", undefined, "GET" , "Content-Type", "application/x-www-form-urlencoded");
corsNoPreflight("Cross domain [GET] [Content-Type: multipart/form-data]", "http", "www1", undefined, "GET" , "Content-Type", "multipart/form-data");
corsNoPreflight("Cross domain [GET] [Content-Type: text/plain]", "http", "www1", undefined, "GET" , "Content-Type", "text/plain");
corsNoPreflight("Cross domain [GET] [Content-Type: text/plain;charset=utf-8]", "http", "www1", undefined, "GET" , "Content-Type", "text/plain;charset=utf-8");
var host_info = get_host_info();
corsNoPreflight("Cross domain basic usage [GET]", host_info.HTTP_REMOTE_ORIGIN, "GET");
corsNoPreflight("Same domain different port [GET]", host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT, "GET");
corsNoPreflight("Cross domain different port [GET]", host_info.HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT, "GET");
corsNoPreflight("Cross domain different protocol [GET]", host_info.HTTPS_REMOTE_ORIGIN, "GET");
corsNoPreflight("Same domain different protocol different port [GET]", host_info.HTTPS_ORIGIN, "GET");
corsNoPreflight("Cross domain [POST]", host_info.HTTP_REMOTE_ORIGIN, "POST");
corsNoPreflight("Cross domain [HEAD]", host_info.HTTP_REMOTE_ORIGIN, "HEAD");
corsNoPreflight("Cross domain [GET] [Accept: */*]", host_info.HTTP_REMOTE_ORIGIN, "GET" , "Accept", "*/*");
corsNoPreflight("Cross domain [GET] [Accept-Language: fr]", host_info.HTTP_REMOTE_ORIGIN, "GET" , "Accept-Language", "fr");
corsNoPreflight("Cross domain [GET] [Content-Language: fr]", host_info.HTTP_REMOTE_ORIGIN, "GET" , "Content-Language", "fr");
corsNoPreflight("Cross domain [GET] [Content-Type: application/x-www-form-urlencoded]", host_info.HTTP_REMOTE_ORIGIN, "GET" , "Content-Type", "application/x-www-form-urlencoded");
corsNoPreflight("Cross domain [GET] [Content-Type: multipart/form-data]", host_info.HTTP_REMOTE_ORIGIN, "GET" , "Content-Type", "multipart/form-data");
corsNoPreflight("Cross domain [GET] [Content-Type: text/plain]", host_info.HTTP_REMOTE_ORIGIN, "GET" , "Content-Type", "text/plain");
corsNoPreflight("Cross domain [GET] [Content-Type: text/plain;charset=utf-8]", host_info.HTTP_REMOTE_ORIGIN, "GET" , "Content-Type", "text/plain;charset=utf-8");
corsNoPreflight("Cross domain [GET] [Content-Type: Text/Plain;charset=utf-8]", host_info.HTTP_REMOTE_ORIGIN, "GET" , "Content-Type", "Text/Plain;charset=utf-8");
done();

View file

@ -13,7 +13,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-origin.js?pipe=sub"));
fetch_tests_from_worker(new Worker("cors-origin.js"));
</script>
</body>
</html>
</html>

View file

@ -14,6 +14,7 @@
<body>
<script src="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="cors-origin.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-origin.js"></script>
</body>
</html>
</html>

View file

@ -1,27 +1,22 @@
if (this.document === undefined) {
importScripts("/common/utils.js");
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/utils.js");
importScripts("/common/get-host-info.sub.js")
}
/* If origin is undefined, it is set to fetched url's origin*/
function corsOrigin(desc, scheme, subdomain, port, method, origin, shouldPass) {
if (!port)
port = location.port;
if (subdomain)
subdomain = subdomain + ".";
else
subdomain = "";
function corsOrigin(desc, baseURL, method, origin, shouldPass) {
if (!origin)
origin = scheme + "://" + subdomain + "{{host}}" + ":" + port;
origin = baseURL;
var uuid_token = token();
var urlParameters = "?token=" + uuid_token + "&max_age=0&origin=" + encodeURIComponent(origin) + "&allow_methods=" + method;
var url = scheme + "://" + subdomain + "{{host}}" + ":" + port + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var url = baseURL + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var requestInit = {"mode": "cors", "method": method};
promise_test(function(test) {
fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
assert_equals(resp.status, 200, "Clean stash response's status is 200");
if (shouldPass) {
return fetch(url + urlParameters, requestInit).then(function(resp) {
@ -34,28 +29,28 @@ function corsOrigin(desc, scheme, subdomain, port, method, origin, shouldPass) {
}, desc);
}
var port = "{{ports[http][0]}}";
var port2 = "{{ports[http][1]}}";
var httpsPort = "{{ports[https][0]}}";
/* Actual origin */
var origin = "http://{{host}}:{{ports[http][0]}}";
corsOrigin("Cross domain different subdomain [origin OK]", "http", "www1", undefined, "GET", origin, true);
corsOrigin("Cross domain different subdomain [origin KO]", "http", "www1", undefined, "GET", undefined, false);
corsOrigin("Same domain different port [origin OK]", "http", undefined, port2, "GET", origin, true);
corsOrigin("Same domain different port [origin KO]", "http", undefined, port2, "GET", undefined, false);
corsOrigin("Cross domain different port [origin OK]", "http", "www1", port2, "GET", origin, true);
corsOrigin("Cross domain different port [origin KO]", "http", "www1", port2, "GET", undefined, false);
corsOrigin("Cross domain different protocol [origin OK]", "https", "www1", httpsPort, "GET", origin, true);
corsOrigin("Cross domain different protocol [origin KO]", "https", "www1", httpsPort, "GET", undefined, false);
corsOrigin("Same domain different protocol different port [origin OK]", "https", undefined, httpsPort, "GET", origin, true);
corsOrigin("Same domain different protocol different port [origin KO]", "https", undefined, httpsPort, "GET", undefined, false);
corsOrigin("Cross domain [POST] [origin OK]", "http", "www1", undefined, "POST", origin, true);
corsOrigin("Cross domain [POST] [origin KO]", "http", "www1", undefined, "POST", undefined, false);
corsOrigin("Cross domain [HEAD] [origin OK]", "http", "www1", undefined, "HEAD", origin, true);
corsOrigin("Cross domain [HEAD] [origin KO]", "http", "www1", undefined, "HEAD", undefined, false);
corsOrigin("CORS preflight [PUT] [origin OK]", "http", "www1", undefined, "PUT", origin, true);
corsOrigin("CORS preflight [PUT] [origin KO]", "http", "www1", undefined, "PUT", undefined, false);
corsOrigin("Allowed origin: \"\" [origin KO]", "http", "www1", undefined, "GET", "" , false);
var host_info = get_host_info();
/* Actual origin */
var origin = host_info.HTTP_ORIGIN;
corsOrigin("Cross domain different subdomain [origin OK]", host_info.HTTP_REMOTE_ORIGIN, "GET", origin, true);
corsOrigin("Cross domain different subdomain [origin KO]", host_info.HTTP_REMOTE_ORIGIN, "GET", undefined, false);
corsOrigin("Same domain different port [origin OK]", host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT, "GET", origin, true);
corsOrigin("Same domain different port [origin KO]", host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT, "GET", undefined, false);
corsOrigin("Cross domain different port [origin OK]", host_info.HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT, "GET", origin, true);
corsOrigin("Cross domain different port [origin KO]", host_info.HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT, "GET", undefined, false);
corsOrigin("Cross domain different protocol [origin OK]", host_info.HTTPS_REMOTE_ORIGIN, "GET", origin, true);
corsOrigin("Cross domain different protocol [origin KO]", host_info.HTTPS_REMOTE_ORIGIN, "GET", undefined, false);
corsOrigin("Same domain different protocol different port [origin OK]", host_info.HTTPS_ORIGIN, "GET", origin, true);
corsOrigin("Same domain different protocol different port [origin KO]", host_info.HTTPS_ORIGIN, "GET", undefined, false);
corsOrigin("Cross domain [POST] [origin OK]", host_info.HTTP_REMOTE_ORIGIN, "POST", origin, true);
corsOrigin("Cross domain [POST] [origin KO]", host_info.HTTP_REMOTE_ORIGIN, "POST", undefined, false);
corsOrigin("Cross domain [HEAD] [origin OK]", host_info.HTTP_REMOTE_ORIGIN, "HEAD", origin, true);
corsOrigin("Cross domain [HEAD] [origin KO]", host_info.HTTP_REMOTE_ORIGIN, "HEAD", undefined, false);
corsOrigin("CORS preflight [PUT] [origin OK]", host_info.HTTP_REMOTE_ORIGIN, "PUT", origin, true);
corsOrigin("CORS preflight [PUT] [origin KO]", host_info.HTTP_REMOTE_ORIGIN, "PUT", undefined, false);
corsOrigin("Allowed origin: \"\" [origin KO]", host_info.HTTP_REMOTE_ORIGIN, "GET", "" , false);
done();

View file

@ -12,7 +12,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-preflight-redirect.js?pipe=sub"));
fetch_tests_from_worker(new Worker("cors-preflight-redirect.js"));
</script>
</body>
</html>
</html>

View file

@ -13,6 +13,7 @@
<body>
<script src="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="cors-preflight-redirect.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-preflight-redirect.js"></script>
</body>
</html>
</html>

View file

@ -2,6 +2,7 @@ if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/utils.js");
importScripts("/common/get-host-info.sub.js");
}
function corsPreflightRedirect(desc, redirectUrl, redirectLocation, redirectStatus, redirectPreflight) {
@ -27,8 +28,8 @@ function corsPreflightRedirect(desc, redirectUrl, redirectLocation, redirectStat
}, desc);
}
var redirectUrl = "http://www1.{{host}}:{{ports[http][0]}}" + dirname(location.pathname) + RESOURCES_DIR + "redirect.py";
var locationUrl = "http://www1.{{host}}:{{ports[http][0]}}" + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var redirectUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "redirect.py";
var locationUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
for (var code of [301, 302, 303, 307, 308]) {
/* preflight should not follow the redirection */

View file

@ -12,7 +12,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-preflight-referrer.js?pipe=sub"));
fetch_tests_from_worker(new Worker("cors-preflight-referrer.js"));
</script>
</body>
</html>
</html>

View file

@ -13,6 +13,7 @@
<body>
<script src="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="cors-preflight-referrer.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-preflight-referrer.js"></script>
</body>
</html>
</html>

View file

@ -1,6 +1,7 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("/common/utils.js");
importScripts("/common/get-host-info.sub.js");
importScripts("../resources/utils.js");
}
@ -15,23 +16,24 @@ function corsPreflightReferrer(desc, corsUrl, referrerPolicy, expectedReferrer)
urlParameters += "&allow_headers=x-force-preflight";
promise_test(function(test) {
fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
assert_equals(resp.status, 200, "Clean stash response's status is 200");
return fetch(url + urlParameters, requestInit).then(function(resp) {
assert_equals(resp.status, 200, "Response's status is 200");
assert_equals(resp.headers.get("x-did-preflight"), "1", "Preflight request has been made");
assert_equals(resp.headers.get("x-preflight-referrer"), expectedReferrer, "Preflight's referrer is correct");
assert_equals(resp.headers.get("x-referrer"), expectedReferrer, "Request's refferer is correct");
assert_equals(resp.headers.get("x-referrer"), expectedReferrer, "Request's referrer is correct");
});
});
}, desc);
}
var corsUrl = "http://www1.{{host}}:{{ports[http][0]}}" + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var origin = "http://{{host}}:{{ports[http][0]}}";
var corsUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var origin = get_host_info().HTTP_ORIGIN + "/";
corsPreflightReferrer("Referrer policy: no-referrer", corsUrl, "no-referrer", "");
corsPreflightReferrer("Referrer policy: \"\"", corsUrl, "", "");
corsPreflightReferrer("Referrer policy: \"\"", corsUrl, "", location.toString())
corsPreflightReferrer("Referrer policy: origin", corsUrl, "origin", origin);
corsPreflightReferrer("Referrer policy: origin-when-cross-origin", corsUrl, "origin-when-cross-origin", origin);
corsPreflightReferrer("Referrer policy: unsafe-url", corsUrl, "unsafe-url", location.toString());

View file

@ -12,7 +12,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-preflight-status.js?pipe=sub"));
fetch_tests_from_worker(new Worker("cors-preflight-status.js"));
</script>
</body>
</html>
</html>

View file

@ -12,6 +12,7 @@
<body>
<script src="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="cors-preflight-status.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-preflight-status.js"></script>
</body>
</html>
</html>

View file

@ -2,6 +2,7 @@ if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/utils.js");
importScripts("/common/get-host-info.sub.js");
}
/* Check preflight is ok if status is ok status (200 to 299)*/
@ -31,7 +32,7 @@ function corsPreflightStatus(desc, corsUrl, preflightStatus) {
}, desc);
}
var corsUrl = "http://www1.{{host}}:{{ports[http][0]}}" + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var corsUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
for (status of [200, 201, 202, 203, 204, 205, 206,
300, 301, 302, 303, 304, 305, 306, 307, 308,
400, 401, 402, 403, 404, 405,

View file

@ -14,7 +14,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-preflight.js?pipe=sub"));
fetch_tests_from_worker(new Worker("cors-preflight.js"));
</script>
</body>
</html>
</html>

View file

@ -14,7 +14,8 @@
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="cors-preflight.js?pipe=sub"></script>
<script src="cors-preflight.js"></script>
</body>
</html>
</html>

View file

@ -1,7 +1,16 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/utils.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js");
}
function headerNames(headers)
{
let names = [];
for (let header of headers)
names.push(header[0].toLowerCase());
return names
}
/*
@ -9,54 +18,54 @@ if (this.document === undefined) {
Control if server allows method and headers and check accordingly
Check control access headers added by UA (for method and headers)
*/
function corsPreflight(desc, corsUrl, method, allowed, headers) {
var uuid_token = token();
fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(response) {
function corsPreflight(desc, corsUrl, method, allowed, headers, safeHeaders) {
return promise_test(function(test) {
var uuid_token = token();
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(response) {
var url = corsUrl;
var urlParameters = "?token=" + uuid_token + "&max_age=0";
var requestInit = {"mode": "cors", "method": method};
var requestHeaders = [];
if (headers)
requestHeaders.push.apply(requestHeaders, headers);
if (safeHeaders)
requestHeaders.push.apply(requestHeaders, safeHeaders);
requestInit["headers"] = requestHeaders;
var url = corsUrl;
var urlParameters = "?token=" + uuid_token + "&max_age=0";
var requestInit = {"mode": "cors", "method": method};
if (headers)
requestInit["headers"] = headers;
if (allowed) {
urlParameters += "&allow_methods=" + method;
if (headers) {
//Let's check prefligh request.
//Server will send back headers from Access-Control-Request-Headers in x-control-request-headers
urlParameters += "&control_request_headers"
//Make the server allow the headers
urlParameters += "&allow_headers="
urlParameters += headers.map(function (x) { return x[0]; }).join("%2C%20");
}
promise_test(function(test) {
test.add_cleanup(function() {
fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token);
});
if (allowed) {
urlParameters += "&allow_methods=" + method;
if (headers) {
//Let's check prefligh request.
//Server will send back headers from Access-Control-Request-Headers in x-control-request-headers
urlParameters += "&control_request_headers"
//Make the server allow the headers
urlParameters += "&allow_headers=" + headerNames(headers).join("%20%2C");
}
return fetch(url + urlParameters, requestInit).then(function(resp) {
assert_equals(resp.status, 200, "Response's status is 200");
assert_equals(resp.headers.get("x-did-preflight"), "1", "Preflight request has been made");
if (headers) {
var actualHeaders = resp.headers.get("x-control-request-headers").split(",");
var actualHeaders = resp.headers.get("x-control-request-headers").toLowerCase().split(",");
for (var i in actualHeaders)
actualHeaders[i] = actualHeaders[i].trim();
for (var header of headers)
assert_in_array(header[0], actualHeaders, "Preflight asked permission for header: " + header);
assert_in_array(header[0].toLowerCase(), actualHeaders, "Preflight asked permission for header: " + header);
let accessControlAllowHeaders = headerNames(headers).sort().join(",");
assert_equals(resp.headers.get("x-control-request-headers").replace(new RegExp(" ", "g"), ""), accessControlAllowHeaders, "Access-Control-Allow-Headers value");
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token);
}
});
}, desc);
} else {
promise_test(function(test) {
test.add_cleanup(function() {
fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token);
} else {
return promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit)).then(function(){
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token);
});
return promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit));
}, desc);
}
});
}
});
}, desc);
}
var corsUrl = "http://www1.{{host}}:{{ports[http][0]}}" + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var corsUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
corsPreflight("CORS [DELETE], server allows", corsUrl, "DELETE", true);
corsPreflight("CORS [DELETE], server refuses", corsUrl, "DELETE", false);
@ -70,10 +79,25 @@ corsPreflight("CORS [NEW], server refuses", corsUrl, "NEW", false);
corsPreflight("CORS [GET] [x-test-header: allowed], server allows", corsUrl, "GET", true, [["x-test-header1", "allowed"]]);
corsPreflight("CORS [GET] [x-test-header: refused], server refuses", corsUrl, "GET", false, [["x-test-header1", "refused"]]);
var headers = [["x-test-header1", "allowedOrRefused"],
["x-test-header2", "allowedOrRefused"],
["x-test-header3", "allowedOrRefused"]];
corsPreflight("CORS [GET] [several headers], server allows", corsUrl, "GET", true, headers);
corsPreflight("CORS [GET] [several headers], server refuses", corsUrl, "GET", false, headers);
corsPreflight("CORS [PUT] [several headers], server allows", corsUrl, "PUT", true, headers);
corsPreflight("CORS [PUT] [several headers], server refuses", corsUrl, "PUT", false, headers);
var headers = [
["x-test-header1", "allowedOrRefused"],
["x-test-header2", "allowedOrRefused"],
["X-test-header3", "allowedOrRefused"],
["x-test-header-b", "allowedOrRefused"],
["x-test-header-D", "allowedOrRefused"],
["x-test-header-C", "allowedOrRefused"],
["x-test-header-a", "allowedOrRefused"],
["Content-Type", "allowedOrRefused"],
];
var safeHeaders= [
["Accept", "*"],
["Accept-Language", "bzh"],
["Content-Language", "eu"],
];
corsPreflight("CORS [GET] [several headers], server allows", corsUrl, "GET", true, headers, safeHeaders);
corsPreflight("CORS [GET] [several headers], server refuses", corsUrl, "GET", false, headers, safeHeaders);
corsPreflight("CORS [PUT] [several headers], server allows", corsUrl, "PUT", true, headers, safeHeaders);
corsPreflight("CORS [PUT] [several headers], server refuses", corsUrl, "PUT", false, headers, safeHeaders);
done();

View file

@ -10,6 +10,7 @@
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="cors-redirect-credentials.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-redirect-credentials.js"></script>
</body>
</html>
</html>

View file

@ -1,6 +1,7 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
function corsRedirectCredentials(desc, redirectUrl, redirectLocation, redirectStatus, locationCredentials) {
@ -19,12 +20,14 @@ function corsRedirectCredentials(desc, redirectUrl, redirectLocation, redirectSt
var redirPath = dirname(location.pathname) + RESOURCES_DIR + "redirect.py";
var preflightPath = dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var localRedirect = "http://{{host}}:{{ports[http][0]}}" + redirPath;
var remoteRedirect = "http://{{host}}:{{ports[http][1]}}" + redirPath;
var host_info = get_host_info();
var localLocation = "http://{{host}}:{{ports[http][0]}}" + preflightPath;
var remoteLocation = "http://{{host}}:{{ports[http][1]}}" + preflightPath;
var remoteLocation2 = "http://www.{{host}}:{{ports[http][0]}}" + preflightPath;
var localRedirect = host_info.HTTP_ORIGIN + redirPath;
var remoteRedirect = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT + redirPath;
var localLocation = host_info.HTTP_ORIGIN + preflightPath;
var remoteLocation = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT + preflightPath;
var remoteLocation2 = host_info.HTTP_REMOTE_ORIGIN + preflightPath;
for (var code of [301, 302, 303, 307, 308]) {
corsRedirectCredentials("Redirect " + code + " from same origin to remote with user and password", localRedirect, remoteLocation, code, "user:password");

View file

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: CORS preflight after redirection</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#http-redirect-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-redirect-preflight.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: CORS preflight after redirection</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#http-redirect-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="../resources/utils.js"></script>
<script src="cors-redirect-preflight.js"></script>
</body>
</html>

View file

@ -0,0 +1,50 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("/common/utils.js");
importScripts("/common/get-host-info.sub.js");
importScripts("../resources/utils.js");
}
function corsRedirect(desc, redirectUrl, redirectLocation, redirectStatus, expectSuccess) {
var urlBaseParameters = "&redirect_status=" + redirectStatus;
var urlParametersSuccess = urlBaseParameters + "&allow_headers=x-w3c&location=" + encodeURIComponent(redirectLocation + "?allow_headers=x-w3c");
var urlParametersFailure = urlBaseParameters + "&location=" + encodeURIComponent(redirectLocation);
var requestInit = {"mode": "cors", "redirect": "follow", "headers" : [["x-w3c", "test"]]};
promise_test(function(test) {
var uuid_token = token();
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
return fetch(redirectUrl + "?token=" + uuid_token + "&max_age=0" + urlParametersSuccess, requestInit).then(function(resp) {
assert_equals(resp.status, 200, "Response's status is 200");
assert_equals(resp.headers.get("x-did-preflight"), "1", "Preflight request has been made");
});
});
}, desc + " (preflight after redirection success case)");
promise_test(function(test) {
var uuid_token = token();
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
return promise_rejects(test, new TypeError(), fetch(redirectUrl + "?token=" + uuid_token + "&max_age=0" + urlParametersFailure, requestInit));
});
}, desc + " (preflight after redirection failure case)");
}
var redirPath = dirname(location.pathname) + RESOURCES_DIR + "redirect.py";
var preflightPath = dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var host_info = get_host_info();
var localRedirect = host_info.HTTP_ORIGIN + redirPath;
var remoteRedirect = host_info.HTTP_REMOTE_ORIGIN + redirPath;
var localLocation = host_info.HTTP_ORIGIN + preflightPath;
var remoteLocation = host_info.HTTP_REMOTE_ORIGIN + preflightPath;
var remoteLocation2 = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT + preflightPath;
for (var code of [301, 302, 303, 307, 308]) {
corsRedirect("Redirect " + code + ": same origin to cors", localRedirect, remoteLocation, code);
corsRedirect("Redirect " + code + ": cors to same origin", remoteRedirect, localLocation, code);
corsRedirect("Redirect " + code + ": cors to another cors", remoteRedirect, remoteLocation2, code);
}
done();

View file

@ -11,7 +11,7 @@
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-redirect.js?pipe=sub"));
fetch_tests_from_worker(new Worker("cors-redirect.js"));
</script>
</body>
</html>
</html>

View file

@ -12,6 +12,7 @@
<body>
<script src="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="cors-redirect.js?pipe=sub"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-redirect.js"></script>
</body>
</html>
</html>

View file

@ -2,6 +2,7 @@ if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("/common/utils.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js");
}
function corsRedirect(desc, redirectUrl, redirectLocation, redirectStatus, expectedOrigin) {
@ -13,7 +14,7 @@ function corsRedirect(desc, redirectUrl, redirectLocation, redirectStatus, expec
var requestInit = {"mode": "cors", "redirect": "follow"};
promise_test(function(test) {
return promise_test(function(test) {
fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
return fetch(url + urlParameters, requestInit).then(function(resp) {
assert_equals(resp.status, 200, "Response's status is 200");
@ -27,12 +28,14 @@ function corsRedirect(desc, redirectUrl, redirectLocation, redirectStatus, expec
var redirPath = dirname(location.pathname) + RESOURCES_DIR + "redirect.py";
var preflightPath = dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var localRedirect = "http://{{host}}:{{ports[http][0]}}" + redirPath;
var remoteRedirect = "http://www1.{{host}}:{{ports[http][0]}}" + redirPath;
var host_info = get_host_info();
var localLocation = "http://{{host}}:{{ports[http][0]}}" + preflightPath;
var remoteLocation = "http://www1.{{host}}:{{ports[http][0]}}" + preflightPath;
var remoteLocation2 = "http://www.{{host}}:{{ports[http][0]}}" + preflightPath;
var localRedirect = host_info.HTTP_ORIGIN + redirPath;
var remoteRedirect = host_info.HTTP_REMOTE_ORIGIN + redirPath;
var localLocation = host_info.HTTP_ORIGIN + preflightPath;
var remoteLocation = host_info.HTTP_REMOTE_ORIGIN + preflightPath;
var remoteLocation2 = host_info.HTTP_ORIGIN_WITH_DIFFERENT_PORT + preflightPath;
for (var code of [301, 302, 303, 307, 308]) {
corsRedirect("Redirect " + code + ": cors to same cors", remoteRedirect, remoteLocation, code, location.origin);

View file

@ -120,14 +120,29 @@
"Content-Types": "value6"
};
var sortedHeaderDict = {};
var headerValues = [];
var sortedHeaderKeys = Object.keys(headerEntriesDict).map(function(value) {
sortedHeaderDict[value.toLowerCase()] = headerEntriesDict[value];
headerValues.push(headerEntriesDict[value]);
return value.toLowerCase();
}).sort();
var iteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([].values()));
function checkIteratorProperties(iterator) {
var prototype = Object.getPrototypeOf(iterator);
assert_equals(Object.getPrototypeOf(prototype), iteratorPrototype);
var descriptor = Object.getOwnPropertyDescriptor(prototype, "next");
assert_true(descriptor.configurable, "configurable");
assert_true(descriptor.enumerable, "enumerable");
assert_true(descriptor.writable, "writable");
}
test(function() {
var headers = new Headers(headerEntriesDict);
var actual = headers.keys();
checkIteratorProperties(actual);
sortedHeaderKeys.forEach(function(key) {
entry = actual.next();
assert_false(entry.done);
@ -135,11 +150,15 @@
});
assert_true(actual.next().done);
assert_true(actual.next().done);
for (key of headers.keys())
assert_true(sortedHeaderKeys.indexOf(key) != -1);
}, "Check keys method");
test(function() {
var headers = new Headers(headerEntriesDict);
var actual = headers.values();
checkIteratorProperties(actual);
sortedHeaderKeys.forEach(function(key) {
entry = actual.next();
@ -148,11 +167,15 @@
});
assert_true(actual.next().done);
assert_true(actual.next().done);
for (value of headers.values())
assert_true(headerValues.indexOf(value) != -1);
}, "Check values method");
test(function() {
var headers = new Headers(headerEntriesDict);
var actual = headers.entries();
checkIteratorProperties(actual);
sortedHeaderKeys.forEach(function(key) {
entry = actual.next();
@ -162,6 +185,9 @@
});
assert_true(actual.next().done);
assert_true(actual.next().done);
for (entry of headers.entries())
assert_equals(entry[1], sortedHeaderDict[entry[0]]);
}, "Check entries method");
test(function() {

View file

@ -18,8 +18,8 @@
["triple", "tripleValue3"]
];
var expectedDict = {"single": "singleValue",
"double": "doubleValue1, doubleValue2",
"triple": "tripleValue1, tripleValue2, tripleValue3"
"double": "doubleValue1,doubleValue2",
"triple": "tripleValue1,tripleValue2,tripleValue3"
};
test(function() {
@ -51,7 +51,7 @@
for (name in expectedDict) {
var value = headers.get(name);
headers.append(name,"newSingleValue");
assert_equals(headers.get(name), (value + ", " + "newSingleValue"),
assert_equals(headers.get(name), (value + "," + "newSingleValue"),
"name: " + name + " has value: " + headers.get(name));
}
}, "Check append methods when called with already used name");

View file

@ -1 +1 @@
Content-Security-Policy: referrer no-referrer;
Referrer-Policy: no-referrer

View file

@ -1 +1 @@
Content-Security-Policy: referrer no-referrer;
Referrer-Policy: no-referrer

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: referrer with origin-when-cross-origin policy</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-network-or-cache-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("referrer-origin-when-cross-origin.js?pipe=sub"));
</script>
</body>
</html>

View file

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: referrer with origin-when-cross-origin policy</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-network-or-cache-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="referrer-origin-when-cross-origin.js?pipe=sub"></script>
</body>
</html>

View file

@ -0,0 +1 @@
Referrer-Policy: origin-when-cross-origin

View file

@ -0,0 +1,16 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
var referrerOrigin = "http://{{host}}:{{ports[http][0]}}/";
var fetchedUrl = "http://{{host}}:{{ports[http][1]}}" + dirname(location.pathname) + RESOURCES_DIR + "inspect-headers.py?cors&headers=referer";
promise_test(function(test) {
return fetch(fetchedUrl).then(function(resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
assert_equals(resp.headers.get("x-request-referer"), referrerOrigin, "request's referrer is " + referrerOrigin);
});
}, "Request's referrer is origin");
done();

View file

@ -0,0 +1 @@
Referrer-Policy: origin-when-cross-origin

View file

@ -1 +1 @@
Content-Security-Policy: referrer origin;
Referrer-Policy: origin

View file

@ -1 +1 @@
Content-Security-Policy: referrer origin;
Referrer-Policy: origin

View file

@ -1 +1 @@
Content-Security-Policy: referrer unsafe-url;
Referrer-Policy: unsafe-url

View file

@ -1 +1 @@
Content-Security-Policy: referrer unsafe-url;
Referrer-Policy: unsafe-url

View file

@ -10,7 +10,7 @@
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="redirect-mode.js"></script>
</body>
</html>
</html>

View file

@ -1,6 +1,6 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
function redirectMode(desc, redirectUrl, redirectLocation, redirectStatus, redirectMode) {
@ -18,6 +18,7 @@ function redirectMode(desc, redirectUrl, redirectLocation, redirectStatus, redir
assert_equals(resp.status, 0, "Response's status is 0");
assert_equals(resp.type, "opaqueredirect", "Response's type is opaqueredirect");
assert_equals(resp.statusText, "", "Response's statusText is \"\"");
assert_equals(resp.url, url + urlParameters, "Response URL should be the original one");
});
if (redirectMode === "follow")
return fetch(url + urlParameters, requestInit).then(function(resp) {
@ -28,7 +29,7 @@ function redirectMode(desc, redirectUrl, redirectLocation, redirectStatus, redir
}, desc);
}
var redirUrl = RESOURCES_DIR + "redirect.py";
var redirUrl = get_host_info().HTTP_ORIGIN + "/fetch/api/resources/redirect.py";
var locationUrl = "top.txt";
for (var statusCode of [301, 302, 303, 307, 308]) {

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: redirect mode handling</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-network-or-cache-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("redirect-origin.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: redirect mode handling</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-network-or-cache-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="redirect-origin.js"></script>
</body>
</html>

View file

@ -0,0 +1,40 @@
if (this.document === undefined) {
importScripts("/common/utils.js");
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js");
}
function testOriginAfterRedirection(desc, redirectUrl, redirectLocation, redirectStatus, expectedOrigin) {
var uuid_token = token();
var url = redirectUrl;
var urlParameters = "?token=" + uuid_token + "&max_age=0";
urlParameters += "&redirect_status=" + redirectStatus;
urlParameters += "&location=" + encodeURIComponent(redirectLocation);
var requestInit = {"mode": "cors", "redirect": "follow"};
promise_test(function(test) {
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
assert_equals(resp.status, 200, "Clean stash response's status is 200");
return fetch(url + urlParameters, requestInit).then(function(response) {
assert_equals(response.status, 200, "Inspect header response's status is 200");
assert_equals(response.headers.get("x-request-origin"), expectedOrigin, "Check origin header");
});
});
}, desc);
}
var redirectUrl = RESOURCES_DIR + "redirect.py";
var corsRedirectUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "redirect.py";
var locationUrl = get_host_info().HTTP_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "inspect-headers.py?headers=origin";
var corsLocationUrl = get_host_info().HTTP_REMOTE_ORIGIN + dirname(location.pathname) + RESOURCES_DIR + "inspect-headers.py?cors&headers=origin";
for (var code of [301, 302, 303, 307, 308]) {
testOriginAfterRedirection("Same origin to same origin redirection " + code, redirectUrl, locationUrl, code, null);
testOriginAfterRedirection("Same origin to other origin redirection " + code, redirectUrl, corsLocationUrl, code, get_host_info().HTTP_ORIGIN);
testOriginAfterRedirection("Other origin to other origin redirection " + code, corsRedirectUrl, corsLocationUrl, code, get_host_info().HTTP_ORIGIN);
testOriginAfterRedirection("Other origin to same origin redirection " + code, corsRedirectUrl, locationUrl + "&cors", code, "null");
}
done();

View file

@ -6,18 +6,18 @@
<div id=log></div>
<script>
// All non-HTTP(S) schemes cannot survive redirects
var url = "../resources/redirect.py?location=",
tests = [
fetch(url + "mailto:a@a.com"),
fetch(url + "data:,HI"),
fetch(url + "facetime:a@a.org"),
fetch(url + "about:blank"),
fetch(url + "about:unicorn"),
fetch(url + "blob:djfksfjs")
var url = "../resources/redirect.py?location=";
var tests = [
url + "mailto:a@a.com",
url + "data:,HI",
url + "facetime:a@a.org",
url + "about:blank",
url + "about:unicorn",
url + "blob:djfksfjs"
];
tests.forEach(function(f) {
promise_test(function(t) {
return promise_rejects(t, new TypeError(), f)
tests.forEach(function(url) {
promise_test(function(test) {
return promise_rejects(test, new TypeError(), fetch(url))
})
})
</script>

View file

@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: data URL loading after redirections</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("redirect-to-dataurl.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: data URL loading after redirections</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="/common/get-host-info.sub.js"></script>
<script src="redirect-to-dataurl.js"></script>
</body>
</html>

View file

@ -0,0 +1,35 @@
if (this.document === undefined) {
importScripts("/common/get-host-info.sub.js")
importScripts("/resources/testharness.js");
}
var dataURL = "data:text/plain;base64,cmVzcG9uc2UncyBib2R5";
var body = "response's body";
var contentType = "text/plain";
function redirectDataURL(desc, redirectUrl, mode, isOK) {
var url = redirectUrl + "?cors&location=" + encodeURIComponent(dataURL);
var requestInit = {"mode": mode};
promise_test(function(test) {
var promise = fetch(url, requestInit).then(function(response) {
assert_equals(response.type, "opaque", "Response's type should be opaque");
assert_equals(response.url, "", "Response URL is empty");
assert_equals(response.status, 0, "Response's status should be 0");
});
return isOK ? promise : promise_rejects(test, new TypeError(), promise);
}, desc);
}
var redirUrl = get_host_info().HTTP_ORIGIN + "/fetch/api/resources/redirect.py";
var corsRedirUrl = get_host_info().HTTP_REMOTE_ORIGIN + "/fetch/api/resources/redirect.py";
redirectDataURL("Testing data URL loading after same-origin redirection (cors mode)", redirUrl, "cors", false);
redirectDataURL("Testing data URL loading after same-origin redirection (no-cors mode)", redirUrl, "no-cors", true);
redirectDataURL("Testing data URL loading after same-origin redirection (same-origin mode)", redirUrl, "same-origin", false);
redirectDataURL("Testing data URL loading after cross-origin redirection (cors mode)", corsRedirUrl, "cors", false);
redirectDataURL("Testing data URL loading after cross-origin redirection (no-cors mode)", corsRedirUrl, "no-cors", true);
done();

View file

@ -8,7 +8,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="resources/get-host-info.sub.js"></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script>

View file

@ -13,14 +13,17 @@
<body>
<script>
function checkBodyText(request, expectedBody) {
return request.text().then( function(bodyAsText) {
return request.text().then(function(bodyAsText) {
assert_equals(bodyAsText, expectedBody, "Retrieve and verify request's body");
assert_true(request.bodyUsed, "body as text: bodyUsed turned true");
});
}
function checkBodyBlob(request, expectedBody) {
function checkBodyBlob(request, expectedBody, checkContentType) {
return request.blob().then(function(bodyAsBlob) {
if (checkContentType)
assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the request Content-Type");
var promise = new Promise(function (resolve, reject) {
var reader = new FileReader();
reader.onload = function(evt) {
@ -60,24 +63,64 @@
});
}
function checkRequestBody(body, bodyType, checkFunction) {
function checkRequestBody(body, expected, bodyType) {
promise_test(function(test) {
var request = new Request("", {"method": "POST", "body": body, "headers": [["Content-Type", "text/PLAIN"]] });
assert_false(request.bodyUsed, "bodyUsed is false at init");
return checkBodyText(request, expected);
}, "Consume " + bodyType + " request's body as text");
promise_test(function(test) {
var request = new Request("", {"method": "POST", "body": body });
assert_false(request.bodyUsed, "bodyUsed is false at init");
return checkFunction(request, body);
}, "Consume request's body as " + bodyType);
return checkBodyBlob(request, expected);
}, "Consume " + bodyType + " request's body as blob");
promise_test(function(test) {
var request = new Request("", {"method": "POST", "body": body });
assert_false(request.bodyUsed, "bodyUsed is false at init");
return checkBodyArrayBuffer(request, expected);
}, "Consume " + bodyType + " request's body as arrayBuffer");
promise_test(function(test) {
var request = new Request("", {"method": "POST", "body": body });
assert_false(request.bodyUsed, "bodyUsed is false at init");
return checkBodyJSON(request, expected);
}, "Consume " + bodyType + " request's body as JSON");
}
var formData = new FormData();
formData.append("name", "value")
var textData = JSON.stringify("This is response's body");
var blob = new Blob([textData], { "type" : "text/plain" });
checkRequestBody(textData, "text", checkBodyText);
checkRequestBody(textData, "blob", checkBodyBlob);
checkRequestBody(textData, "arrayBuffer", checkBodyArrayBuffer);
checkRequestBody(textData, "json", checkBodyJSON);
checkRequestBody(formData, "formData", checkBodyFormData);
checkRequestBody(textData, textData, "String");
var string = "\"123456\"";
function getArrayBuffer() {
var arrayBuffer = new ArrayBuffer(8);
var int8Array = new Int8Array(arrayBuffer);
for (var cptr = 0; cptr < 8; cptr++)
int8Array[cptr] = string.charCodeAt(cptr);
return arrayBuffer;
}
function getArrayBufferWithZeros() {
var arrayBuffer = new ArrayBuffer(10);
var int8Array = new Int8Array(arrayBuffer);
for (var cptr = 0; cptr < 8; cptr++)
int8Array[cptr + 1] = string.charCodeAt(cptr);
return arrayBuffer;
}
checkRequestBody(getArrayBuffer(), string, "ArrayBuffer");
checkRequestBody(new Uint8Array(getArrayBuffer()), string, "Uint8Array");
checkRequestBody(new Int8Array(getArrayBufferWithZeros(), 1, 8), string, "Int8Array");
checkRequestBody(new Float32Array(getArrayBuffer()), string, "Float32Array");
checkRequestBody(new DataView(getArrayBufferWithZeros(), 1, 8), string, "DataView");
promise_test(function(test) {
var formData = new FormData();
formData.append("name", "value")
var request = new Request("", {"method": "POST", "body": formData });
assert_false(request.bodyUsed, "bodyUsed is false at init");
return checkBodyFormData(request, formData);
}, "Consume FormData request's body as FormData");
function checkBlobResponseBody(blobBody, blobData, bodyType, checkFunction) {
promise_test(function(test) {
@ -91,6 +134,7 @@
checkBlobResponseBody(blob, textData, "text", checkBodyText);
checkBlobResponseBody(blob, textData, "json", checkBodyJSON);
checkBlobResponseBody(blob, textData, "arrayBuffer", checkBodyArrayBuffer);
checkBlobResponseBody(new Blob([""]), "", "blob (empty blob as input)", checkBodyBlob);
var goodJSONValues = ["null", "1", "true", "\"string\""];
goodJSONValues.forEach(function(value) {

View file

@ -50,6 +50,28 @@
assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
return promise_rejects(test, new TypeError(), bodyConsumed.blob());
}, "Check consuming a disturbed request");
test(function() {
var req = new Request(URL, {method: 'POST', body: 'hello'});
assert_false(req.bodyUsed,
'Request should not be flagged as used if it has not been ' +
'consumed.');
assert_throws(new TypeError(),
function() { new Request(req, {method: 'GET'}); },
'A get request may not have body.');
assert_false(req.bodyUsed, 'After the GET case');
assert_throws(new TypeError(),
function() { new Request(req, {method: 'CONNECT'}); },
'Request() with a forbidden method must throw.');
assert_false(req.bodyUsed, 'After the forbidden method case');
var req2 = new Request(req);
assert_true(req.bodyUsed,
'Request should be flagged as used if it has been consumed.');
}, 'Request construction failure should not set "bodyUsed"');
</script>
</body>
</html>

View file

@ -145,6 +145,29 @@
assert_equals(request.headers.get("Content-Type"), "potato");
}, "Request should get its content-type from init headers if one is provided");
test(function() {
var array = [["hello", "worldAHH"]];
var object = {"hello": 'worldOOH'};
var headers = new Headers(array);
assert_equals(headers.get("hello"), "worldAHH");
var request1 = new Request("", {"headers": headers});
var request2 = new Request("", {"headers": array});
var request3 = new Request("", {"headers": object});
assert_equals(request1.headers.get("hello"), "worldAHH");
assert_equals(request2.headers.get("hello"), "worldAHH");
assert_equals(request3.headers.get("hello"), "worldOOH");
}, "Testing request header creations with various objects");
promise_test(function(test) {
var request = new Request("", {"headers" : [["Content-Type", ""]], "body" : "this is my plate", "method" : "POST"});
return request.blob().then(function(blob) {
assert_equals(blob.type, "", "Blob type should be the empty string");
});
}, "Testing empty Request Content-Type header");
</script>
</body>
</html>

View file

@ -31,9 +31,8 @@
promise_test(function(test) {
var request = new Request("", makeRequestInit(body, "POST"));
if (body) {
assert_throws(new TypeError(),
function() { new Request("", makeRequestInit(body, "GET")); }
);
assert_throws(new TypeError(), function() { new Request("", makeRequestInit(body, "GET")); });
assert_throws(new TypeError(), function() { new Request("", makeRequestInit(body, "HEAD")); });
} else {
new Request("", makeRequestInit(body, "GET")); // should not throw
}

View file

@ -1,32 +0,0 @@
// This file is duplicated verbatim from:
// service-workers/service-worker/resources/get-host-info.sub.js
// with the rationale that:
// - it's better to not reinvent this
// - at the same time, referencing tests deep inside a sibling test group is
// not a great idea and copying the file is the lesser evil.
function get_host_info() {
var ORIGINAL_HOST = '127.0.0.1';
var REMOTE_HOST = 'localhost';
var UNAUTHENTICATED_HOST = 'example.test';
var HTTP_PORT = 8000;
var HTTPS_PORT = 8443;
try {
// In W3C test, we can get the hostname and port number in config.json
// using wptserve's built-in pipe.
// http://wptserve.readthedocs.org/en/latest/pipes.html#built-in-pipes
HTTP_PORT = eval('{{ports[http][0]}}');
HTTPS_PORT = eval('{{ports[https][0]}}');
ORIGINAL_HOST = eval('\'{{host}}\'');
REMOTE_HOST = 'www1.' + ORIGINAL_HOST;
} catch (e) {
}
return {
HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT,
HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT,
HTTPS_ORIGIN_WITH_CREDS: 'https://foo:bar@' + ORIGINAL_HOST + ':' + HTTPS_PORT,
HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT,
HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT,
HTTPS_REMOTE_ORIGIN_WITH_CREDS: 'https://foo:bar@' + REMOTE_HOST + ':' + HTTPS_PORT,
UNAUTHENTICATED_ORIGIN: 'http://' + UNAUTHENTICATED_HOST + ':' + HTTP_PORT
};
}

View file

@ -1,3 +1,6 @@
from urllib import urlencode
from urlparse import urlparse
def main(request, response):
stashed_data = {'count': 0, 'preflight': "0"}
status = 302
@ -28,13 +31,19 @@ def main(request, response):
stashed_data['count'] += 1
#keep url parameters in location
url_parameters = "?" + "&".join(map(lambda x: x[0][0] + "=" + x[1][0], request.GET.items()))
#make sure location changes during redirection loop
url_parameters += "&count=" + str(stashed_data['count'])
if "location" in request.GET:
headers.append(("Location", request.GET['location'] + url_parameters))
url = request.GET['location']
scheme = urlparse(url).scheme
if scheme == "" or scheme == "http" or scheme == "https":
url += "&" if '?' in url else "?"
#keep url parameters in location
url_parameters = {}
for item in request.GET.items():
url_parameters[item[0]] = item[1][0]
url += urlencode(url_parameters)
#make sure location changes during redirection loop
url += "&count=" + str(stashed_data['count'])
headers.append(("Location", url))
if token:
request.server.stash.put(request.GET.first("token"), stashed_data)

View file

@ -0,0 +1,9 @@
def main(request, response):
code = int(request.GET.first("code", 200))
text = request.GET.first("text", "OMG")
content = request.GET.first("content", "")
type = request.GET.first("type", "")
status = (code, text)
headers = [("Content-Type", type),
("X-Request-Method", request.method)]
return status, headers, content

View file

@ -53,12 +53,13 @@ function stringToArray(str) {
function validateBufferFromString(buffer, expectedValue, message)
{
return assert_array_equals(new Uint8Array(buffer), stringToArray(expectedValue), message);
return assert_array_equals(new Uint8Array(buffer !== undefined ? buffer : []), stringToArray(expectedValue), message);
}
function validateStreamFromString(reader, expectedValue, retrievedArrayBuffer) {
return reader.read().then(function(data) {
if (!data.done) {
assert_true(data.value instanceof Uint8Array, "Fetch ReadableStream chunks should be Uint8Array");
var newBuffer;
if (retrievedArrayBuffer) {
newBuffer = new ArrayBuffer(data.value.length + retrievedArrayBuffer.length);

View file

@ -54,13 +54,45 @@
}, "Check cloned response's body");
promise_test(function(test) {
var disturbedResponse = new Response();
var disturbedResponse = new Response("data");
return disturbedResponse.text().then(function() {
assert_true(disturbedResponse.bodyUsed, "response is disturbed");
assert_throws(new TypeError() , function() { disturbedResponse.clone(); },
"Expect TypeError exception");
});
}, "Cannot clone a disturbed response");
promise_test(function(t) {
var clone;
var result;
var response;
return fetch('../resources/trickle.py?count=2&delay=100').then(function(res) {
clone = res.clone();
response = res;
return clone.arrayBuffer();
}).then(function(r) {
assert_equals(r.byteLength, 26);
result = r;
return response.arrayBuffer();
}).then(function(r) {
assert_array_equals(r, result, "cloned responses should provide the same data");
});
}, 'Cloned responses should provide the same data');
promise_test(function(t) {
var clone;
return fetch('../resources/trickle.py?count=2&delay=100').then(function(res) {
clone = res.clone();
res.body.cancel();
assert_true(res.bodyUsed);
assert_false(clone.bodyUsed);
return clone.arrayBuffer();
}).then(function(r) {
assert_equals(r.byteLength, 26);
assert_true(clone.bodyUsed);
});
}, 'Cancelling stream should not affect cloned one');
</script>
</body>
</html>

View file

@ -39,6 +39,15 @@ promise_test(function(test) {
return validateStreamFromString(response.body.getReader(), textData);
}, "Read text response's body as readableStream");
promise_test(function(test) {
var arrayBuffer = new ArrayBuffer(textData.length);
var int8Array = new Int8Array(arrayBuffer);
for (var cptr = 0; cptr < textData.length; cptr++)
int8Array[cptr] = textData.charCodeAt(cptr);
return validateStreamFromString(new Response(arrayBuffer).body.getReader(), textData);
}, "Read array buffer response's body as readableStream");
promise_test(function(test) {
var response = new Response(formData);
return validateStreamFromString(response.body.getReader(), "name=value");

View file

@ -19,8 +19,11 @@
});
}
function checkBodyBlob(response, expectedBody) {
function checkBodyBlob(response, expectedBody, checkContentType) {
return response.blob().then(function(bodyAsBlob) {
if (checkContentType)
assert_equals(bodyAsBlob.type, "text/plain", "Blob body type should be computed from the response Content-Type");
var promise = new Promise( function (resolve, reject) {
var reader = new FileReader();
reader.onload = function(evt) {
@ -62,7 +65,7 @@
function checkResponseBody(body, bodyType, checkFunction) {
promise_test(function(test) {
var response = new Response(body);
var response = new Response(body, { "headers": [["Content-Type", "text/PLAIN"]] });
assert_false(response.bodyUsed, "bodyUsed is false at init");
return checkFunction(response, body);
}, "Consume response's body as " + bodyType);
@ -74,7 +77,7 @@
var blob = new Blob([textData], { "type" : "text/plain" });
checkResponseBody(textData, "text", checkBodyText);
checkResponseBody(textData, "blob", checkBodyBlob);
checkResponseBody(textData, "blob", function(response, body) { checkBodyBlob(response, body, true); });
checkResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer);
checkResponseBody(textData, "json", checkBodyJSON);
checkResponseBody(formData, "formData", checkBodyFormData);
@ -92,6 +95,37 @@
checkBlobResponseBody(blob, textData, "json", checkBodyJSON);
checkBlobResponseBody(blob, textData, "arrayBuffer", checkBodyArrayBuffer);
function checkReadableStreamResponseBody(streamData, bodyType, checkFunction) {
promise_test(function(test) {
var stream = new ReadableStream({
start: function(controller) {
controller.enqueue((stringToArray(streamData)));
controller.close();
}
});
var response = new Response(stream);
assert_false(response.bodyUsed, "bodyUsed is false at init");
return checkFunction(response, streamData);
}, "Consume stream response's body as " + bodyType);
}
checkReadableStreamResponseBody(textData, "blob", checkBodyBlob);
checkReadableStreamResponseBody(textData, "text", checkBodyText);
checkReadableStreamResponseBody(textData, "json", checkBodyJSON);
checkReadableStreamResponseBody(textData, "arrayBuffer", checkBodyArrayBuffer);
function checkFetchedResponseBody(bodyType, checkFunction) {
return promise_test(function(test) {
return fetch("../resources/top.txt").then(function(response) {
assert_false(response.bodyUsed, "bodyUsed is false at init");
return checkFunction(response, "top");
});
}, "Consume fetched response's body as " + bodyType);
}
checkFetchedResponseBody("blob", checkBodyBlob);
checkFetchedResponseBody("text", checkBodyText);
checkFetchedResponseBody("arrayBuffer", checkBodyArrayBuffer);
</script>
</body>
</html>

View file

@ -57,6 +57,14 @@
var response = new Response(body);
return validateStreamFromString(response.body.getReader(), body);
}, "Read Response's body as readableStream");
promise_test(function(test) {
var response = new Response("This is my fork", {"headers" : [["Content-Type", ""]]});
return response.blob().then(function(blob) {
assert_equals(blob.type, "", "Blob type should be the empty string");
});
}, "Testing empty Response Content-Type header");
</script>
</body>
</html>