|
1 | 1 | // META: global=window,worker,shadowrealm |
2 | 2 | // META: script=third_party/pako/pako_inflate.min.js |
| 3 | +// META: script=resources/decompress.js |
| 4 | +// META: script=resources/formats.js |
3 | 5 | // META: timeout=long |
4 | 6 |
|
5 | 7 | 'use strict'; |
6 | 8 |
|
7 | 9 | const SMALL_FILE = "/media/foo.vtt"; |
8 | 10 | const LARGE_FILE = "/media/test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm"; |
9 | 11 |
|
| 12 | +let dataPromiseList = [ |
| 13 | + ["empty data", Promise.resolve(new Uint8Array(0))], |
| 14 | + ["small amount data", fetch(SMALL_FILE).then(response => response.bytes())], |
| 15 | + ["large amount data", fetch(LARGE_FILE).then(response => response.bytes())], |
| 16 | +]; |
| 17 | + |
10 | 18 | async function compressArrayBuffer(input, format) { |
11 | 19 | const cs = new CompressionStream(format); |
12 | 20 | const writer = cs.writable.getWriter(); |
@@ -38,54 +46,14 @@ test(() => { |
38 | 46 | }, "non supported format should throw"); |
39 | 47 | }, "CompressionStream constructor should throw on invalid format"); |
40 | 48 |
|
41 | | -promise_test(async () => { |
42 | | - const buffer = new ArrayBuffer(0); |
43 | | - const bufferView = new Uint8Array(buffer); |
44 | | - const compressedData = await compressArrayBuffer(bufferView, "deflate"); |
45 | | - // decompress with pako, and check that we got the same result as our original string |
46 | | - assert_array_equals(bufferView, pako.inflate(compressedData)); |
47 | | -}, "deflated empty data should be reinflated back to its origin"); |
48 | | - |
49 | | -promise_test(async () => { |
50 | | - const response = await fetch(SMALL_FILE) |
51 | | - const buffer = await response.arrayBuffer(); |
52 | | - const bufferView = new Uint8Array(buffer); |
53 | | - const compressedData = await compressArrayBuffer(bufferView, "deflate"); |
54 | | - // decompress with pako, and check that we got the same result as our original string |
55 | | - assert_array_equals(bufferView, pako.inflate(compressedData)); |
56 | | -}, "deflated small amount data should be reinflated back to its origin"); |
57 | | - |
58 | | -promise_test(async () => { |
59 | | - const response = await fetch(LARGE_FILE) |
60 | | - const buffer = await response.arrayBuffer(); |
61 | | - const bufferView = new Uint8Array(buffer); |
62 | | - const compressedData = await compressArrayBuffer(bufferView, "deflate"); |
63 | | - // decompress with pako, and check that we got the same result as our original string |
64 | | - assert_array_equals(bufferView, pako.inflate(compressedData)); |
65 | | -}, "deflated large amount data should be reinflated back to its origin"); |
66 | | - |
67 | | -promise_test(async () => { |
68 | | - const buffer = new ArrayBuffer(0); |
69 | | - const bufferView = new Uint8Array(buffer); |
70 | | - const compressedData = await compressArrayBuffer(bufferView, "gzip"); |
71 | | - // decompress with pako, and check that we got the same result as our original string |
72 | | - assert_array_equals(bufferView, pako.inflate(compressedData)); |
73 | | -}, "gzipped empty data should be reinflated back to its origin"); |
74 | | - |
75 | | -promise_test(async () => { |
76 | | - const response = await fetch(SMALL_FILE) |
77 | | - const buffer = await response.arrayBuffer(); |
78 | | - const bufferView = new Uint8Array(buffer); |
79 | | - const compressedData = await compressArrayBuffer(bufferView, "gzip"); |
80 | | - // decompress with pako, and check that we got the same result as our original string |
81 | | - assert_array_equals(bufferView, pako.inflate(compressedData)); |
82 | | -}, "gzipped small amount data should be reinflated back to its origin"); |
83 | | - |
84 | | -promise_test(async () => { |
85 | | - const response = await fetch(LARGE_FILE) |
86 | | - const buffer = await response.arrayBuffer(); |
87 | | - const bufferView = new Uint8Array(buffer); |
88 | | - const compressedData = await compressArrayBuffer(bufferView, "gzip"); |
89 | | - // decompress with pako, and check that we got the same result as our original string |
90 | | - assert_array_equals(bufferView, pako.inflate(compressedData)); |
91 | | -}, "gzipped large amount data should be reinflated back to its origin"); |
| 49 | +for (const format of formats) { |
| 50 | + for (const [label, dataPromise] of dataPromiseList) { |
| 51 | + promise_test(async () => { |
| 52 | + const bufferView = await dataPromise; |
| 53 | + const compressedData = await compressArrayBuffer(bufferView, format); |
| 54 | + const decompressedData = await decompressDataOrPako(compressedData, format); |
| 55 | + // check that we got the same result as our original string |
| 56 | + assert_array_equals(decompressedData, bufferView, 'value should match'); |
| 57 | + }, `${format} ${label} should be reinflated back to its origin`); |
| 58 | + } |
| 59 | +} |
0 commit comments