tor-browser

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

sec-ch-quotes.https.html (2300B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Tests Stale While Revalidate is not executed for fetch API</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/common/utils.js"></script>
      7 <script>
      8 const verify_headers = (header_list, response, verification_func) => {
      9  header_list.forEach(header => {
     10    const value = response.headers.get(header+"-received");
     11    if(value) {
     12      verification_func(value);
     13    }
     14  });
     15 };
     16 
     17 promise_test(async (test) => {
     18  const request_token = token();
     19  const string_list_client_hint_headers = [
     20    "sec-ch-ua",
     21  ];
     22  const string_client_hint_headers = [
     23    "sec-ch-ua-arch",
     24    "sec-ch-ua-platform",
     25    "sec-ch-ua-platform-version",
     26    "sec-ch-ua-model",
     27    "sec-ch-ua-full-version",
     28    "sec-ch-prefers-color-scheme",
     29    "sec-ch-prefers-reduced-motion",
     30    "sec-ch-ua-full-version-list",
     31    "sec-ch-ua-wow64",
     32    "sec-ch-prefers-reduced-transparency",
     33  ];
     34  const boolean_client_hint_headers = [
     35    "sec-ch-mobile",
     36  ];
     37 
     38  const response = await fetch("resources/echo-ua-client-hints-received.py");
     39  verify_headers(string_client_hint_headers, response, value => {
     40    if(value) {
     41      // Check that the hints have quotes
     42      // TODO(yoav): this doesn't account for parameters. Need an SH parser, that verifies no parameters are present.
     43      assert_equals(value.slice(0,1), "\"");
     44      assert_equals(value.slice(-1), "\"");
     45    }
     46  });
     47  verify_headers(string_list_client_hint_headers, response, value => {
     48    // Check that the hints have quotes
     49    // TODO(yoav): this doesn't account for list parsing or parameters. Need an SH parser, that verifies this is a list of strings with a "v" parameter present in at least one value.
     50    assert_false((typeof value) == "undefined");
     51    assert_equals(value.slice(0,1), "\"");
     52    assert_equals(value.slice(-1), "\"");
     53  });
     54  verify_headers(boolean_client_hint_headers, response, value => {
     55    if(value) {
     56      // Check that the value is a valid boolean
     57      assert_false((typeof value) == "undefined");
     58      assert_equals(value.slice(0,1), "?");
     59      const num = value.slice(-1);
     60      assert_true(num == "0" || num == "1");
     61    }
     62  });
     63 }, 'User agent client hint header values are surrounded by quotes');
     64 </script>