Skip to content

Commit 55d0c94

Browse files
committed
Bug 1921583 - Part 1: Refactor decompression tests to share chunk data r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D269442
1 parent c476444 commit 55d0c94

7 files changed

Lines changed: 48 additions & 42 deletions

testing/web-platform/meta/compression/decompression-corrupt-input.any.js.ini

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,25 @@
33
if (os == "mac") and not debug: [OK, CRASH]
44

55
[decompression-corrupt-input.any.worker.html]
6+
7+
[decompression-corrupt-input.any.shadowrealm-in-sharedworker.html]
8+
expected: ERROR
9+
10+
[decompression-corrupt-input.any.serviceworker.html]
11+
12+
[decompression-corrupt-input.any.sharedworker.html]
13+
14+
[decompression-corrupt-input.any.shadowrealm-in-window.html]
15+
expected: ERROR
16+
17+
[decompression-corrupt-input.https.any.shadowrealm-in-serviceworker.html]
18+
expected: ERROR
19+
20+
[decompression-corrupt-input.any.shadowrealm-in-dedicatedworker.html]
21+
expected: ERROR
22+
23+
[decompression-corrupt-input.any.shadowrealm-in-shadowrealm.html]
24+
expected: ERROR
25+
26+
[decompression-corrupt-input.https.any.shadowrealm-in-audioworklet.html]
27+
expected: ERROR
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
// META: global=window,worker,shadowrealm
2-
// META: script=decompression-correct-input.js
2+
// META: script=resources/decompression-input.js
33

44
'use strict';
55

