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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// 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.setSignals({}));
}, 'setSignals() rejects if the port is not open');
serial_test(async (t, fake) => {
const {port, fakePort} = await getFakeSerialPort(fake);
await port.open({baudRate: 9600});
let expectedSignals = {
dataTerminalReady: true,
requestToSend: false,
break: false
};
assert_object_equals(fakePort.outputSignals, expectedSignals, 'initial');
await promise_rejects_js(t, TypeError, port.setSignals());
assert_object_equals(fakePort.outputSignals, expectedSignals, 'no-op');
await promise_rejects_js(t, TypeError, port.setSignals({}));
assert_object_equals(fakePort.outputSignals, expectedSignals, 'no-op');
await port.setSignals({dataTerminalReady: false});
expectedSignals.dataTerminalReady = false;
assert_object_equals(fakePort.outputSignals, expectedSignals, 'clear DTR');
await port.setSignals({requestToSend: true});
expectedSignals.requestToSend = true;
assert_object_equals(fakePort.outputSignals, expectedSignals, 'set RTS');
await port.setSignals({break: true});
expectedSignals.break = true;
assert_object_equals(fakePort.outputSignals, expectedSignals, 'set BRK');
await port.setSignals(
{dataTerminalReady: true, requestToSend: false, break: false});
expectedSignals.dataTerminalReady = true;
expectedSignals.requestToSend = false;
expectedSignals.break = false;
assert_object_equals(fakePort.outputSignals, expectedSignals, 'invert');
}, 'setSignals() modifies the state of the port');
serial_test(async (t, fake) => {
const {port, fakePort} = await getFakeSerialPort(fake);
await port.open({baudRate: 9600});
fakePort.simulateOutputSignalFailure(true);
await promise_rejects_dom(t, 'NetworkError', port.setSignals({break: true}));
fakePort.simulateOutputSignalFailure(false);
await port.setSignals({break: true});
assert_true(fakePort.outputSignals.break);
await port.close();
}, 'setSignals() rejects on failure');
|