import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo

This commit is contained in:
Roy Tam 2018-01-19 03:59:58 +08:00
commit dcd9973243
150858 changed files with 23884658 additions and 0 deletions

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: accept header</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#fetching">
<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("accept-header.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: accept header</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#fetching">
<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="accept-header.js"></script>
</body>
</html>

View file

@ -0,0 +1,38 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
promise_test(function() {
return fetch(RESOURCES_DIR + "inspect-headers.py?headers=Accept").then(function(response) {
assert_equals(response.status, 200, "HTTP status is 200");
assert_equals(response.type , "basic", "Response's type is basic");
assert_equals(response.headers.get("x-request-accept"), "*/*", "Request has accept header with value '*/*'");
});
}, "Request through fetch should have 'accept' header with value '*/*'");
promise_test(function() {
return fetch(RESOURCES_DIR + "inspect-headers.py?headers=Accept", {"headers": [["Accept", "custom/*"]]}).then(function(response) {
assert_equals(response.status, 200, "HTTP status is 200");
assert_equals(response.type , "basic", "Response's type is basic");
assert_equals(response.headers.get("x-request-accept"), "custom/*", "Request has accept header with value 'custom/*'");
});
}, "Request through fetch should have 'accept' header with value 'custom/*'");
promise_test(function() {
return fetch(RESOURCES_DIR + "inspect-headers.py?headers=Accept-Language").then(function(response) {
assert_equals(response.status, 200, "HTTP status is 200");
assert_equals(response.type , "basic", "Response's type is basic");
assert_true(response.headers.has("x-request-accept-language"));
});
}, "Request through fetch should have a 'accept-language' header");
promise_test(function() {
return fetch(RESOURCES_DIR + "inspect-headers.py?headers=Accept-Language", {"headers": [["Accept-Language", "bzh"]]}).then(function(response) {
assert_equals(response.status, 200, "HTTP status is 200");
assert_equals(response.type , "basic", "Response's type is basic");
assert_equals(response.headers.get("x-request-accept-language"), "bzh", "Request has accept header with value 'bzh'");
});
}, "Request through fetch should have 'accept-language' header with value 'bzh'");
done();

View file

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in sharedworker: integrity handling</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new SharedWorker("integrity.js?pipe=sub"));
</script>
</body>
</html>

View file

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

View file

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: integrity handling</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="integrity.js?pipe=sub"></script>
</body>
</html>

View file

@ -0,0 +1,45 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function integrity(desc, url, integrity, shouldPass) {
if (shouldPass) {
promise_test(function(test) {
return fetch(url, {'integrity': integrity}).then(function(resp) {
assert_equals(resp.status, 200, "Response's status is 200");
});
}, desc);
} else {
promise_test(function(test) {
return promise_rejects(test, new TypeError(), fetch(url, {'integrity': integrity}));
}, desc);
}
}
var topSha256 = "sha256-KHIDZcXnR2oBHk9DrAA+5fFiR6JjudYjqoXtMR1zvzk=";
var topSha384 = "sha384-MgZYnnAzPM/MjhqfOIMfQK5qcFvGZsGLzx4Phd7/A8fHTqqLqXqKo8cNzY3xEPTL";
var topSha512 = "sha512-D6yns0qxG0E7+TwkevZ4Jt5t7Iy3ugmAajG/dlf6Pado1JqTyneKXICDiqFIkLMRExgtvg8PlxbKTkYfRejSOg==";
var invalidSha256 = "sha256-dKUcPOn/AlUjWIwcHeHNqYXPlvyGiq+2dWOdFcE+24I=";
var invalidSha512 = "sha512-oUceBRNxPxnY60g/VtPCj2syT4wo4EZh2CgYdWy9veW8+OsReTXoh7dizMGZafvx9+QhMS39L/gIkxnPIn41Zg==";
var url = "../resources/top.txt";
var corsUrl = "http://{{host}}:{{ports[http][1]}}" + dirname(location.pathname) + RESOURCES_DIR + "top.txt";
/* Enable CORS*/
corsUrl += "?pipe=header(Access-Control-Allow-Origin,*)";
integrity("Empty string integrity", url, "", true);
integrity("SHA-256 integrity", url, topSha256, true);
integrity("SHA-384 integrity", url, topSha384, true);
integrity("SHA-512 integrity", url, topSha512, true);
integrity("Invalid integrity", url, invalidSha256, false);
integrity("Multiple integrities: valid stronger than invalid", url, invalidSha256 + " " + topSha384, true);
integrity("Multiple integrities: invalid stronger than valid", url, invalidSha512 + " " + topSha384, false);
integrity("Multiple integrities: invalid as strong as valid", url, invalidSha512 + " " + topSha512, true);
integrity("Multiple integrities: both are valid", url, topSha384 + " " + topSha512, true);
integrity("Multiple integrities: both are invalid", url, invalidSha256 + " " + invalidSha512, false);
integrity("CORS empty integrity", corsUrl, "", true);
integrity("CORS SHA-512 integrity", corsUrl, topSha512, true);
integrity("CORS invalid integrity", corsUrl, invalidSha512, false);
done();

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: no-cors mode and opaque filtering</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-opaque">
<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("mode-no-cors.js?pipe=sub"));
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: no-cors mode and opaque filtering</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-opaque">
<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="mode-no-cors.js?pipe=sub"></script>
</body>
</html>

View file

