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

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

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 years, 3 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_service_impl.cc ('k') | device/usb/mojo/device_impl.h » ('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 <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"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "device/serial/serial.mojom.h" 13 #include "device/serial/serial.mojom.h"
14 #include "device/serial/serial_service_impl.h" 14 #include "device/serial/serial_service_impl.h"
15 #include "device/serial/test_serial_io_handler.h" 15 #include "device/serial/test_serial_io_handler.h"
16 #include "mojo/public/cpp/bindings/interface_ptr.h" 16 #include "mojo/public/cpp/bindings/interface_ptr.h"
17 #include "mojo/public/cpp/bindings/interface_request.h" 17 #include "mojo/public/cpp/bindings/interface_request.h"
18 #include "mojo/public/cpp/bindings/strong_binding.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace device { 21 namespace device {
21 namespace { 22 namespace {
22 23
23 class FakeSerialDeviceEnumerator : public SerialDeviceEnumerator { 24 class FakeSerialDeviceEnumerator : public SerialDeviceEnumerator {
24 mojo::Array<serial::DeviceInfoPtr> GetDevices() override { 25 mojo::Array<serial::DeviceInfoPtr> GetDevices() override {
25 mojo::Array<serial::DeviceInfoPtr> devices(1); 26 mojo::Array<serial::DeviceInfoPtr> devices(1);
26 devices[0] = serial::DeviceInfo::New(); 27 devices[0] = serial::DeviceInfo::New();
27 devices[0]->path = "device"; 28 devices[0]->path = "device";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 connected_ = true; 72 connected_ = true;
72 StopMessageLoop(); 73 StopMessageLoop();
73 } 74 }
74 75
75 scoped_refptr<SerialIoHandler> ReturnIoHandler() { return io_handler_; } 76 scoped_refptr<SerialIoHandler> ReturnIoHandler() { return io_handler_; }
76 77
77 void RunConnectTest(const std::string& path, bool expecting_success) { 78 void RunConnectTest(const std::string& path, bool expecting_success) {
78 if (!io_handler_.get()) 79 if (!io_handler_.get())
79 io_handler_ = new TestSerialIoHandler; 80 io_handler_ = new TestSerialIoHandler;
80 mojo::InterfacePtr<serial::SerialService> service; 81 mojo::InterfacePtr<serial::SerialService> service;
81 new SerialServiceImpl( 82 mojo::MakeStrongBinding(
82 new SerialConnectionFactory( 83 base::MakeUnique<SerialServiceImpl>(
83 base::Bind(&SerialServiceTest::ReturnIoHandler, 84 new SerialConnectionFactory(
84 base::Unretained(this)), 85 base::Bind(&SerialServiceTest::ReturnIoHandler,
85 base::ThreadTaskRunnerHandle::Get()), 86 base::Unretained(this)),
86 std::unique_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator), 87 base::ThreadTaskRunnerHandle::Get()),
88 base::MakeUnique<FakeSerialDeviceEnumerator>()),
87 mojo::GetProxy(&service)); 89 mojo::GetProxy(&service));
88 mojo::InterfacePtr<serial::Connection> connection; 90 mojo::InterfacePtr<serial::Connection> connection;
89 mojo::InterfacePtr<serial::DataSink> sink; 91 mojo::InterfacePtr<serial::DataSink> sink;
90 mojo::InterfacePtr<serial::DataSource> source; 92 mojo::InterfacePtr<serial::DataSource> source;
91 mojo::InterfacePtr<serial::DataSourceClient> source_client; 93 mojo::InterfacePtr<serial::DataSourceClient> source_client;
92 mojo::GetProxy(&source_client); 94 mojo::GetProxy(&source_client);
93 service->Connect(path, serial::ConnectionOptions::New(), 95 service->Connect(path, serial::ConnectionOptions::New(),
94 mojo::GetProxy(&connection), mojo::GetProxy(&sink), 96 mojo::GetProxy(&connection), mojo::GetProxy(&sink),
95 mojo::GetProxy(&source), std::move(source_client)); 97 mojo::GetProxy(&source), std::move(source_client));
96 connection.set_connection_error_handler(base::Bind( 98 connection.set_connection_error_handler(base::Bind(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 TEST_F(SerialServiceTest, ConnectInvalidPath) { 140 TEST_F(SerialServiceTest, ConnectInvalidPath) {
139 RunConnectTest("invalid_path", false); 141 RunConnectTest("invalid_path", false);
140 } 142 }
141 143
142 TEST_F(SerialServiceTest, ConnectOpenFailed) { 144 TEST_F(SerialServiceTest, ConnectOpenFailed) {
143 io_handler_ = new FailToOpenIoHandler; 145 io_handler_ = new FailToOpenIoHandler;
144 RunConnectTest("device", false); 146 RunConnectTest("device", false);
145 } 147 }
146 148
147 } // namespace device 149 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_service_impl.cc ('k') | device/usb/mojo/device_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698