1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef DEVICE_SERIAL_TEST_SERIAL_IO_HANDLER_H_
6 #define DEVICE_SERIAL_TEST_SERIAL_IO_HANDLER_H_
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "device/serial/serial_io_handler.h"
13 #include "services/device/public/mojom/serial.mojom.h"
17 class TestSerialIoHandler : public SerialIoHandler {
19 TestSerialIoHandler();
21 static scoped_refptr<SerialIoHandler> Create();
23 // SerialIoHandler overrides.
24 void Open(const std::string& port,
25 const mojom::SerialConnectionOptions& options,
26 OpenCompleteCallback callback) override;
27 void ReadImpl() override;
28 void CancelReadImpl() override;
29 void WriteImpl() override;
30 void CancelWriteImpl() override;
31 bool ConfigurePortImpl() override;
32 mojom::SerialDeviceControlSignalsPtr GetControlSignals() const override;
33 mojom::SerialConnectionInfoPtr GetPortInfo() const override;
34 bool Flush() const override;
35 bool SetControlSignals(
36 const mojom::SerialHostControlSignals& signals) override;
37 bool SetBreak() override;
38 bool ClearBreak() override;
39 void ForceReceiveError(device::mojom::SerialReceiveError error);
40 void ForceSendError(device::mojom::SerialSendError error);
42 mojom::SerialConnectionInfo* connection_info() { return &info_; }
43 mojom::SerialDeviceControlSignals* device_control_signals() {
44 return &device_control_signals_;
46 bool dtr() { return dtr_; }
47 bool rts() { return rts_; }
48 int flushes() { return flushes_; }
49 // This callback will be called when this IoHandler processes its next write,
50 // instead of the normal behavior of echoing the data to reads.
51 void set_send_callback(base::OnceClosure callback) {
52 send_callback_ = std::move(callback);
56 ~TestSerialIoHandler() override;
60 mojom::SerialConnectionInfo info_;
61 mojom::SerialDeviceControlSignals device_control_signals_;
65 std::vector<uint8_t> buffer_;
66 base::OnceClosure send_callback_;
68 DISALLOW_COPY_AND_ASSIGN(TestSerialIoHandler);
73 #endif // DEVICE_SERIAL_TEST_SERIAL_IO_HANDLER_H_