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/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");
362 EXPECT_CALL(mock_device(), GetConfiguration());
365 device
->GetDeviceInfo(base::Bind(&ExpectDeviceInfoAndThen
,
366 mock_device().guid(), 0x1234, 0x5678, "ACME",
367 "Frobinator", "ABCDEF", loop
.QuitClosure()));
370 EXPECT_CALL(mock_handle(), Close());
373 TEST_F(USBDeviceImplTest
, SetInvalidConfiguration
) {
374 DevicePtr device
= GetMockDeviceProxy();
376 EXPECT_CALL(mock_handle(), SetConfiguration(42, _
));
378 // SetConfiguration should fail because 42 is not a valid mock configuration.
380 device
->SetConfiguration(
381 42, base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
384 EXPECT_CALL(mock_handle(), Close());
387 TEST_F(USBDeviceImplTest
, SetValidConfiguration
) {
388 DevicePtr device
= GetMockDeviceProxy();
390 EXPECT_CALL(mock_handle(), SetConfiguration(42, _
));
392 AddMockConfig(ConfigBuilder(42));
394 // SetConfiguration should succeed because 42 is a valid mock configuration.
396 device
->SetConfiguration(
397 42, base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
400 EXPECT_CALL(mock_handle(), Close());
403 // Verify that the result of Reset() reflects the underlying UsbDeviceHandle's
404 // ResetDevice() result.
405 TEST_F(USBDeviceImplTest
, Reset
) {
406 DevicePtr device
= GetMockDeviceProxy();
408 EXPECT_CALL(mock_handle(), ResetDevice(_
));
410 set_allow_reset(true);
414 device
->Reset(base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
418 EXPECT_CALL(mock_handle(), ResetDevice(_
));
420 set_allow_reset(false);
424 device
->Reset(base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
428 EXPECT_CALL(mock_handle(), Close());
431 TEST_F(USBDeviceImplTest
, ClaimAndReleaseInterface
) {
432 DevicePtr device
= GetMockDeviceProxy();
434 // Now add a mock interface #1.
435 AddMockConfig(ConfigBuilder(0).AddInterface(1, 0, 1, 2, 3));
437 EXPECT_CALL(mock_handle(), ClaimInterface(2, _
));
440 // Try to claim an invalid interface and expect failure.
442 device
->ClaimInterface(
443 2, base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
447 EXPECT_CALL(mock_handle(), ClaimInterface(1, _
));
451 device
->ClaimInterface(
452 1, base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
456 EXPECT_CALL(mock_handle(), ReleaseInterface(2));
459 // Releasing a non-existent interface should fail.
461 device
->ReleaseInterface(
462 2, base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
466 EXPECT_CALL(mock_handle(), ReleaseInterface(1));
469 // Now this should release the claimed interface and close the handle.
471 device
->ReleaseInterface(
472 1, base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
476 EXPECT_CALL(mock_handle(), Close());
479 TEST_F(USBDeviceImplTest
, SetInterfaceAlternateSetting
) {
480 DevicePtr device
= GetMockDeviceProxy();
482 AddMockConfig(ConfigBuilder(0)
483 .AddInterface(1, 0, 1, 2, 3)
484 .AddInterface(1, 42, 1, 2, 3)
485 .AddInterface(2, 0, 1, 2, 3));
487 EXPECT_CALL(mock_handle(), SetInterfaceAlternateSetting(1, 42, _
));
491 device
->SetInterfaceAlternateSetting(
492 1, 42, base::Bind(&ExpectResultAndThen
, true, loop
.QuitClosure()));
496 EXPECT_CALL(mock_handle(), SetInterfaceAlternateSetting(1, 100, _
));
500 device
->SetInterfaceAlternateSetting(
501 1, 100, base::Bind(&ExpectResultAndThen
, false, loop
.QuitClosure()));
505 EXPECT_CALL(mock_handle(), Close());
508 TEST_F(USBDeviceImplTest
, ControlTransfer
) {
509 DevicePtr device
= GetMockDeviceProxy();
511 std::vector
<uint8_t> fake_data
;
512 fake_data
.push_back(41);
513 fake_data
.push_back(42);
514 fake_data
.push_back(43);
516 AddMockInboundData(fake_data
);
518 EXPECT_CALL(mock_handle(),
519 ControlTransfer(USB_DIRECTION_INBOUND
, UsbDeviceHandle::STANDARD
,
520 UsbDeviceHandle::DEVICE
, 5, 6, 7, _
, _
, 0, _
));
523 auto params
= ControlTransferParams::New();
524 params
->type
= CONTROL_TRANSFER_TYPE_STANDARD
;
525 params
->recipient
= CONTROL_TRANSFER_RECIPIENT_DEVICE
;
530 device
->ControlTransferIn(
531 params
.Pass(), static_cast<uint32_t>(fake_data
.size()), 0,
532 base::Bind(&ExpectTransferInAndThen
, TRANSFER_STATUS_COMPLETED
,
533 fake_data
, loop
.QuitClosure()));
537 AddMockConfig(ConfigBuilder(0).AddInterface(7, 0, 1, 2, 3));
538 AddMockOutboundData(fake_data
);
540 EXPECT_CALL(mock_handle(),
541 ControlTransfer(USB_DIRECTION_OUTBOUND
, UsbDeviceHandle::STANDARD
,
542 UsbDeviceHandle::INTERFACE
, 5, 6, 7, _
, _
, 0, _
));
545 auto params
= ControlTransferParams::New();
546 params
->type
= CONTROL_TRANSFER_TYPE_STANDARD
;
547 params
->recipient
= CONTROL_TRANSFER_RECIPIENT_INTERFACE
;
552 device
->ControlTransferOut(
553 params
.Pass(), mojo::Array
<uint8_t>::From(fake_data
), 0,
554 base::Bind(&ExpectTransferStatusAndThen
, TRANSFER_STATUS_COMPLETED
,
555 loop
.QuitClosure()));
559 EXPECT_CALL(mock_handle(), Close());
562 TEST_F(USBDeviceImplTest
, BulkTransfer
) {
563 DevicePtr device
= GetMockDeviceProxy();
565 std::string message1
= "say hello please";
566 std::vector
<uint8_t> fake_outbound_data(message1
.size());
567 std::copy(message1
.begin(), message1
.end(), fake_outbound_data
.begin());
569 std::string message2
= "hello world!";
570 std::vector
<uint8_t> fake_inbound_data(message2
.size());
571 std::copy(message2
.begin(), message2
.end(), fake_inbound_data
.begin());
573 AddMockConfig(ConfigBuilder(0).AddInterface(7, 0, 1, 2, 3));
574 AddMockOutboundData(fake_outbound_data
);
575 AddMockInboundData(fake_inbound_data
);
577 EXPECT_CALL(mock_handle(), BulkTransfer(USB_DIRECTION_OUTBOUND
, 0, _
,
578 fake_outbound_data
.size(), 0, _
));
582 device
->BulkTransferOut(
583 0, mojo::Array
<uint8_t>::From(fake_outbound_data
), 0,
584 base::Bind(&ExpectTransferStatusAndThen
, TRANSFER_STATUS_COMPLETED
,
585 loop
.QuitClosure()));
589 EXPECT_CALL(mock_handle(), BulkTransfer(USB_DIRECTION_INBOUND
, 0, _
,
590 fake_inbound_data
.size(), 0, _
));
594 device
->BulkTransferIn(
595 0, static_cast<uint32_t>(fake_inbound_data
.size()), 0,
596 base::Bind(&ExpectTransferInAndThen
, TRANSFER_STATUS_COMPLETED
,
597 fake_inbound_data
, loop
.QuitClosure()));
601 EXPECT_CALL(mock_handle(), Close());
604 TEST_F(USBDeviceImplTest
, InterruptTransfer
) {
605 DevicePtr device
= GetMockDeviceProxy();
607 std::string message1
= "say hello please";
608 std::vector
<uint8_t> fake_outbound_data(message1
.size());
609 std::copy(message1
.begin(), message1
.end(), fake_outbound_data
.begin());
611 std::string message2
= "hello world!";
612 std::vector
<uint8_t> fake_inbound_data(message2
.size());
613 std::copy(message2
.begin(), message2
.end(), fake_inbound_data
.begin());
615 AddMockConfig(ConfigBuilder(0).AddInterface(7, 0, 1, 2, 3));
616 AddMockOutboundData(fake_outbound_data
);
617 AddMockInboundData(fake_inbound_data
);
619 EXPECT_CALL(mock_handle(),
620 InterruptTransfer(USB_DIRECTION_OUTBOUND
, 0, _
,
621 fake_outbound_data
.size(), 0, _
));
625 device
->InterruptTransferOut(
626 0, mojo::Array
<uint8_t>::From(fake_outbound_data
), 0,
627 base::Bind(&ExpectTransferStatusAndThen
, TRANSFER_STATUS_COMPLETED
,
628 loop
.QuitClosure()));
632 EXPECT_CALL(mock_handle(), InterruptTransfer(USB_DIRECTION_INBOUND
, 0, _
,
633 fake_inbound_data
.size(), 0, _
));
637 device
->InterruptTransferIn(
638 0, static_cast<uint32_t>(fake_inbound_data
.size()), 0,
639 base::Bind(&ExpectTransferInAndThen
, TRANSFER_STATUS_COMPLETED
,
640 fake_inbound_data
, loop
.QuitClosure()));
644 EXPECT_CALL(mock_handle(), Close());
647 TEST_F(USBDeviceImplTest
, IsochronousTransfer
) {
648 DevicePtr device
= GetMockDeviceProxy();
650 std::string outbound_packet_data
= "aaaaaaaabbbbbbbbccccccccdddddddd";
651 std::vector
<uint8_t> fake_outbound_packets(outbound_packet_data
.size());
652 std::copy(outbound_packet_data
.begin(), outbound_packet_data
.end(),
653 fake_outbound_packets
.begin());
655 std::string inbound_packet_data
= "ddddddddccccccccbbbbbbbbaaaaaaaa";
656 std::vector
<uint8_t> fake_inbound_packets(inbound_packet_data
.size());
657 std::copy(inbound_packet_data
.begin(), inbound_packet_data
.end(),
658 fake_inbound_packets
.begin());
660 AddMockConfig(ConfigBuilder(0).AddInterface(7, 0, 1, 2, 3));
661 AddMockOutboundData(fake_outbound_packets
);
662 AddMockInboundData(fake_inbound_packets
);
664 EXPECT_CALL(mock_handle(),
665 IsochronousTransfer(USB_DIRECTION_OUTBOUND
, 0, _
,
666 fake_outbound_packets
.size(), 4, 8, 0, _
));
670 mojo::Array
<mojo::Array
<uint8_t>> packets
=
671 mojo::Array
<mojo::Array
<uint8_t>>::New(4);
672 for (size_t i
= 0; i
< 4; ++i
) {
673 std::vector
<uint8_t> bytes(8);
674 std::copy(outbound_packet_data
.begin() + i
* 8,
675 outbound_packet_data
.begin() + i
* 8 + 8, bytes
.begin());
676 packets
[i
].Swap(&bytes
);
678 device
->IsochronousTransferOut(
679 0, packets
.Pass(), 0,
680 base::Bind(&ExpectTransferStatusAndThen
, TRANSFER_STATUS_COMPLETED
,
681 loop
.QuitClosure()));
685 EXPECT_CALL(mock_handle(),
686 IsochronousTransfer(USB_DIRECTION_INBOUND
, 0, _
,
687 fake_inbound_packets
.size(), 4, 8, 0, _
));
691 std::vector
<std::vector
<uint8_t>> packets(4);
692 for (size_t i
= 0; i
< 4; ++i
) {
693 packets
[i
].resize(8);
694 std::copy(inbound_packet_data
.begin() + i
* 8,
695 inbound_packet_data
.begin() + i
* 8 + 8, packets
[i
].begin());
697 device
->IsochronousTransferIn(
698 0, 4, 8, 0, base::Bind(&ExpectPacketsAndThen
, TRANSFER_STATUS_COMPLETED
,
699 packets
, loop
.QuitClosure()));
703 EXPECT_CALL(mock_handle(), Close());
707 } // namespace device