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
3 // found in the LICENSE file.
10 #include "base/bind.h"
11 #include "base/macros.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "base/stl_util.h"
15 #include "device/devices_app/usb/device_impl.h"
16 #include "device/usb/mock_usb_device.h"
17 #include "device/usb/mock_usb_device_handle.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h"
21 using ::testing::Invoke
;
31 ConfigBuilder(uint8_t value
) { config_
.configuration_value
= value
; }
33 ConfigBuilder
& AddInterface(uint8_t interface_number
,
34 uint8_t alternate_setting
,
36 uint8_t subclass_code
,
37 uint8_t protocol_code
) {
38 UsbInterfaceDescriptor interface
;
39 interface
.interface_number
= interface_number
;
40 interface
.alternate_setting
= alternate_setting
;
41 interface
.interface_class
= class_code
;
42 interface
.interface_subclass
= subclass_code
;
43 interface
.interface_protocol
= protocol_code
;
44 config_
.interfaces
.push_back(interface
);
48 const UsbConfigDescriptor
& config() const { return config_
; }
51 UsbConfigDescriptor config_
;
54 void ExpectDeviceInfoAndThen(const std::string
& guid
,
57 const std::string
& manufacturer
,
58 const std::string
& product
,
59 const std::string
& serial_number
,
60 const base::Closure
& continuation
,
61 DeviceInfoPtr device_info
) {
62 EXPECT_EQ(guid
, device_info
->guid
);
63 EXPECT_EQ(vendor_id
, device_info
->vendor_id
);
64 EXPECT_EQ(product_id
, device_info
->product_id
);
65 EXPECT_EQ(manufacturer
, device_info
->manufacturer
);
66 EXPECT_EQ(product
, device_info
->product
);
67 EXPECT_EQ(serial_number
, device_info
->serial_number
);
71 void ExpectResultAndThen(bool expected_result
,
72 const base::Closure
& continuation
,
74 EXPECT_EQ(expected_result
, actual_result
);
78 void ExpectTransferInAndThen(TransferStatus expected_status
,
79 const std::vector
<uint8_t>& expected_bytes
,
80 const base::Closure
& continuation
,
81 TransferStatus actual_status
,
82 mojo::Array
<uint8_t> actual_bytes
) {
83 EXPECT_EQ(expected_status
, actual_status
);
84 ASSERT_EQ(expected_bytes
.size(), actual_bytes
.size());
85 for (size_t i
= 0; i
< actual_bytes
.size(); ++i
) {
86 EXPECT_EQ(expected_bytes
[i
], actual_bytes
[i
])
87 << "Contents differ at index: " << i
;
92 void ExpectPacketsAndThen(
93 TransferStatus expected_status
,
94 const std::vector
<std::vector
<uint8_t>>& expected_packets
,
95 const base::Closure
& continuation
,
96 TransferStatus actual_status
,
97 mojo::Array
<mojo::Array
<uint8_t>> actual_packets
) {
98 EXPECT_EQ(expected_status
, actual_status
);
99 ASSERT_EQ(expected_packets
.size(), actual_packets
.size());
100 for (size_t i
= 0; i
< expected_packets
.size(); ++i
) {
101 EXPECT_EQ(expected_packets
[i
].size(), actual_packets
[i
].size())
102 << "Packet sizes differ at index: " << i
;
103 for (size_t j
= 0; j
< expected_packets
[i
].size(); ++j
) {
104 EXPECT_EQ(expected_packets
[i
][j
], actual_packets
[i
][j
])
105 << "Contents of packet " << i
<< " differ at index " << j
;
111 void ExpectTransferStatusAndThen(TransferStatus expected_status
,
112 const base::Closure
& continuation
,
113 TransferStatus actual_status
) {
114 EXPECT_EQ(expected_status
, actual_status
);
118 class USBDeviceImplTest
: public testing::Test
{
121 : message_loop_(new base::MessageLoop
),
122 is_device_open_(false),
124 current_config_(0) {}
126 ~USBDeviceImplTest() override
{}
129 MockUsbDevice
& mock_device() { return *mock_device_
.get(); }
130 bool is_device_open() const { return is_device_open_
; }
131 MockUsbDeviceHandle
& mock_handle() { return *mock_handle_
.get(); }
133 void set_allow_reset(bool allow_reset
) { allow_reset_
= allow_reset
; }
135 // Creates a mock device and binds a Device proxy to a Device service impl
136 // wrapping the mock device.
137 DevicePtr
GetMockDeviceProxy(uint16_t vendor_id
,
139 const std::string
& manufacturer
,
140 const std::string
& product
,
141 const std::string
& serial
) {
142 is_device_open_
= true;
145 new MockUsbDevice(vendor_id
, product_id
, manufacturer
, product
, serial
);
146 mock_handle_
= new MockUsbDeviceHandle(mock_device_
.get());
149 new DeviceImpl(mock_handle_
, mojo::GetProxy(&proxy
));
151 // Set up mock handle calls to respond based on mock device configs
152 // established by the test.
153 ON_CALL(mock_handle(), Close())
154 .WillByDefault(Invoke(this, &USBDeviceImplTest::CloseMockHandle
));
155 ON_CALL(mock_handle(), SetConfiguration(_
, _
))
156 .WillByDefault(Invoke(this, &USBDeviceImplTest::SetConfiguration
));
157 ON_CALL(mock_handle(), ClaimInterface(_
, _
))
158 .WillByDefault(Invoke(this, &USBDeviceImplTest::ClaimInterface
));
159 ON_CALL(mock_handle(), ReleaseInterface(_
))
160 .WillByDefault(Invoke(this, &USBDeviceImplTest::ReleaseInterface
));
161 ON_CALL(mock_handle(), SetInterfaceAlternateSetting(_
, _
, _
))
163 Invoke(this, &USBDeviceImplTest::SetInterfaceAlternateSetting
));
164 ON_CALL(mock_handle(), ResetDevice(_
))
165 .WillByDefault(Invoke(this, &USBDeviceImplTest::ResetDevice
));
166 ON_CALL(mock_handle(), ControlTransfer(_
, _
, _
, _
, _
, _
, _
, _
, _
, _
))
167 .WillByDefault(Invoke(this, &USBDeviceImplTest::ControlTransfer
));
168 ON_CALL(mock_handle(), BulkTransfer(_
, _
, _
, _
, _
, _
))
170 Invoke(this, &USBDeviceImplTest::BulkOrInterruptTransfer
));
171 ON_CALL(mock_handle(), InterruptTransfer(_
, _
, _
, _
, _
, _
))
173 Invoke(this, &USBDeviceImplTest::BulkOrInterruptTransfer
));
174 ON_CALL(mock_handle(), IsochronousTransfer(_
, _
, _
, _
, _
, _
, _
, _
))
175 .WillByDefault(Invoke(this, &USBDeviceImplTest::IsochronousTransfer
));
180 DevicePtr
GetMockDeviceProxy() {
181 return GetMockDeviceProxy(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF");
184 void AddMockConfig(const ConfigBuilder
& builder
) {
185 const UsbConfigDescriptor
& config
= builder
.config();
186 DCHECK(!ContainsKey(mock_configs_
, config
.configuration_value
));
187 mock_configs_
[config
.configuration_value
] = config
;
190 void AddMockInboundData(const std::vector
<uint8_t>& data
) {
191 mock_inbound_data_
.push(data
);
194 void AddMockOutboundData(const std::vector
<uint8_t>& data
) {
195 mock_outbound_data_
.push(data
);
199 void CloseMockHandle() {
200 EXPECT_TRUE(is_device_open_
);
201 is_device_open_
= false;
204 void SetConfiguration(uint8_t value
,
205 const UsbDeviceHandle::ResultCallback
& callback
) {
206 if (mock_configs_
.find(value
) != mock_configs_
.end()) {
207 current_config_
= value
;
214 void ClaimInterface(uint8_t interface_number
,
215 const UsbDeviceHandle::ResultCallback
& callback
) {
216 for (const auto& config
: mock_configs_
) {
217 for (const auto& interface
: config
.second
.interfaces
) {
218 if (interface
.interface_number
== interface_number
) {
219 claimed_interfaces_
.insert(interface_number
);
228 bool ReleaseInterface(uint8_t interface_number
) {
229 if (ContainsKey(claimed_interfaces_
, interface_number
)) {
230 claimed_interfaces_
.erase(interface_number
);
236 void SetInterfaceAlternateSetting(
237 uint8_t interface_number
,
238 uint8_t alternate_setting
,
239 const UsbDeviceHandle::ResultCallback
& callback
) {
240 for (const auto& config
: mock_configs_
) {
241 for (const auto& interface
: config
.second
.interfaces
) {
242 if (interface
.interface_number
== interface_number
&&
243 interface
.alternate_setting
== alternate_setting
) {
252 void ResetDevice(const UsbDeviceHandle::ResultCallback
& callback
) {
253 callback
.Run(allow_reset_
);
256 void InboundTransfer(const UsbDeviceHandle::TransferCallback
& callback
) {
257 ASSERT_GE(mock_inbound_data_
.size(), 1u);
258 const std::vector
<uint8_t>& bytes
= mock_inbound_data_
.front();
259 size_t length
= bytes
.size();
260 scoped_refptr
<net::IOBuffer
> buffer
= new net::IOBuffer(length
);
261 std::copy(bytes
.begin(), bytes
.end(), buffer
->data());
262 mock_inbound_data_
.pop();
263 callback
.Run(USB_TRANSFER_COMPLETED
, buffer
, length
);
266 void OutboundTransfer(scoped_refptr
<net::IOBuffer
> buffer
,
268 const UsbDeviceHandle::TransferCallback
& callback
) {
269 ASSERT_GE(mock_outbound_data_
.size(), 1u);
270 const std::vector
<uint8_t>& bytes
= mock_outbound_data_
.front();
271 ASSERT_EQ(bytes
.size(), length
);
272 for (size_t i
= 0; i
< length
; ++i
) {
273 EXPECT_EQ(bytes
[i
], buffer
->data()[i
])
274 << "Contents differ at index: " << i
;
276 mock_outbound_data_
.pop();
277 callback
.Run(USB_TRANSFER_COMPLETED
, buffer
, length
);
280 void ControlTransfer(UsbEndpointDirection direction
,
281 UsbDeviceHandle::TransferRequestType request_type
,
282 UsbDeviceHandle::TransferRecipient recipient
,
286 scoped_refptr
<net::IOBuffer
> buffer
,
288 unsigned int timeout
,
289 const UsbDeviceHandle::TransferCallback
& callback
) {
290 if (direction
== USB_DIRECTION_INBOUND
)
291 InboundTransfer(callback
);
293 OutboundTransfer(buffer
, length
, callback
);
296 void BulkOrInterruptTransfer(
297 UsbEndpointDirection direction
,
299 scoped_refptr
<net::IOBuffer
> buffer
,
301 unsigned int timeout
,
302 const UsbDeviceHandle::TransferCallback
& callback
) {
303 if (direction
== USB_DIRECTION_INBOUND
)
304 InboundTransfer(callback
);
306 OutboundTransfer(buffer
, length
, callback
);
309 void IsochronousTransfer(UsbEndpointDirection direction
,
311 scoped_refptr
<net::IOBuffer
> buffer
,
313 unsigned int packets
,
314 unsigned int packet_length
,
315 unsigned int timeout
,
316 const UsbDeviceHandle::TransferCallback
& callback
) {
317 if (direction
== USB_DIRECTION_INBOUND
)
318 InboundTransfer(callback
);
320 OutboundTransfer(buffer
, length
, callback
);
323 scoped_ptr
<base::MessageLoop
> message_loop_
;
324 scoped_refptr
<MockUsbDevice
> mock_device_
;
325 scoped_refptr
<MockUsbDeviceHandle
> mock_handle_
;
326 bool is_device_open_
;
329 std::map
<uint8_t, UsbConfigDescriptor
> mock_configs_
;
330 uint8_t current_config_
;
332 std::queue
<std::vector
<uint8_t>> mock_inbound_data_
;
333 std::queue
<std::vector
<uint8_t>> mock_outbound_data_
;
335 std::set
<uint8_t> claimed_interfaces_
;
337 DISALLOW_COPY_AND_ASSIGN(USBDeviceImplTest
);
342 TEST_F(USBDeviceImplTest
, Close
) {
343 DevicePtr device
= GetMockDeviceProxy();
345 EXPECT_TRUE(is_device_open());
347 EXPECT_CALL(mock_handle(), Close());
350 device
->Close(loop
.QuitClosure());
353 EXPECT_FALSE(is_device_open());
356 // Test that the information returned via the Device::GetDeviceInfo matches that
357 // of the underlying device.
358 TEST_F(USBDeviceImplTest
, GetDeviceInfo
) {
360 GetMockDeviceProxy(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF");
363 device
->GetDeviceInfo(base::Bind(&ExpectDeviceInfoAndThen
,
364 mock_device().guid(), 0x1234, 0x5678, "ACME",
365 "Frobinator", "ABCDEF", loop
.QuitClosure()));
368 EXPECT_CALL(mock_handle(), Close());
371 TEST_F(USBDeviceImplTest
, SetInvalidConfiguration
) {
372 DevicePtr device
= GetMockDeviceProxy();
374 EXPECT_CALL(mock_handle(), SetConfiguration(42, _
));
376 // SetConfiguration should fail because 42 is not a valid mock configuration.
378 device
->SetConfiguration(
379 42, base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
382 EXPECT_CALL(mock_handle(), Close());
385 TEST_F(USBDeviceImplTest
, SetValidConfiguration
) {
386 DevicePtr device
= GetMockDeviceProxy();
388 EXPECT_CALL(mock_handle(), SetConfiguration(42, _
));
390 AddMockConfig(ConfigBuilder(42));
392 // SetConfiguration should succeed because 42 is a valid mock configuration.
394 device
->SetConfiguration(
395 42, base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
398 EXPECT_CALL(mock_handle(), Close());
401 // Verify that the result of Reset() reflects the underlying UsbDeviceHandle's
402 // ResetDevice() result.
403 TEST_F(USBDeviceImplTest
, Reset
) {
404 DevicePtr device
= GetMockDeviceProxy();
406 EXPECT_CALL(mock_handle(), ResetDevice(_
));
408 set_allow_reset(true);
412 device
->Reset(base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
416 EXPECT_CALL(mock_handle(), ResetDevice(_
));
418 set_allow_reset(false);
422 device
->Reset(base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
426 EXPECT_CALL(mock_handle(), Close());
429 TEST_F(USBDeviceImplTest
, ClaimAndReleaseInterface
) {
430 DevicePtr device
= GetMockDeviceProxy();
432 // Now add a mock interface #1.
433 AddMockConfig(ConfigBuilder(0).AddInterface(1, 0, 1, 2, 3));
435 EXPECT_CALL(mock_handle(), ClaimInterface(2, _
));
438 // Try to claim an invalid interface and expect failure.
440 device
->ClaimInterface(
441 2, base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
445 EXPECT_CALL(mock_handle(), ClaimInterface(1, _
));
449 device
->ClaimInterface(
450 1, base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
454 EXPECT_CALL(mock_handle(), ReleaseInterface(2));
457 // Releasing a non-existent interface should fail.
459 device
->ReleaseInterface(
460 2, base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
464 EXPECT_CALL(mock_handle(), ReleaseInterface(1));
467 // Now this should release the claimed interface and close the handle.
469 device
->ReleaseInterface(
470 1, base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
474 EXPECT_CALL(mock_handle(), Close());
477 TEST_F(USBDeviceImplTest
, SetInterfaceAlternateSetting
) {
478 DevicePtr device
= GetMockDeviceProxy();
480 AddMockConfig(ConfigBuilder(0)
481 .AddInterface(1, 0, 1, 2, 3)
482 .AddInterface(1, 42, 1, 2, 3)
483 .AddInterface(2, 0, 1, 2, 3));
485 EXPECT_CALL(mock_handle(), SetInterfaceAlternateSetting(1, 42, _
));
489 device
->SetInterfaceAlternateSetting(
490 1, 42, base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
494 EXPECT_CALL(mock_handle(), SetInterfaceAlternateSetting(1, 100, _
));
498 device
->SetInterfaceAlternateSetting(
499 1, 100, base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
503 EXPECT_CALL(mock_handle(), Close());
506 TEST_F(USBDeviceImplTest
, ControlTransfer
) {
507 DevicePtr device
= GetMockDeviceProxy();
509 std::vector
<uint8_t> fake_data
;
510 fake_data
.push_back(41);
511 fake_data
.push_back(42);
512 fake_data
.push_back(43);
514 AddMockInboundData(fake_data
);
516 EXPECT_CALL(mock_handle(),
517 ControlTransfer(USB_DIRECTION_INBOUND
, UsbDeviceHandle::STANDARD
,
518 UsbDeviceHandle::DEVICE
, 5, 6, 7, _
, _
, 0, _
));
521 auto params
= ControlTransferParams::New();
522 params
->type
= CONTROL_TRANSFER_TYPE_STANDARD
;
523 params
->recipient
= CONTROL_TRANSFER_RECIPIENT_DEVICE
;
528 device
->ControlTransferIn(
529 params
.Pass(), static_cast<uint32_t>(fake_data
.size()), 0,
530 base::Bind(&ExpectTransferInAndThen
, TRANSFER_STATUS_COMPLETED
,
531 fake_data
, loop
.QuitClosure()));
535 AddMockConfig(ConfigBuilder(0).AddInterface(7, 0, 1, 2, 3));
536 AddMockOutboundData(fake_data
);
538 EXPECT_CALL(mock_handle(),
539 ControlTransfer(USB_DIRECTION_OUTBOUND
, UsbDeviceHandle::STANDARD
,
540 UsbDeviceHandle::INTERFACE
, 5, 6, 7, _
, _
, 0, _
));
543 auto params
= ControlTransferParams::New();
544 params
->type
= CONTROL_TRANSFER_TYPE_STANDARD
;
545 params
->recipient
= CONTROL_TRANSFER_RECIPIENT_INTERFACE
;
550 device
->ControlTransferOut(
551 params
.Pass(), mojo::Array
<uint8_t>::From(fake_data
), 0,
552 base::Bind(&ExpectTransferStatusAndThen
, TRANSFER_STATUS_COMPLETED
,
553 loop
.QuitClosure()));
557 EXPECT_CALL(mock_handle(), Close());
560 TEST_F(USBDeviceImplTest
, BulkTransfer
) {
561 DevicePtr device
= GetMockDeviceProxy();
563 std::string message1
= "say hello please";
564 std::vector
<uint8_t> fake_outbound_data(message1
.size());
565 std::copy(message1
.begin(), message1
.end(), fake_outbound_data
.begin());
567 std::string message2
= "hello world!";
568 std::vector
<uint8_t> fake_inbound_data(message2
.size());
569 std::copy(message2
.begin(), message2
.end(), fake_inbound_data
.begin());
571 AddMockConfig(ConfigBuilder(0).AddInterface(7, 0, 1, 2, 3));
572 AddMockOutboundData(fake_outbound_data
);
573 AddMockInboundData(fake_inbound_data
);
575 EXPECT_CALL(mock_handle(), BulkTransfer(USB_DIRECTION_OUTBOUND
, 0, _
,
576 fake_outbound_data
.size(), 0, _
));
580 device
->BulkTransferOut(
581 0, mojo::Array
<uint8_t>::From(fake_outbound_data
), 0,
582 base::Bind(&ExpectTransferStatusAndThen
, TRANSFER_STATUS_COMPLETED
,
583 loop
.QuitClosure()));
587 EXPECT_CALL(mock_handle(), BulkTransfer(USB_DIRECTION_INBOUND
, 0, _
,
588 fake_inbound_data
.size(), 0, _
));
592 device
->BulkTransferIn(
593 0, static_cast<uint32_t>(fake_inbound_data
.size()), 0,
594 base::Bind(&ExpectTransferInAndThen
, TRANSFER_STATUS_COMPLETED
,
595 fake_inbound_data
, loop
.QuitClosure()));
599 EXPECT_CALL(mock_handle(), Close());
602 TEST_F(USBDeviceImplTest
, InterruptTransfer
) {
603 DevicePtr device
= GetMockDeviceProxy();
605 std::string message1
= "say hello please";
606 std::vector
<uint8_t> fake_outbound_data(message1
.size());
607 std::copy(message1
.begin(), message1
.end(), fake_outbound_data
.begin());
609 std::string message2
= "hello world!";
610 std::vector
<uint8_t> fake_inbound_data(message2
.size());
611 std::copy(message2
.begin(), message2
.end(), fake_inbound_data
.begin());
613 AddMockConfig(ConfigBuilder(0).AddInterface(7, 0, 1, 2, 3));
614 AddMockOutboundData(fake_outbound_data
);
615 AddMockInboundData(fake_inbound_data
);
617 EXPECT_CALL(mock_handle(),
618 InterruptTransfer(USB_DIRECTION_OUTBOUND
, 0, _
,
619 fake_outbound_data
.size(), 0, _
));
623 device
->InterruptTransferOut(
624 0, mojo::Array
<uint8_t>::From(fake_outbound_data
), 0,
625 base::Bind(&ExpectTransferStatusAndThen
, TRANSFER_STATUS_COMPLETED
,
626 loop
.QuitClosure()));
630 EXPECT_CALL(mock_handle(), InterruptTransfer(USB_DIRECTION_INBOUND
, 0, _
,
631 fake_inbound_data
.size(), 0, _
));
635 device
->InterruptTransferIn(
636 0, static_cast<uint32_t>(fake_inbound_data
.size()), 0,
637 base::Bind(&ExpectTransferInAndThen
, TRANSFER_STATUS_COMPLETED
,
638 fake_inbound_data
, loop
.QuitClosure()));
642 EXPECT_CALL(mock_handle(), Close());
645 TEST_F(USBDeviceImplTest
, IsochronousTransfer
) {
646 DevicePtr device
= GetMockDeviceProxy();
648 std::string outbound_packet_data
= "aaaaaaaabbbbbbbbccccccccdddddddd";
649 std::vector
<uint8_t> fake_outbound_packets(outbound_packet_data
.size());
650 std::copy(outbound_packet_data
.begin(), outbound_packet_data
.end(),
651 fake_outbound_packets
.begin());
653 std::string inbound_packet_data
= "ddddddddccccccccbbbbbbbbaaaaaaaa";
654 std::vector
<uint8_t> fake_inbound_packets(inbound_packet_data
.size());
655 std::copy(inbound_packet_data
.begin(), inbound_packet_data
.end(),
656 fake_inbound_packets
.begin());
658 AddMockConfig(ConfigBuilder(0).AddInterface(7, 0, 1, 2, 3));
659 AddMockOutboundData(fake_outbound_packets
);
660 AddMockInboundData(fake_inbound_packets
);
662 EXPECT_CALL(mock_handle(),
663 IsochronousTransfer(USB_DIRECTION_OUTBOUND
, 0, _
,
664 fake_outbound_packets
.size(), 4, 8, 0, _
));
668 mojo::Array
<mojo::Array
<uint8_t>> packets
=
669 mojo::Array
<mojo::Array
<uint8_t>>::New(4);
670 for (size_t i
= 0; i
< 4; ++i
) {
671 std::vector
<uint8_t> bytes(8);
672 std::copy(outbound_packet_data
.begin() + i
* 8,
673 outbound_packet_data
.begin() + i
* 8 + 8, bytes
.begin());
674 packets
[i
].Swap(&bytes
);
676 device
->IsochronousTransferOut(
677 0, packets
.Pass(), 0,
678 base::Bind(&ExpectTransferStatusAndThen
, TRANSFER_STATUS_COMPLETED
,
679 loop
.QuitClosure()));
683 EXPECT_CALL(mock_handle(),
684 IsochronousTransfer(USB_DIRECTION_INBOUND
, 0, _
,
685 fake_inbound_packets
.size(), 4, 8, 0, _
));
689 std::vector
<std::vector
<uint8_t>> packets(4);
690 for (size_t i
= 0; i
< 4; ++i
) {
691 packets
[i
].resize(8);
692 std::copy(inbound_packet_data
.begin() + i
* 8,
693 inbound_packet_data
.begin() + i
* 8 + 8, packets
[i
].begin());
695 device
->IsochronousTransferIn(
696 0, 4, 8, 0, base::Bind(&ExpectPacketsAndThen
, TRANSFER_STATUS_COMPLETED
,
697 packets
, loop
.QuitClosure()));
701 EXPECT_CALL(mock_handle(), Close());
705 } // namespace device