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

Side by Side Diff: device/usb/usb_device_handle_unittest.cc

Issue 1877503003: Replace libusb in the Linux/Chrome OS USB I/O path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 << "Mismatch at index " << i << "."; 243 << "Mismatch at index " << i << ".";
244 } 244 }
245 245
246 TestResultCallback release_interface; 246 TestResultCallback release_interface;
247 handle->ReleaseInterface(1, release_interface.callback()); 247 handle->ReleaseInterface(1, release_interface.callback());
248 ASSERT_TRUE(release_interface.WaitForResult()); 248 ASSERT_TRUE(release_interface.WaitForResult());
249 249
250 handle->Close(); 250 handle->Close();
251 } 251 }
252 252
253 TEST_F(UsbDeviceHandleTest, ControlTransfer) {
254 if (!UsbTestGadget::IsTestEnabled())
255 return;
256
257 scoped_ptr<UsbTestGadget> gadget =
258 UsbTestGadget::Claim(io_thread_->task_runner());
259 ASSERT_TRUE(gadget.get());
260
261 TestOpenCallback open_device;
262 gadget->GetDevice()->Open(open_device.callback());
263 scoped_refptr<UsbDeviceHandle> handle = open_device.WaitForResult();
264 ASSERT_TRUE(handle.get());
265
266 scoped_refptr<net::IOBufferWithSize> buffer(new net::IOBufferWithSize(255));
267 TestCompletionCallback completion;
268 handle->ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD,
269 UsbDeviceHandle::DEVICE, 0x06, 0x0301, 0x0409, buffer,
270 buffer->size(), 0, completion.callback());
271 completion.WaitForResult();
272 ASSERT_EQ(USB_TRANSFER_COMPLETED, completion.status());
273 const char expected_str[] = "\x18\x03G\0o\0o\0g\0l\0e\0 \0I\0n\0c\0.\0";
274 EXPECT_EQ(sizeof(expected_str) - 1, completion.transferred());
275 for (size_t i = 0; i < completion.transferred(); ++i) {
276 EXPECT_EQ(expected_str[i], buffer->data()[i]) << "Mismatch at index " << i
277 << ".";
278 }
279
280 handle->Close();
281 }
282
253 TEST_F(UsbDeviceHandleTest, SetInterfaceAlternateSetting) { 283 TEST_F(UsbDeviceHandleTest, SetInterfaceAlternateSetting) {
254 if (!UsbTestGadget::IsTestEnabled()) { 284 if (!UsbTestGadget::IsTestEnabled()) {
255 return; 285 return;
256 } 286 }
257 287
258 scoped_ptr<UsbTestGadget> gadget = 288 scoped_ptr<UsbTestGadget> gadget =
259 UsbTestGadget::Claim(io_thread_->task_runner()); 289 UsbTestGadget::Claim(io_thread_->task_runner());
260 ASSERT_TRUE(gadget.get()); 290 ASSERT_TRUE(gadget.get());
261 ASSERT_TRUE(gadget->SetType(UsbTestGadget::ECHO)); 291 ASSERT_TRUE(gadget->SetType(UsbTestGadget::ECHO));
262 292
(...skipping 13 matching lines...) Expand all
276 TestResultCallback release_interface; 306 TestResultCallback release_interface;
277 handle->ReleaseInterface(2, release_interface.callback()); 307 handle->ReleaseInterface(2, release_interface.callback());
278 ASSERT_TRUE(release_interface.WaitForResult()); 308 ASSERT_TRUE(release_interface.WaitForResult());
279 309
280 handle->Close(); 310 handle->Close();
281 } 311 }
282 312
283 } // namespace 313 } // namespace
284 314
285 } // namespace device 315 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698