File: decoded-body-size-compressed.https.html

package info (click to toggle)
firefox 147.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,324 kB
  • sloc: cpp: 7,607,156; javascript: 6,532,492; ansic: 3,775,158; python: 1,415,368; xml: 634,556; asm: 438,949; java: 186,241; sh: 62,751; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (186 lines) | stat: -rw-r--r-- 8,072 bytes parent folder | download | duplicates (2)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="timeout" content="long"/>
  <title>PerformanceResourceTiming.decodedBodySize for compressed resources</title>
  <link rel="help" href="https://www.w3.org/TR/resource-timing-2/#dom-performanceresourcetiming-decodedbodysize" />
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="/fetch/compression-dictionary/resources/compression-dictionary-util.sub.js"></script>
  <script>
    const waitForResourceTiming = (url) => {
      return new Promise(resolve => {
        const observer = new PerformanceObserver((list) => {
          const entries = list.getEntries();
          for (const entry of entries) {
            if (entry.name.includes(url)) {
              observer.disconnect();
              resolve(entry);
            }
          }
        });
        observer.observe({ entryTypes: ["resource"] });
      });
    };

    promise_test(async (t) => {
      const url = "/resource-timing/resources/gzip_xml.py";
      const expectedDecodedSize = 125;

      const timingPromise = waitForResourceTiming(url);
      const response = await fetch(url);
      await response.text();
      const entry = await timingPromise;

      assert_equals(entry.decodedBodySize, expectedDecodedSize,
        "decodedBodySize should match the uncompressed XML file size");
      assert_greater_than(entry.encodedBodySize, 0,
        "encodedBodySize should be non-zero");
    }, "decodedBodySize for gzip-compressed XML resource");

    promise_test(async (t) => {
      const url = "/resource-timing/resources/foo.text.br";
      const expectedDecodedSize = 10500;
      const expectedEncodedSize = 15;

      const timingPromise = waitForResourceTiming(url);
      const response = await fetch(url);
      await response.text();
      const entry = await timingPromise;

      assert_equals(entry.decodedBodySize, expectedDecodedSize,
        "decodedBodySize should match the uncompressed brotli file size");
      assert_equals(entry.encodedBodySize, expectedEncodedSize,
        "encodedBodySize should match the compressed brotli file size");
    }, "decodedBodySize for brotli-compressed text resource");

    promise_test(async (t) => {
      const url = "/resource-timing/resources/foo.text.gz";
      const expectedDecodedSize = 10500;
      const expectedEncodedSize = 57;

      const timingPromise = waitForResourceTiming(url);
      const response = await fetch(url);
      await response.text();
      const entry = await timingPromise;

      assert_equals(entry.decodedBodySize, expectedDecodedSize,
        "decodedBodySize should match the uncompressed gzip file size");
      assert_equals(entry.encodedBodySize, expectedEncodedSize,
        "encodedBodySize should match the compressed gzip file size");
    }, "decodedBodySize for gzip-compressed text resource");

    promise_test(async (t) => {
      const url = "/resource-timing/resources/compressed-js.py?content_encoding=gzip";
      const expectedDecodedSize = 53;

      const timingPromise = waitForResourceTiming(url);
      const response = await fetch(url);
      await response.text();
      const entry = await timingPromise;

      assert_equals(entry.decodedBodySize, expectedDecodedSize,
        "decodedBodySize should match the uncompressed JS file size");
      assert_not_equals(entry.encodedBodySize, entry.decodedBodySize,
        "encodedBodySize should differ from decodedBodySize for gzip-compressed JS");
      assert_greater_than(entry.encodedBodySize, 0,
        "encodedBodySize should be non-zero");
    }, "decodedBodySize for dynamically gzip-compressed JS resource");

    promise_test(async (t) => {
      const url = "/resource-timing/resources/compressed-js.py?content_encoding=deflate";
      const expectedDecodedSize = 53;

      const timingPromise = waitForResourceTiming(url);
      const response = await fetch(url);
      await response.text();
      const entry = await timingPromise;

      assert_equals(entry.decodedBodySize, expectedDecodedSize,
        "decodedBodySize should match the uncompressed JS file size");
      assert_not_equals(entry.encodedBodySize, entry.decodedBodySize,
        "encodedBodySize should differ from decodedBodySize for deflate-compressed JS");
      assert_greater_than(entry.encodedBodySize, 0,
        "encodedBodySize should be non-zero");
    }, "decodedBodySize for deflate-compressed JS resource");

    promise_test(async (t) => {
      const url = "/resource-timing/resources/compressed-js.py?content_encoding=identity";
      const expectedSize = 53;

      const timingPromise = waitForResourceTiming(url);
      const response = await fetch(url);
      await response.text();
      const entry = await timingPromise;

      assert_equals(entry.decodedBodySize, expectedSize,
        "decodedBodySize should match file size for uncompressed resource");
      assert_equals(entry.encodedBodySize, expectedSize,
        "encodedBodySize should equal decodedBodySize for uncompressed resource");
    }, "decodedBodySize equals encodedBodySize for uncompressed resource");

    compression_dictionary_promise_test(async (t) => {
      const registerDictionaryUrl = '/fetch/compression-dictionary/resources/register-dictionary.py';
      const compressedDataUrl = '/fetch/compression-dictionary/resources/compressed-data.py';

      const dict = await (await fetch(registerDictionaryUrl)).text();
      assert_equals(dict, kDefaultDictionaryContent);

      await new Promise(resolve => t.step_timeout(resolve, 500));

      const url = `${compressedDataUrl}?content_encoding=dcb`;
      const expectedDecodedSize = 52;
      const expectedEncodedSize = 75;

      const timingPromise = waitForResourceTiming(url);
      const response = await fetch(url);
      const text = await response.text();
      assert_equals(text, kExpectedCompressedData,
        "The resource should decompress correctly");
      const entry = await timingPromise;

      assert_equals(entry.decodedBodySize, expectedDecodedSize,
        "decodedBodySize should match the uncompressed data size (52 bytes)");
      assert_equals(entry.encodedBodySize, expectedEncodedSize,
        "encodedBodySize should match the dictionary-compressed brotli size (75 bytes including dictionary hash)");
    }, "decodedBodySize for dictionary-compressed brotli (dcb) resource");

    compression_dictionary_promise_test(async (t) => {
      const registerDictionaryUrl = '/fetch/compression-dictionary/resources/register-dictionary.py';
      const compressedDataUrl = '/fetch/compression-dictionary/resources/compressed-data.py';

      const dict = await (await fetch(registerDictionaryUrl)).text();
      assert_equals(dict, kDefaultDictionaryContent);

      await new Promise(resolve => t.step_timeout(resolve, 500));

      const url = `${compressedDataUrl}?content_encoding=dcz`;
      const expectedDecodedSize = 52;
      const expectedEncodedSize = 83;

      const timingPromise = waitForResourceTiming(url);
      const response = await fetch(url);
      const text = await response.text();
      assert_equals(text, kExpectedCompressedData,
        "The resource should decompress correctly");
      const entry = await timingPromise;

      assert_equals(entry.decodedBodySize, expectedDecodedSize,
        "decodedBodySize should match the uncompressed data size (52 bytes)");
      assert_equals(entry.encodedBodySize, expectedEncodedSize,
        "encodedBodySize should match the dictionary-compressed zstd size (83 bytes including dictionary hash)");
    }, "decodedBodySize for dictionary-compressed zstd (dcz) resource");

  </script>
</head>
<body>
  <h1>Description</h1>
  <p>
    This test validates that PerformanceResourceTiming.decodedBodySize correctly reports
    the size of resources after removing content encoding (gzip, brotli, deflate, and
    compression dictionaries with dcb and dcz), and that it differs from encodedBodySize
    for compressed resources.
  </p>
</body>
</html>