6-
const tests = [
7-
["deflate", deflateChunkValue],
8-
["gzip", gzipChunkValue],
9-
["deflate-raw", deflateRawChunkValue],
10-
];
11-
12-
for (const [format, chunk] of tests) {
6+
for (const [format, chunk] of compressedBytes) {
137
promise_test(async t => {
148
const ds = new DecompressionStream(format);
159
const reader = ds.readable.getReader();
1610
const writer = ds.writable.getWriter();
1711
const writePromise = writer.write(chunk);
1812
const { done, value } = await reader.read();
19-
assert_array_equals(Array.from(value), trueChunkValue, "value should match");
13+
assert_array_equals(Array.from(value), expectedChunkValue, "value should match");
2014
}, `decompressing ${format} input should work`);
2115
}

testing/web-platform/tests/compression/decompression-corrupt-input.any.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// META global=window,worker,shadowrealm
1+
// META: global=window,worker,shadowrealm
2+
// META: script=resources/decompression-input.js
23

34
// This test checks that DecompressionStream behaves according to the standard
45
// when the input is corrupted. To avoid a combinatorial explosion in the
@@ -13,8 +14,7 @@ const expectations = [
1314
format: 'deflate',
1415

1516
// Decompresses to 'expected output'.
16-
baseInput: [120, 156, 75, 173, 40, 72, 77, 46, 73, 77, 81, 200, 47, 45, 41,
17-
40, 45, 1, 0, 48, 173, 6, 36],
17+
baseInput: deflateChunkValue,
1818

1919
// See RFC1950 for the definition of the various fields used by deflate:
2020
// https://tools.ietf.org/html/rfc1950.
@@ -102,9 +102,7 @@ const expectations = [
102102
format: 'gzip',
103103

104104
// Decompresses to 'expected output'.
105-
baseInput: [31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 75, 173, 40, 72, 77, 46, 73,
106-
77, 81, 200, 47, 45, 41, 40, 45, 1, 0, 176, 1, 57, 179, 15, 0,
107-
0, 0],
105+
baseInput: gzipChunkValue,
108106

109107
// See RFC1952 for the definition of the various fields used by gzip:
110108
// https://tools.ietf.org/html/rfc1952.
@@ -274,18 +272,18 @@ function corruptInput(input, offset, length, value) {
274272

275273
for (const { format, baseInput, fields } of expectations) {
276274
promise_test(async () => {
277-
const { result } = await tryDecompress(new Uint8Array(baseInput), format);
275+
const { result } = await tryDecompress(baseInput, format);
278276
assert_equals(result, 'success', 'decompression should succeed');
279277
}, `the unchanged input for '${format}' should decompress successfully`);
280278

281279
promise_test(async () => {
282-
const truncatedInput = new Uint8Array(baseInput.slice(0, -1));
280+
const truncatedInput = baseInput.subarray(0, -1);
283281
const { result } = await tryDecompress(truncatedInput, format);
284282
assert_equals(result, 'error', 'decompression should fail');
285283
}, `truncating the input for '${format}' should give an error`);
286284

287285
promise_test(async () => {
288-
const extendedInput = new Uint8Array(baseInput.concat([0]));
286+
const extendedInput = new Uint8Array([...baseInput, 0]);
289287
const { result } = await tryDecompress(extendedInput, format);
290288
assert_equals(result, 'error', 'decompression should fail');
291289
}, `trailing junk for '${format}' should give an error`);
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// META: global=window,worker,shadowrealm
2-
// META: script=decompression-correct-input.js
2+
// META: script=resources/decompression-input.js
33

44
'use strict';
55

6-
const tests = [
7-
["deflate", new Uint8Array([...deflateChunkValue, 0])],
8-
["gzip", new Uint8Array([...gzipChunkValue, 0])],
9-
["deflate-raw", new Uint8Array([...deflateRawChunkValue, 0])],
10-
];
6+
const tests = compressedBytes.map(
7+
([format, chunk]) => [format, new Uint8Array([...chunk, 0])]
8+
);
119

1210
for (const [format, chunk] of tests) {
1311
promise_test(async t => {
@@ -16,7 +14,7 @@ for (const [format, chunk] of tests) {
1614
const writer = ds.writable.getWriter();
1715
writer.write(chunk).catch(() => { });
1816
const { done, value } = await reader.read();
19-
assert_array_equals(Array.from(value), trueChunkValue, "value should match");
17+
assert_array_equals(Array.from(value), expectedChunkValue, "value should match");
2018
await promise_rejects_js(t, TypeError, reader.read(), "Extra input should eventually throw");
2119
}, `decompressing ${format} input with extra pad should still give the output`);
2220
}

testing/web-platform/tests/compression/decompression-split-chunk.any.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
// META: global=window,worker,shadowrealm
2+
// META: script=resources/decompression-input.js
23

34
'use strict';
45

5-
const compressedBytes = [
6-
["deflate", new Uint8Array([120, 156, 75, 173, 40, 72, 77, 46, 73, 77, 81, 200, 47, 45, 41, 40, 45, 1, 0, 48, 173, 6, 36])],
7-
["gzip", new Uint8Array([31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 75, 173, 40, 72, 77, 46, 73, 77, 81, 200, 47, 45, 41, 40, 45, 1, 0, 176, 1, 57, 179, 15, 0, 0, 0])],
8-
["deflate-raw", new Uint8Array([
9-
0x4b, 0xad, 0x28, 0x48, 0x4d, 0x2e, 0x49, 0x4d, 0x51, 0xc8,
10-
0x2f, 0x2d, 0x29, 0x28, 0x2d, 0x01, 0x00,
11-
])],
12-
]
13-
const expectedChunkValue = new TextEncoder().encode('expected output');
14-
156
async function decompressArrayBuffer(input, format, chunkSize) {
167
const ds = new DecompressionStream(format);
178
const reader = ds.readable.getReader();

testing/web-platform/tests/compression/decompression-uint8array-output.any.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
// META: global=window,worker,shadowrealm
2+
// META: script=resources/decompression-input.js
23

34
'use strict';
45

5-
const chunkValues = [
6-
["deflate", new Uint8Array([120, 156, 75, 173, 40, 72, 77, 46, 73, 77, 81, 200, 47, 45, 41, 40, 45, 1, 0, 48, 173, 6, 36])],
7-
["gzip", new Uint8Array([31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 75, 173, 40, 72, 77, 46, 73, 77, 81, 200, 47, 45, 41, 40, 45, 1, 0, 176, 1, 57, 179, 15, 0, 0, 0])],
8-
];
9-
10-
for (const [format, chunkValue] of chunkValues) {
6+
for (const [format, chunkValue] of compressedBytes) {
117
promise_test(async t => {
128
const ds = new DecompressionStream(format);
139
const reader = ds.readable.getReader();

testing/web-platform/tests/compression/decompression-correct-input.js renamed to testing/web-platform/tests/compression/resources/decompression-input.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ const deflateRawChunkValue = new Uint8Array([
44
0x4b, 0xad, 0x28, 0x48, 0x4d, 0x2e, 0x49, 0x4d, 0x51, 0xc8,
55
0x2f, 0x2d, 0x29, 0x28, 0x2d, 0x01, 0x00,
66
]);
7-
const trueChunkValue = new TextEncoder().encode('expected output');
7+
8+
const compressedBytes = [
9+
["deflate", deflateChunkValue],
10+
["gzip", gzipChunkValue],
11+
["deflate-raw", deflateRawChunkValue],
12+
];
13+
14+
const expectedChunkValue = new TextEncoder().encode('expected output');

0 commit comments

Comments
 (0)