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

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

Issue 2589663003: mojo:: Rename mojo::GetProxy() to mojo::MakeRequest() (Closed)
Patch Set: Rebase Created 4 years 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
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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 if (!io_handler_.get()) 79 if (!io_handler_.get())
80 io_handler_ = new TestSerialIoHandler; 80 io_handler_ = new TestSerialIoHandler;
81 mojo::InterfacePtr<serial::SerialService> service; 81 mojo::InterfacePtr<serial::SerialService> service;
82 mojo::MakeStrongBinding( 82 mojo::MakeStrongBinding(
83 base::MakeUnique<SerialServiceImpl>( 83 base::MakeUnique<SerialServiceImpl>(
84 new SerialConnectionFactory( 84 new SerialConnectionFactory(
85 base::Bind(&SerialServiceTest::ReturnIoHandler, 85 base::Bind(&SerialServiceTest::ReturnIoHandler,
86 base::Unretained(this)), 86 base::Unretained(this)),
87 base::ThreadTaskRunnerHandle::Get()), 87 base::ThreadTaskRunnerHandle::Get()),
88 base::MakeUnique<FakeSerialDeviceEnumerator>()), 88 base::MakeUnique<FakeSerialDeviceEnumerator>()),
89 mojo::GetProxy(&service)); 89 mojo::MakeRequest(&service));
90 mojo::InterfacePtr<serial::Connection> connection; 90 mojo::InterfacePtr<serial::Connection> connection;
91 mojo::InterfacePtr<serial::DataSink> sink; 91 mojo::InterfacePtr<serial::DataSink> sink;
92 mojo::InterfacePtr<serial::DataSource> source; 92 mojo::InterfacePtr<serial::DataSource> source;
93 mojo::InterfacePtr<serial::DataSourceClient> source_client; 93 mojo::InterfacePtr<serial::DataSourceClient> source_client;
94 mojo::GetProxy(&source_client); 94 mojo::MakeRequest(&source_client);
95 service->Connect(path, serial::ConnectionOptions::New(), 95 service->Connect(path, serial::ConnectionOptions::New(),
96 mojo::GetProxy(&connection), mojo::GetProxy(&sink), 96 mojo::MakeRequest(&connection), mojo::MakeRequest(&sink),
97 mojo::GetProxy(&source), std::move(source_client)); 97 mojo::MakeRequest(&source), std::move(source_client));
98 connection.set_connection_error_handler(base::Bind( 98 connection.set_connection_error_handler(base::Bind(
99 &SerialServiceTest::OnConnectionError, base::Unretained(this))); 99 &SerialServiceTest::OnConnectionError, base::Unretained(this)));
100 expecting_error_ = !expecting_success; 100 expecting_error_ = !expecting_success;
101 connection->GetInfo( 101 connection->GetInfo(
102 base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this))); 102 base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this)));
103 RunMessageLoop(); 103 RunMessageLoop();
104 EXPECT_EQ(!expecting_success, connection.encountered_error()); 104 EXPECT_EQ(!expecting_success, connection.encountered_error());
105 EXPECT_EQ(expecting_success, connected_); 105 EXPECT_EQ(expecting_success, connected_);
106 connection.reset(); 106 connection.reset();
107 } 107 }
108 108
109 base::MessageLoop message_loop_; 109 base::MessageLoop message_loop_;
110 std::unique_ptr<base::RunLoop> run_loop_; 110 std::unique_ptr<base::RunLoop> run_loop_;
111 mojo::Array<serial::DeviceInfoPtr> devices_; 111 mojo::Array<serial::DeviceInfoPtr> devices_;
112 scoped_refptr<TestSerialIoHandler> io_handler_; 112 scoped_refptr<TestSerialIoHandler> io_handler_;
113 bool connected_; 113 bool connected_;
114 bool expecting_error_; 114 bool expecting_error_;
115 serial::ConnectionInfoPtr info_; 115 serial::ConnectionInfoPtr info_;
116 116
117 private: 117 private:
118 DISALLOW_COPY_AND_ASSIGN(SerialServiceTest); 118 DISALLOW_COPY_AND_ASSIGN(SerialServiceTest);
119 }; 119 };
120 120
121 TEST_F(SerialServiceTest, GetDevices) { 121 TEST_F(SerialServiceTest, GetDevices) {
122 mojo::InterfacePtr<serial::SerialService> service; 122 mojo::InterfacePtr<serial::SerialService> service;
123 SerialServiceImpl::Create(NULL, NULL, mojo::GetProxy(&service)); 123 SerialServiceImpl::Create(NULL, NULL, mojo::MakeRequest(&service));
124 service.set_connection_error_handler(base::Bind( 124 service.set_connection_error_handler(base::Bind(
125 &SerialServiceTest::OnConnectionError, base::Unretained(this))); 125 &SerialServiceTest::OnConnectionError, base::Unretained(this)));
126 mojo::Array<serial::DeviceInfoPtr> result; 126 mojo::Array<serial::DeviceInfoPtr> result;
127 service->GetDevices( 127 service->GetDevices(
128 base::Bind(&SerialServiceTest::StoreDevices, base::Unretained(this))); 128 base::Bind(&SerialServiceTest::StoreDevices, base::Unretained(this)));
129 RunMessageLoop(); 129 RunMessageLoop();
130 130
131 // Because we're running on unknown hardware, only check that we received a 131 // Because we're running on unknown hardware, only check that we received a
132 // non-null result. 132 // non-null result.
133 EXPECT_TRUE(devices_); 133 EXPECT_TRUE(devices_);
134 } 134 }
135 135
136 TEST_F(SerialServiceTest, Connect) { 136 TEST_F(SerialServiceTest, Connect) {
137 RunConnectTest("device", true); 137 RunConnectTest("device", true);
138 } 138 }
139 139
140 TEST_F(SerialServiceTest, ConnectInvalidPath) { 140 TEST_F(SerialServiceTest, ConnectInvalidPath) {
141 RunConnectTest("invalid_path", false); 141 RunConnectTest("invalid_path", false);
142 } 142 }
143 143
144 TEST_F(SerialServiceTest, ConnectOpenFailed) { 144 TEST_F(SerialServiceTest, ConnectOpenFailed) {
145 io_handler_ = new FailToOpenIoHandler; 145 io_handler_ = new FailToOpenIoHandler;
146 RunConnectTest("device", false); 146 RunConnectTest("device", false);
147 } 147 }
148 148
149 } // namespace device 149 } // namespace device
OLDNEW
« no previous file with comments | « device/power_monitor/public/cpp/power_monitor_broadcast_source.cc ('k') | device/usb/mojo/device_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698