@ -0,0 +1,31 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function fetchNoCors(url, isOpaqueFiltered) {
var urlQuery = "?pipe=header(x-is-filtered,value)"
promise_test(function(test) {
if (isOpaqueFiltered)
return fetch(url + urlQuery, {"mode": "no-cors"}).then(function(resp) {
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");
assert_equals(resp.headers.get("x-is-filtered"), null, "Header x-is-filtered is filtered");
});
else
return fetch(url + urlQuery, {"mode": "no-cors"}).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-is-filtered"), "value", "Header x-is-filtered is not filtered");
});
}, "Fetch "+ url + " with no-cors mode");
}
fetchNoCors(RESOURCES_DIR + "top.txt", false);
fetchNoCors("http://{{host}}:{{ports[http][0]}}/fetch/api/resources/top.txt", false);
fetchNoCors("https://{{host}}:{{ports[https][0]}}/fetch/api/resources/top.txt", true);
fetchNoCors("http://{{host}}:{{ports[http][1]}}/fetch/api/resources/top.txt", true);
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("mode-same-origin.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="mode-same-origin.js"></script>
</body>
</html>

View file

@ -0,0 +1,34 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
function fetchSameOrigin(url, shouldPass) {
promise_test(function(test) {
if (shouldPass)
return fetch(url , {"mode": "same-origin"}).then(function(resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
assert_equals(resp.type, "basic", "response type is basic");
});
else
return promise_rejects(test, new TypeError, fetch(url, {mode: "same-origin"}));
}, "Fetch "+ url + " with same-origin mode");
}
var host_info = get_host_info();
fetchSameOrigin(RESOURCES_DIR + "top.txt", true);
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,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: forbidden request header management</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#forbidden-header-name">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("request-forbidden-headers.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: forbidden request header management</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#forbidden-header-name">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="request-forbidden-headers.js"></script>
</body>
</html>

View file

@ -0,0 +1,48 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function requestForbiddenHeaders(desc, forbiddenHeaders) {
var url = RESOURCES_DIR + "inspect-headers.py";
var requestInit = {"headers": forbiddenHeaders}
var urlParameters = "?headers=" + Object.keys(forbiddenHeaders).join("|");
promise_test(function(test){
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");
for (var header in forbiddenHeaders)
assert_not_equals(resp.headers.get("x-request-" + header), forbiddenHeaders[header], header + " does not have the value we defined");
});
}, desc);
}
requestForbiddenHeaders("Accept-Charset is a forbidden request header", {"Accept-Charset": "utf-8"});
requestForbiddenHeaders("Accept-Encoding is a forbidden request header", {"Accept-Encoding": ""});
requestForbiddenHeaders("Access-Control-Request-Headers is a forbidden request header", {"Access-Control-Request-Headers": ""});
requestForbiddenHeaders("Access-Control-Request-Method is a forbidden request header", {"Access-Control-Request-Method": ""});
requestForbiddenHeaders("Connection is a forbidden request header", {"Connection": "close"});
requestForbiddenHeaders("Content-Length is a forbidden request header", {"Content-Length": "42"});
requestForbiddenHeaders("Cookie is a forbidden request header", {"Cookie": "cookie=none"});
requestForbiddenHeaders("Cookie2 is a forbidden request header", {"Cookie2": "cookie2=none"});
requestForbiddenHeaders("Date is a forbidden request header", {"Date": "Wed, 04 May 1988 22:22:22 GMT"});
requestForbiddenHeaders("DNT is a forbidden request header", {"DNT": "4"});
requestForbiddenHeaders("Expect is a forbidden request header", {"Expect": "100-continue"});
requestForbiddenHeaders("Host is a forbidden request header", {"Host": "http://wrong-host.com"});
requestForbiddenHeaders("Keep-Alive is a forbidden request header", {"Keep-Alive": "timeout=15"});
requestForbiddenHeaders("Origin is a forbidden request header", {"Origin": "http://wrong-origin.com"});
requestForbiddenHeaders("Referer is a forbidden request header", {"Referer": "http://wrong-referer.com"});
requestForbiddenHeaders("TE is a forbidden request header", {"TE": "trailers"});
requestForbiddenHeaders("Trailer is a forbidden request header", {"Trailer": "Accept"});
requestForbiddenHeaders("Transfer-Encoding is a forbidden request header", {"Transfer-Encoding": "chunked"});
requestForbiddenHeaders("Upgrade is a forbidden request header", {"Upgrade": "HTTP/2.0"});
requestForbiddenHeaders("Via is a forbidden request header", {"Via": "1.1 nowhere.com"});
requestForbiddenHeaders("Proxy- is a forbidden request header", {"Proxy-": "value"});
requestForbiddenHeaders("Proxy-Test is a forbidden request header", {"Proxy-Test": "value"});
requestForbiddenHeaders("Sec- is a forbidden request header", {"Sec-": "value"});
requestForbiddenHeaders("Sec-Test is a forbidden request header", {"Sec-Test": "value"});
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

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: User agent add headers to request</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<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("request-headers.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: User agent add headers to request</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<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="request-headers.js"></script>
</body>
</html>

View file

@ -0,0 +1,63 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
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|content-type";
var requestInit = {"method": method}
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_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);
}
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, 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 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");
done();

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

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: response url getter</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#response-class">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("response-url.js?pipe=sub"));
</script>
</body>
</html>

View file

@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: response url getter</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#response-class">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="response-url.js?pipe=sub"></script>
</body>
</html>

View file

@ -0,0 +1,21 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
}
function checkResponseURL(fetchedURL, expectedURL)
{
promise_test(function() {
return fetch(fetchedURL).then(function(response) {
assert_equals(response.url, expectedURL);
});
}, "Testing response url getter with " +fetchedURL);
}
var baseURL = "http://{{host}}:{{ports[http][0]}}";
checkResponseURL(baseURL + "/ada", baseURL + "/ada");
checkResponseURL(baseURL + "/#", baseURL + "/");
checkResponseURL(baseURL + "/#ada", baseURL + "/");
checkResponseURL(baseURL + "#ada", baseURL + "/");
done();

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: about scheme</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("scheme-about.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: about scheme</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="scheme-about.js"></script>
</body>
</html>

View file

@ -0,0 +1,39 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function checkFetchResponse(url, method, desc) {
if (!desc) {
var cut = (url.length >= 40) ? "[...]" : "";
cut += " (" + method + ")"
desc = "Fetching " + url.substring(0, 40) + cut + " is OK"
}
promise_test(function(test) {
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"), "text/html;charset=utf-8", "Content-Type is " + resp.headers.get("Content-Type"));
return resp.text();
})
}, desc);
}
checkFetchResponse("about:blank", "GET");
checkFetchResponse("about:blank", "PUT");
checkFetchResponse("about:blank", "POST");
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");
checkKoUrl("about:unicorn");
done();

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: blob scheme</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("scheme-blob.js?pipe=sub"));
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: blob scheme</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="scheme-blob.js?pipe=sub"></script>
</body>
</html>

View file

