|
| 1 | +// META: global=worker |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +const compressedBytesWithDeflate = [120, 156, 75, 52, 48, 52, 50, 54, 49, 53, 3, 0, 8, 136, 1, 199]; |
| 6 | +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]; |
| 7 | +// Two chunk values below were chosen to make the length of the compressed |
| 8 | +// output be a multiple of 8 bytes. |
| 9 | +const deflateExpectedChunkValue = new TextEncoder().encode('a0123456'); |
| 10 | +const gzipExpectedChunkValue = new TextEncoder().encode('a012'); |
| 11 | + |
| 12 | +const bufferSourceChunksForDeflate = [ |
| 13 | + { |
| 14 | + name: 'ArrayBuffer', |
| 15 | + value: new Uint8Array(compressedBytesWithDeflate).buffer |
| 16 | + }, |
| 17 | + { |
| 18 | + name: 'Int8Array', |
| 19 | + value: new Int8Array(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 20 | + }, |
| 21 | + { |
| 22 | + name: 'Uint8Array', |
| 23 | + value: new Uint8Array(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 24 | + }, |
| 25 | + { |
| 26 | + name: 'Uint8ClampedArray', |
| 27 | + value: new Uint8ClampedArray(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 28 | + }, |
| 29 | + { |
| 30 | + name: 'Int16Array', |
| 31 | + value: new Int16Array(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 32 | + }, |
| 33 | + { |
| 34 | + name: 'Uint16Array', |
| 35 | + value: new Uint16Array(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 36 | + }, |
| 37 | + { |
| 38 | + name: 'Int32Array', |
| 39 | + value: new Int32Array(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 40 | + }, |
| 41 | + { |
| 42 | + name: 'Uint32Array', |
| 43 | + value: new Uint32Array(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 44 | + }, |
| 45 | + { |
| 46 | + name: 'Float32Array', |
| 47 | + value: new Float32Array(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 48 | + }, |
| 49 | + { |
| 50 | + name: 'Float64Array', |
| 51 | + value: new Float64Array(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 52 | + }, |
| 53 | + { |
| 54 | + name: 'DataView', |
| 55 | + value: new DataView(new Uint8Array(compressedBytesWithDeflate).buffer) |
| 56 | + }, |
| 57 | +]; |
| 58 | + |
| 59 | +const bufferSourceChunksForGzip = [ |
| 60 | + { |
| 61 | + name: 'ArrayBuffer', |
| 62 | + value: new Uint8Array(compressedBytesWithGzip).buffer |
| 63 | + }, |
| 64 | + { |
| 65 | + name: 'Int8Array', |
| 66 | + value: new Int8Array(new Uint8Array(compressedBytesWithGzip).buffer) |
| 67 | + }, |
| 68 | + { |
| 69 | + name: 'Uint8Array', |
| 70 | + value: new Uint8Array(new Uint8Array(compressedBytesWithGzip).buffer) |
| 71 | + }, |
| 72 | + { |
| 73 | + name: 'Uint8ClambedArray', |
| 74 | + value: new Uint8ClampedArray(new Uint8Array(compressedBytesWithGzip).buffer) |
| 75 | + }, |
| 76 | + { |
| 77 | + name: 'Int16Array', |
| 78 | + value: new Int16Array(new Uint8Array(compressedBytesWithGzip).buffer) |
| 79 | + }, |
| 80 | + { |
| 81 | + name: 'Uint16Array', |
| 82 | + value: new Uint16Array(new Uint8Array(compressedBytesWithGzip).buffer) |
| 83 | + }, |
| 84 | + { |
| 85 | + name: 'Int32Array', |
| 86 | + value: new Int32Array(new Uint8Array(compressedBytesWithGzip).buffer) |
| 87 | + }, |
| 88 | + { |
| 89 | + name: 'Uint32Array', |
| 90 | + value: new Uint32Array(new Uint8Array(compressedBytesWithGzip).buffer) |
| 91 | + }, |
| 92 | + { |
| 93 | + name: 'Float32Array', |
| 94 | + value: new Float32Array(new Uint8Array(compressedBytesWithGzip).buffer) |
| 95 | + }, |
| 96 | + { |
| 97 | + name: 'Float64Array', |
| 98 | + value: new Float64Array(new Uint8Array(compressedBytesWithGzip).buffer) |
| 99 | + }, |
| 100 | + { |
| 101 | + name: 'DataView', |
| 102 | + value: new DataView(new Uint8Array(compressedBytesWithGzip).buffer) |
| 103 | + }, |
| 104 | +]; |
| 105 | + |
| 106 | +for (const chunk of bufferSourceChunksForDeflate) { |
| 107 | + promise_test(async t => { |
| 108 | + const ds = new DecompressionStream('deflate'); |
| 109 | + const reader = ds.readable.getReader(); |
| 110 | + const writer = ds.writable.getWriter(); |
| 111 | + const writePromise = writer.write(chunk.value); |
| 112 | + writer.close(); |
| 113 | + const { value } = await reader.read(); |
| 114 | + assert_array_equals(Array.from(value), deflateExpectedChunkValue, 'value should match'); |
| 115 | + }, `chunk of type ${chunk.name} should work for deflate`); |
| 116 | +} |
| 117 | + |
| 118 | +for (const chunk of bufferSourceChunksForGzip) { |
| 119 | + promise_test(async t => { |
| 120 | + const ds = new DecompressionStream('gzip'); |
| 121 | + const reader = ds.readable.getReader(); |
| 122 | + const writer = ds.writable.getWriter(); |
| 123 | + const writePromise = writer.write(chunk.value); |
| 124 | + writer.close(); |
| 125 | + const { value } = await reader.read(); |
| 126 | + assert_array_equals(Array.from(value), gzipExpectedChunkValue, 'value should match'); |
| 127 | + }, `chunk of type ${chunk.name} should work for gzip`); |
| 128 | +} |
0 commit comments