summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api/request/request-error.any.js
blob: 9ec8015198daddf55d61fbd98a9d093da0f6a76d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// META: global=window,worker
// META: title=Request error
// META: script=request-error.js

// badRequestArgTests is from response-error.js
for (const { args, testName } of badRequestArgTests) {
  test(() => {
    assert_throws_js(
      TypeError,
      () => new Request(...args),
      "Expect TypeError exception"
    );
  }, testName);
}

test(function() {
  assert_throws_js(
      TypeError,
      () => Request("about:blank"),
      "Calling Request constructor without 'new' must throw"
    );
});

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");