tor-browser

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

headers-normalize.any.js (1634B)


      1 // META: title=Headers normalize values
      2 // META: global=window,worker
      3 
      4 "use strict";
      5 
      6 const expectations = {
      7  "name1": [" space ", "space"],
      8  "name2": ["\ttab\t", "tab"],
      9  "name3": [" spaceAndTab\t", "spaceAndTab"],
     10  "name4": ["\r\n newLine", "newLine"], //obs-fold cases
     11  "name5": ["newLine\r\n ", "newLine"],
     12  "name6": ["\r\n\tnewLine", "newLine"],
     13  "name7": ["\t\f\tnewLine\n", "\f\tnewLine"],
     14  "name8": ["newLine\xa0", "newLine\xa0"], // \xa0 == non breaking space
     15 };
     16 
     17 test(function () {
     18  const headerDict = Object.fromEntries(
     19    Object.entries(expectations).map(([name, [actual]]) => [name, actual]),
     20  );
     21  var headers = new Headers(headerDict);
     22  for (const name in expectations) {
     23    const expected = expectations[name][1];
     24    assert_equals(
     25      headers.get(name),
     26      expected,
     27      "name: " + name + " has normalized value: " + expected,
     28    );
     29  }
     30 }, "Create headers with not normalized values");
     31 
     32 test(function () {
     33  var headers = new Headers();
     34  for (const name in expectations) {
     35    headers.append(name, expectations[name][0]);
     36    const expected = expectations[name][1];
     37    assert_equals(
     38      headers.get(name),
     39      expected,
     40      "name: " + name + " has value: " + expected,
     41    );
     42  }
     43 }, "Check append method with not normalized values");
     44 
     45 test(function () {
     46  var headers = new Headers();
     47  for (const name in expectations) {
     48    headers.set(name, expectations[name][0]);
     49    const expected = expectations[name][1];
     50    assert_equals(
     51      headers.get(name),
     52      expected,
     53      "name: " + name + " has value: " + expected,
     54    );
     55  }
     56 }, "Check set method with not normalized values");