GeezerVison is showing github.com — test,stream: enable compression WPTs · nodejs/node@7ebc8c2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/common/wpt.js +13-6Lines changed: 13 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -210,6 +210,7 @@ class ResourceLoader { | 210 | 210 | const data = await fsPromises.readFile(file); | 211 | 211 | return { | 212 | 212 | ok: true, | | 213 | + arrayBuffer() { return data.buffer; }, | 213 | 214 | json() { return JSON.parse(data.toString()); }, | 214 | 215 | text() { return data.toString(); }, | 215 | 216 | }; | @@ -382,7 +383,7 @@ const kIntlRequirement = { | 382 | 383 | // TODO(joyeecheung): we may need to deal with --with-intl=system-icu | 383 | 384 | }; | 384 | 385 |
| 385 | | -class IntlRequirement { | | 386 | +class BuildRequirement { | 386 | 387 | constructor() { | 387 | 388 | this.currentIntl = kIntlRequirement.none; | 388 | 389 | if (process.config.variables.v8_enable_i18n_support === 0) { | @@ -395,6 +396,9 @@ class IntlRequirement { | 395 | 396 | } else { | 396 | 397 | this.currentIntl = kIntlRequirement.full; | 397 | 398 | } | | 399 | + // Not using common.hasCrypto because of the global leak checks | | 400 | + this.hasCrypto = Boolean(process.versions.openssl) && | | 401 | + !process.env.NODE_SKIP_CRYPTO; | 398 | 402 | } | 399 | 403 |
| 400 | 404 | /** | @@ -409,11 +413,14 @@ class IntlRequirement { | 409 | 413 | if (requires.has('small-icu') && current < kIntlRequirement.small) { | 410 | 414 | return 'small-icu'; | 411 | 415 | } | | 416 | + if (requires.has('crypto') && !this.hasCrypto) { | | 417 | + return 'crypto'; | | 418 | + } | 412 | 419 | return false; | 413 | 420 | } | 414 | 421 | } | 415 | 422 |
| 416 | | -const intlRequirements = new IntlRequirement(); | | 423 | +const buildRequirements = new BuildRequirement(); | 417 | 424 |
| 418 | 425 | class StatusLoader { | 419 | 426 | /** | @@ -440,7 +447,7 @@ class StatusLoader { | 440 | 447 | const list = this.grep(filepath); | 441 | 448 | result = result.concat(list); | 442 | 449 | } else { | 443 | | - if (!(/\.\w+\.js$/.test(filepath)) || filepath.endsWith('.helper.js')) { | | 450 | + if (!(/\.\w+\.js$/.test(filepath))) { | 444 | 451 | continue; | 445 | 452 | } | 446 | 453 | result.push(filepath); | @@ -945,9 +952,9 @@ class WPTRunner { | 945 | 952 | continue; | 946 | 953 | } | 947 | 954 |
| 948 | | - const lackingIntl = intlRequirements.isLacking(spec.requires); | 949 | | - if (lackingIntl) { | 950 | | - this.skip(spec, [ `requires ${lackingIntl}` ]); | | 955 | + const lackingSupport = buildRequirements.isLacking(spec.requires); | | 956 | + if (lackingSupport) { | | 957 | + this.skip(spec, [ `requires ${lackingSupport}` ]); | 951 | 958 | continue; | 952 | 959 | } | 953 | 960 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/wpt/README.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,7 @@ See [test/wpt](../../wpt/README.md) for information on how these tests are run. | 11 | 11 | Last update: | 12 | 12 |
| 13 | 13 | - common: https://github.com/web-platform-tests/wpt/tree/dbd648158d/common | | 14 | +- compression: https://github.com/web-platform-tests/wpt/tree/c82521cfa5/compression | 14 | 15 | - console: https://github.com/web-platform-tests/wpt/tree/767ae35464/console | 15 | 16 | - dom/abort: https://github.com/web-platform-tests/wpt/tree/d1f1ecbd52/dom/abort | 16 | 17 | - dom/events: https://github.com/web-platform-tests/wpt/tree/ab8999891c/dom/events | |
Collapse file Copy file name to clipboard +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +spec: https://wicg.github.io/compression/ | | 2 | +suggested_reviewers: | | 3 | + - ricea |
Collapse file Copy file name to clipboard +74Lines changed: 74 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: global=window,worker,shadowrealm | | 2 | + | | 3 | +'use strict'; | | 4 | + | | 5 | +const badChunks = [ | | 6 | + { | | 7 | + name: 'undefined', | | 8 | + value: undefined | | 9 | + }, | | 10 | + { | | 11 | + name: 'null', | | 12 | + value: null | | 13 | + }, | | 14 | + { | | 15 | + name: 'numeric', | | 16 | + value: 3.14 | | 17 | + }, | | 18 | + { | | 19 | + name: 'object, not BufferSource', | | 20 | + value: {} | | 21 | + }, | | 22 | + { | | 23 | + name: 'array', | | 24 | + value: [65] | | 25 | + }, | | 26 | + { | | 27 | + name: 'SharedArrayBuffer', | | 28 | + // Use a getter to postpone construction so that all tests don't fail where | | 29 | + // SharedArrayBuffer is not yet implemented. | | 30 | + get value() { | | 31 | + // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()` | | 32 | + return new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer; | | 33 | + } | | 34 | + }, | | 35 | + { | | 36 | + name: 'shared Uint8Array', | | 37 | + get value() { | | 38 | + // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()` | | 39 | + return new Uint8Array(new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer) | | 40 | + } | | 41 | + }, | | 42 | +]; | | 43 | + | | 44 | +for (const chunk of badChunks) { | | 45 | + promise_test(async t => { | | 46 | + const cs = new CompressionStream('gzip'); | | 47 | + const reader = cs.readable.getReader(); | | 48 | + const writer = cs.writable.getWriter(); | | 49 | + const writePromise = writer.write(chunk.value); | | 50 | + const readPromise = reader.read(); | | 51 | + await promise_rejects_js(t, TypeError, writePromise, 'write should reject'); | | 52 | + await promise_rejects_js(t, TypeError, readPromise, 'read should reject'); | | 53 | + }, `chunk of type ${chunk.name} should error the stream for gzip`); | | 54 | + | | 55 | + promise_test(async t => { | | 56 | + const cs = new CompressionStream('deflate'); | | 57 | + const reader = cs.readable.getReader(); | | 58 | + const writer = cs.writable.getWriter(); | | 59 | + const writePromise = writer.write(chunk.value); | | 60 | + const readPromise = reader.read(); | | 61 | + await promise_rejects_js(t, TypeError, writePromise, 'write should reject'); | | 62 | + await promise_rejects_js(t, TypeError, readPromise, 'read should reject'); | | 63 | + }, `chunk of type ${chunk.name} should error the stream for deflate`); | | 64 | + | | 65 | + promise_test(async t => { | | 66 | + const cs = new CompressionStream('deflate-raw'); | | 67 | + const reader = cs.readable.getReader(); | | 68 | + const writer = cs.writable.getWriter(); | | 69 | + const writePromise = writer.write(chunk.value); | | 70 | + const readPromise = reader.read(); | | 71 | + await promise_rejects_js(t, TypeError, writePromise, 'write should reject'); | | 72 | + await promise_rejects_js(t, TypeError, readPromise, 'read should reject'); | | 73 | + }, `chunk of type ${chunk.name} should error the stream for deflate-raw`); | | 74 | +} |
Collapse file Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: global=window,worker,shadowrealm | | 2 | + | | 3 | +'use strict'; | | 4 | + | | 5 | +test(t => { | | 6 | + assert_throws_js(TypeError, () => new CompressionStream('a'), 'constructor should throw'); | | 7 | +}, '"a" should cause the constructor to throw'); | | 8 | + | | 9 | +test(t => { | | 10 | + assert_throws_js(TypeError, () => new CompressionStream(), 'constructor should throw'); | | 11 | +}, 'no input should cause the constructor to throw'); | | 12 | + | | 13 | +test(t => { | | 14 | + assert_throws_js(Error, () => new CompressionStream({ toString() { throw Error(); } }), 'constructor should throw'); | | 15 | +}, 'non-string input should cause the constructor to throw'); |
Collapse file Copy file name to clipboard +63Lines changed: 63 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: global=window,worker,shadowrealm | | 2 | +// META: script=third_party/pako/pako_inflate.min.js | | 3 | +// META: timeout=long | | 4 | + | | 5 | +'use strict'; | | 6 | + | | 7 | +// This test asserts that compressing '' doesn't affect the compressed data. | | 8 | +// Example: compressing ['Hello', '', 'Hello'] results in 'HelloHello' | | 9 | + | | 10 | +async function compressChunkList(chunkList, format) { | | 11 | + const cs = new CompressionStream(format); | | 12 | + const writer = cs.writable.getWriter(); | | 13 | + for (const chunk of chunkList) { | | 14 | + const chunkByte = new TextEncoder().encode(chunk); | | 15 | + writer.write(chunkByte); | | 16 | + } | | 17 | + const closePromise = writer.close(); | | 18 | + const out = []; | | 19 | + const reader = cs.readable.getReader(); | | 20 | + let totalSize = 0; | | 21 | + while (true) { | | 22 | + const { value, done } = await reader.read(); | | 23 | + if (done) | | 24 | + break; | | 25 | + out.push(value); | | 26 | + totalSize += value.byteLength; | | 27 | + } | | 28 | + await closePromise; | | 29 | + const concatenated = new Uint8Array(totalSize); | | 30 | + let offset = 0; | | 31 | + for (const array of out) { | | 32 | + concatenated.set(array, offset); | | 33 | + offset += array.byteLength; | | 34 | + } | | 35 | + return concatenated; | | 36 | +} | | 37 | + | | 38 | +const chunkLists = [ | | 39 | + ['', 'Hello', 'Hello'], | | 40 | + ['Hello', '', 'Hello'], | | 41 | + ['Hello', 'Hello', ''] | | 42 | +]; | | 43 | +const expectedValue = new TextEncoder().encode('HelloHello'); | | 44 | + | | 45 | +for (const chunkList of chunkLists) { | | 46 | + promise_test(async t => { | | 47 | + const compressedData = await compressChunkList(chunkList, 'deflate'); | | 48 | + // decompress with pako, and check that we got the same result as our original string | | 49 | + assert_array_equals(expectedValue, pako.inflate(compressedData), 'value should match'); | | 50 | + }, `the result of compressing [${chunkList}] with deflate should be 'HelloHello'`); | | 51 | + | | 52 | + promise_test(async t => { | | 53 | + const compressedData = await compressChunkList(chunkList, 'gzip'); | | 54 | + // decompress with pako, and check that we got the same result as our original string | | 55 | + assert_array_equals(expectedValue, pako.inflate(compressedData), 'value should match'); | | 56 | + }, `the result of compressing [${chunkList}] with gzip should be 'HelloHello'`); | | 57 | + | | 58 | + promise_test(async t => { | | 59 | + const compressedData = await compressChunkList(chunkList, 'deflate-raw'); | | 60 | + // decompress with pako, and check that we got the same result as our original string | | 61 | + assert_array_equals(expectedValue, pako.inflateRaw(compressedData), 'value should match'); | | 62 | + }, `the result of compressing [${chunkList}] with deflate-raw should be 'HelloHello'`); | | 63 | +} |
Collapse file Copy file name to clipboard +41Lines changed: 41 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: global=window,worker,shadowrealm | | 2 | +// META: script=third_party/pako/pako_inflate.min.js | | 3 | +// META: script=resources/concatenate-stream.js | | 4 | +// META: timeout=long | | 5 | + | | 6 | +'use strict'; | | 7 | + | | 8 | +// This test verifies that a large flush output will not truncate the | | 9 | +// final results. | | 10 | + | | 11 | +async function compressData(chunk, format) { | | 12 | + const cs = new CompressionStream(format); | | 13 | + const writer = cs.writable.getWriter(); | | 14 | + writer.write(chunk); | | 15 | + writer.close(); | | 16 | + return await concatenateStream(cs.readable); | | 17 | +} | | 18 | + | | 19 | +// JSON-encoded array of 10 thousands numbers ("[0,1,2,...]"). This produces 48_891 bytes of data. | | 20 | +const fullData = new TextEncoder().encode(JSON.stringify(Array.from({ length: 10_000 }, (_, i) => i))); | | 21 | +const data = fullData.subarray(0, 35_579); | | 22 | +const expectedValue = data; | | 23 | + | | 24 | +promise_test(async t => { | | 25 | + const compressedData = await compressData(data, 'deflate'); | | 26 | + // decompress with pako, and check that we got the same result as our original string | | 27 | + assert_array_equals(expectedValue, pako.inflate(compressedData), 'value should match'); | | 28 | +}, `deflate compression with large flush output`); | | 29 | + | | 30 | +promise_test(async t => { | | 31 | + const compressedData = await compressData(data, 'gzip'); | | 32 | + // decompress with pako, and check that we got the same result as our original string | | 33 | + assert_array_equals(expectedValue, pako.inflate(compressedData), 'value should match'); | | 34 | +}, `gzip compression with large flush output`); | | 35 | + | | 36 | +promise_test(async t => { | | 37 | + const compressedData = await compressData(data, 'deflate-raw'); | | 38 | + // decompress with pako, and check that we got the same result as our original string | | 39 | + assert_array_equals(expectedValue, pako.inflateRaw(compressedData), 'value should match'); | | 40 | +}, `deflate-raw compression with large flush output`); | | 41 | + |
Collapse file Copy file name to clipboard +67Lines changed: 67 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// META: global=window,worker,shadowrealm | | 2 | +// META: script=third_party/pako/pako_inflate.min.js | | 3 | +// META: timeout=long | | 4 | + | | 5 | +'use strict'; | | 6 | + | | 7 | +// This test asserts that compressing multiple chunks should work. | | 8 | + | | 9 | +// Example: ('Hello', 3) => TextEncoder().encode('HelloHelloHello') | | 10 | +function makeExpectedChunk(input, numberOfChunks) { | | 11 | + const expectedChunk = input.repeat(numberOfChunks); | | 12 | + return new TextEncoder().encode(expectedChunk); | | 13 | +} | | 14 | + | | 15 | +// Example: ('Hello', 3, 'deflate') => compress ['Hello', 'Hello', Hello'] | | 16 | +async function compressMultipleChunks(input, numberOfChunks, format) { | | 17 | + const cs = new CompressionStream(format); | | 18 | + const writer = cs.writable.getWriter(); | | 19 | + const chunk = new TextEncoder().encode(input); | | 20 | + for (let i = 0; i < numberOfChunks; ++i) { | | 21 | + writer.write(chunk); | | 22 | + } | | 23 | + const closePromise = writer.close(); | | 24 | + const out = []; | | 25 | + const reader = cs.readable.getReader(); | | 26 | + let totalSize = 0; | | 27 | + while (true) { | | 28 | + const { value, done } = await reader.read(); | | 29 | + if (done) | | 30 | + break; | | 31 | + out.push(value); | | 32 | + totalSize += value.byteLength; | | 33 | + } | | 34 | + await closePromise; | | 35 | + const concatenated = new Uint8Array(totalSize); | | 36 | + let offset = 0; | | 37 | + for (const array of out) { | | 38 | + concatenated.set(array, offset); | | 39 | + offset += array.byteLength; | | 40 | + } | | 41 | + return concatenated; | | 42 | +} | | 43 | + | | 44 | +const hello = 'Hello'; | | 45 | + | | 46 | +for (let numberOfChunks = 2; numberOfChunks <= 16; ++numberOfChunks) { | | 47 | + promise_test(async t => { | | 48 | + const compressedData = await compressMultipleChunks(hello, numberOfChunks, 'deflate'); | | 49 | + const expectedValue = makeExpectedChunk(hello, numberOfChunks); | | 50 | + // decompress with pako, and check that we got the same result as our original string | | 51 | + assert_array_equals(expectedValue, pako.inflate(compressedData), 'value should match'); | | 52 | + }, `compressing ${numberOfChunks} chunks with deflate should work`); | | 53 | + | | 54 | + promise_test(async t => { | | 55 | + const compressedData = await compressMultipleChunks(hello, numberOfChunks, 'gzip'); | | 56 | + const expectedValue = makeExpectedChunk(hello, numberOfChunks); | | 57 | + // decompress with pako, and check that we got the same result as our original string | | 58 | + assert_array_equals(expectedValue, pako.inflate(compressedData), 'value should match'); | | 59 | + }, `compressing ${numberOfChunks} chunks with gzip should work`); | | 60 | + | | 61 | + promise_test(async t => { | | 62 | + const compressedData = await compressMultipleChunks(hello, numberOfChunks, 'deflate-raw'); | | 63 | + const expectedValue = makeExpectedChunk(hello, numberOfChunks); | | 64 | + // decompress with pako, and check that we got the same result as our original string | | 65 | + assert_array_equals(expectedValue, pako.inflateRaw(compressedData), 'value should match'); | | 66 | + }, `compressing ${numberOfChunks} chunks with deflate-raw should work`); | | 67 | +} |
|