summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/compression/decompression-buffersource.tentative.any.js
blob: e81fc566779800f324034eb338957cf1b2f24106 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// 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: '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: '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: '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(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(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(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`);
}