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

Side by Side Diff: device/hid/hid_connection_unittest.cc

Issue 1314273002: Manage UsbService lifetime in DeviceClient implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/devices_app/devices_app.cc ('k') | device/test/test_device_client.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 (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/scoped_observer.h" 12 #include "base/scoped_observer.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/test_io_thread.h" 14 #include "base/test/test_io_thread.h"
15 #include "device/hid/hid_connection.h" 15 #include "device/hid/hid_connection.h"
16 #include "device/hid/hid_service.h" 16 #include "device/hid/hid_service.h"
17 #include "device/test/test_device_client.h"
17 #include "device/test/usb_test_gadget.h" 18 #include "device/test/usb_test_gadget.h"
18 #include "device/usb/usb_device.h" 19 #include "device/usb/usb_device.h"
19 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace device { 23 namespace device {
23 24
24 namespace { 25 namespace {
25 26
26 using net::IOBufferWithSize; 27 using net::IOBufferWithSize;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 144
144 } // namespace 145 } // namespace
145 146
146 class HidConnectionTest : public testing::Test { 147 class HidConnectionTest : public testing::Test {
147 protected: 148 protected:
148 void SetUp() override { 149 void SetUp() override {
149 if (!UsbTestGadget::IsTestEnabled()) return; 150 if (!UsbTestGadget::IsTestEnabled()) return;
150 151
151 message_loop_.reset(new base::MessageLoopForUI()); 152 message_loop_.reset(new base::MessageLoopForUI());
152 io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart)); 153 io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart));
154 device_client_.reset(new TestDeviceClient(io_thread_->task_runner()));
153 155
154 service_ = HidService::GetInstance(io_thread_->task_runner()); 156 service_ = HidService::GetInstance(io_thread_->task_runner());
155 ASSERT_TRUE(service_); 157 ASSERT_TRUE(service_);
156 158
157 test_gadget_ = UsbTestGadget::Claim(io_thread_->task_runner()); 159 test_gadget_ = UsbTestGadget::Claim(io_thread_->task_runner());
158 ASSERT_TRUE(test_gadget_); 160 ASSERT_TRUE(test_gadget_);
159 ASSERT_TRUE(test_gadget_->SetType(UsbTestGadget::HID_ECHO)); 161 ASSERT_TRUE(test_gadget_->SetType(UsbTestGadget::HID_ECHO));
160 162
161 DeviceCatcher device_catcher(service_, 163 DeviceCatcher device_catcher(service_,
162 test_gadget_->GetDevice()->serial_number()); 164 test_gadget_->GetDevice()->serial_number());
163 device_id_ = device_catcher.WaitForDevice(); 165 device_id_ = device_catcher.WaitForDevice();
164 ASSERT_NE(device_id_, kInvalidHidDeviceId); 166 ASSERT_NE(device_id_, kInvalidHidDeviceId);
165 } 167 }
166 168
167 scoped_ptr<base::MessageLoopForUI> message_loop_; 169 scoped_ptr<base::MessageLoopForUI> message_loop_;
168 scoped_ptr<base::TestIOThread> io_thread_; 170 scoped_ptr<base::TestIOThread> io_thread_;
171 scoped_ptr<TestDeviceClient> device_client_;
169 HidService* service_; 172 HidService* service_;
170 scoped_ptr<UsbTestGadget> test_gadget_; 173 scoped_ptr<UsbTestGadget> test_gadget_;
171 HidDeviceId device_id_; 174 HidDeviceId device_id_;
172 }; 175 };
173 176
174 TEST_F(HidConnectionTest, ReadWrite) { 177 TEST_F(HidConnectionTest, ReadWrite) {
175 if (!UsbTestGadget::IsTestEnabled()) return; 178 if (!UsbTestGadget::IsTestEnabled()) return;
176 179
177 TestConnectCallback connect_callback; 180 TestConnectCallback connect_callback;
178 service_->Connect(device_id_, connect_callback.callback()); 181 service_->Connect(device_id_, connect_callback.callback());
(...skipping 19 matching lines...) Expand all
198 ASSERT_EQ(0, read_callback.buffer()->data()[0]); 201 ASSERT_EQ(0, read_callback.buffer()->data()[0]);
199 for (unsigned char j = 1; j < kBufferSize; ++j) { 202 for (unsigned char j = 1; j < kBufferSize; ++j) {
200 ASSERT_EQ(i + j - 1, read_callback.buffer()->data()[j]); 203 ASSERT_EQ(i + j - 1, read_callback.buffer()->data()[j]);
201 } 204 }
202 } 205 }
203 206
204 conn->Close(); 207 conn->Close();
205 } 208 }
206 209
207 } // namespace device 210 } // namespace device
OLDNEW
« no previous file with comments | « device/devices_app/devices_app.cc ('k') | device/test/test_device_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698