tor-browser

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

content-encoding.https.html (5865B)


      1 <!DOCTYPE html>
      2 <html>
      3 
      4 <head>
      5  <meta charset="utf-8">
      6  <title>contentEncoding in resource timing</title>
      7  <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
      8  <link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming" />
      9  <script src="/common/get-host-info.sub.js"></script>
     10  <script src="/resources/testharness.js"></script>
     11  <script src="/resources/testharnessreport.js"></script>
     12  <script src="resources/entry-invariants.js"></script>
     13  <script src="resources/resource-loaders.js"></script>
     14  <script>
     15 
     16    const { ORIGIN, REMOTE_ORIGIN } = get_host_info();
     17 
     18    const run_same_origin_test = (path, contentEncoding) => {
     19      const url = new URL(path, ORIGIN);
     20      attribute_test(
     21        fetch, url,
     22        entry => {
     23          assert_equals(entry.contentEncoding, contentEncoding,
     24            `run_same_origin_test failed, unexpected contentEncoding value.`);
     25        });
     26    }
     27 
     28    run_same_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcb", "dcb");
     29    run_same_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcz", "dcz");
     30    run_same_origin_test("/resource-timing/resources/gzip_xml.py", "gzip");
     31    run_same_origin_test("/resource-timing/resources/foo.text.br", "br");
     32    run_same_origin_test("/resource-timing/resources/foo.text.gz", "gzip");
     33    run_same_origin_test("/resource-timing/resources/foo.text.zst", "zstd");
     34    run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate", "deflate");
     35    run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip", "gzip");
     36    // Unrecognized content encoding value should be transformed to "@unknown".
     37    run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=unrecognizedname", "@unknown");
     38    // "identity" is not allowed in response header and should be transformed to "@unknown".
     39    run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=identity", "@unknown");
     40    // Mult-encodinging and formatting tests.
     41    run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=gzip, deflate,Apple", "multiple");
     42    run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=gzip, ", "multiple");
     43    run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=gZip ", "gzip");
     44    // Empty value test.
     45    run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=", "");
     46 
     47    const run_cross_origin_test = (path) => {
     48      const url = new URL(path, REMOTE_ORIGIN);
     49      attribute_test(
     50        load.xhr_async, url,
     51        entry => {
     52          assert_equals(entry.contentEncoding, "",
     53            `run_cross_origin_test failed, contentEncoding should be empty.`);
     54        });
     55    }
     56 
     57    run_cross_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcb");
     58    run_cross_origin_test("/resource-timing/resources/gzip_xml.py");
     59    run_cross_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcz");
     60    run_cross_origin_test("/resource-timing/resources/foo.text.br");
     61    run_cross_origin_test("/resource-timing/resources/foo.text.gz");
     62    run_cross_origin_test("/resource-timing/resources/foo.text.zst");
     63    run_cross_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate");
     64    run_cross_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip");
     65 
     66    const run_cross_origin_allowed_test = (path, contentEncoding) => {
     67      const url = new URL(path, REMOTE_ORIGIN);
     68      url.searchParams.set("allow_origin", ORIGIN);
     69      attribute_test(
     70        load.xhr_async, url,
     71        entry => {
     72          assert_equals(entry.contentEncoding, contentEncoding,
     73            `run_cross_origin_allowed_test failed, unexpected contentEncoding value.`);
     74        });
     75    }
     76 
     77    run_cross_origin_allowed_test("/resource-timing/resources/compressed-data.py?content_encoding=dcb", "dcb");
     78    run_cross_origin_allowed_test("/resource-timing/resources/compressed-data.py?content_encoding=dcz", "dcz");
     79    run_cross_origin_allowed_test("/resource-timing/resources/gzip_xml.py", "gzip");
     80    run_cross_origin_allowed_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate", "deflate");
     81    run_cross_origin_allowed_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip", "gzip");
     82 
     83    // Content-Encoding for iframes is empty when cross origin redirects are present.
     84    const multiRedirect = new URL(`${ORIGIN}/resource-timing/resources/multi_redirect.py`);
     85    multiRedirect.searchParams.append("page_origin", ORIGIN);
     86    multiRedirect.searchParams.append("cross_origin", REMOTE_ORIGIN);
     87    multiRedirect.searchParams.append("final_resource", "/resource-timing/resources/compressed-js.py?content_encoding=gzip");
     88    attribute_test(load.iframe, multiRedirect, (entry) => {
     89      assert_equals(entry.contentEncoding, "",
     90        `content-encoding should be empty for iframes having cross origin redirects`);
     91    });
     92 
     93 
     94    // Content-Encoding for iframes is exposed for same origin redirects.
     95    const redirectCORS = new URL(`${ORIGIN}/resource-timing/resources/redirect-cors.py`);
     96    const dest = `${ORIGIN}/resource-timing/resources/compressed-js.py?content_encoding=gzip`;
     97    redirectCORS.searchParams.append("location", dest)
     98    attribute_test(load.iframe, redirectCORS, (entry) => {
     99      assert_equals(entry.contentEncoding, "gzip",
    100        `content-encoding should be exposed for iframes having only same origin redirects`);
    101    });
    102 
    103  </script>
    104 </head>
    105 
    106 <body>
    107  <h1>
    108    Description</h1>
    109  <p>
    110    This test validates contentEncoding in resource timing.</p>
    111 </body>
    112 
    113 </html>