mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
test: update WPT compression to ae05f5cb53
PR-URL: https://github.com/nodejs/node/pull/62107 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mattias Buelens <mattias@buelens.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
This commit is contained in:
1 parent
19efe60548
commit
cfc847d233
33 files changed
+525
-727
No files matched your search
Vendored
+1
-1
@@ -11,7 +11,7 @@ See [test/wpt](../../wpt/README.md) for information on how these tests are run.
|
||||
Last update:
|
||||
|
||||
- common: https://github.com/web-platform-tests/wpt/tree/dbd648158d/common
|
||||
- compression: https://github.com/web-platform-tests/wpt/tree/67880a4eb8/compression
|
||||
- compression: https://github.com/web-platform-tests/wpt/tree/ae05f5cb53/compression
|
||||
- console: https://github.com/web-platform-tests/wpt/tree/e48251b778/console
|
||||
- dom/abort: https://github.com/web-platform-tests/wpt/tree/dc928169ee/dom/abort
|
||||
- dom/events: https://github.com/web-platform-tests/wpt/tree/0a811c5161/dom/events
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=resources/formats.js
|
||||
|
||||
'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 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}`);
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
|
||||
'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`);
|
||||
}
|
||||
File renamed without changes.
+11
-18
@@ -1,5 +1,7 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=third_party/pako/pako_inflate.min.js
|
||||
// META: script=resources/decompress.js
|
||||
// META: script=resources/formats.js
|
||||
// META: timeout=long
|
||||
|
||||
'use strict';
|
||||
@@ -42,22 +44,13 @@ const chunkLists = [
|
||||
];
|
||||
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'`);
|
||||
for (const format of formats) {
|
||||
for (const chunkList of chunkLists) {
|
||||
promise_test(async t => {
|
||||
const compressedData = await compressChunkList(chunkList, format);
|
||||
const decompressedData = await decompressDataOrPako(compressedData, format);
|
||||
// check that we got the same result as our original string
|
||||
assert_array_equals(expectedValue, decompressedData, 'value should match');
|
||||
}, `the result of compressing [${chunkList}] with ${format} should be 'HelloHello'`);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=third_party/pako/pako_inflate.min.js
|
||||
// META: script=resources/concatenate-stream.js
|
||||
// META: script=resources/decompress.js
|
||||
// META: script=resources/formats.js
|
||||
// META: timeout=long
|
||||
|
||||
'use strict';
|
||||
@@ -21,21 +23,11 @@ const fullData = new TextEncoder().encode(JSON.stringify(Array.from({ length: 10
|
||||
const data = fullData.subarray(0, 35_579);
|
||||
const expectedValue = data;
|
||||
|
||||
promise_test(async t => {
|
||||
const compressedData = await compressData(data, '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');
|
||||
}, `deflate compression with large flush output`);
|
||||
|
||||
promise_test(async t => {
|
||||
const compressedData = await compressData(data, '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');
|
||||
}, `gzip compression with large flush output`);
|
||||
|
||||
promise_test(async t => {
|
||||
const compressedData = await compressData(data, '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');
|
||||
}, `deflate-raw compression with large flush output`);
|
||||
|
||||
for (const format of formats) {
|
||||
promise_test(async t => {
|
||||
const compressedData = await compressData(data, format);
|
||||
const decompressedData = await decompressDataOrPako(compressedData, format);
|
||||
// check that we got the same result as our original string
|
||||
assert_array_equals(decompressedData, expectedValue, 'value should match');
|
||||
}, `${format} compression with large flush output`);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=third_party/pako/pako_inflate.min.js
|
||||
// META: script=resources/decompress.js
|
||||
// META: script=resources/formats.js
|
||||
// META: timeout=long
|
||||
|
||||
'use strict';
|
||||
|
||||
// This test asserts that compressing multiple chunks should work.
|
||||
|
||||
// Example: ('Hello', 3) => TextEncoder().encode('HelloHelloHello')
|
||||
function makeExpectedChunk(input, numberOfChunks) {
|
||||
const expectedChunk = input.repeat(numberOfChunks);
|
||||
return new TextEncoder().encode(expectedChunk);
|
||||
}
|
||||
|
||||
// Example: ('Hello', 3, 'deflate') => compress ['Hello', 'Hello', Hello']
|
||||
async function compressMultipleChunks(input, numberOfChunks, format) {
|
||||
const cs = new CompressionStream(format);
|
||||
const writer = cs.writable.getWriter();
|
||||
const chunk = new TextEncoder().encode(input);
|
||||
for (let i = 0; i < numberOfChunks; ++i) {
|
||||
writer.write(chunk);
|
||||
}
|
||||
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 hello = 'Hello';
|
||||
|
||||
for (const format of formats) {
|
||||
for (let numberOfChunks = 2; numberOfChunks <= 16; ++numberOfChunks) {
|
||||
promise_test(async t => {
|
||||
const compressedData = await compressMultipleChunks(hello, numberOfChunks, format);
|
||||
const decompressedData = await decompressDataOrPako(compressedData, format);
|
||||
const expectedValue = makeExpectedChunk(hello, numberOfChunks);
|
||||
// check that we got the same result as our original string
|
||||
assert_array_equals(decompressedData, expectedValue, 'value should match');
|
||||
}, `compressing ${numberOfChunks} chunks with ${format} should work`);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=third_party/pako/pako_inflate.min.js
|
||||
// META: timeout=long
|
||||
|
||||
'use strict';
|
||||
|
||||
// This test asserts that compressing multiple chunks should work.
|
||||
|
||||
// Example: ('Hello', 3) => TextEncoder().encode('HelloHelloHello')
|
||||
function makeExpectedChunk(input, numberOfChunks) {
|
||||
const expectedChunk = input.repeat(numberOfChunks);
|
||||
return new TextEncoder().encode(expectedChunk);
|
||||
}
|
||||
|
||||
// Example: ('Hello', 3, 'deflate') => compress ['Hello', 'Hello', Hello']
|
||||
async function compressMultipleChunks(input, numberOfChunks, format) {
|
||||
const cs = new CompressionStream(format);
|
||||
const writer = cs.writable.getWriter();
|
||||
const chunk = new TextEncoder().encode(input);
|
||||
for (let i = 0; i < numberOfChunks; ++i) {
|
||||
writer.write(chunk);
|
||||
}
|
||||
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 hello = 'Hello';
|
||||
|
||||
for (let numberOfChunks = 2; numberOfChunks <= 16; ++numberOfChunks) {
|
||||
promise_test(async t => {
|
||||
const compressedData = await compressMultipleChunks(hello, numberOfChunks, 'deflate');
|
||||
const expectedValue = makeExpectedChunk(hello, numberOfChunks);
|
||||
// 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');
|
||||
}, `compressing ${numberOfChunks} chunks with deflate should work`);
|
||||
|
||||
promise_test(async t => {
|
||||
const compressedData = await compressMultipleChunks(hello, numberOfChunks, 'gzip');
|
||||
const expectedValue = makeExpectedChunk(hello, numberOfChunks);
|
||||
// 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');
|
||||
}, `compressing ${numberOfChunks} chunks with gzip should work`);
|
||||
|
||||
promise_test(async t => {
|
||||
const compressedData = await compressMultipleChunks(hello, numberOfChunks, 'deflate-raw');
|
||||
const expectedValue = makeExpectedChunk(hello, numberOfChunks);
|
||||
// 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');
|
||||
}, `compressing ${numberOfChunks} chunks with deflate-raw should work`);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=resources/formats.js
|
||||
|
||||
'use strict';
|
||||
|
||||
// This test asserts that compressed data length is shorter than the original
|
||||
// data length. If the input is extremely small, the compressed data may be
|
||||
// larger than the original data.
|
||||
|
||||
const LARGE_FILE = '/media/test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm';
|
||||
|
||||
async function compressArrayBuffer(input, format) {
|
||||
const cs = new CompressionStream(format);
|
||||
const writer = cs.writable.getWriter();
|
||||
writer.write(input);
|
||||
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;
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
|
||||
'use strict';
|
||||
|
||||
// This test asserts that compressed data length is shorter than the original
|
||||
// data length. If the input is extremely small, the compressed data may be
|
||||
// larger than the original data.
|
||||
|
||||
const LARGE_FILE = '/media/test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm';
|
||||
|
||||
async function compressArrayBuffer(input, format) {
|
||||
const cs = new CompressionStream(format);
|
||||
const writer = cs.writable.getWriter();
|
||||
writer.write(input);
|
||||
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;
|
||||
}
|
||||
|
||||
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');
|
||||
@@ -0,0 +1,59 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=third_party/pako/pako_inflate.min.js
|
||||
// META: script=resources/decompress.js
|
||||
// META: script=resources/formats.js
|
||||
// META: timeout=long
|
||||
|
||||
'use strict';
|
||||
|
||||
const SMALL_FILE = "/media/foo.vtt";
|
||||
const LARGE_FILE = "/media/test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm";
|
||||
|
||||
let dataPromiseList = [
|
||||
["empty data", Promise.resolve(new Uint8Array(0))],
|
||||
["small amount data", fetch(SMALL_FILE).then(response => response.bytes())],
|
||||
["large amount data", fetch(LARGE_FILE).then(response => response.bytes())],
|
||||
];
|
||||
|
||||
async function compressArrayBuffer(input, format) {
|
||||
const cs = new CompressionStream(format);
|
||||
const writer = cs.writable.getWriter();
|
||||
writer.write(input);
|
||||
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;
|
||||
}
|
||||
|
||||
test(() => {
|
||||
assert_throws_js(TypeError, () => {
|
||||
const transformer = new CompressionStream("nonvalid");
|
||||
}, "non supported format should throw");
|
||||
}, "CompressionStream constructor should throw on invalid format");
|
||||
|
||||
for (const format of formats) {
|
||||
for (const [label, dataPromise] of dataPromiseList) {
|
||||
promise_test(async () => {
|
||||
const bufferView = await dataPromise;
|
||||
const compressedData = await compressArrayBuffer(bufferView, format);
|
||||
const decompressedData = await decompressDataOrPako(compressedData, format);
|
||||
// check that we got the same result as our original string
|
||||
assert_array_equals(decompressedData, bufferView, 'value should match');
|
||||
}, `${format} ${label} should be reinflated back to its origin`);
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=third_party/pako/pako_inflate.min.js
|
||||
// META: timeout=long
|
||||
|
||||
'use strict';
|
||||
|
||||
const SMALL_FILE = "/media/foo.vtt";
|
||||
const LARGE_FILE = "/media/test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm";
|
||||
|
||||
async function compressArrayBuffer(input, format) {
|
||||
const cs = new CompressionStream(format);
|
||||
const writer = cs.writable.getWriter();
|
||||
writer.write(input);
|
||||
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;
|
||||
}
|
||||
|
||||
test(() => {
|
||||
assert_throws_js(TypeError, () => {
|
||||
const transformer = new CompressionStream("nonvalid");
|
||||
}, "non supported format should throw");
|
||||
}, "CompressionStream constructor should throw on invalid format");
|
||||
|
||||
promise_test(async () => {
|
||||
const buffer = new ArrayBuffer(0);
|
||||
const bufferView = new Uint8Array(buffer);
|
||||
const compressedData = await compressArrayBuffer(bufferView, "deflate");
|
||||
// decompress with pako, and check that we got the same result as our original string
|
||||
assert_array_equals(bufferView, pako.inflate(compressedData));
|
||||
}, "deflated empty data should be reinflated back to its origin");
|
||||
|
||||
promise_test(async () => {
|
||||
const response = await fetch(SMALL_FILE)
|
||||
const buffer = await response.arrayBuffer();
|
||||
const bufferView = new Uint8Array(buffer);
|
||||
const compressedData = await compressArrayBuffer(bufferView, "deflate");
|
||||
// decompress with pako, and check that we got the same result as our original string
|
||||
assert_array_equals(bufferView, pako.inflate(compressedData));
|
||||
}, "deflated small amount data should be reinflated back to its origin");
|
||||
|
||||
promise_test(async () => {
|
||||
const response = await fetch(LARGE_FILE)
|
||||
const buffer = await response.arrayBuffer();
|
||||
const bufferView = new Uint8Array(buffer);
|
||||
const compressedData = await compressArrayBuffer(bufferView, "deflate");
|
||||
// decompress with pako, and check that we got the same result as our original string
|
||||
assert_array_equals(bufferView, pako.inflate(compressedData));
|
||||
}, "deflated large amount data should be reinflated back to its origin");
|
||||
|
||||
promise_test(async () => {
|
||||
const buffer = new ArrayBuffer(0);
|
||||
const bufferView = new Uint8Array(buffer);
|
||||
const compressedData = await compressArrayBuffer(bufferView, "gzip");
|
||||
// decompress with pako, and check that we got the same result as our original string
|
||||
assert_array_equals(bufferView, pako.inflate(compressedData));
|
||||
}, "gzipped empty data should be reinflated back to its origin");
|
||||
|
||||
promise_test(async () => {
|
||||
const response = await fetch(SMALL_FILE)
|
||||
const buffer = await response.arrayBuffer();
|
||||
const bufferView = new Uint8Array(buffer);
|
||||
const compressedData = await compressArrayBuffer(bufferView, "gzip");
|
||||
// decompress with pako, and check that we got the same result as our original string
|
||||
assert_array_equals(bufferView, pako.inflate(compressedData));
|
||||
}, "gzipped small amount data should be reinflated back to its origin");
|
||||
|
||||
promise_test(async () => {
|
||||
const response = await fetch(LARGE_FILE)
|
||||
const buffer = await response.arrayBuffer();
|
||||
const bufferView = new Uint8Array(buffer);
|
||||
const compressedData = await compressArrayBuffer(bufferView, "gzip");
|
||||
// decompress with pako, and check that we got the same result as our original string
|
||||
assert_array_equals(bufferView, pako.inflate(compressedData));
|
||||
}, "gzipped large amount data should be reinflated back to its origin");
|
||||
File renamed without changes.
+7
-12
@@ -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}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
|
||||
'use strict';
|
||||
|
||||
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,
|
||||
]],
|
||||
["brotli", [0x21, 0x08, 0x00, 0x04, 0x66, 0x6F, 0x6F, 0x03]]
|
||||
];
|
||||
// These chunk values below were chosen to make the length of the compressed
|
||||
// output be a multiple of 8 bytes.
|
||||
const expectedChunkValue = new Map(Object.entries({
|
||||
"deflate": new TextEncoder().encode('a0123456'),
|
||||
"gzip": new TextEncoder().encode('a012'),
|
||||
"deflate-raw": new TextEncoder().encode('ABCDEF'),
|
||||
"brotli": new TextEncoder().encode('foo'),
|
||||
}));
|
||||
|
||||
const bufferSourceChunks = compressedBytes.map(([format, bytes]) => [format, [
|
||||
{
|
||||
name: 'ArrayBuffer',
|
||||
value: new Uint8Array(bytes).buffer
|
||||
},
|
||||
{
|
||||
name: 'Int8Array',
|
||||
value: new Int8Array(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Uint8Array',
|
||||
value: new Uint8Array(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Uint8ClampedArray',
|
||||
value: new Uint8ClampedArray(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Int16Array',
|
||||
value: new Int16Array(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Uint16Array',
|
||||
value: new Uint16Array(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Int32Array',
|
||||
value: new Int32Array(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Uint32Array',
|
||||
value: new Uint32Array(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Float16Array',
|
||||
value: () => new Float16Array(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Float32Array',
|
||||
value: new Float32Array(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Float64Array',
|
||||
value: new Float64Array(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
{
|
||||
name: 'DataView',
|
||||
value: new DataView(new Uint8Array(bytes).buffer)
|
||||
},
|
||||
]]);
|
||||
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
|
||||
'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,
|
||||
];
|
||||
// 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 bufferSourceChunksForDeflate = [
|
||||
{
|
||||
name: 'ArrayBuffer',
|
||||
value: new Uint8Array(compressedBytesWithDeflate).buffer
|
||||
},
|
||||
{
|
||||
name: 'Int8Array',
|
||||
value: new Int8Array(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Uint8Array',
|
||||
value: new Uint8Array(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Uint8ClampedArray',
|
||||
value: new Uint8ClampedArray(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Int16Array',
|
||||
value: new Int16Array(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Uint16Array',
|
||||
value: new Uint16Array(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Int32Array',
|
||||
value: new Int32Array(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Uint32Array',
|
||||
value: new Uint32Array(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Float16Array',
|
||||
value: () => new Float16Array(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Float32Array',
|
||||
value: new Float32Array(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'Float64Array',
|
||||
value: new Float64Array(new Uint8Array(compressedBytesWithDeflate).buffer)
|
||||
},
|
||||
{
|
||||
name: 'DataView',
|
||||
value: new DataView(new Uint8Array(compressedBytesWithDeflate).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`);
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,15 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=resources/decompression-input.js
|
||||
|
||||
'use strict';
|
||||
|
||||
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), expectedChunkValue, "value should match");
|
||||
}, `decompressing ${format} input should work`);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
|
||||
'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 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');
|
||||
|
||||
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');
|
||||
|
||||
promise_test(async t => {
|
||||
const ds = new DecompressionStream('deflate-raw');
|
||||
const reader = ds.readable.getReader();
|
||||
const writer = ds.writable.getWriter();
|
||||
const writePromise = writer.write(deflateRawChunkValue);
|
||||
const { done, value } = await reader.read();
|
||||
assert_array_equals(Array.from(value), trueChunkValue, "value should match");
|
||||
}, 'decompressing deflated (with -raw) input should work');
|
||||
+15
-9
@@ -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.
|
||||
@@ -224,6 +222,14 @@ const expectations = [
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
format: 'brotli',
|
||||
|
||||
// Decompresses to 'expected output'.
|
||||
baseInput: brotliChunkValue,
|
||||
|
||||
fields: []
|
||||
}
|
||||
];
|
||||
|
||||
@@ -274,18 +280,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`);
|
||||
@@ -0,0 +1,24 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
|
||||
'use strict';
|
||||
|
||||
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])],
|
||||
["brotli", new Uint8Array([0xa1, 0x01])],
|
||||
];
|
||||
|
||||
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`);
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
|
||||
'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]);
|
||||
|
||||
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');
|
||||
@@ -0,0 +1,20 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=resources/decompression-input.js
|
||||
|
||||
'use strict';
|
||||
|
||||
const tests = compressedBytes.map(
|
||||
([format, chunk]) => [format, new Uint8Array([...chunk, 0])]
|
||||
);
|
||||
|
||||
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();
|
||||
writer.write(chunk).catch(() => { });
|
||||
const { done, value } = await reader.read();
|
||||
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`);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=resources/decompression-input.js
|
||||
|
||||
'use strict';
|
||||
|
||||
async function decompressArrayBuffer(input, format, chunkSize) {
|
||||
const ds = new DecompressionStream(format);
|
||||
const reader = ds.readable.getReader();
|
||||
const writer = ds.writable.getWriter();
|
||||
for (let beginning = 0; beginning < input.length; beginning += chunkSize) {
|
||||
writer.write(input.slice(beginning, beginning + chunkSize));
|
||||
}
|
||||
writer.close();
|
||||
const out = [];
|
||||
let totalSize = 0;
|
||||
while (true) {
|
||||
const { value, done } = await reader.read();
|
||||
if (done) break;
|
||||
out.push(value);
|
||||
totalSize += value.byteLength;
|
||||
}
|
||||
const concatenated = new Uint8Array(totalSize);
|
||||
let offset = 0;
|
||||
for (const array of out) {
|
||||
concatenated.set(array, offset);
|
||||
offset += array.byteLength;
|
||||
}
|
||||
return concatenated;
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
|
||||
'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 expectedChunkValue = new TextEncoder().encode('expected output');
|
||||
|
||||
async function decompressArrayBuffer(input, format, chunkSize) {
|
||||
const ds = new DecompressionStream(format);
|
||||
const reader = ds.readable.getReader();
|
||||
const writer = ds.writable.getWriter();
|
||||
for (let beginning = 0; beginning < input.length; beginning += chunkSize) {
|
||||
writer.write(input.slice(beginning, beginning + chunkSize));
|
||||
}
|
||||
writer.close();
|
||||
const out = [];
|
||||
let totalSize = 0;
|
||||
while (true) {
|
||||
const { value, done } = await reader.read();
|
||||
if (done) break;
|
||||
out.push(value);
|
||||
totalSize += value.byteLength;
|
||||
}
|
||||
const concatenated = new Uint8Array(totalSize);
|
||||
let offset = 0;
|
||||
for (const array of out) {
|
||||
concatenated.set(array, offset);
|
||||
offset += array.byteLength;
|
||||
}
|
||||
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`);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// META: global=window,worker,shadowrealm
|
||||
// META: script=resources/decompression-input.js
|
||||
|
||||
'use strict';
|
||||
|
||||
for (const [format, chunkValue] 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(chunkValue);
|
||||
const { value } = await reader.read();
|
||||
assert_equals(value.constructor, Uint8Array, "type should match");
|
||||
await writePromise;
|
||||
}, `decompressing ${format} output should give Uint8Array chunks`);
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
// 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]);
|
||||
|
||||
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');
|
||||
File renamed without changes.
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @param {Uint8Array} chunk
|
||||
* @param {string} format
|
||||
*/
|
||||
async function decompressData(chunk, format) {
|
||||
const ds = new DecompressionStream(format);
|
||||
const writer = ds.writable.getWriter();
|
||||
writer.write(chunk);
|
||||
writer.close();
|
||||
const decompressedChunkList = await Array.fromAsync(ds.readable);
|
||||
const mergedBlob = new Blob(decompressedChunkList);
|
||||
return await mergedBlob.bytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} chunk
|
||||
* @param {string} format
|
||||
*/
|
||||
async function decompressDataOrPako(chunk, format) {
|
||||
// Keep using pako for zlib to preserve existing test behavior
|
||||
if (["deflate", "gzip"].includes(format)) {
|
||||
return pako.inflate(chunk);
|
||||
}
|
||||
if (format === "deflate-raw") {
|
||||
return pako.inflateRaw(chunk);
|
||||
}
|
||||
|
||||
// Use DecompressionStream for any newer formats, assuming implementations
|
||||
// always implement decompression if they implement compression.
|
||||
return decompressData(chunk, format);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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 brotliChunkValue = new Uint8Array([
|
||||
0x21, 0x38, 0x00, 0x04, 0x65, 0x78, 0x70, 0x65,
|
||||
0x63, 0x74, 0x65, 0x64, 0x20, 0x6F, 0x75, 0x74,
|
||||
0x70, 0x75, 0x74, 0x03
|
||||
]);
|
||||
|
||||
const compressedBytes = [
|
||||
["deflate", deflateChunkValue],
|
||||
["gzip", gzipChunkValue],
|
||||
["deflate-raw", deflateRawChunkValue],
|
||||
["brotli", brotliChunkValue],
|
||||
];
|
||||
|
||||
const expectedChunkValue = new TextEncoder().encode('expected output');
|
||||
@@ -0,0 +1,6 @@
|
||||
const formats = [
|
||||
"deflate",
|
||||
"deflate-raw",
|
||||
"gzip",
|
||||
"brotli",
|
||||
]
|
||||
Vendored
+1
-1
@@ -4,7 +4,7 @@
|
||||
"path": "common"
|
||||
},
|
||||
"compression": {
|
||||
"commit": "67880a4eb83ca9aa732eec4b35a1971ff5bf37ff",
|
||||
"commit": "ae05f5cb53d3e290b91ae1e92069baa188292880",
|
||||
"path": "compression"
|
||||
},
|
||||
"console": {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"compression-bad-chunks.tentative.any.js": {
|
||||
"compression-bad-chunks.any.js": {
|
||||
"skip": "Execution \"hangs\", ArrayBuffer and TypedArray is not accepted and throws, instead of rejects during writer.write"
|
||||
},
|
||||
"decompression-bad-chunks.tentative.any.js": {
|
||||
"decompression-bad-chunks.any.js": {
|
||||
"skip": "Execution \"hangs\", ArrayBuffer and TypedArray is not accepted and throws, instead of rejects during writer.write"
|
||||
},
|
||||
"compression-with-detach.tentative.window.js": {
|
||||
"compression-with-detach.window.js": {
|
||||
"requires": ["crypto"]
|
||||
},
|
||||
"idlharness-shadowrealm.window.js": {
|
||||
|
||||
Reference in new issue
Block a user