OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <memory> |
5 #include <utility> | 6 #include <utility> |
6 | 7 |
7 #include "base/bind.h" | 8 #include "base/bind.h" |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "device/serial/serial.mojom.h" | 12 #include "device/serial/serial.mojom.h" |
12 #include "device/serial/serial_service_impl.h" | 13 #include "device/serial/serial_service_impl.h" |
13 #include "device/serial/test_serial_io_handler.h" | 14 #include "device/serial/test_serial_io_handler.h" |
14 #include "mojo/public/cpp/bindings/interface_ptr.h" | 15 #include "mojo/public/cpp/bindings/interface_ptr.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 75 |
75 void RunConnectTest(const std::string& path, bool expecting_success) { | 76 void RunConnectTest(const std::string& path, bool expecting_success) { |
76 if (!io_handler_.get()) | 77 if (!io_handler_.get()) |
77 io_handler_ = new TestSerialIoHandler; | 78 io_handler_ = new TestSerialIoHandler; |
78 mojo::InterfacePtr<serial::SerialService> service; | 79 mojo::InterfacePtr<serial::SerialService> service; |
79 new SerialServiceImpl( | 80 new SerialServiceImpl( |
80 new SerialConnectionFactory( | 81 new SerialConnectionFactory( |
81 base::Bind(&SerialServiceTest::ReturnIoHandler, | 82 base::Bind(&SerialServiceTest::ReturnIoHandler, |
82 base::Unretained(this)), | 83 base::Unretained(this)), |
83 base::ThreadTaskRunnerHandle::Get()), | 84 base::ThreadTaskRunnerHandle::Get()), |
84 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator), | 85 std::unique_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator), |
85 mojo::GetProxy(&service)); | 86 mojo::GetProxy(&service)); |
86 mojo::InterfacePtr<serial::Connection> connection; | 87 mojo::InterfacePtr<serial::Connection> connection; |
87 mojo::InterfacePtr<serial::DataSink> sink; | 88 mojo::InterfacePtr<serial::DataSink> sink; |
88 mojo::InterfacePtr<serial::DataSource> source; | 89 mojo::InterfacePtr<serial::DataSource> source; |
89 mojo::InterfacePtr<serial::DataSourceClient> source_client; | 90 mojo::InterfacePtr<serial::DataSourceClient> source_client; |
90 mojo::GetProxy(&source_client); | 91 mojo::GetProxy(&source_client); |
91 service->Connect(path, serial::ConnectionOptions::New(), | 92 service->Connect(path, serial::ConnectionOptions::New(), |
92 mojo::GetProxy(&connection), mojo::GetProxy(&sink), | 93 mojo::GetProxy(&connection), mojo::GetProxy(&sink), |
93 mojo::GetProxy(&source), std::move(source_client)); | 94 mojo::GetProxy(&source), std::move(source_client)); |
94 connection.set_connection_error_handler(base::Bind( | 95 connection.set_connection_error_handler(base::Bind( |
95 &SerialServiceTest::OnConnectionError, base::Unretained(this))); | 96 &SerialServiceTest::OnConnectionError, base::Unretained(this))); |
96 expecting_error_ = !expecting_success; | 97 expecting_error_ = !expecting_success; |
97 connection->GetInfo( | 98 connection->GetInfo( |
98 base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this))); | 99 base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this))); |
99 RunMessageLoop(); | 100 RunMessageLoop(); |
100 EXPECT_EQ(!expecting_success, connection.encountered_error()); | 101 EXPECT_EQ(!expecting_success, connection.encountered_error()); |
101 EXPECT_EQ(expecting_success, connected_); | 102 EXPECT_EQ(expecting_success, connected_); |
102 connection.reset(); | 103 connection.reset(); |
103 } | 104 } |
104 | 105 |
105 base::MessageLoop message_loop_; | 106 base::MessageLoop message_loop_; |
106 scoped_ptr<base::RunLoop> run_loop_; | 107 std::unique_ptr<base::RunLoop> run_loop_; |
107 mojo::Array<serial::DeviceInfoPtr> devices_; | 108 mojo::Array<serial::DeviceInfoPtr> devices_; |
108 scoped_refptr<TestSerialIoHandler> io_handler_; | 109 scoped_refptr<TestSerialIoHandler> io_handler_; |
109 bool connected_; | 110 bool connected_; |
110 bool expecting_error_; | 111 bool expecting_error_; |
111 serial::ConnectionInfoPtr info_; | 112 serial::ConnectionInfoPtr info_; |
112 | 113 |
113 private: | 114 private: |
114 DISALLOW_COPY_AND_ASSIGN(SerialServiceTest); | 115 DISALLOW_COPY_AND_ASSIGN(SerialServiceTest); |
115 }; | 116 }; |
116 | 117 |
(...skipping 19 matching lines...) Expand all Loading... |
136 TEST_F(SerialServiceTest, ConnectInvalidPath) { | 137 TEST_F(SerialServiceTest, ConnectInvalidPath) { |
137 RunConnectTest("invalid_path", false); | 138 RunConnectTest("invalid_path", false); |
138 } | 139 } |
139 | 140 |
140 TEST_F(SerialServiceTest, ConnectOpenFailed) { | 141 TEST_F(SerialServiceTest, ConnectOpenFailed) { |
141 io_handler_ = new FailToOpenIoHandler; | 142 io_handler_ = new FailToOpenIoHandler; |
142 RunConnectTest("device", false); | 143 RunConnectTest("device", false); |
143 } | 144 } |
144 | 145 |
145 } // namespace device | 146 } // namespace device |
OLD | NEW |