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

Side by Side Diff: device/devices_app/usb/device_manager_impl_unittest.cc

Issue 1226163009: Convert usages of mojo::ErrorHandler in //device to callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comment. 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/devices_app/usb/device_manager_impl.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
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/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "device/core/device_client.h" 14 #include "device/core/device_client.h"
15 #include "device/devices_app/usb/device_impl.h" 15 #include "device/devices_app/usb/device_impl.h"
16 #include "device/devices_app/usb/device_manager_impl.h" 16 #include "device/devices_app/usb/device_manager_impl.h"
17 #include "device/devices_app/usb/public/cpp/device_manager_delegate.h" 17 #include "device/devices_app/usb/public/cpp/device_manager_delegate.h"
18 #include "device/usb/mock_usb_device.h" 18 #include "device/usb/mock_usb_device.h"
19 #include "device/usb/mock_usb_device_handle.h" 19 #include "device/usb/mock_usb_device_handle.h"
20 #include "device/usb/mock_usb_service.h" 20 #include "device/usb/mock_usb_service.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
23 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" 22 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
24 23
25 using ::testing::Invoke; 24 using ::testing::Invoke;
26 using ::testing::_; 25 using ::testing::_;
27 26
28 namespace device { 27 namespace device {
29 namespace usb { 28 namespace usb {
30 29
31 namespace { 30 namespace {
32 31
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 scoped_ptr<DeviceManagerDelegate>(new TestDeviceManagerDelegate), 72 scoped_ptr<DeviceManagerDelegate>(new TestDeviceManagerDelegate),
74 base::ThreadTaskRunnerHandle::Get()); 73 base::ThreadTaskRunnerHandle::Get());
75 return device_manager.Pass(); 74 return device_manager.Pass();
76 } 75 }
77 76
78 private: 77 private:
79 scoped_ptr<base::MessageLoop> message_loop_; 78 scoped_ptr<base::MessageLoop> message_loop_;
80 scoped_ptr<TestDeviceClient> device_client_; 79 scoped_ptr<TestDeviceClient> device_client_;
81 }; 80 };
82 81
83 // This is used this to watch a MessagePipe and run a given callback when the
84 // pipe is closed.
85 class PipeWatcher : public mojo::ErrorHandler {
86 public:
87 PipeWatcher(const base::Closure& error_callback)
88 : error_callback_(error_callback) {}
89 ~PipeWatcher() override {}
90
91 private:
92 // mojo::ErrorHandler:
93 void OnConnectionError() override { error_callback_.Run(); }
94
95 const base::Closure error_callback_;
96
97 DISALLOW_COPY_AND_ASSIGN(PipeWatcher);
98 };
99
100 class MockOpenCallback { 82 class MockOpenCallback {
101 public: 83 public:
102 explicit MockOpenCallback(UsbDevice* device) : device_(device) {} 84 explicit MockOpenCallback(UsbDevice* device) : device_(device) {}
103 85
104 void Open(const UsbDevice::OpenCallback& callback) { 86 void Open(const UsbDevice::OpenCallback& callback) {
105 device_handle_ = new MockUsbDeviceHandle(device_); 87 device_handle_ = new MockUsbDeviceHandle(device_);
106 callback.Run(device_handle_); 88 callback.Run(device_handle_);
107 } 89 }
108 90
109 scoped_refptr<MockUsbDeviceHandle> mock_handle() { return device_handle_; } 91 scoped_refptr<MockUsbDeviceHandle> mock_handle() { return device_handle_; }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 DCHECK(open_callback.mock_handle()); 197 DCHECK(open_callback.mock_handle());
216 EXPECT_CALL(*open_callback.mock_handle().get(), Close()); 198 EXPECT_CALL(*open_callback.mock_handle().get(), Close());
217 199
218 DevicePtr bad_device; 200 DevicePtr bad_device;
219 device_manager->OpenDevice( 201 device_manager->OpenDevice(
220 "not a real guid", mojo::GetProxy(&bad_device), 202 "not a real guid", mojo::GetProxy(&bad_device),
221 base::Bind(&ExpectOpenDeviceError, OPEN_DEVICE_ERROR_NOT_FOUND)); 203 base::Bind(&ExpectOpenDeviceError, OPEN_DEVICE_ERROR_NOT_FOUND));
222 204
223 { 205 {
224 base::RunLoop loop; 206 base::RunLoop loop;
225 scoped_ptr<PipeWatcher> watcher(new PipeWatcher(loop.QuitClosure())); 207 bad_device.set_connection_error_handler(loop.QuitClosure());
226 bad_device.set_error_handler(watcher.get());
227 bad_device->GetDeviceInfo(base::Bind(&FailOnGetDeviceInfoResponse)); 208 bad_device->GetDeviceInfo(base::Bind(&FailOnGetDeviceInfoResponse));
228 loop.Run(); 209 loop.Run();
229 } 210 }
230 } 211 }
231 212
232 } // namespace usb 213 } // namespace usb
233 } // namespace device 214 } // namespace device
OLDNEW
« no previous file with comments | « device/devices_app/usb/device_manager_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698