tor-browser

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

commit 55d0c9428ed35bc533838aa15b1a5dcac712ed77
parent c476444271964862cc91284c341a019473e63008
Author: Kagami Sascha Rosylight <krosylight@proton.me>
Date:   Wed, 22 Oct 2025 14:45:19 +0000

Bug 1921583 - Part 1: Refactor decompression tests to share chunk data r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D269442

Diffstat:
Mtesting/web-platform/meta/compression/decompression-corrupt-input.any.js.ini | 22++++++++++++++++++++++
Mtesting/web-platform/tests/compression/decompression-correct-input.any.js | 12+++---------
Dtesting/web-platform/tests/compression/decompression-correct-input.js | 7-------
Mtesting/web-platform/tests/compression/decompression-corrupt-input.any.js | 16+++++++---------
Mtesting/web-platform/tests/compression/decompression-extra-input.any.js | 12+++++-------
Mtesting/web-platform/tests/compression/decompression-split-chunk.any.js | 11+----------
Mtesting/web-platform/tests/compression/decompression-uint8array-output.any.js | 8++------
Atesting/web-platform/tests/compression/resources/decompression-input.js | 14++++++++++++++
8 files changed, 54 insertions(+), 48 deletions(-)

diff --git a/testing/web-platform/meta/compression/decompression-corrupt-input.any.js.ini b/testing/web-platform/meta/compression/decompression-corrupt-input.any.js.ini @@ -3,3 +3,25 @@ if (os == "mac") and not debug: [OK, CRASH] [decompression-corrupt-input.any.worker.html] + +[decompression-corrupt-input.any.shadowrealm-in-sharedworker.html] + expected: ERROR + +[decompression-corrupt-input.any.serviceworker.html] + +[decompression-corrupt-input.any.sharedworker.html] + +[decompression-corrupt-input.any.shadowrealm-in-window.html] + expected: ERROR + +[decompression-corrupt-input.https.any.shadowrealm-in-serviceworker.html] + expected: ERROR + +[decompression-corrupt-input.any.shadowrealm-in-dedicatedworker.html] + expected: ERROR + +[decompression-corrupt-input.any.shadowrealm-in-shadowrealm.html] + expected: ERROR + +[decompression-corrupt-input.https.any.shadowrealm-in-audioworklet.html] + expected: ERROR diff --git a/testing/web-platform/tests/compression/decompression-correct-input.any.js b/testing/web-platform/tests/compression/decompression-correct-input.any.js @@ -1,21 +1,15 @@ // META: global=window,worker,shadowrealm -// META: script=decompression-correct-input.js +// META: script=resources/decompression-input.js 'use strict'; -const tests = [ - ["deflate", deflateChunkValue], - ["gzip", gzipChunkValue], - ["deflate-raw", deflateRawChunkValue], -]; - -for (const [format, chunk] of tests) { +for (const [format, chunk] of compressedBytes) { promise_test(async t => { const ds = new DecompressionStream(format); const reader = ds.readable.getReader(); const writer = ds.writable.getWriter(); const writePromise = writer.write(chunk); const { done, value } = await reader.read(); - assert_array_equals(Array.from(value), trueChunkValue, "value should match"); + assert_array_equals(Array.from(value), expectedChunkValue, "value should match"); }, `decompressing ${format} input should work`); } diff --git a/testing/web-platform/tests/compression/decompression-correct-input.js b/testing/web-platform/tests/compression/decompression-correct-input.js @@ -1,7 +0,0 @@ -const deflateChunkValue = 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]); -const gzipChunkValue = 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]); -const deflateRawChunkValue = new Uint8Array([ - 0x4b, 0xad, 0x28, 0x48, 0x4d, 0x2e, 0x49, 0x4d, 0x51, 0xc8, - 0x2f, 0x2d, 0x29, 0x28, 0x2d, 0x01, 0x00, -]); -const trueChunkValue = new TextEncoder().encode('expected output'); diff --git a/testing/web-platform/tests/compression/decompression-corrupt-input.any.js b/testing/web-platform/tests/compression/decompression-corrupt-input.any.js @@ -1,4 +1,5 @@ -// META global=window,worker,shadowrealm +// META: global=window,worker,shadowrealm +// META: script=resources/decompression-input.js // This test checks that DecompressionStream behaves according to the standard // when the input is corrupted. To avoid a combinatorial explosion in the @@ -13,8 +14,7 @@ const expectations = [ format: 'deflate', // Decompresses to 'expected output'. - baseInput: [120, 156, 75, 173, 40, 72, 77, 46, 73, 77, 81, 200, 47, 45, 41, - 40, 45, 1, 0, 48, 173, 6, 36], + baseInput: deflateChunkValue, // See RFC1950 for the definition of the various fields used by deflate: // https://tools.ietf.org/html/rfc1950. @@ -102,9 +102,7 @@ const expectations = [ format: 'gzip', // Decompresses to 'expected output'. - baseInput: [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], + baseInput: gzipChunkValue, // See RFC1952 for the definition of the various fields used by gzip: // https://tools.ietf.org/html/rfc1952. @@ -274,18 +272,18 @@ function corruptInput(input, offset, length, value) { for (const { format, baseInput, fields } of expectations) { promise_test(async () => { - const { result } = await tryDecompress(new Uint8Array(baseInput), format); + const { result } = await tryDecompress(baseInput, format); assert_equals(result, 'success', 'decompression should succeed'); }, `the unchanged input for '${format}' should decompress successfully`); promise_test(async () => { - const truncatedInput = new Uint8Array(baseInput.slice(0, -1)); + const truncatedInput = baseInput.subarray(0, -1); const { result } = await tryDecompress(truncatedInput, format); assert_equals(result, 'error', 'decompression should fail'); }, `truncating the input for '${format}' should give an error`); promise_test(async () => { - const extendedInput = new Uint8Array(baseInput.concat([0])); + const extendedInput = new Uint8Array([...baseInput, 0]); const { result } = await tryDecompress(extendedInput, format); assert_equals(result, 'error', 'decompression should fail'); }, `trailing junk for '${format}' should give an error`); diff --git a/testing/web-platform/tests/compression/decompression-extra-input.any.js b/testing/web-platform/tests/compression/decompression-extra-input.any.js @@ -1,13 +1,11 @@ // META: global=window,worker,shadowrealm -// META: script=decompression-correct-input.js +// META: script=resources/decompression-input.js 'use strict'; -const tests = [ - ["deflate", new Uint8Array([...deflateChunkValue, 0])], - ["gzip", new Uint8Array([...gzipChunkValue, 0])], - ["deflate-raw", new Uint8Array([...deflateRawChunkValue, 0])], -]; +const tests = compressedBytes.map( + ([format, chunk]) => [format, new Uint8Array([...chunk, 0])] +); for (const [format, chunk] of tests) { promise_test(async t => { @@ -16,7 +14,7 @@ for (const [format, chunk] of tests) { const writer = ds.writable.getWriter(); writer.write(chunk).catch(() => { }); const { done, value } = await reader.read(); - assert_array_equals(Array.from(value), trueChunkValue, "value should match"); + assert_array_equals(Array.from(value), expectedChunkValue, "value should match"); await promise_rejects_js(t, TypeError, reader.read(), "Extra input should eventually throw"); }, `decompressing ${format} input with extra pad should still give the output`); } diff --git a/testing/web-platform/tests/compression/decompression-split-chunk.any.js b/testing/web-platform/tests/compression/decompression-split-chunk.any.js @@ -1,17 +1,8 @@ // META: global=window,worker,shadowrealm +// META: script=resources/decompression-input.js 'use strict'; -const compressedBytes = [ - ["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])], - ["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])], - ["deflate-raw", new Uint8Array([ - 0x4b, 0xad, 0x28, 0x48, 0x4d, 0x2e, 0x49, 0x4d, 0x51, 0xc8, - 0x2f, 0x2d, 0x29, 0x28, 0x2d, 0x01, 0x00, - ])], -] -const expectedChunkValue = new TextEncoder().encode('expected output'); - async function decompressArrayBuffer(input, format, chunkSize) { const ds = new DecompressionStream(format); const reader = ds.readable.getReader(); diff --git a/testing/web-platform/tests/compression/decompression-uint8array-output.any.js b/testing/web-platform/tests/compression/decompression-uint8array-output.any.js @@ -1,13 +1,9 @@ // META: global=window,worker,shadowrealm +// META: script=resources/decompression-input.js 'use strict'; -const chunkValues = [ - ["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])], - ["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])], -]; - -for (const [format, chunkValue] of chunkValues) { +for (const [format, chunkValue] of compressedBytes) { promise_test(async t => { const ds = new DecompressionStream(format); const reader = ds.readable.getReader(); diff --git a/testing/web-platform/tests/compression/resources/decompression-input.js b/testing/web-platform/tests/compression/resources/decompression-input.js @@ -0,0 +1,14 @@ +const deflateChunkValue = 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]); +const gzipChunkValue = 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]); +const deflateRawChunkValue = new Uint8Array([ + 0x4b, 0xad, 0x28, 0x48, 0x4d, 0x2e, 0x49, 0x4d, 0x51, 0xc8, + 0x2f, 0x2d, 0x29, 0x28, 0x2d, 0x01, 0x00, +]); + +const compressedBytes = [ + ["deflate", deflateChunkValue], + ["gzip", gzipChunkValue], + ["deflate-raw", deflateRawChunkValue], +]; + +const expectedChunkValue = new TextEncoder().encode('expected output');