summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/serial/serialPort_close.https.any.js
blob: ec949a9917699d343192ff6b69ba999ba39a9787 (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
// 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);

  await promise_rejects_dom(t, 'InvalidStateError', port.close());
}, 'A SerialPort cannot be closed if it was never opened.');

serial_test(async (t, fake) => {
  const {port, fakePort} = await getFakeSerialPort(fake);

  await port.open({baudRate: 9600});
  await port.close();
  await promise_rejects_dom(t, 'InvalidStateError', port.close());
}, 'A SerialPort cannot be closed if it is already closed.');

serial_test(async (t, fake) => {
  const {port, fakePort} = await getFakeSerialPort(fake);

  await port.open({baudRate: 9600});
  const closePromise = port.close();
  await promise_rejects_dom(t, 'InvalidStateError', port.close());
  await closePromise;
}, 'A SerialPort cannot be closed if it is being closed.');