Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Compression Streams
https://bugs.webkit.org/show_bug.cgi?id=242665

Reviewed by Brent Fulgham.

This patch implements the Compression Streams API.
Currently we are passing all WPT test cases (except for an initialization one where
we are throwing a typeError instead of a standard Error).

This implementation uses the compression and decompression functions from the Zlib library.

For compression I attempt to perform the compression in one shot by allocating enough memory up front per chunk.
For decompression I am using a scaling allocation approach. We first allocate 1 page (16KB) of memory, then two, then 4 and so on...
I added a hard limit of 1GB per allocation to make sure I don't blow away all the device's memory.
For every chunk, I take all these allocations and merge them into one array.

* LayoutTests/imported/w3c/web-platform-tests/compression/META.yml: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any.js: Added.
(get value):
(const.chunk.of.badChunks.promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-bad-chunks.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any.js: Added.
(async compressChunkList):
(const.chunkList.of.chunkLists.promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-including-empty-chunk.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any.js: Added.
(makeExpectedChunk):
(async compressMultipleChunks):
(numberOfChunks.promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-multiple-chunks.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any.js: Added.
(async compressArrayBuffer):
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-output-length.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-stream.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-stream.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-stream.tentative.any.js: Added.
(async compressArrayBuffer):
(test):
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-stream.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-stream.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-stream.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-stream.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-stream.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-stream.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-with-detach.tentative.window-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-with-detach.tentative.window.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/compression-with-detach.tentative.window.js: Added.
(createLargeRandomInput):
(decompress):
(promise_test.async const):
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-bad-chunks.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-bad-chunks.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-bad-chunks.tentative.any.js: Added.
(get value):
(return.new.Uint8Array):
(value.new.Uint8Array):
(const.chunk.of.badChunks.promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-bad-chunks.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-bad-chunks.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-bad-chunks.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-bad-chunks.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-bad-chunks.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-bad-chunks.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-buffersource.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-buffersource.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-buffersource.tentative.any.js: Added.
(value.new.Int8Array.new.Uint8Array):
(value.new.Uint8Array):
(value.new.Uint8ClampedArray):
(value.new.Int16Array):
(value.new.Uint16Array):
(value.new.Int32Array):
(value.new.Uint32Array):
(value.new.Float32Array):
(value.new.Float64Array):
(const.chunk.of.bufferSourceChunksForDeflate.promise_test.async t):
(const.chunk.of.bufferSourceChunksForGzip.promise_test.async t):
(const.chunk.of.bufferSourceChunksForDeflateRaw.promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-buffersource.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-buffersource.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-buffersource.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-buffersource.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-buffersource.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-buffersource.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.js: Added.
(test.t.new.DecompressionStream.toString):
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-constructor-error.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-correct-input.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-correct-input.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-correct-input.tentative.any.js: Added.
(promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-correct-input.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-correct-input.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-correct-input.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-correct-input.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-correct-input.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-correct-input.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-corrupt-input.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-corrupt-input.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-corrupt-input.tentative.any.js: Added.
(async tryDecompress):
(corruptInput):
(of.expectations.promise_test.async const):
(of.expectations.promise_test):
(of.expectations.of.fields.of.cases.promise_test.async const):
(of.expectations.of.fields.of.cases.promise_test):
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-corrupt-input.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-corrupt-input.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-empty-input.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-empty-input.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-empty-input.tentative.any.js: Added.
(promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-empty-input.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-empty-input.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-empty-input.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-empty-input.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-empty-input.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-empty-input.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-split-chunk.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-split-chunk.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-split-chunk.tentative.any.js: Added.
(async decompressArrayBuffer):
(chunkSize.promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-split-chunk.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-split-chunk.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-split-chunk.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-split-chunk.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-split-chunk.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-split-chunk.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-uint8array-output.tentative.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-uint8array-output.tentative.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-uint8array-output.tentative.any.js: Added.
(promise_test.async t):
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-uint8array-output.tentative.any.serviceworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-uint8array-output.tentative.any.serviceworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-uint8array-output.tentative.any.sharedworker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-uint8array-output.tentative.any.sharedworker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-uint8array-output.tentative.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-uint8array-output.tentative.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-with-detach.tentative.window-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-with-detach.tentative.window.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/decompression-with-detach.tentative.window.js: Added.
(async createLargeCompressedInput):
(promise_test.async const):
* LayoutTests/imported/w3c/web-platform-tests/compression/idlharness-shadowrealm.window-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/idlharness-shadowrealm.window.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/idlharness-shadowrealm.window.js: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/idlharness.https.any-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/idlharness.https.any.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/idlharness.https.any.js: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/idlharness.https.any.worker-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/idlharness.https.any.worker.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/resources/concatenate-stream.js: Added.
(async concatenateStream):
* LayoutTests/imported/w3c/web-platform-tests/compression/resources/w3c-import.log: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/third_party/pako/LICENSE: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/third_party/pako/README: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/third_party/pako/pako_inflate.min.js: Added.
(l):
(return.r):
(i.assign):
(i.shrinkBuf):
(a.arraySet):
(a.flattenChunks):
(r.arraySet):
(r.flattenChunks):
(i.setTyped):
(1):
(d):
(i.string2buf):
(i.buf2binstring):
(i.binstring2buf):
(i.buf2string):
(i.utf8border):
(2):
(t.exports):
(3):
(4):
(s):
(5):
(6):
(7):
(L):
(r):
(o):
(f):
(H):
(j):
(i.inflateInit):
(i.inflate):
(i.inflateEnd):
(i.inflateGetHeader):
(i.inflateSetDictionary):
(8):
(9):
(10):
(11):
(o.prototype.push):
(o.prototype.onData):
(o.prototype.onEnd):
(i.inflateRaw):
(string_appeared_here):
* LayoutTests/imported/w3c/web-platform-tests/compression/third_party/pako/w3c-import.log: Added.
* LayoutTests/imported/w3c/web-platform-tests/compression/w3c-import.log: Added.
* Source/WebCore/Modules/compression/CompressionStream.js:
(initializeCompressionStream):
* Source/WebCore/Modules/compression/CompressionStreamEncoder.cpp:
(WebCore::CompressionStreamEncoder::encode):
(WebCore::CompressionStreamEncoder::flush):
(WebCore::CompressionStreamEncoder::initialize):
(WebCore::CompressionStreamEncoder::compress):
* Source/WebCore/Modules/compression/CompressionStreamEncoder.h:
(WebCore::CompressionStreamEncoder::~CompressionStreamEncoder):
(WebCore::CompressionStreamEncoder::CompressionStreamEncoder):
* Source/WebCore/Modules/compression/DecompressionStream.js:
(initializeDecompressionStream):
* Source/WebCore/Modules/compression/DecompressionStreamDecoder.cpp:
(WebCore::DecompressionStreamDecoder::decode):
(WebCore::DecompressionStreamDecoder::flush):
(WebCore::DecompressionStreamDecoder::initialize):
(WebCore::DecompressionStreamDecoder::decompress):
* Source/WebCore/Modules/compression/DecompressionStreamDecoder.h:
(WebCore::DecompressionStreamDecoder::~DecompressionStreamDecoder):
(WebCore::DecompressionStreamDecoder::DecompressionStreamDecoder):
* Source/WebCore/Modules/compression/Formats.h:

Canonical link: https://commits.webkit.org/253093@main
  • Loading branch information
stwrt committed Aug 4, 2022
1 parent 62782a8 commit f044be8
Show file tree
Hide file tree
Showing 144 changed files with 2,755 additions and 52 deletions.
@@ -0,0 +1,3 @@
spec: https://wicg.github.io/compression/
suggested_reviewers:
- ricea
@@ -0,0 +1,23 @@

PASS chunk of type undefined should error the stream for gzip
PASS chunk of type undefined should error the stream for deflate
PASS chunk of type undefined should error the stream for deflate-raw
PASS chunk of type null should error the stream for gzip
PASS chunk of type null should error the stream for deflate
PASS chunk of type null should error the stream for deflate-raw
PASS chunk of type numeric should error the stream for gzip
PASS chunk of type numeric should error the stream for deflate
PASS chunk of type numeric should error the stream for deflate-raw
PASS chunk of type object, not BufferSource should error the stream for gzip
PASS chunk of type object, not BufferSource should error the stream for deflate
PASS chunk of type object, not BufferSource should error the stream for deflate-raw
PASS chunk of type array should error the stream for gzip
PASS chunk of type array should error the stream for deflate
PASS chunk of type array should error the stream for deflate-raw
PASS chunk of type SharedArrayBuffer should error the stream for gzip
PASS chunk of type SharedArrayBuffer should error the stream for deflate
PASS chunk of type SharedArrayBuffer should error the stream for deflate-raw
PASS chunk of type shared Uint8Array should error the stream for gzip
PASS chunk of type shared Uint8Array should error the stream for deflate
PASS chunk of type shared Uint8Array should error the stream for deflate-raw

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,74 @@
// META: global=window,worker

'use strict';

const badChunks = [
{
name: 'undefined',
value: undefined
},
{
name: 'null',
value: null
},
{
name: 'numeric',
value: 3.14
},
{
name: 'object, not BufferSource',
value: {}
},
{
name: 'array',
value: [65]
},
{
name: 'SharedArrayBuffer',
// Use a getter to postpone construction so that all tests don't fail where
// SharedArrayBuffer is not yet implemented.
get value() {
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
return new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
}
},
{
name: 'shared Uint8Array',
get value() {
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
return new Uint8Array(new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer)
}
},
];

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`);
}
@@ -0,0 +1,23 @@

PASS chunk of type undefined should error the stream for gzip
PASS chunk of type undefined should error the stream for deflate
PASS chunk of type undefined should error the stream for deflate-raw
PASS chunk of type null should error the stream for gzip
PASS chunk of type null should error the stream for deflate
PASS chunk of type null should error the stream for deflate-raw
PASS chunk of type numeric should error the stream for gzip
PASS chunk of type numeric should error the stream for deflate
PASS chunk of type numeric should error the stream for deflate-raw
PASS chunk of type object, not BufferSource should error the stream for gzip
PASS chunk of type object, not BufferSource should error the stream for deflate
PASS chunk of type object, not BufferSource should error the stream for deflate-raw
PASS chunk of type array should error the stream for gzip
PASS chunk of type array should error the stream for deflate
PASS chunk of type array should error the stream for deflate-raw
PASS chunk of type SharedArrayBuffer should error the stream for gzip
PASS chunk of type SharedArrayBuffer should error the stream for deflate
PASS chunk of type SharedArrayBuffer should error the stream for deflate-raw
PASS chunk of type shared Uint8Array should error the stream for gzip
PASS chunk of type shared Uint8Array should error the stream for deflate
PASS chunk of type shared Uint8Array should error the stream for deflate-raw

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,23 @@

PASS chunk of type undefined should error the stream for gzip
PASS chunk of type undefined should error the stream for deflate
PASS chunk of type undefined should error the stream for deflate-raw
PASS chunk of type null should error the stream for gzip
PASS chunk of type null should error the stream for deflate
PASS chunk of type null should error the stream for deflate-raw
PASS chunk of type numeric should error the stream for gzip
PASS chunk of type numeric should error the stream for deflate
PASS chunk of type numeric should error the stream for deflate-raw
PASS chunk of type object, not BufferSource should error the stream for gzip
PASS chunk of type object, not BufferSource should error the stream for deflate
PASS chunk of type object, not BufferSource should error the stream for deflate-raw
PASS chunk of type array should error the stream for gzip
PASS chunk of type array should error the stream for deflate
PASS chunk of type array should error the stream for deflate-raw
PASS chunk of type SharedArrayBuffer should error the stream for gzip
PASS chunk of type SharedArrayBuffer should error the stream for deflate
PASS chunk of type SharedArrayBuffer should error the stream for deflate-raw
PASS chunk of type shared Uint8Array should error the stream for gzip
PASS chunk of type shared Uint8Array should error the stream for deflate
PASS chunk of type shared Uint8Array should error the stream for deflate-raw

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,23 @@

PASS chunk of type undefined should error the stream for gzip
PASS chunk of type undefined should error the stream for deflate
PASS chunk of type undefined should error the stream for deflate-raw
PASS chunk of type null should error the stream for gzip
PASS chunk of type null should error the stream for deflate
PASS chunk of type null should error the stream for deflate-raw
PASS chunk of type numeric should error the stream for gzip
PASS chunk of type numeric should error the stream for deflate
PASS chunk of type numeric should error the stream for deflate-raw
PASS chunk of type object, not BufferSource should error the stream for gzip
PASS chunk of type object, not BufferSource should error the stream for deflate
PASS chunk of type object, not BufferSource should error the stream for deflate-raw
PASS chunk of type array should error the stream for gzip
PASS chunk of type array should error the stream for deflate
PASS chunk of type array should error the stream for deflate-raw
PASS chunk of type SharedArrayBuffer should error the stream for gzip
PASS chunk of type SharedArrayBuffer should error the stream for deflate
PASS chunk of type SharedArrayBuffer should error the stream for deflate-raw
PASS chunk of type shared Uint8Array should error the stream for gzip
PASS chunk of type shared Uint8Array should error the stream for deflate
PASS chunk of type shared Uint8Array should error the stream for deflate-raw

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,11 @@

PASS the result of compressing [,Hello,Hello] with deflate should be 'HelloHello'
PASS the result of compressing [,Hello,Hello] with gzip should be 'HelloHello'
PASS the result of compressing [,Hello,Hello] with deflate-raw should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with deflate should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with gzip should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with deflate-raw should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with deflate should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with gzip should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with deflate-raw should be 'HelloHello'

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,63 @@
// META: global=window,worker
// META: script=third_party/pako/pako_inflate.min.js
// META: timeout=long

'use strict';

// This test asserts that compressing '' doesn't affect the compressed data.
// Example: compressing ['Hello', '', 'Hello'] results in 'HelloHello'

async function compressChunkList(chunkList, format) {
const cs = new CompressionStream(format);
const writer = cs.writable.getWriter();
for (const chunk of chunkList) {
const chunkByte = new TextEncoder().encode(chunk);
writer.write(chunkByte);
}
const closePromise = writer.close();
const out = [];
const reader = cs.readable.getReader();
let totalSize = 0;
while (true) {
const { value, done } = await reader.read();
if (done)
break;
out.push(value);
totalSize += value.byteLength;
}
await closePromise;
const concatenated = new Uint8Array(totalSize);
let offset = 0;
for (const array of out) {
concatenated.set(array, offset);
offset += array.byteLength;
}
return concatenated;
}

const chunkLists = [
['', 'Hello', 'Hello'],
['Hello', '', 'Hello'],
['Hello', 'Hello', '']
];
const expectedValue = new TextEncoder().encode('HelloHello');

for (const chunkList of chunkLists) {
promise_test(async t => {
const compressedData = await compressChunkList(chunkList, 'deflate');
// decompress with pako, and check that we got the same result as our original string
assert_array_equals(expectedValue, pako.inflate(compressedData), 'value should match');
}, `the result of compressing [${chunkList}] with deflate should be 'HelloHello'`);

promise_test(async t => {
const compressedData = await compressChunkList(chunkList, 'gzip');
// decompress with pako, and check that we got the same result as our original string
assert_array_equals(expectedValue, pako.inflate(compressedData), 'value should match');
}, `the result of compressing [${chunkList}] with gzip should be 'HelloHello'`);

promise_test(async t => {
const compressedData = await compressChunkList(chunkList, 'deflate-raw');
// decompress with pako, and check that we got the same result as our original string
assert_array_equals(expectedValue, pako.inflateRaw(compressedData), 'value should match');
}, `the result of compressing [${chunkList}] with deflate-raw should be 'HelloHello'`);
}
@@ -0,0 +1,11 @@

PASS the result of compressing [,Hello,Hello] with deflate should be 'HelloHello'
PASS the result of compressing [,Hello,Hello] with gzip should be 'HelloHello'
PASS the result of compressing [,Hello,Hello] with deflate-raw should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with deflate should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with gzip should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with deflate-raw should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with deflate should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with gzip should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with deflate-raw should be 'HelloHello'

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,11 @@

PASS the result of compressing [,Hello,Hello] with deflate should be 'HelloHello'
PASS the result of compressing [,Hello,Hello] with gzip should be 'HelloHello'
PASS the result of compressing [,Hello,Hello] with deflate-raw should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with deflate should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with gzip should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with deflate-raw should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with deflate should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with gzip should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with deflate-raw should be 'HelloHello'

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,11 @@

PASS the result of compressing [,Hello,Hello] with deflate should be 'HelloHello'
PASS the result of compressing [,Hello,Hello] with gzip should be 'HelloHello'
PASS the result of compressing [,Hello,Hello] with deflate-raw should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with deflate should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with gzip should be 'HelloHello'
PASS the result of compressing [Hello,,Hello] with deflate-raw should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with deflate should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with gzip should be 'HelloHello'
PASS the result of compressing [Hello,Hello,] with deflate-raw should be 'HelloHello'

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,47 @@

PASS compressing 2 chunks with deflate should work
PASS compressing 2 chunks with gzip should work
PASS compressing 2 chunks with deflate-raw should work
PASS compressing 3 chunks with deflate should work
PASS compressing 3 chunks with gzip should work
PASS compressing 3 chunks with deflate-raw should work
PASS compressing 4 chunks with deflate should work
PASS compressing 4 chunks with gzip should work
PASS compressing 4 chunks with deflate-raw should work
PASS compressing 5 chunks with deflate should work
PASS compressing 5 chunks with gzip should work
PASS compressing 5 chunks with deflate-raw should work
PASS compressing 6 chunks with deflate should work
PASS compressing 6 chunks with gzip should work
PASS compressing 6 chunks with deflate-raw should work
PASS compressing 7 chunks with deflate should work
PASS compressing 7 chunks with gzip should work
PASS compressing 7 chunks with deflate-raw should work
PASS compressing 8 chunks with deflate should work
PASS compressing 8 chunks with gzip should work
PASS compressing 8 chunks with deflate-raw should work
PASS compressing 9 chunks with deflate should work
PASS compressing 9 chunks with gzip should work
PASS compressing 9 chunks with deflate-raw should work
PASS compressing 10 chunks with deflate should work
PASS compressing 10 chunks with gzip should work
PASS compressing 10 chunks with deflate-raw should work
PASS compressing 11 chunks with deflate should work
PASS compressing 11 chunks with gzip should work
PASS compressing 11 chunks with deflate-raw should work
PASS compressing 12 chunks with deflate should work
PASS compressing 12 chunks with gzip should work
PASS compressing 12 chunks with deflate-raw should work
PASS compressing 13 chunks with deflate should work
PASS compressing 13 chunks with gzip should work
PASS compressing 13 chunks with deflate-raw should work
PASS compressing 14 chunks with deflate should work
PASS compressing 14 chunks with gzip should work
PASS compressing 14 chunks with deflate-raw should work
PASS compressing 15 chunks with deflate should work
PASS compressing 15 chunks with gzip should work
PASS compressing 15 chunks with deflate-raw should work
PASS compressing 16 chunks with deflate should work
PASS compressing 16 chunks with gzip should work
PASS compressing 16 chunks with deflate-raw should work

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->

0 comments on commit f044be8

Please sign in to comment.