tor-browser

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

commit 6f0fc61cf655588ebf495934b6d5d527b9af2ab2
parent ad7fddd733cd01f63f5acd0242d2875ab52aac93
Author: Kagami Sascha Rosylight <krosylight@proton.me>
Date:   Fri, 17 Oct 2025 18:27:55 +0000

Bug 1994999 - Refactor WPT compression tests to reduce duplication per format r=smaug

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

Diffstat:
Mtesting/web-platform/tests/compression/compression-bad-chunks.tentative.any.js | 43+++++++++++++------------------------------
Mtesting/web-platform/tests/compression/compression-output-length.tentative.any.js | 41++++++++++++-----------------------------
Mtesting/web-platform/tests/compression/decompression-bad-chunks.tentative.any.js | 19+++++++------------
Mtesting/web-platform/tests/compression/decompression-buffersource.tentative.any.js | 196++++++++++++++++---------------------------------------------------------------
Mtesting/web-platform/tests/compression/decompression-correct-input.any.js | 32+++++++++++---------------------
Mtesting/web-platform/tests/compression/decompression-empty-input.tentative.any.js | 56++++++++++++++++++--------------------------------------
Mtesting/web-platform/tests/compression/decompression-split-chunk.tentative.any.js | 36+++++++++++++++---------------------
Mtesting/web-platform/tests/compression/decompression-uint8array-output.tentative.any.js | 40+++++++++++++++-------------------------
Atesting/web-platform/tests/compression/resources/formats.js | 5+++++
9 files changed, 134 insertions(+), 334 deletions(-)

