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

Side by Side Diff: device/serial/serial_service_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/serial_connection_unittest.cc ('k') | no next file » | 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "device/serial/serial.mojom.h" 8 #include "device/serial/serial.mojom.h"
9 #include "device/serial/serial_service_impl.h" 9 #include "device/serial/serial_service_impl.h"
10 #include "device/serial/test_serial_io_handler.h" 10 #include "device/serial/test_serial_io_handler.h"
(...skipping 21 matching lines...) Expand all
32 const OpenCompleteCallback& callback) override { 32 const OpenCompleteCallback& callback) override {
33 callback.Run(false); 33 callback.Run(false);
34 } 34 }
35 35
36 protected: 36 protected:
37 ~FailToOpenIoHandler() override {} 37 ~FailToOpenIoHandler() override {}
38 }; 38 };
39 39
40 } // namespace 40 } // namespace
41 41
42 class SerialServiceTest : public testing::Test, public mojo::ErrorHandler { 42 class SerialServiceTest : public testing::Test {
43 public: 43 public:
44 SerialServiceTest() : connected_(false), expecting_error_(false) {} 44 SerialServiceTest() : connected_(false), expecting_error_(false) {}
45 45
46 void StoreDevices(mojo::Array<serial::DeviceInfoPtr> devices) { 46 void StoreDevices(mojo::Array<serial::DeviceInfoPtr> devices) {
47 devices_ = devices.Pass(); 47 devices_ = devices.Pass();
48 StopMessageLoop(); 48 StopMessageLoop();
49 } 49 }
50 50
51 void OnConnectionError() override { 51 void OnConnectionError() {
52 StopMessageLoop(); 52 StopMessageLoop();
53 EXPECT_TRUE(expecting_error_); 53 EXPECT_TRUE(expecting_error_);
54 } 54 }
55 55
56 void RunMessageLoop() { 56 void RunMessageLoop() {
57 run_loop_.reset(new base::RunLoop); 57 run_loop_.reset(new base::RunLoop);
58 run_loop_->Run(); 58 run_loop_->Run();
59 } 59 }
60 60
61 void StopMessageLoop() { 61 void StopMessageLoop() {
(...skipping 20 matching lines...) Expand all
82 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator), 82 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator),
83 mojo::GetProxy(&service)); 83 mojo::GetProxy(&service));
84 mojo::InterfacePtr<serial::Connection> connection; 84 mojo::InterfacePtr<serial::Connection> connection;
85 mojo::InterfacePtr<serial::DataSink> sink; 85 mojo::InterfacePtr<serial::DataSink> sink;
86 mojo::InterfacePtr<serial::DataSource> source; 86 mojo::InterfacePtr<serial::DataSource> source;
87 mojo::InterfacePtr<serial::DataSourceClient> source_client; 87 mojo::InterfacePtr<serial::DataSourceClient> source_client;
88 mojo::GetProxy(&source_client); 88 mojo::GetProxy(&source_client);
89 service->Connect(path, serial::ConnectionOptions::New(), 89 service->Connect(path, serial::ConnectionOptions::New(),
90 mojo::GetProxy(&connection), mojo::GetProxy(&sink), 90 mojo::GetProxy(&connection), mojo::GetProxy(&sink),
91 mojo::GetProxy(&source), source_client.Pass()); 91 mojo::GetProxy(&source), source_client.Pass());
92 connection.set_error_handler(this); 92 connection.set_connection_error_handler(base::Bind(
93 &SerialServiceTest::OnConnectionError, base::Unretained(this)));
93 expecting_error_ = !expecting_success; 94 expecting_error_ = !expecting_success;
94 connection->GetInfo( 95 connection->GetInfo(
95 base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this))); 96 base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this)));
96 RunMessageLoop(); 97 RunMessageLoop();
97 EXPECT_EQ(!expecting_success, connection.encountered_error()); 98 EXPECT_EQ(!expecting_success, connection.encountered_error());
98 EXPECT_EQ(expecting_success, connected_); 99 EXPECT_EQ(expecting_success, connected_);
99 connection.reset(); 100 connection.reset();
100 } 101 }
101 102
102 base::MessageLoop message_loop_; 103 base::MessageLoop message_loop_;
103 scoped_ptr<base::RunLoop> run_loop_; 104 scoped_ptr<base::RunLoop> run_loop_;
104 mojo::Array<serial::DeviceInfoPtr> devices_; 105 mojo::Array<serial::DeviceInfoPtr> devices_;
105 scoped_refptr<TestSerialIoHandler> io_handler_; 106 scoped_refptr<TestSerialIoHandler> io_handler_;
106 bool connected_; 107 bool connected_;
107 bool expecting_error_; 108 bool expecting_error_;
108 serial::ConnectionInfoPtr info_; 109 serial::ConnectionInfoPtr info_;
109 110
110 private: 111 private:
111 DISALLOW_COPY_AND_ASSIGN(SerialServiceTest); 112 DISALLOW_COPY_AND_ASSIGN(SerialServiceTest);
112 }; 113 };
113 114
114 TEST_F(SerialServiceTest, GetDevices) { 115 TEST_F(SerialServiceTest, GetDevices) {
115 mojo::InterfacePtr<serial::SerialService> service; 116 mojo::InterfacePtr<serial::SerialService> service;
116 SerialServiceImpl::Create(NULL, NULL, mojo::GetProxy(&service)); 117 SerialServiceImpl::Create(NULL, NULL, mojo::GetProxy(&service));
117 service.set_error_handler(this); 118 service.set_connection_error_handler(base::Bind(
119 &SerialServiceTest::OnConnectionError, base::Unretained(this)));
118 mojo::Array<serial::DeviceInfoPtr> result; 120 mojo::Array<serial::DeviceInfoPtr> result;
119 service->GetDevices( 121 service->GetDevices(
120 base::Bind(&SerialServiceTest::StoreDevices, base::Unretained(this))); 122 base::Bind(&SerialServiceTest::StoreDevices, base::Unretained(this)));
121 RunMessageLoop(); 123 RunMessageLoop();
122 124
123 // Because we're running on unknown hardware, only check that we received a 125 // Because we're running on unknown hardware, only check that we received a
124 // non-null result. 126 // non-null result.
125 EXPECT_TRUE(devices_); 127 EXPECT_TRUE(devices_);
126 } 128 }
127 129
128 TEST_F(SerialServiceTest, Connect) { 130 TEST_F(SerialServiceTest, Connect) {
129 RunConnectTest("device", true); 131 RunConnectTest("device", true);
130 } 132 }
131 133
132 TEST_F(SerialServiceTest, ConnectInvalidPath) { 134 TEST_F(SerialServiceTest, ConnectInvalidPath) {
133 RunConnectTest("invalid_path", false); 135 RunConnectTest("invalid_path", false);
134 } 136 }
135 137
136 TEST_F(SerialServiceTest, ConnectOpenFailed) { 138 TEST_F(SerialServiceTest, ConnectOpenFailed) {
137 io_handler_ = new FailToOpenIoHandler; 139 io_handler_ = new FailToOpenIoHandler;
138 RunConnectTest("device", false); 140 RunConnectTest("device", false);
139 } 141 }
140 142
141 } // namespace device 143 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_connection_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698