• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: global=worker
2// META: script=resources/readable-stream-from-array.js
3// META: script=resources/readable-stream-to-array.js
4
5'use strict';
6
7const emptyChunk = new Uint8Array([]);
8const inputChunk = new Uint8Array([73, 32, 240, 159, 146, 153, 32, 115, 116,
9                                   114, 101, 97, 109, 115]);
10const expectedOutputString = 'I \u{1F499} streams';
11
12promise_test(async () => {
13  const input = readableStreamFromArray([inputChunk]);
14  const output = input.pipeThrough(new TextDecoderStream());
15  const array = await readableStreamToArray(output);
16  assert_array_equals(array, [expectedOutputString],
17                      'the output should be in one chunk');
18}, 'decoding one UTF-8 chunk should give one output string');
19
20promise_test(async () => {
21  const input = readableStreamFromArray([emptyChunk]);
22  const output = input.pipeThrough(new TextDecoderStream());
23  const array = await readableStreamToArray(output);
24  assert_array_equals(array, [], 'no chunks should be output');
25}, 'decoding an empty chunk should give no output chunks');
26
27promise_test(async () => {
28  const input = readableStreamFromArray([emptyChunk, inputChunk]);
29  const output = input.pipeThrough(new TextDecoderStream());
30  const array = await readableStreamToArray(output);
31  assert_array_equals(array, [expectedOutputString],
32                      'the output should be in one chunk');
33}, 'an initial empty chunk should be ignored');
34
35promise_test(async () => {
36  const input = readableStreamFromArray([inputChunk, emptyChunk]);
37  const output = input.pipeThrough(new TextDecoderStream());
38  const array = await readableStreamToArray(output);
39  assert_array_equals(array, [expectedOutputString],
40                      'the output should be in one chunk');
41}, 'a trailing empty chunk should be ignored');
42
43promise_test(async () => {
44  const buffer = new ArrayBuffer(3);
45  const view = new Uint8Array(buffer, 1, 1);
46  view[0] = 65;
47  new MessageChannel().port1.postMessage(buffer, [buffer]);
48  const input = readableStreamFromArray([view]);
49  const output = input.pipeThrough(new TextDecoderStream());
50  const array = await readableStreamToArray(output);
51  assert_array_equals(array, [], 'no chunks should be output');
52}, 'decoding a transferred Uint8Array chunk should give no output');
53
54promise_test(async () => {
55  const buffer = new ArrayBuffer(1);
56  new MessageChannel().port1.postMessage(buffer, [buffer]);
57  const input = readableStreamFromArray([buffer]);
58  const output = input.pipeThrough(new TextDecoderStream());
59  const array = await readableStreamToArray(output);
60  assert_array_equals(array, [], 'no chunks should be output');
61}, 'decoding a transferred ArrayBuffer chunk should give no output');
62