@ -0,0 +1,48 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function checkFetchResponse(url, data, mime, size, desc) {
promise_test(function(test) {
size = size.toString();
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"));
assert_equals(resp.headers.get("Content-Length"), size, "Content-Length is " + resp.headers.get("Content-Length"));
return resp.text();
}).then(function(bodyAsText) {
assert_equals(bodyAsText, data, "Response's body is " + data);
});
}, desc);
}
var blob = new Blob(["Blob's data"], { "type" : "text/plain" });
checkFetchResponse(URL.createObjectURL(blob), "Blob's data", "text/plain", blob.size,
"Fetching [GET] URL.createObjectURL(blob) is OK");
function checkKoUrl(url, method, desc) {
promise_test(function(test) {
var promise = fetch(url, {"method": method});
return promise_rejects(test, new TypeError(), promise);
}, desc);
}
var blob2 = new Blob(["Blob's data"], { "type" : "text/plain" });
checkKoUrl("blob:http://{{domains[www]}}:{{ports[http][0]}}/", "GET",
"Fetching [GET] blob:http://{{domains[www]}}:{{ports[http][0]}}/ is KO");
var invalidRequestMethods = [
"POST",
"OPTIONS",
"HEAD",
"PUT",
"DELETE",
"INVALID",
];
invalidRequestMethods.forEach(function(method) {
checkKoUrl(URL.createObjectURL(blob2), method, "Fetching [" + method + "] URL.createObjectURL(blob) is KO");
});
done();

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: data scheme</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("scheme-data.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: data scheme</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="scheme-data.js"></script>
</body>
</html>

View file

@ -0,0 +1,48 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
<<<<<<< b45946c54935c6113fefb5199b3fe0e4bf087777
function checkFetchResponse(url, data, mime, fetchMode, method) {
var cut = (url.length >= 40) ? "[...]" : "";
desc = "Fetching " + (method ? "[" + method + "] " : "") + url.substring(0, 40) + cut + " is OK";
var init = {"method": method || "GET"};
if (fetchMode) {
init.mode = fetchMode;
desc += " (" + fetchMode + ")";
}
promise_test(function(test) {
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();
}).then(function(body) {
assert_equals(body, data, "Response's body is correct");
});
}, desc);
}
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",
"image/png");
checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", null, "POST");
checkFetchResponse("data:,response%27s%20body", "response's body", "text/plain;charset=US-ASCII", null, "HEAD");
function checkKoUrl(url, method, desc) {
var cut = (url.length >= 40) ? "[...]" : "";
desc = "Fetching [" + method + "] " + url.substring(0, 45) + cut + " is KO"
promise_test(function(test) {
return promise_rejects(test, new TypeError(), fetch(url, {"method": method}));
}, desc);
}
checkKoUrl("data:notAdataUrl.com", "GET");
done();

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: urls with unsupported schemes</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("scheme-others.js?pipe=sub"));
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: urls with unsupported schemes</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="scheme-others.js?pipe=sub"></script>
</body>
</html>

View file

@ -0,0 +1,33 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
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);
}
var urlWithoutScheme = "://{{host}}:{{ports[http][0]}}/";
checkKoUrl("aaa" + urlWithoutScheme);
checkKoUrl("cap" + urlWithoutScheme);
checkKoUrl("cid" + urlWithoutScheme);
checkKoUrl("dav" + urlWithoutScheme);
checkKoUrl("dict" + urlWithoutScheme);
checkKoUrl("dns" + urlWithoutScheme);
checkKoUrl("geo" + urlWithoutScheme);
checkKoUrl("im" + urlWithoutScheme);
checkKoUrl("imap" + urlWithoutScheme);
checkKoUrl("ipp" + urlWithoutScheme);
checkKoUrl("ldap" + urlWithoutScheme);
checkKoUrl("mailto" + urlWithoutScheme);
checkKoUrl("nfs" + urlWithoutScheme);
checkKoUrl("pop" + urlWithoutScheme);
checkKoUrl("rtsp" + urlWithoutScheme);
checkKoUrl("snmp" + urlWithoutScheme);
done();

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: retrieve response's body progressively</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-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("stream-response.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: retrieve response's body progressively</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-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="stream-response.js"></script>
</body>
</html>

View file

@ -0,0 +1,33 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function streamBody(reader, test, count) {
return reader.read().then(function(data) {
if (!data.done && count < 2) {
count += 1;
return streamBody(reader, test, count);
} else {
test.step(function() {
assert_true(count >= 2, "Retrieve body progressively");
});
}
});
}
//simulate streaming:
//count is large enough to let the UA deliver the body before it is completely retrieved
promise_test(function(test) {
return fetch(RESOURCES_DIR + "trickle.py?ms=30&count=100").then(function(resp) {
var count = 0;
if (resp.body)
return streamBody(resp.body.getReader(), test, count);
else
test.step(function() {
assert_unreached( "Body does not exist in response");
});
});
}, "Stream response's body");
done();

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

@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: basic CORS</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-cors">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-cors-check">
<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("cors-basic.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: basic CORS</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-cors">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-cors-check">
<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="cors-basic.js"></script>
</body>
</html>

View file

@ -0,0 +1,42 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js");
}
function cors(desc, origin) {
var url = origin + dirname(location.pathname);
var urlParameters = "?pipe=header(Access-Control-Allow-Origin,*)";
promise_test(function(test) {
return fetch(url + RESOURCES_DIR + "top.txt" + urlParameters, {"mode": "no-cors"} ).then(function(resp) {
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) {
return promise_rejects(test, new TypeError(), fetch(url + RESOURCES_DIR + "top.txt", {"mode": "cors"}));
}, desc + " [server forbid CORS]");
promise_test(function(test) {
return fetch(url + RESOURCES_DIR + "top.txt" + urlParameters, {"mode": "cors"} ).then(function(resp) {
assert_equals(resp.status, 200, "Fetch's response's status is 200");
assert_equals(resp.type , "cors", "CORS response's type is cors");
});
}, desc + " [cors mode]");
}
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

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

View file

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: cookies management for cors requests</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-network-fetch">
<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="cors-cookies.js"></script>
</body>
</html>

View file

@ -0,0 +1,61 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
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)";
var urlCleanParameters = "?pipe=header(Access-Control-Allow-Origin," + location.origin + ")";
urlCleanParameters += "|header(Access-Control-Allow-Credentials,true)";
if (cookies) {
urlParameters += "|header(Set-Cookie,";
urlParameters += cookies.join(",True)|header(Set-Cookie,") + ",True)";
urlCleanParameters += "|header(Set-Cookie,";
urlCleanParameters += cookies.join("%3B%20max-age=0,True)|header(Set-Cookie,") + "%3B%20max-age=0,True)";
}
var requestInit = {"credentials": credentialsMode, "mode": "cors"};
promise_test(function(test){
return fetch(urlSetCookie + urlParameters, requestInit).then(function(resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
//check cookies sent
return fetch(urlCheckCookies, requestInit);
}).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" && baseURL1 === baseURL2) {
assert_equals(resp.headers.get("x-request-cookie") , cookies.join("; "), "Request includes cookie(s)");
}
else {
assert_false(resp.headers.has("x-request-cookie") , "Request should have no cookie");
}
//clean cookies
return fetch(urlSetCookie + urlCleanParameters, {"credentials": "include"});
}).catch(function(e) {
return fetch(urlSetCookie + urlCleanParameters, {"credentials": "include"}).then(function(resp) {
throw e;
})
});
}, desc);
}
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("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

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: filtered headers in CORS response</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-cors">
<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("cors-filtering.js?pipe=sub"));
</script>
</body>
</html>

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: filtered headers in CORS response</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-filtered-response-cors">
<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="cors-filtering.js?pipe=sub"></script>
</body>
</html>

