tor-browser

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

csp-basic.html (1486B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="early-hints-helpers.sub.js"></script>
      6 <body>
      7 <script>
      8 const SEARCH_PARAMS = new URLSearchParams(window.location.search);
      9 const EARLY_HINTS_POLICY = SEARCH_PARAMS.get("early-hints-policy");
     10 const FINAL_POLICY = SEARCH_PARAMS.get("final-policy");
     11 
     12 function isResourceAllowed() {
     13    return FINAL_POLICY === "absent" || FINAL_POLICY === "allowed";
     14 }
     15 
     16 function shouldEarlyHintsPreloadResource() {
     17    return EARLY_HINTS_POLICY === "absent" || EARLY_HINTS_POLICY == "allowed";
     18 }
     19 
     20 promise_test(async (t) => {
     21    const resource_url = SEARCH_PARAMS.get("resource-url");
     22    if (isResourceAllowed()) {
     23        await fetchScript(resource_url);
     24        const early_hints_preloaded = isPreloadedByEarlyHints(resource_url);
     25        const should_early_hints_preload = shouldEarlyHintsPreloadResource();
     26        const description = "Early Hints " +
     27            (early_hints_preloaded ? "preloaded" : "didn't preload") +
     28            " the resource, should " +
     29            (should_early_hints_preload ? "" : "not ") + "preload.";
     30        assert_equals(early_hints_preloaded, should_early_hints_preload,
     31            description);
     32    } else {
     33        await promise_rejects_js(t, Error, fetchScript(resource_url));
     34    }
     35 }, `Early Hints CSP: Early Hints policy = ${EARLY_HINTS_POLICY}, final response policy = ${FINAL_POLICY}.`);
     36 </script>
     37 </body>