diff --git a/testing/web-platform/tests/compression/compression-bad-chunks.tentative.any.js b/testing/web-platform/tests/compression/compression-bad-chunks.tentative.any.js @@ -1,4 +1,5 @@ // META: global=window,worker,shadowrealm +// META: script=resources/formats.js 'use strict'; @@ -41,34 +42,16 @@ const badChunks = [ }, ]; -for (const chunk of badChunks) { - promise_test(async t => { - const cs = new CompressionStream('gzip'); - const reader = cs.readable.getReader(); - const writer = cs.writable.getWriter(); - const writePromise = writer.write(chunk.value); - const readPromise = reader.read(); - await promise_rejects_js(t, TypeError, writePromise, 'write should reject'); - await promise_rejects_js(t, TypeError, readPromise, 'read should reject'); - }, `chunk of type ${chunk.name} should error the stream for gzip`); - - promise_test(async t => { - const cs = new CompressionStream('deflate'); - const reader = cs.readable.getReader(); - const writer = cs.writable.getWriter(); - const writePromise = writer.write(chunk.value); - const readPromise = reader.read(); - await promise_rejects_js(t, TypeError, writePromise, 'write should reject'); - await promise_rejects_js(t, TypeError, readPromise, 'read should reject'); - }, `chunk of type ${chunk.name} should error the stream for deflate`); - - promise_test(async t => { - const cs = new CompressionStream('deflate-raw'); - const reader = cs.readable.getReader(); - const writer = cs.writable.getWriter(); - const writePromise = writer.write(chunk.value); - const readPromise = reader.read(); - await promise_rejects_js(t, TypeError, writePromise, 'write should reject'); - await promise_rejects_js(t, TypeError, readPromise, 'read should reject'); - }, `chunk of type ${chunk.name} should error the stream for deflate-raw`); +for (const format of formats) { + for (const chunk of badChunks) { + promise_test(async t => { + const cs = new CompressionStream(format); + const reader = cs.readable.getReader(); + const writer = cs.writable.getWriter(); + const writePromise = writer.write(chunk.value); + const readPromise = reader.read(); + await promise_rejects_js(t, TypeError, writePromise, 'write should reject'); + await promise_rejects_js(t, TypeError, readPromise, 'read should reject'); + }, `chunk of type ${chunk.name} should error the stream for ${format}`); + } } diff --git a/testing/web-platform/tests/compression/compression-output-length.tentative.any.js b/testing/web-platform/tests/compression/compression-output-length.tentative.any.js @@ -1,4 +1,5 @@ // META: global=window,worker,shadowrealm +// META: script=resources/formats.js 'use strict'; @@ -33,32 +34,14 @@ async function compressArrayBuffer(input, format) { return concatenated; } -promise_test(async () => { - const response = await fetch(LARGE_FILE); - const buffer = await response.arrayBuffer(); - const bufferView = new Uint8Array(buffer); - const originalLength = bufferView.length; - const compressedData = await compressArrayBuffer(bufferView, 'deflate'); - const compressedLength = compressedData.length; - assert_less_than(compressedLength, originalLength, 'output should be smaller'); -}, 'the length of deflated data should be shorter than that of the original data'); - -promise_test(async () => { - const response = await fetch(LARGE_FILE); - const buffer = await response.arrayBuffer(); - const bufferView = new Uint8Array(buffer); - const originalLength = bufferView.length; - const compressedData = await compressArrayBuffer(bufferView, 'gzip'); - const compressedLength = compressedData.length; - assert_less_than(compressedLength, originalLength, 'output should be smaller'); -}, 'the length of gzipped data should be shorter than that of the original data'); - -promise_test(async () => { - const response = await fetch(LARGE_FILE); - const buffer = await response.arrayBuffer(); - const bufferView = new Uint8Array(buffer); - const originalLength = bufferView.length; - const compressedData = await compressArrayBuffer(bufferView, 'deflate-raw'); - const compressedLength = compressedData.length; - assert_less_than(compressedLength, originalLength, 'output should be smaller'); -}, 'the length of deflated (with -raw) data should be shorter than that of the original data'); +for (const format of formats) { + promise_test(async () => { + const response = await fetch(LARGE_FILE); + const buffer = await response.arrayBuffer(); + const bufferView = new Uint8Array(buffer); + const originalLength = bufferView.length; + const compressedData = await compressArrayBuffer(bufferView, format); + const compressedLength = compressedData.length; + assert_less_than(compressedLength, originalLength, 'output should be smaller'); + }, `the length of ${format} data should be shorter than that of the original data`); +} diff --git a/testing/web-platform/tests/compression/decompression-bad-chunks.tentative.any.js b/testing/web-platform/tests/compression/decompression-bad-chunks.tentative.any.js @@ -1,4 +1,5 @@ // META: global=window,worker,shadowrealm +// META: script=resources/formats.js 'use strict'; @@ -70,16 +71,10 @@ async function decompress(chunk, format, t) await promise_rejects_js(t, TypeError, reader.closed, 'read.closed should reject'); } -for (const chunk of badChunks) { - promise_test(async t => { - await decompress(chunk, 'gzip', t); - }, `chunk of type ${chunk.name} should error the stream for gzip`); - - promise_test(async t => { - await decompress(chunk, 'deflate', t); - }, `chunk of type ${chunk.name} should error the stream for deflate`); - - promise_test(async t => { - await decompress(chunk, 'deflate-raw', t); - }, `chunk of type ${chunk.name} should error the stream for deflate-raw`); +for (const format of formats) { + for (const chunk of badChunks) { + promise_test(async t => { + await decompress(chunk, format, t); + }, `chunk of type ${chunk.name} should error the stream for ${format}`); + } } diff --git a/testing/web-platform/tests/compression/decompression-buffersource.tentative.any.js b/testing/web-platform/tests/compression/decompression-buffersource.tentative.any.js @@ -2,203 +2,83 @@ 'use strict'; -const compressedBytesWithDeflate = [120, 156, 75, 52, 48, 52, 50, 54, 49, 53, 3, 0, 8, 136, 1, 199]; -const compressedBytesWithGzip = [31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 75, 52, 48, 52, 2, 0, 216, 252, 63, 136, 4, 0, 0, 0]; -const compressedBytesWithDeflateRaw = [ - 0x00, 0x06, 0x00, 0xf9, 0xff, 0x41, 0x42, 0x43, - 0x44, 0x45, 0x46, 0x01, 0x00, 0x00, 0xff, 0xff, +const compressedBytes = [ + ["deflate", [120, 156, 75, 52, 48, 52, 50, 54, 49, 53, 3, 0, 8, 136, 1, 199]], + ["gzip", [31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 75, 52, 48, 52, 2, 0, 216, 252, 63, 136, 4, 0, 0, 0]], + ["deflate-raw", [ + 0x00, 0x06, 0x00, 0xf9, 0xff, 0x41, 0x42, 0x43, + 0x44, 0x45, 0x46, 0x01, 0x00, 0x00, 0xff, 0xff, + ]], ]; // These chunk values below were chosen to make the length of the compressed // output be a multiple of 8 bytes. -const deflateExpectedChunkValue = new TextEncoder().encode('a0123456'); -const gzipExpectedChunkValue = new TextEncoder().encode('a012'); -const deflateRawExpectedChunkValue = new TextEncoder().encode('ABCDEF'); +const expectedChunkValue = new Map(Object.entries({ + "deflate": new TextEncoder().encode('a0123456'), + "gzip": new TextEncoder().encode('a012'), + "deflate-raw": new TextEncoder().encode('ABCDEF'), +})); -const bufferSourceChunksForDeflate = [ +const bufferSourceChunks = compressedBytes.map(([format, bytes]) => [format, [ { name: 'ArrayBuffer', - value: new Uint8Array(compressedBytesWithDeflate).buffer + value: new Uint8Array(bytes).buffer }, { name: 'Int8Array', - value: new Int8Array(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new Int8Array(new Uint8Array(bytes).buffer) }, { name: 'Uint8Array', - value: new Uint8Array(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new Uint8Array(new Uint8Array(bytes).buffer) }, { name: 'Uint8ClampedArray', - value: new Uint8ClampedArray(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new Uint8ClampedArray(new Uint8Array(bytes).buffer) }, { name: 'Int16Array', - value: new Int16Array(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new Int16Array(new Uint8Array(bytes).buffer) }, { name: 'Uint16Array', - value: new Uint16Array(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new Uint16Array(new Uint8Array(bytes).buffer) }, { name: 'Int32Array', - value: new Int32Array(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new Int32Array(new Uint8Array(bytes).buffer) }, { name: 'Uint32Array', - value: new Uint32Array(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new Uint32Array(new Uint8Array(bytes).buffer) }, { name: 'Float16Array', - value: () => new Float16Array(new Uint8Array(compressedBytesWithDeflate).buffer) + value: () => new Float16Array(new Uint8Array(bytes).buffer) }, { name: 'Float32Array', - value: new Float32Array(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new Float32Array(new Uint8Array(bytes).buffer) }, { name: 'Float64Array', - value: new Float64Array(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new Float64Array(new Uint8Array(bytes).buffer) }, { name: 'DataView', - value: new DataView(new Uint8Array(compressedBytesWithDeflate).buffer) + value: new DataView(new Uint8Array(bytes).buffer) }, -]; - -const bufferSourceChunksForGzip = [ - { - name: 'ArrayBuffer', - value: new Uint8Array(compressedBytesWithGzip).buffer - }, - { - name: 'Int8Array', - value: new Int8Array(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'Uint8Array', - value: new Uint8Array(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'Uint8ClambedArray', - value: new Uint8ClampedArray(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'Int16Array', - value: new Int16Array(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'Uint16Array', - value: new Uint16Array(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'Int32Array', - value: new Int32Array(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'Uint32Array', - value: new Uint32Array(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'Float16Array', - value: () => new Float16Array(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'Float32Array', - value: new Float32Array(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'Float64Array', - value: new Float64Array(new Uint8Array(compressedBytesWithGzip).buffer) - }, - { - name: 'DataView', - value: new DataView(new Uint8Array(compressedBytesWithGzip).buffer) - }, -]; - -const bufferSourceChunksForDeflateRaw = [ - { - name: 'ArrayBuffer', - value: new Uint8Array(compressedBytesWithDeflateRaw).buffer - }, - { - name: 'Int8Array', - value: new Int8Array(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'Uint8Array', - value: new Uint8Array(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'Uint8ClampedArray', - value: new Uint8ClampedArray(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'Int16Array', - value: new Int16Array(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'Uint16Array', - value: new Uint16Array(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'Int32Array', - value: new Int32Array(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'Uint32Array', - value: new Uint32Array(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'Float16Array', - value: () => new Float16Array(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'Float32Array', - value: new Float32Array(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'Float64Array', - value: new Float64Array(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, - { - name: 'DataView', - value: new DataView(new Uint8Array(compressedBytesWithDeflateRaw).buffer) - }, -]; - -for (const chunk of bufferSourceChunksForDeflate) { - promise_test(async t => { - const ds = new DecompressionStream('deflate'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(typeof chunk.value === 'function' ? chunk.value() : chunk.value); - writer.close(); - const { value } = await reader.read(); - assert_array_equals(Array.from(value), deflateExpectedChunkValue, 'value should match'); - }, `chunk of type ${chunk.name} should work for deflate`); -} - -for (const chunk of bufferSourceChunksForGzip) { - promise_test(async t => { - const ds = new DecompressionStream('gzip'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(typeof chunk.value === 'function' ? chunk.value() : chunk.value); - writer.close(); - const { value } = await reader.read(); - assert_array_equals(Array.from(value), gzipExpectedChunkValue, 'value should match'); - }, `chunk of type ${chunk.name} should work for gzip`); -} +]]); -for (const chunk of bufferSourceChunksForDeflateRaw) { - promise_test(async t => { - const ds = new DecompressionStream('deflate-raw'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(typeof chunk.value === 'function' ? chunk.value() : chunk.value); - writer.close(); - const { value } = await reader.read(); - assert_array_equals(Array.from(value), deflateRawExpectedChunkValue, 'value should match'); - }, `chunk of type ${chunk.name} should work for deflate-raw`); +for (const [format, chunks] of bufferSourceChunks) { + for (const chunk of chunks) { + promise_test(async t => { + const ds = new DecompressionStream(format); + const reader = ds.readable.getReader(); + const writer = ds.writable.getWriter(); + const writePromise = writer.write(typeof chunk.value === 'function' ? chunk.value() : chunk.value); + writer.close(); + const { value } = await reader.read(); + assert_array_equals(Array.from(value), expectedChunkValue.get(format), 'value should match'); + }, `chunk of type ${chunk.name} should work for ${format}`); + } } diff --git a/testing/web-platform/tests/compression/decompression-correct-input.any.js b/testing/web-platform/tests/compression/decompression-correct-input.any.js @@ -3,29 +3,19 @@ 'use strict'; -promise_test(async t => { - const ds = new DecompressionStream('deflate'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(deflateChunkValue); - const { done, value } = await reader.read(); - assert_array_equals(Array.from(value), trueChunkValue, "value should match"); -}, 'decompressing deflated input should work'); - -promise_test(async t => { - const ds = new DecompressionStream('gzip'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(gzipChunkValue); - const { done, value } = await reader.read(); - assert_array_equals(Array.from(value), trueChunkValue, "value should match"); -}, 'decompressing gzip input should work'); +const tests = [ + ["deflate", deflateChunkValue], + ["gzip", gzipChunkValue], + ["deflate-raw", deflateRawChunkValue], +]; -promise_test(async t => { - const ds = new DecompressionStream('deflate-raw'); +for (const [format, chunk] of tests) { + promise_test(async t => { + const ds = new DecompressionStream(format); const reader = ds.readable.getReader(); const writer = ds.writable.getWriter(); - const writePromise = writer.write(deflateRawChunkValue); + const writePromise = writer.write(chunk); const { done, value } = await reader.read(); assert_array_equals(Array.from(value), trueChunkValue, "value should match"); -}, 'decompressing deflated (with -raw) input should work'); + }, `decompressing ${format} input should work`); +} diff --git a/testing/web-platform/tests/compression/decompression-empty-input.tentative.any.js b/testing/web-platform/tests/compression/decompression-empty-input.tentative.any.js @@ -2,42 +2,22 @@ 'use strict'; -const gzipEmptyValue = new Uint8Array([31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0]); -const deflateEmptyValue = new Uint8Array([120, 156, 3, 0, 0, 0, 0, 1]); -const deflateRawEmptyValue = new Uint8Array([1, 0, 0, 255, 255]); +const emptyValues = [ + ["gzip", new Uint8Array([31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0])], + ["deflate", new Uint8Array([120, 156, 3, 0, 0, 0, 0, 1])], + ["deflate-raw", new Uint8Array([1, 0, 0, 255, 255])], +]; -promise_test(async t => { - const ds = new DecompressionStream('gzip'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(gzipEmptyValue); - writer.close(); - const { value, done } = await reader.read(); - assert_true(done, "read() should set done"); - assert_equals(value, undefined, "value should be undefined"); - await writePromise; -}, 'decompressing gzip empty input should work'); - -promise_test(async t => { - const ds = new DecompressionStream('deflate'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(deflateEmptyValue); - writer.close(); - const { value, done } = await reader.read(); - assert_true(done, "read() should set done"); - assert_equals(value, undefined, "value should be undefined"); - await writePromise; -}, 'decompressing deflate empty input should work'); - -promise_test(async t => { - const ds = new DecompressionStream('deflate-raw'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(deflateRawEmptyValue); - writer.close(); - const { value, done } = await reader.read(); - assert_true(done, "read() should set done"); - assert_equals(value, undefined, "value should be undefined"); - await writePromise; -}, 'decompressing deflate-raw empty input should work'); +for (const [format, emptyValue] of emptyValues) { + promise_test(async t => { + const ds = new DecompressionStream(format); + const reader = ds.readable.getReader(); + const writer = ds.writable.getWriter(); + const writePromise = writer.write(emptyValue); + writer.close(); + const { value, done } = await reader.read(); + assert_true(done, "read() should set done"); + assert_equals(value, undefined, "value should be undefined"); + await writePromise; + }, `decompressing ${format} empty input should work`); +} diff --git a/testing/web-platform/tests/compression/decompression-split-chunk.tentative.any.js b/testing/web-platform/tests/compression/decompression-split-chunk.tentative.any.js @@ -2,12 +2,14 @@ 'use strict'; -const compressedBytesWithDeflate = 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 compressedBytesWithGzip = 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 compressedBytesWithDeflateRaw = new Uint8Array([ - 0x4b, 0xad, 0x28, 0x48, 0x4d, 0x2e, 0x49, 0x4d, 0x51, 0xc8, - 0x2f, 0x2d, 0x29, 0x28, 0x2d, 0x01, 0x00, -]); +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) { @@ -35,19 +37,11 @@ async function decompressArrayBuffer(input, format, chunkSize) { return concatenated; } -for (let chunkSize = 1; chunkSize < 16; ++chunkSize) { - promise_test(async t => { - const decompressedData = await decompressArrayBuffer(compressedBytesWithDeflate, 'deflate', chunkSize); - assert_array_equals(decompressedData, expectedChunkValue, "value should match"); - }, `decompressing splitted chunk into pieces of size ${chunkSize} should work in deflate`); - - promise_test(async t => { - const decompressedData = await decompressArrayBuffer(compressedBytesWithGzip, 'gzip', chunkSize); - assert_array_equals(decompressedData, expectedChunkValue, "value should match"); - }, `decompressing splitted chunk into pieces of size ${chunkSize} should work in gzip`); - - promise_test(async t => { - const decompressedData = await decompressArrayBuffer(compressedBytesWithDeflateRaw, 'deflate-raw', chunkSize); - assert_array_equals(decompressedData, expectedChunkValue, "value should match"); - }, `decompressing splitted chunk into pieces of size ${chunkSize} should work in deflate-raw`); +for (const [format, bytes] of compressedBytes) { + for (let chunkSize = 1; chunkSize < 16; ++chunkSize) { + promise_test(async t => { + const decompressedData = await decompressArrayBuffer(bytes, format, chunkSize); + assert_array_equals(decompressedData, expectedChunkValue, "value should match"); + }, `decompressing splitted chunk into pieces of size ${chunkSize} should work in ${format}`); + } } diff --git a/testing/web-platform/tests/compression/decompression-uint8array-output.tentative.any.js b/testing/web-platform/tests/compression/decompression-uint8array-output.tentative.any.js @@ -1,30 +1,20 @@ // META: global=window,worker,shadowrealm -// META: timeout=long -// -// This test isn't actually slow usually, but sometimes it takes >10 seconds on -// Firefox with service worker for no obvious reason. 'use strict'; -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 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])], +]; -promise_test(async t => { - const ds = new DecompressionStream('deflate'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(deflateChunkValue); - const { value } = await reader.read(); - assert_equals(value.constructor, Uint8Array, "type should match"); - await writePromise; -}, 'decompressing deflated output should give Uint8Array chunks'); - -promise_test(async t => { - const ds = new DecompressionStream('gzip'); - const reader = ds.readable.getReader(); - const writer = ds.writable.getWriter(); - const writePromise = writer.write(gzipChunkValue); - const { value } = await reader.read(); - assert_equals(value.constructor, Uint8Array, "type should match"); - await writePromise; -}, 'decompressing gzip output should give Uint8Array chunks'); +for (const [format, chunkValue] of chunkValues) { + promise_test(async t => { + const ds = new DecompressionStream(format); + const reader = ds.readable.getReader(); + const writer = ds.writable.getWriter(); + const writePromise = writer.write(chunkValue); + const { value } = await reader.read(); + assert_equals(value.constructor, Uint8Array, "type should match"); + await writePromise; + }, `decompressing ${format} output should give Uint8Array chunks`); +} diff --git a/testing/web-platform/tests/compression/resources/formats.js b/testing/web-platform/tests/compression/resources/formats.js @@ -0,0 +1,5 @@ +const formats = [ + "deflate", + "deflate-raw", + "gzip", +]