summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/serial/serialPort_readable_largeRead.https.any.js
blob: f8087514f71b0040c6b947885acdf554e4e17d97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// META: script=/resources/test-only-api.js
// META: script=/serial/resources/common.js
// META: script=resources/automation.js

serial_test(async (t, fake) => {
  const {port, fakePort} = await getFakeSerialPort(fake);
  // Select a buffer size smaller than the amount of data transferred.
  await port.open({baudRate: 9600, bufferSize: 64});

  const reader = port.readable.getReader();

  await fakePort.writable();
  const data = new Uint8Array(1024);  // Much larger than bufferSize above.
  for (let i = 0; i < data.byteLength; ++i)
    data[i] = i & 0xff;
  fakePort.write(data);

  const value = await readWithLength(reader, data.byteLength);
  compareArrays(data, value);
  reader.releaseLock();

  await port.close();
}, 'Can read a large amount of data');