tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

request-error.any.js (2243B)


      1 // META: global=window,worker
      2 // META: title=Request error
      3 // META: script=request-error.js
      4 
      5 // badRequestArgTests is from response-error.js
      6 for (const { args, testName } of badRequestArgTests) {
      7  test(() => {
      8    assert_throws_js(
      9      TypeError,
     10      () => new Request(...args),
     11      "Expect TypeError exception"
     12    );
     13  }, testName);
     14 }
     15 
     16 test(function() {
     17  assert_throws_js(
     18      TypeError,
     19      () => Request("about:blank"),
     20      "Calling Request constructor without 'new' must throw"
     21    );
     22 });
     23 
     24 test(function() {
     25  var initialHeaders = new Headers([["Content-Type", "potato"]]);
     26  var initialRequest = new Request("", {"headers" : initialHeaders});
     27  var request = new Request(initialRequest);
     28  assert_equals(request.headers.get("Content-Type"), "potato");
     29 }, "Request should get its content-type from the init request");
     30 
     31 test(function() {
     32  var initialHeaders = new Headers([["Content-Type", "potato"]]);
     33  var initialRequest = new Request("", {"headers" : initialHeaders});
     34  var headers = new Headers([]);
     35  var request = new Request(initialRequest, {"headers" : headers});
     36  assert_false(request.headers.has("Content-Type"));
     37 }, "Request should not get its content-type from the init request if init headers are provided");
     38 
     39 test(function() {
     40  var initialHeaders = new Headers([["Content-Type-Extra", "potato"]]);
     41  var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
     42  var request = new Request(initialRequest);
     43  assert_equals(request.headers.get("Content-Type"), "text/plain;charset=UTF-8");
     44 }, "Request should get its content-type from the body if none is provided");
     45 
     46 test(function() {
     47  var initialHeaders = new Headers([["Content-Type", "potato"]]);
     48  var initialRequest = new Request("", {"headers" : initialHeaders, "body" : "this is my plate", "method" : "POST"});
     49  var request = new Request(initialRequest);
     50  assert_equals(request.headers.get("Content-Type"), "potato");
     51 }, "Request should get its content-type from init headers if one is provided");
     52 
     53 test(function() {
     54  var options = {"cache": "only-if-cached", "mode": "same-origin"};
     55  new Request("test", options);
     56 }, "Request with cache mode: only-if-cached and fetch mode: same-origin");