View file

@ -0,0 +1,66 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function corsFilter(corsUrl, headerName, headerValue, isFiltered) {
var url = corsUrl + "?pipe=header(" + headerName + "," + encodeURIComponent(headerValue) +")|header(Access-Control-Allow-Origin,*)";
promise_test(function(test) {
return fetch(url).then(function(resp) {
assert_equals(resp.status, 200, "Fetch success with code 200");
assert_equals(resp.type , "cors", "CORS fetch's response has cors type");
if (!isFiltered) {
assert_equals(resp.headers.get(headerName), headerValue,
headerName + " header should be included in response with value: " + headerValue);
} else {
assert_false(resp.headers.has(headerName), "UA should exclude " + headerName + " header from response");
}
test.done();
});
}, "CORS filter on " + headerName + " header");
}
function corsExposeFilter(corsUrl, headerName, headerValue, isForbidden) {
var url = corsUrl + "?pipe=header(" + headerName + "," + encodeURIComponent(headerValue) +")|" +
"header(Access-Control-Allow-Origin,*)" +
"header(Access-Control-Expose-Headers," + headerName + ")";
promise_test(function(test) {
return fetch(url).then(function(resp) {
assert_equals(resp.status, 200, "Fetch success with code 200");
assert_equals(resp.type , "cors", "CORS fetch's response has cors type");
if (!isForbidden) {
assert_equals(resp.headers.get(headerName), headerValue,
headerName + " header should be included in response with value: " + headerValue);
} else {
assert_false(resp.headers.has(headerName), "UA should exclude " + headerName + " header from response");
}
test.done();
});
}, "CORS filter on " + headerName + " header, header is exposed");
}
var url = "http://{{host}}:{{ports[http][1]}}" + dirname(location.pathname) + RESOURCES_DIR + "top.txt";
corsFilter(url, "Cache-Control", "no-cache", false);
corsFilter(url, "Content-Language", "fr", false);
corsFilter(url, "Content-Type", "text/html", false);
corsFilter(url, "Expires","04 May 1988 22:22:22 GMT" , false);
corsFilter(url, "Last-Modified", "04 May 1988 22:22:22 GMT", false);
corsFilter(url, "Pragma", "no-cache", false);
corsFilter(url, "Age", "27", true);
corsFilter(url, "Server", "wptServe" , true);
corsFilter(url, "Warning", "Mind the gap" , true);
corsFilter(url, "Content-Length", "0" , true);
corsFilter(url, "Set-Cookie", "name=value" , true);
corsFilter(url, "Set-Cookie2", "name=value" , true);
corsExposeFilter(url, "Age", "27", false);
corsExposeFilter(url, "Server", "wptServe" , false);
corsExposeFilter(url, "Warning", "Mind the gap" , false);
corsExposeFilter(url, "Content-Length", "0" , false);
corsExposeFilter(url, "Set-Cookie", "name=value" , true);
corsExposeFilter(url, "Set-Cookie2", "name=value" , true);
done();

View file

@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: check multiple Access-Control-Allow-Origin header management</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#cors-check">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-multiple-origins.js?pipe=sub"));
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: check multiple Access-Control-Allow-Origin header management</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#cors-check">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="cors-multiple-origins.js?pipe=sub"></script>
</body>
</html>

View file

@ -0,0 +1,32 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function corsMultipleOrigins(desc, originList, shouldPass) {
var urlParameters = "?origin=" + encodeURIComponent(originList.join(", "));
var url = "http://{{host}}:{{ports[http][1]}}" + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
if (shouldPass) {
promise_test(function(test) {
return fetch(url + urlParameters).then(function(resp) {
assert_equals(resp.status, 200, "Response's status is 200");
});
}, desc);
} else {
promise_test(function(test) {
return promise_rejects(test, new TypeError(), fetch(url + urlParameters));
}, desc);
}
}
/* Actual origin */
var origin = "http://{{host}}:{{ports[http][0]}}";
corsMultipleOrigins("3 origins allowed, match the 3rd (" + origin + ")", ["\"\"", "http://example.com", origin], true);
corsMultipleOrigins("3 origins allowed, match the 3rd (\"*\")", ["\"\"", "http://example.com", "*"], true);
corsMultipleOrigins("3 origins allowed, match twice (" + origin + ")", ["\"\"", origin, origin], true);
corsMultipleOrigins("3 origins allowed, match twice (\"*\")", ["*", "http://example.com", "*"], true);
corsMultipleOrigins("3 origins allowed, match twice (\"*\" and " + origin + ")", ["*", "http://example.com", origin], true);
corsMultipleOrigins("3 origins allowed, no match", ["", "http://example.com", "https://example2.com"], false);
done();

View file

@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: CORS request with simple methods and headers</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#simple-method">
<meta name="help" href="https://fetch.spec.whatwg.org/#simple-header">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-no-preflight.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,21 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: CORS request with simple methods and headers</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#simple-method">
<meta name="help" href="https://fetch.spec.whatwg.org/#simple-header">
<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="cors-no-preflight.js"></script>
</body>
</html>

View file

@ -0,0 +1,46 @@
if (this.document === undefined) {
importScripts("/common/utils.js");
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
function corsNoPreflight(desc, baseURL, method, headerName, headerValue) {
var uuid_token = token();
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) {
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"), "0", "No preflight request has been made");
});
});
}, desc);
}
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

@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: check Access-Control-Allow-Origin header management</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#cors-check">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-origin.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: check Access-Control-Allow-Origin header management</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#cors-check">
<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="cors-origin.js"></script>
</body>
</html>

View file

