Files
firefox/testing/web-platform/tests/fetch/api/request/request-error.html
T
Andrew Sutherland 1a4f099a52 Bug 1272436 - P1 Fetch "only-if-cached" cache mode tests. r=bkelly
request-error.html:
- Add test verifying we enforce only-if-cached requires same-origin mode.

request-cache.html (only-if-cached does not hit network):
- Add comment block explaining the test dictionary arguments.
- Eliminate duplicated code in populate_cache which seems to have existed only
  for historical reasons and is now moot.
- Add `response` optional test dictionary array for cases where a network error
  is expected as the result of the fetch.  Normalize server results to handle
  this case since test cases may no longer talk to the server at all.
- Add only-if-cached tests that verify the network is not touched in any of
  the fresh cached, stale cached, and not cached cases.

request-cache.html (cross-origin redirects in the cache are not traversed):
- Tests added to request/request-cache.html instead of under redirect/ because
  redirect/ and redirect.py explicitly disable caching.  Also, the issue is
  about cache behavior, not the redirect-following logic.
- Enhance cache.py to accept a "redirect" parameter that generates a 302
  redirect using a Location header when received.
- Make the "error" handling generate a test failure if we don't fail when
  expected.
- Add "redirect" argument to request-cache.html test info dicts to tell
  cache.py to generate a redirect.
- Add test cases for "only-if-cached" to first prime with redirect, expecting
  success on same-origin redirects and failure on cross-origin redirects.
2016-06-08 12:10:21 -04:00

111 lines
5.0 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>
</head>
<body>
<script>
test(function() {
assert_throws(new TypeError() , function() { new Request("", {"window" : "http://test.url"}); },
"Expect TypeError exception");
},"RequestInit's window is not null");
test(function() {
assert_throws(new TypeError() , function() { new Request("http://:not a valid URL"); },
"Expect TypeError exception");
},"Input URL is not valid")
test(function() {
assert_throws(new TypeError() , function() { new Request("http://user:[email protected]"); },
"Expect TypeError exception");
},"Input URL has credentials");
test(function() {
assert_throws(new TypeError() , function() { new Request("", {"mode" : "navigate"}); },
"Expect TypeError exception");
},"RequestInit's mode is navigate");
test(function() {
assert_throws(new TypeError() , function() { new Request("", {"referrer" : "http://:not a valid URL"}); },
"Expect TypeError exception");
},"RequestInit's referrer is invalid");
test(function() {
assert_throws(new TypeError() , function() { new Request("", {"referrer" : "http://test.url"}); },
"Expect TypeError exception");
},"RequestInit's referrer has invalid origin")
test(function() {
assert_throws(new TypeError() , function() { new Request("", {"method" : "IN VALID"}); },
"Expect TypeError exception");
}, "RequestInit's method is invalid");
test(function() {
assert_throws(new TypeError() , function() { new Request("", {"method" : "TRACE"}); },
"Expect TypeError exception");
}, "RequestInit's method is forbidden");
test(function() {
assert_throws(new TypeError() , function() { new Request("", {"mode" : "no-cors", "method" : "PUT"}); },
"Expect TypeError exception");
},"RequestInit's mode is no-cors and method is not simple");
test(function() {
assert_throws(new TypeError() ,
function() { new Request("", {"mode" : "no-cors", "integrity" : "not an empty string"}); },
"Expect TypeError exception");
},"RequestInit's mode is no-cors and integrity is not empty");
test(function() {
assert_throws(new TypeError() ,
function() { new Request("", {"mode" : "cors", "cache" : "only-if-cached"}); },
"Expect TypeError exception");
},"RequestInit's cache mode is only-if-cached and mode is not same-origin");
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");
var parameters = ["referrerPolicy", "mode", "credentials", "cache", "redirect"];
parameters.forEach(function(parameter) {
test(function() {
var options = { };
options[parameter] = "BAD";
assert_throws(new TypeError(), function() { new Request("", options); });
},"Bad " + parameter +" init parameter value");
});
</script>
</body>
</html>