Bug 1770047 [wpt PR 34117] - [Clipboard API] Clipboard Web Custom Formats implementat...
[gecko.git] / testing / web-platform / tests / serial / serialPort_setSignals.https.any.js
blob27911ab7db5448b67086e4cda538dc1c80d0f8f0
1 // META: script=/resources/test-only-api.js
2 // META: script=/serial/resources/common.js
3 // META: script=resources/automation.js
5 serial_test(async (t, fake) => {
6   const {port, fakePort} = await getFakeSerialPort(fake);
7   await promise_rejects_dom(t, 'InvalidStateError', port.setSignals({}));
8 }, 'setSignals() rejects if the port is not open');
10 serial_test(async (t, fake) => {
11   const {port, fakePort} = await getFakeSerialPort(fake);
12   await port.open({baudRate: 9600});
14   let expectedSignals = {
15     dataTerminalReady: true,
16     requestToSend: false,
17     break: false
18   };
19   assert_object_equals(fakePort.outputSignals, expectedSignals, 'initial');
21   await promise_rejects_js(t, TypeError, port.setSignals());
22   assert_object_equals(fakePort.outputSignals, expectedSignals, 'no-op');
24   await promise_rejects_js(t, TypeError, port.setSignals({}));
25   assert_object_equals(fakePort.outputSignals, expectedSignals, 'no-op');
27   await port.setSignals({dataTerminalReady: false});
28   expectedSignals.dataTerminalReady = false;
29   assert_object_equals(fakePort.outputSignals, expectedSignals, 'clear DTR');
31   await port.setSignals({requestToSend: true});
32   expectedSignals.requestToSend = true;
33   assert_object_equals(fakePort.outputSignals, expectedSignals, 'set RTS');
35   await port.setSignals({break: true});
36   expectedSignals.break = true;
37   assert_object_equals(fakePort.outputSignals, expectedSignals, 'set BRK');
39   await port.setSignals(
40       {dataTerminalReady: true, requestToSend: false, break: false});
41   expectedSignals.dataTerminalReady = true;
42   expectedSignals.requestToSend = false;
43   expectedSignals.break = false;
44   assert_object_equals(fakePort.outputSignals, expectedSignals, 'invert');
45 }, 'setSignals() modifies the state of the port');
47 serial_test(async (t, fake) => {
48   const {port, fakePort} = await getFakeSerialPort(fake);
49   await port.open({baudRate: 9600});
51   fakePort.simulateOutputSignalFailure(true);
52   await promise_rejects_dom(t, 'NetworkError', port.setSignals({break: true}));
54   fakePort.simulateOutputSignalFailure(false);
55   await port.setSignals({break: true});
56   assert_true(fakePort.outputSignals.break);
58   await port.close();
59 }, 'setSignals() rejects on failure');