@ -0,0 +1,56 @@
if (this.document === undefined) {
importScripts("/common/utils.js");
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
importScripts("/common/get-host-info.sub.js")
}
/* If origin is undefined, it is set to fetched url's origin*/
function corsOrigin(desc, baseURL, method, origin, shouldPass) {
if (!origin)
origin = baseURL;
var uuid_token = token();
var urlParameters = "?token=" + uuid_token + "&max_age=0&origin=" + encodeURIComponent(origin) + "&allow_methods=" + method;
var url = baseURL + dirname(location.pathname) + RESOURCES_DIR + "preflight.py";
var requestInit = {"mode": "cors", "method": method};
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");
if (shouldPass) {
return fetch(url + urlParameters, requestInit).then(function(resp) {
assert_equals(resp.status, 200, "Response's status is 200");
});
} else {
return promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit));
}
});
}, desc);
}
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

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: redirection handling for cors with preflight</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-preflight-redirect.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: redirection handling for cors with preflight</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-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="cors-preflight-redirect.js"></script>
</body>
</html>

View file

@ -0,0 +1,41 @@
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) {
var uuid_token = token();
var url = redirectUrl;
var urlParameters = "?token=" + uuid_token + "&max_age=0";
urlParameters += "&redirect_status=" + redirectStatus;
urlParameters += "&location=" + encodeURIComponent(redirectLocation);
if (redirectPreflight)
urlParameters += "&redirect_preflight";
var requestInit = {"mode": "cors", "redirect": "follow"};
/* Force preflight */
requestInit["headers"] = {"x-force-preflight": ""};
urlParameters += "&allow_headers=x-force-preflight";
promise_test(function(test) {
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 promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit));
});
}, desc);
}
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 */
corsPreflightRedirect("Redirection " + code + " on preflight failed", redirectUrl, locationUrl, code, true);
/* preflight is done before redirection: preflight force redirect to error */
corsPreflightRedirect("Redirection " + code + " after preflight failed", redirectUrl, locationUrl, code, false);
}
done();

View file

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: Referer header management in CORS request with preflight</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#cors-preflight-fetch">
<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("cors-preflight-referrer.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: Referer header management in CORS request with preflight</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#cors-preflight-fetch">
<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="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-preflight-referrer.js"></script>
</body>
</html>

View file

@ -0,0 +1,53 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("/common/utils.js");
importScripts("/common/get-host-info.sub.js");
importScripts("../resources/utils.js");
}
function corsPreflightReferrer(desc, corsUrl, referrerPolicy, referrer, expectedReferrer) {
var uuid_token = token();
var url = corsUrl;
var urlParameters = "?token=" + uuid_token + "&max_age=0";
var requestInit = {"mode": "cors", "referrerPolicy": referrerPolicy};
if (referrer)
requestInit.referrer = referrer;
/* Force preflight */
requestInit["headers"] = {"x-force-preflight": ""};
urlParameters += "&allow_headers=x-force-preflight";
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(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 referrer is correct");
assert_equals(resp.headers.get("x-control-request-headers"), "", "Access-Control-Allow-Headers value");
});
});
}, desc + " and referrer: " + (referrer ? "'" + referrer + "'" : "default"));
}
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", undefined, "");
corsPreflightReferrer("Referrer policy: no-referrer", corsUrl, "no-referrer", "myreferrer", "");
corsPreflightReferrer("Referrer policy: \"\"", corsUrl, "", undefined, location.toString())
corsPreflightReferrer("Referrer policy: \"\"", corsUrl, "", "myreferrer", new URL("myreferrer", location).toString());
corsPreflightReferrer("Referrer policy: origin", corsUrl, "origin", undefined, origin);
corsPreflightReferrer("Referrer policy: origin", corsUrl, "origin", "myreferrer", origin);
corsPreflightReferrer("Referrer policy: origin-when-cross-origin", corsUrl, "origin-when-cross-origin", undefined, origin);
corsPreflightReferrer("Referrer policy: origin-when-cross-origin", corsUrl, "origin-when-cross-origin", "myreferrer", origin);
corsPreflightReferrer("Referrer policy: unsafe-url", corsUrl, "unsafe-url", undefined, location.toString());
corsPreflightReferrer("Referrer policy: unsafe-url", corsUrl, "unsafe-url", "myreferrer", new URL("myreferrer", location).toString());
done();

View file

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: preflight status code handling</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#cors-preflight-fetch">
<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("cors-preflight-status.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: preflight status code handling</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#cors-preflight-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="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-preflight-status.js"></script>
</body>
</html>

View file

@ -0,0 +1,42 @@
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)*/
function corsPreflightStatus(desc, corsUrl, preflightStatus) {
var uuid_token = token();
var url = corsUrl;
var requestInit = {"mode": "cors"};
/* Force preflight */
requestInit["headers"] = {"x-force-preflight": ""};
var urlParameters = "?token=" + uuid_token + "&max_age=0";
urlParameters += "&allow_headers=x-force-preflight";
urlParameters += "&preflight_status=" + preflightStatus;
promise_test(function(test) {
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 (200 <= preflightStatus && 299 >= preflightStatus) {
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");
});
} else {
return promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit));
}
});
}, desc);
}
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,
501, 502, 503, 504, 505])
corsPreflightStatus("Preflight answered with status " + status, corsUrl, status);
done();

View file

@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: Check cors fetches requiring prefligh</title>
<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>
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#simple-method">
<meta name="help" href="https://fetch.spec.whatwg.org/#simple-header">
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-preflight.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,21 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: Check cors fetches requiring preflight</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cors-protocol">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#simple-method">
<meta name="help" href="https://fetch.spec.whatwg.org/#simple-header">
<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="/common/utils.js"></script>
<script src="cors-preflight.js"></script>
</body>
</html>

View file

