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,
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);
59 }, 'setSignals() rejects on failure');