File: content-encoding.https.html

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (113 lines) | stat: -rw-r--r-- 5,865 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>contentEncoding in resource timing</title>
  <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
  <link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming" />
  <script src="/common/get-host-info.sub.js"></script>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="resources/entry-invariants.js"></script>
  <script src="resources/resource-loaders.js"></script>
  <script>

    const { ORIGIN, REMOTE_ORIGIN } = get_host_info();

    const run_same_origin_test = (path, contentEncoding) => {
      const url = new URL(path, ORIGIN);
      attribute_test(
        fetch, url,
        entry => {
          assert_equals(entry.contentEncoding, contentEncoding,
            `run_same_origin_test failed, unexpected contentEncoding value.`);
        });
    }

    run_same_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcb", "dcb");
    run_same_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcz", "dcz");
    run_same_origin_test("/resource-timing/resources/gzip_xml.py", "gzip");
    run_same_origin_test("/resource-timing/resources/foo.text.br", "br");
    run_same_origin_test("/resource-timing/resources/foo.text.gz", "gzip");
    run_same_origin_test("/resource-timing/resources/foo.text.zst", "zstd");
    run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate", "deflate");
    run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip", "gzip");
    // Unrecognized content encoding value should be transformed to "@unknown".
    run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=unrecognizedname", "@unknown");
    // "identity" is not allowed in response header and should be transformed to "@unknown".
    run_same_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=identity", "@unknown");
    // Mult-encodinging and formatting tests.
    run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=gzip, deflate,Apple", "multiple");
    run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=gzip, ", "multiple");
    run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=gZip ", "gzip");
    // Empty value test.
    run_same_origin_test("/resource-timing/resources/content-encoding-headers.py?content_encoding=", "");

    const run_cross_origin_test = (path) => {
      const url = new URL(path, REMOTE_ORIGIN);
      attribute_test(
        load.xhr_async, url,
        entry => {
          assert_equals(entry.contentEncoding, "",
            `run_cross_origin_test failed, contentEncoding should be empty.`);
        });
    }

    run_cross_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcb");
    run_cross_origin_test("/resource-timing/resources/gzip_xml.py");
    run_cross_origin_test("/resource-timing/resources/compressed-data.py?content_encoding=dcz");
    run_cross_origin_test("/resource-timing/resources/foo.text.br");
    run_cross_origin_test("/resource-timing/resources/foo.text.gz");
    run_cross_origin_test("/resource-timing/resources/foo.text.zst");
    run_cross_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate");
    run_cross_origin_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip");

    const run_cross_origin_allowed_test = (path, contentEncoding) => {
      const url = new URL(path, REMOTE_ORIGIN);
      url.searchParams.set("allow_origin", ORIGIN);
      attribute_test(
        load.xhr_async, url,
        entry => {
          assert_equals(entry.contentEncoding, contentEncoding,
            `run_cross_origin_allowed_test failed, unexpected contentEncoding value.`);
        });
    }

    run_cross_origin_allowed_test("/resource-timing/resources/compressed-data.py?content_encoding=dcb", "dcb");
    run_cross_origin_allowed_test("/resource-timing/resources/compressed-data.py?content_encoding=dcz", "dcz");
    run_cross_origin_allowed_test("/resource-timing/resources/gzip_xml.py", "gzip");
    run_cross_origin_allowed_test("/resource-timing/resources/compressed-js.py?content_encoding=deflate", "deflate");
    run_cross_origin_allowed_test("/resource-timing/resources/compressed-js.py?content_encoding=gzip", "gzip");

    // Content-Encoding for iframes is empty when cross origin redirects are present.
    const multiRedirect = new URL(`${ORIGIN}/resource-timing/resources/multi_redirect.py`);
    multiRedirect.searchParams.append("page_origin", ORIGIN);
    multiRedirect.searchParams.append("cross_origin", REMOTE_ORIGIN);
    multiRedirect.searchParams.append("final_resource", "/resource-timing/resources/compressed-js.py?content_encoding=gzip");
    attribute_test(load.iframe, multiRedirect, (entry) => {
      assert_equals(entry.contentEncoding, "",
        `content-encoding should be empty for iframes having cross origin redirects`);
    });


    // Content-Encoding for iframes is exposed for same origin redirects.
    const redirectCORS = new URL(`${ORIGIN}/resource-timing/resources/redirect-cors.py`);
    const dest = `${ORIGIN}/resource-timing/resources/compressed-js.py?content_encoding=gzip`;
    redirectCORS.searchParams.append("location", dest)
    attribute_test(load.iframe, redirectCORS, (entry) => {
      assert_equals(entry.contentEncoding, "gzip",
        `content-encoding should be exposed for iframes having only same origin redirects`);
    });

  </script>
</head>

<body>
  <h1>
    Description</h1>
  <p>
    This test validates contentEncoding in resource timing.</p>
</body>

</html>