Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: device/serial/serial_connection_unittest.cc

Issue 1212023004: Convert all usages of mojo::ErrorHandler in //device/serial to callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/serial/data_source_sender.cc ('k') | device/serial/serial_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
11 #include "device/serial/data_receiver.h" 11 #include "device/serial/data_receiver.h"
12 #include "device/serial/data_sender.h" 12 #include "device/serial/data_sender.h"
13 #include "device/serial/data_stream.mojom.h" 13 #include "device/serial/data_stream.mojom.h"
14 #include "device/serial/serial.mojom.h" 14 #include "device/serial/serial.mojom.h"
15 #include "device/serial/serial_connection.h" 15 #include "device/serial/serial_connection.h"
16 #include "device/serial/serial_service_impl.h" 16 #include "device/serial/serial_service_impl.h"
17 #include "device/serial/test_serial_io_handler.h" 17 #include "device/serial/test_serial_io_handler.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
20 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h" 19 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h"
21 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" 20 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
22 21
23 namespace device { 22 namespace device {
24 namespace { 23 namespace {
25 24
26 class FakeSerialDeviceEnumerator : public SerialDeviceEnumerator { 25 class FakeSerialDeviceEnumerator : public SerialDeviceEnumerator {
27 mojo::Array<serial::DeviceInfoPtr> GetDevices() override { 26 mojo::Array<serial::DeviceInfoPtr> GetDevices() override {
28 mojo::Array<serial::DeviceInfoPtr> devices(1); 27 mojo::Array<serial::DeviceInfoPtr> devices(1);
29 devices[0] = serial::DeviceInfo::New(); 28 devices[0] = serial::DeviceInfo::New();
30 devices[0]->path = "device"; 29 devices[0]->path = "device";
31 return devices.Pass(); 30 return devices.Pass();
32 } 31 }
33 }; 32 };
34 33
35 } // namespace 34 } // namespace
36 35
37 class SerialConnectionTest : public testing::Test, public mojo::ErrorHandler { 36 class SerialConnectionTest : public testing::Test {
38 public: 37 public:
39 enum Event { 38 enum Event {
40 EVENT_NONE, 39 EVENT_NONE,
41 EVENT_GOT_INFO, 40 EVENT_GOT_INFO,
42 EVENT_SET_OPTIONS, 41 EVENT_SET_OPTIONS,
43 EVENT_GOT_CONTROL_SIGNALS, 42 EVENT_GOT_CONTROL_SIGNALS,
44 EVENT_SET_CONTROL_SIGNALS, 43 EVENT_SET_CONTROL_SIGNALS,
45 EVENT_FLUSHED, 44 EVENT_FLUSHED,
46 EVENT_DATA_AT_IO_HANDLER, 45 EVENT_DATA_AT_IO_HANDLER,
47 EVENT_DATA_SENT, 46 EVENT_DATA_SENT,
(...skipping 17 matching lines...) Expand all
65 void SetUp() override { 64 void SetUp() override {
66 message_loop_.reset(new base::MessageLoop); 65 message_loop_.reset(new base::MessageLoop);
67 mojo::InterfacePtr<serial::SerialService> service; 66 mojo::InterfacePtr<serial::SerialService> service;
68 new SerialServiceImpl( 67 new SerialServiceImpl(
69 new SerialConnectionFactory( 68 new SerialConnectionFactory(
70 base::Bind(&SerialConnectionTest::CreateIoHandler, 69 base::Bind(&SerialConnectionTest::CreateIoHandler,
71 base::Unretained(this)), 70 base::Unretained(this)),
72 base::ThreadTaskRunnerHandle::Get()), 71 base::ThreadTaskRunnerHandle::Get()),
73 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator), 72 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator),
74 mojo::GetProxy(&service)); 73 mojo::GetProxy(&service));
75 service.set_error_handler(this); 74 service.set_connection_error_handler(base::Bind(
75 &SerialConnectionTest::OnConnectionError, base::Unretained(this)));
76 mojo::InterfacePtr<serial::DataSink> sink; 76 mojo::InterfacePtr<serial::DataSink> sink;
77 mojo::InterfacePtr<serial::DataSource> source; 77 mojo::InterfacePtr<serial::DataSource> source;
78 mojo::InterfacePtr<serial::DataSourceClient> source_client; 78 mojo::InterfacePtr<serial::DataSourceClient> source_client;
79 mojo::InterfaceRequest<serial::DataSourceClient> source_client_request = 79 mojo::InterfaceRequest<serial::DataSourceClient> source_client_request =
80 mojo::GetProxy(&source_client); 80 mojo::GetProxy(&source_client);
81 service->Connect("device", serial::ConnectionOptions::New(), 81 service->Connect("device", serial::ConnectionOptions::New(),
82 mojo::GetProxy(&connection_), mojo::GetProxy(&sink), 82 mojo::GetProxy(&connection_), mojo::GetProxy(&sink),
83 mojo::GetProxy(&source), source_client.Pass()); 83 mojo::GetProxy(&source), source_client.Pass());
84 sender_.reset(new DataSender(sink.Pass(), kBufferSize, 84 sender_.reset(new DataSender(sink.Pass(), kBufferSize,
85 serial::SEND_ERROR_DISCONNECTED)); 85 serial::SEND_ERROR_DISCONNECTED));
86 receiver_ = 86 receiver_ =
87 new DataReceiver(source.Pass(), source_client_request.Pass(), 87 new DataReceiver(source.Pass(), source_client_request.Pass(),
88 kBufferSize, serial::RECEIVE_ERROR_DISCONNECTED); 88 kBufferSize, serial::RECEIVE_ERROR_DISCONNECTED);
89 connection_.set_error_handler(this); 89 connection_.set_connection_error_handler(base::Bind(
90 &SerialConnectionTest::OnConnectionError, base::Unretained(this)));
90 connection_->GetInfo( 91 connection_->GetInfo(
91 base::Bind(&SerialConnectionTest::StoreInfo, base::Unretained(this))); 92 base::Bind(&SerialConnectionTest::StoreInfo, base::Unretained(this)));
92 WaitForEvent(EVENT_GOT_INFO); 93 WaitForEvent(EVENT_GOT_INFO);
93 ASSERT_TRUE(io_handler_.get()); 94 ASSERT_TRUE(io_handler_.get());
94 } 95 }
95 96
96 void StoreInfo(serial::ConnectionInfoPtr options) { 97 void StoreInfo(serial::ConnectionInfoPtr options) {
97 info_ = options.Pass(); 98 info_ = options.Pass();
98 EventReceived(EVENT_GOT_INFO); 99 EventReceived(EVENT_GOT_INFO);
99 } 100 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 buffer->Done(buffer->GetSize()); 163 buffer->Done(buffer->GetSize());
163 receive_error_ = serial::RECEIVE_ERROR_NONE; 164 receive_error_ = serial::RECEIVE_ERROR_NONE;
164 EventReceived(EVENT_DATA_RECEIVED); 165 EventReceived(EVENT_DATA_RECEIVED);
165 } 166 }
166 167
167 void OnReceiveError(int32_t error) { 168 void OnReceiveError(int32_t error) {
168 receive_error_ = static_cast<serial::ReceiveError>(error); 169 receive_error_ = static_cast<serial::ReceiveError>(error);
169 EventReceived(EVENT_RECEIVE_ERROR); 170 EventReceived(EVENT_RECEIVE_ERROR);
170 } 171 }
171 172
172 void OnConnectionError() override { 173 void OnConnectionError() {
173 EventReceived(EVENT_ERROR); 174 EventReceived(EVENT_ERROR);
174 FAIL() << "Connection error"; 175 FAIL() << "Connection error";
175 } 176 }
176 177
177 mojo::Array<serial::DeviceInfoPtr> devices_; 178 mojo::Array<serial::DeviceInfoPtr> devices_;
178 serial::ConnectionInfoPtr info_; 179 serial::ConnectionInfoPtr info_;
179 serial::DeviceControlSignalsPtr signals_; 180 serial::DeviceControlSignalsPtr signals_;
180 bool connected_; 181 bool connected_;
181 bool success_; 182 bool success_;
182 int bytes_sent_; 183 int bytes_sent_;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 WaitForEvent(EVENT_DATA_SENT); 325 WaitForEvent(EVENT_DATA_SENT);
325 EXPECT_EQ(serial::SEND_ERROR_NONE, send_error_); 326 EXPECT_EQ(serial::SEND_ERROR_NONE, send_error_);
326 EXPECT_EQ(4, bytes_sent_); 327 EXPECT_EQ(4, bytes_sent_);
327 ASSERT_NO_FATAL_FAILURE(Receive()); 328 ASSERT_NO_FATAL_FAILURE(Receive());
328 WaitForEvent(EVENT_DATA_RECEIVED); 329 WaitForEvent(EVENT_DATA_RECEIVED);
329 EXPECT_EQ("data", data_received_); 330 EXPECT_EQ("data", data_received_);
330 EXPECT_EQ(serial::RECEIVE_ERROR_NONE, receive_error_); 331 EXPECT_EQ(serial::RECEIVE_ERROR_NONE, receive_error_);
331 } 332 }
332 333
333 } // namespace device 334 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/data_source_sender.cc ('k') | device/serial/serial_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698