summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/serial/serialPort_loopback_flowControl-manual.https.html
blob: 930dab74d64fce9585394157593bbc3538a5b19c (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
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
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="resources/common.js"></script>
    <script src="resources/manual.js"></script>
  </head>
  <body>
    <p>
      These tests require a connected serial device configured to act as a
      "loopback" device, with the TX and RX pins and RTS and CTS pins wired
      together.
    </p>
    <script>
      manual_serial_test(async (t, port) => {
        await port.open({
            baudRate: 115200,
            bufferSize: 255,
            flowControl: 'none'
        });
        t.add_cleanup(async () => {
          await port.close();
        });

        await port.setSignals({ requestToSend: true });
        let signals = await port.getSignals();
        assert_true(signals.clearToSend);

        await port.setSignals({ requestToSend: false });
        signals = await port.getSignals();
        assert_false(signals.clearToSend);
      }, 'Manual RTS control works with no flow control enabled');

      manual_serial_test(async (t, port) => {
        await port.open({
            baudRate: 115200,
            bufferSize: 255,
            flowControl: 'hardware'
        });

        const writer = port.writable.getWriter();
        t.add_cleanup(async () => {
          writer.releaseLock();
          await port.close();
        });

        assert_true((await port.getSignals()).clearToSend);

        const buffer = new Uint8Array(1);
        while ((await port.getSignals()).clearToSend) {
          await writer.write(buffer);
        }
      }, 'Hardware flow control automatically sets RTS pin');
    </script>
  </body>
</html>