mirror of
https://github.com/servo/servo
synced 2026-05-11 17:37:21 +02:00
62 lines
2.7 KiB
HTML
62 lines
2.7 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Request error</title>
|
|
<meta name="help" href="https://fetch.spec.whatwg.org/#request">
|
|
<meta name="help" href="https://fetch.spec.whatwg.org/#body-mixin">
|
|
<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="request-error.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
// badRequestArgTests is from response-error.js
|
|
for (const { args, testName } of badRequestArgTests) {
|
|
test(() => {
|
|
assert_throws(
|
|
new TypeError(),
|
|
() => new Request(...args),
|
|
"Expect TypeError exception"
|
|
);
|
|
}, testName);
|
|
}
|
|
|
|
test(function() {
|
|
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
|
var initialRequest = new Request("", {"headers" : initialHeaders});
|
|
var request = new Request(initialRequest);
|
|
assert_equals(request.headers.get("Content-Type"), "potato");
|
|
}, "Request should get its content-type from the init request");
|
|
|
|
test(function() {
|
|
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
|
var initialRequest = new Request("", {"headers" : initialHeaders});
|
|
var headers = new Headers([]);
|
|
var request = new Request(initialRequest, {"headers" : headers});
|
|
assert_false(request.headers.has("Content-Type"));
|
|
}, "Request should not get its content-type from the init request if init headers are provided");
|
|
|
|
test(function() {
|
|
var initialHeaders = new Headers([["Content-Type-Extra", "potato"]]);
|
|
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
|
var request = new Request(initialRequest);
|
|
assert_equals(request.headers.get("Content-Type"), "text/plain;charset=UTF-8");
|
|
}, "Request should get its content-type from the body if none is provided");
|
|
|
|
test(function() {
|
|
var initialHeaders = new Headers([["Content-Type", "potato"]]);
|
|
var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
|
|
var request = new Request(initialRequest);
|
|
assert_equals(request.headers.get("Content-Type"), "potato");
|
|
}, "Request should get its content-type from init headers if one is provided");
|
|
|
|
test(function() {
|
|
var options = {"cache": "only-if-cached", "mode": "same-origin"};
|
|
new Request("test", options);
|
|
}, "Request with cache mode: only-if-cached and fetch mode: same-origin");
|
|
</script>
|
|
</body>
|
|
</html>
|