@ -0,0 +1,103 @@
if (this.document === undefined) {
importScripts("/resources/testharness.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
}
/*
Check preflight is done
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, 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;
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").toLowerCase().split(",");
for (var i in actualHeaders)
actualHeaders[i] = actualHeaders[i].trim();
for (var header of headers)
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"), accessControlAllowHeaders, "Access-Control-Allow-Headers value");
return 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);
});
}
});
}, desc);
}
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);
corsPreflight("CORS [PUT], server allows", corsUrl, "PUT", true);
corsPreflight("CORS [PUT], server refuses", corsUrl, "PUT", false);
corsPreflight("CORS [PATCH], server allows", corsUrl, "PATCH", true);
corsPreflight("CORS [PATCH], server refuses", corsUrl, "PATCH", false);
corsPreflight("CORS [NEW], server allows", corsUrl, "NEW", true);
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"],
["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

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: redirection url has credentials</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker("cors-redirect-credentials.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: redirection url has credentials</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<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="cors-redirect-credentials.js"></script>
</body>
</html>

View file

@ -0,0 +1,50 @@
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) {
var url = redirectUrl
var urlParameters = "?redirect_status=" + redirectStatus;
urlParameters += "&location=" + encodeURIComponent(redirectLocation.replace("://", "://" + locationCredentials + "@"));
var requestInit = {"mode": "cors", "redirect": "follow", "credentials":"include"};
promise_test(function(test) {
return promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit));
}, desc);
}
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_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");
corsRedirectCredentials("Redirect " + code + " from same origin to remote with user", localRedirect, remoteLocation, code, "user:");
corsRedirectCredentials("Redirect " + code + " from same origin to remote with password", localRedirect, remoteLocation, code, ":password");
corsRedirectCredentials("Redirect " + code + " from remote to same origin with user and password", remoteRedirect, localLocation, code, "user:password");
corsRedirectCredentials("Redirect " + code + " from remote to same origin with user", remoteRedirect, localLocation, code, "user:");
corsRedirectCredentials("Redirect " + code + " from remote to same origin with password", remoteRedirect, localLocation, code, ":password");
corsRedirectCredentials("Redirect " + code + " from remote to same remote with user and password", remoteRedirect, remoteLocation, code, "user:password");
corsRedirectCredentials("Redirect " + code + " from remote to same remote with user", remoteRedirect, remoteLocation, code, "user:");
corsRedirectCredentials("Redirect " + code + " from remote to same remote with password", remoteRedirect, remoteLocation, code, ":password");
corsRedirectCredentials("Redirect " + code + " from remote to another remote with user and password", remoteRedirect, remoteLocation2, code, "user:password");
corsRedirectCredentials("Redirect " + code + " from remote to another remote with user", remoteRedirect, remoteLocation2, code, "user:");
corsRedirectCredentials("Redirect " + code + " from remote to another remote with password", remoteRedirect, remoteLocation2, code, ":password");
}
done();

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

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: CORS Redirection with several origins</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<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("cors-redirect.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: CORS Redirection with several origins</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<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="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="cors-redirect.js"></script>
</body>
</html>

View file

@ -0,0 +1,47 @@
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) {
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"};
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");
assert_equals(resp.headers.get("x-did-preflight"), "0", "No preflight request has been made");
assert_equals(resp.headers.get("x-origin"), expectedOrigin, "Origin is correctly set after redirect");
});
});
}, desc);
}
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 + ": cors to same cors", remoteRedirect, remoteLocation, code, location.origin);
corsRedirect("Redirect " + code + ": cors to another cors", remoteRedirect, remoteLocation2, code, "null");
corsRedirect("Redirect " + code + ": same origin to cors", localRedirect, remoteLocation, code, location.origin);
corsRedirect("Redirect " + code + ": cors to same origin", remoteRedirect, localLocation, code, "null");
}
done();

View file

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

View file

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: Authorisation header management for basic authentication</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="authentication-basic.js"></script>
</body>
</html>

View file

@ -0,0 +1,21 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function basicAuth(desc, user, pass, mode, status) {
promise_test(function(test) {
var headers = { "Authorization": "Basic " + btoa(user + ":" + pass)};
var requestInit = {"credentials": mode, "headers": headers};
return fetch(RESOURCES_DIR + "authentication.py?realm=test", requestInit).then(function(resp) {
assert_equals(resp.status, status, "HTTP status is " + status);
assert_equals(resp.type , "basic", "Response's type is basic");
});
}, desc);
}
basicAuth("User-added Authorization header with include mode", "user", "password", "include", 200);
basicAuth("User-added Authorization header with same-origin mode", "user", "password", "same-origin", 200);
basicAuth("User-added Authorization header with omit mode", "user", "password", "omit", 200);
done();

View file

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

View file

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: cookies management</title>
<meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
<meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
<meta name="help" href="https://fetch.spec.whatwg.org/#http-network-fetch">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="cookies.js"></script>
</body>
</html>

View file

@ -0,0 +1,53 @@
if (this.document === undefined) {
importScripts("/resources/testharness.js");
importScripts("../resources/utils.js");
}
function cookies(desc, credentials1, credentials2 ,cookies) {
var url = RESOURCES_DIR + "top.txt"
var urlParameters = "";
var urlCleanParameters = "";
if (cookies) {
urlParameters +="?pipe=header(Set-Cookie,";
urlParameters += cookies.join(",True)|header(Set-Cookie,") + ",True)";
urlCleanParameters +="?pipe=header(Set-Cookie,";
urlCleanParameters += cookies.join("%3B%20max-age=0,True)|header(Set-Cookie,") + "%3B%20max-age=0,True)";
}
var requestInit = {"credentials": credentials1}
promise_test(function(test){
var requestInit = {"credentials": credentials1}
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");
//check cookies sent
return fetch(RESOURCES_DIR + "inspect-headers.py?headers=cookie" , {"credentials": credentials2});
}).then(function(resp) {
assert_equals(resp.status, 200, "HTTP status is 200");
assert_equals(resp.type , "basic", "Response's type is basic");
assert_false(resp.headers.has("Cookie") , "Cookie header is not exposed in response");
if (credentials1 != "omit" && credentials2 != "omit") {
assert_equals(resp.headers.get("x-request-cookie") , cookies.join("; "), "Request include cookie(s)");
}
else {
assert_false(resp.headers.has("x-request-cookie") , "Request does not have cookie(s)");
}
//clean cookies
return fetch(url + urlCleanParameters, {"credentials": "include"});
}).catch(function(e) {
return fetch(url + urlCleanParameters, {"credentials": "include"}).then(function() {
return Promise.reject(e);
});
});
}, desc);
}
cookies("Include mode: 1 cookie", "include", "include", ["a=1"]);
cookies("Include mode: 2 cookies", "include", "include", ["b=2", "c=3"]);
cookies("Omit mode: discard cookies", "omit", "omit", ["d=4"]);
cookies("Omit mode: no cookie is stored", "omit", "include", ["e=5"]);
cookies("Omit mode: no cookie is sent", "include", "omit", ["f=6"]);
cookies("Same-origin mode: 1 cookie", "same-origin", "same-origin", ["a=1"]);
cookies("Same-origin mode: 2 cookies", "same-origin", "same-origin", ["b=2", "c=3"]);
done();

View file

@ -0,0 +1,221 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Headers structure</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#headers">
<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>
test(function() {
new Headers();
}, "Create headers from no parameter");
test(function() {
new Headers(undefined);
}, "Create headers from undefined parameter");
test(function() {
new Headers({});
}, "Create headers from empty object");
var parameters = [null, 1];
parameters.forEach(function(parameter) {
test(function() {
assert_throws(new TypeError(), function() { new Headers(parameter) });
}, "Create headers with " + parameter + " should throw");
});
var headerDict = {"name1": "value1",
"name2": "value2",
"name3": "value3",
"name4": null,
"name5": undefined,
"name6": 1,
"Content-Type": "value4"
};
var headerSeq = [];
for (var name in headerDict)
headerSeq.push([name, headerDict[name]]);
test(function() {
var headers = new Headers(headerSeq);
for (name in headerDict) {
assert_equals(headers.get(name), String(headerDict[name]),
"name: " + name + " has value: " + headerDict[name]);
}
assert_equals(headers.get("length"), null, "init should be treated as a sequence, not as a dictionary");
}, "Create headers with sequence");
test(function() {
var headers = new Headers(headerDict);
for (name in headerDict) {
assert_equals(headers.get(name), String(headerDict[name]),
"name: " + name + " has value: " + headerDict[name]);
}
}, "Create headers with OpenEndedDictionary");
test(function() {
var headers = new Headers(headerDict);
var headers2 = new Headers(headers);
for (name in headerDict) {
assert_equals(headers2.get(name), String(headerDict[name]),
"name: " + name + " has value: " + headerDict[name]);
}
}, "Create headers with existing headers");
test(function() {
var headers = new Headers();
for (name in headerDict) {
headers.append(name, headerDict[name]);
assert_equals(headers.get(name), String(headerDict[name]),
"name: " + name + " has value: " + headerDict[name]);
}
}, "Check append method");
test(function() {
var headers = new Headers();
for (name in headerDict) {
headers.set(name, headerDict[name]);
assert_equals(headers.get(name), String(headerDict[name]),
"name: " + name + " has value: " + headerDict[name]);
}
}, "Check set method");
test(function() {
var headers = new Headers(headerDict);
for (name in headerDict)
assert_true(headers.has(name),"headers has name " + name);
assert_false(headers.has("nameNotInHeaders"),"headers do not have header: nameNotInHeaders");
}, "Check has method");
test(function() {
var headers = new Headers(headerDict);
for (name in headerDict) {
assert_true(headers.has(name),"headers have a header: " + name);
headers.delete(name)
assert_true(!headers.has(name),"headers do not have anymore a header: " + name);
}
}, "Check delete method");
test(function() {
var headers = new Headers(headerDict);
for (name in headerDict)
assert_equals(headers.get(name), String(headerDict[name]),
"name: " + name + " has value: " + headerDict[name]);
assert_equals(headers.get("nameNotInHeaders"), null, "header: nameNotInHeaders has no value");
}, "Check get method");
var headerEntriesDict = {"name1": "value1",
"Name2": "value2",
"name": "value3",
"content-Type": "value4",
"Content-Typ": "value5",
"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([][Symbol.iterator]()));
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);
assert_equals(entry.value, key);
});
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();
assert_false(entry.done);
assert_equals(entry.value, sortedHeaderDict[key]);
});
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();
assert_false(entry.done);
assert_equals(entry.value[0], key);
assert_equals(entry.value[1], sortedHeaderDict[key]);
});
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() {
var headers = new Headers(headerEntriesDict);
var actual = headers[Symbol.iterator]();
sortedHeaderKeys.forEach(function(key) {
entry = actual.next();
assert_false(entry.done);
assert_equals(entry.value[0], key);
assert_equals(entry.value[1], sortedHeaderDict[key]);
});
assert_true(actual.next().done);
assert_true(actual.next().done);
}, "Check Symbol.iterator method");
test(function() {
var headers = new Headers(headerEntriesDict);
var reference = sortedHeaderKeys[Symbol.iterator]();
headers.forEach(function(value, key, container) {
assert_equals(headers, container);
entry = reference.next();
assert_false(entry.done);
assert_equals(key, entry.value);
assert_equals(value, sortedHeaderDict[entry.value]);
});
assert_true(reference.next().done);
}, "Check forEach method");
</script>
</body>
</html>

View file

@ -0,0 +1,64 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Headers case management</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-header-list-append">
<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>
var headerDictCase = {"UPPERCASE": "value1",
"lowercase": "value2",
"mixedCase": "value3",
"Content-TYPE": "value4"
};
function checkHeadersCase(originalName, headersToCheck, expectedDict) {
var lowCaseName = originalName.toLowerCase();
var upCaseName = originalName.toUpperCase();
var expectedValue = expectedDict[originalName];
assert_equals(headersToCheck.get(originalName), expectedValue,
"name: " + originalName + " has value: " + expectedValue);
assert_equals(headersToCheck.get(lowCaseName), expectedValue,
"name: " + lowCaseName + " has value: " + expectedValue);
assert_equals(headersToCheck.get(upCaseName), expectedValue,
"name: " + upCaseName + " has value: " + expectedValue);
}
test(function() {
var headers = new Headers(headerDictCase);
for (name in headerDictCase)
checkHeadersCase(name, headers, headerDictCase)
}, "Create headers, names use characters with different case");
test(function() {
var headers = new Headers();
for (name in headerDictCase) {
headers.append(name, headerDictCase[name]);
checkHeadersCase(name, headers, headerDictCase);
}
}, "Check append method, names use characters with different case");
test(function() {
var headers = new Headers();
for (name in headerDictCase) {
headers.set(name, headerDictCase[name]);
checkHeadersCase(name, headers, headerDictCase);
}
}, "Check set method, names use characters with different case");
test(function() {
var headers = new Headers();
for (name in headerDictCase)
headers.set(name, headerDictCase[name]);
for (name in headerDictCase)
headers.delete(name.toLowerCase());
for (name in headerDictCase)
assert_false(headers.has(name), "header " + name + " should have been deleted");
}, "Check delete method, names use characters with different case");
</script>
</body>
</html>

View file

@ -0,0 +1,60 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Headers nameshake</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#headers">
<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>
var headerSeqCombine = [["single", "singleValue"],
["double", "doubleValue1"],
["double", "doubleValue2"],
["triple", "tripleValue1"],
["triple", "tripleValue2"],
["triple", "tripleValue3"]
];
var expectedDict = {"single": "singleValue",
"double": "doubleValue1,doubleValue2",
"triple": "tripleValue1,tripleValue2,tripleValue3"
};
test(function() {
var headers = new Headers(headerSeqCombine);
for (name in expectedDict)
assert_equals(headers.get(name), expectedDict[name],
"name: " + name + " has value: " + expectedDict[name]);
}, "Create headers using same name for different values");
test(function() {
var headers = new Headers(headerSeqCombine);
for (name in expectedDict) {
assert_true(headers.has(name), "name: " + name + " has value(s)");
headers.delete(name);
assert_false(headers.has(name), "name: " + name + " has no value(s) anymore");
}
}, "Check delete and has methods when using same name for different values");
test(function() {
var headers = new Headers(headerSeqCombine);
for (name in expectedDict) {
headers.set(name,"newSingleValue");
assert_equals(headers.get(name), "newSingleValue", "name: " + name + " has value: newSingleValue");
}
}, "Check set methods when called with already used name");
test(function() {
var headers = new Headers(headerSeqCombine);
for (name in expectedDict) {
var value = headers.get(name);
headers.append(name,"newSingleValue");
assert_equals(headers.get(name), (value + "," + "newSingleValue"),
"name: " + name + " has value: " + headers.get(name));
}
}, "Check append methods when called with already used name");
</script>
</body>
</html>

View file

@ -0,0 +1,107 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Headers errors</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#headers">
<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>
test(function() {
assert_throws(new TypeError() , function() { new Headers([["name"]]); });
}, "Create headers giving an array having one string as init argument");
test(function() {
assert_throws(new TypeError() , function() { new Headers([["invalid", "invalidValue1", "invalidValue2"]]); });
}, "Create headers giving an array having three strings as init argument");
test(function() {
assert_throws(new TypeError() , function() { new Headers([["invalidĀ", "Value1"]]); });
}, "Create headers giving bad header name as init argument");
test(function() {
assert_throws(new TypeError() , function() { new Headers([["name", "invalidValueĀ"]]); });
}, "Create headers giving bad header value as init argument");
var badNames = ["invalidĀ", {}];
var badValues = ["invalidĀ"];
badNames.forEach(function(name) {
test(function() {
var headers = new Headers();
assert_throws(new TypeError() , function() { headers.get(name); });
}, "Check headers get with an invalid name " + name);
});
badNames.forEach(function(name) {
test(function() {
var headers = new Headers();
assert_throws(new TypeError() , function() { headers.delete(name); });
}, "Check headers delete with an invalid name " + name);
});
badNames.forEach(function(name) {
test(function() {
var headers = new Headers();
assert_throws(new TypeError() , function() { headers.has(name); });
}, "Check headers has with an invalid name " + name);
});
badNames.forEach(function(name) {
test(function() {
var headers = new Headers();
assert_throws(new TypeError() , function() { headers.set(name, "Value1"); });
}, "Check headers set with an invalid name " + name);
});
badValues.forEach(function(value) {
test(function() {
var headers = new Headers();
assert_throws(new TypeError() , function() { headers.set("name", value); });
}, "Check headers set with an invalid value " + value);
});
badNames.forEach(function(name) {
test(function() {
var headers = new Headers();
assert_throws(new TypeError() , function() { headers.append("invalidĀ", "Value1"); });
}, "Check headers append with an invalid name " + name);
});
badValues.forEach(function(value) {
test(function() {
var headers = new Headers();
assert_throws(new TypeError() , function() { headers.append("name", value); });
}, "Check headers append with an invalid value " + value);
});
test(function() {
var headers = new Headers([["name", "value"]]);
assert_throws(new TypeError() , function() { headers.forEach(); });
assert_throws(new TypeError() , function() { headers.forEach(undefined); });
assert_throws(new TypeError() , function() { headers.forEach(1); });
}, "Headers forEach throws if argument is not callable");
test(function() {
var headers = new Headers([["name1", "value1"], ["name2", "value2"], ["name3", "value3"]]);
var counter = 0;
try {
headers.forEach(function(value, name) {
counter++;
if (name == "name2")
throw "error";
});
} catch (e) {
assert_equals(counter, 2);
assert_equals(e, "error");
return;
}
assert_unreached();
}, "Headers forEach loop should stop if callback is throwing exception");
</script>
</body>
</html>

View file

@ -0,0 +1,36 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Headers idl interface</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#response">
<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>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>
</head>
<body>
<script id="headers-idl" type="text/plain">
typedef (Headers or sequence<sequence<ByteString>> or OpenEndedDictionary<ByteString>) HeadersInit;
[Constructor(optional HeadersInit init),
Exposed=(Window,Worker)]
interface Headers {
void append(ByteString name, ByteString value);
void delete(ByteString name);
ByteString? get(ByteString name);
boolean has(ByteString name);
void set(ByteString name, ByteString value);
iterable<ByteString, ByteString>;
};
</script>
<script>
var idlsArray = new IdlArray();
var idl = document.getElementById("headers-idl").innerHTML
idlsArray.add_idls(idl);
idlsArray.add_objects({ Headers: ['new Headers()'] });
idlsArray.test();
</script>
</body>
</html>

View file

@ -0,0 +1,47 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Headers normalize values</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#concept-header-value-normalize">
<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>
var headerDictWS = {"name1": " space ",
"name2": "\ttab\t",
"name3": " spaceAndTab\t",
"name4": "\r\n newLine", //obs-fold cases
"name5": "newLine\r\n ",
"name6": "\r\n\tnewLine",
};
test(function() {
var headers = new Headers(headerDictWS);
for (name in headerDictWS)
assert_equals(headers.get(name), headerDictWS[name].trim(),
"name: " + name + " has normalized value: " + headerDictWS[name].trim());
}, "Create headers with not normalized values");
test(function() {
var headers = new Headers();
for (name in headerDictWS) {
headers.append(name, headerDictWS[name]);
assert_equals(headers.get(name), headerDictWS[name].trim(),
"name: " + name + " has value: " + headerDictWS[name].trim());
}
}, "Check append method with not normalized values");
test(function() {
var headers = new Headers();
for (name in headerDictWS) {
headers.set(name, headerDictWS[name]);
assert_equals(headers.get(name), headerDictWS[name].trim(),
"name: " + name + " has value: " + headerDictWS[name].trim());
}
}, "Check set method with not normalized values");
</script>
</body>
</html>

View file

@ -0,0 +1,31 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Headers basic</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#headers">
<meta name="help" href="https://heycam.github.io/webidl/#idl-iterable">
<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>
var headers = new Headers();
var methods = ["append",
"delete",
"get",
"has",
"set",
//Headers is iterable
"entries",
"keys",
"values"
];
for (var idx in methods)
test(function() {
assert_true(methods[idx] in headers, "headers has " + methods[idx] + " method");
}, "Headers has " + methods[idx] + " method");
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch in worker: blocked by CSP</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-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("csp-blocked.js"));
</script>
</body>
</html>

View file

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Fetch: blocked by CSP</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#main-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="csp-blocked.js"></script>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show more