OLD | NEW |
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 "device/usb/mojo/device_impl.h" | 5 #include "device/usb/mojo/device_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 callback.Run(allow_reset_); | 300 callback.Run(allow_reset_); |
301 } | 301 } |
302 | 302 |
303 void InboundTransfer(const UsbDeviceHandle::TransferCallback& callback) { | 303 void InboundTransfer(const UsbDeviceHandle::TransferCallback& callback) { |
304 ASSERT_GE(mock_inbound_data_.size(), 1u); | 304 ASSERT_GE(mock_inbound_data_.size(), 1u); |
305 const std::vector<uint8_t>& bytes = mock_inbound_data_.front(); | 305 const std::vector<uint8_t>& bytes = mock_inbound_data_.front(); |
306 size_t length = bytes.size(); | 306 size_t length = bytes.size(); |
307 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(length); | 307 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(length); |
308 std::copy(bytes.begin(), bytes.end(), buffer->data()); | 308 std::copy(bytes.begin(), bytes.end(), buffer->data()); |
309 mock_inbound_data_.pop(); | 309 mock_inbound_data_.pop(); |
310 callback.Run(USB_TRANSFER_COMPLETED, buffer, length); | 310 callback.Run(UsbTransferStatus::COMPLETED, buffer, length); |
311 } | 311 } |
312 | 312 |
313 void OutboundTransfer(scoped_refptr<net::IOBuffer> buffer, | 313 void OutboundTransfer(scoped_refptr<net::IOBuffer> buffer, |
314 size_t length, | 314 size_t length, |
315 const UsbDeviceHandle::TransferCallback& callback) { | 315 const UsbDeviceHandle::TransferCallback& callback) { |
316 ASSERT_GE(mock_outbound_data_.size(), 1u); | 316 ASSERT_GE(mock_outbound_data_.size(), 1u); |
317 const std::vector<uint8_t>& bytes = mock_outbound_data_.front(); | 317 const std::vector<uint8_t>& bytes = mock_outbound_data_.front(); |
318 ASSERT_EQ(bytes.size(), length); | 318 ASSERT_EQ(bytes.size(), length); |
319 for (size_t i = 0; i < length; ++i) { | 319 for (size_t i = 0; i < length; ++i) { |
320 EXPECT_EQ(bytes[i], buffer->data()[i]) << "Contents differ at index: " | 320 EXPECT_EQ(bytes[i], buffer->data()[i]) << "Contents differ at index: " |
321 << i; | 321 << i; |
322 } | 322 } |
323 mock_outbound_data_.pop(); | 323 mock_outbound_data_.pop(); |
324 callback.Run(USB_TRANSFER_COMPLETED, buffer, length); | 324 callback.Run(UsbTransferStatus::COMPLETED, buffer, length); |
325 } | 325 } |
326 | 326 |
327 void ControlTransfer(UsbEndpointDirection direction, | 327 void ControlTransfer(UsbTransferDirection direction, |
328 UsbDeviceHandle::TransferRequestType request_type, | 328 UsbControlTransferType request_type, |
329 UsbDeviceHandle::TransferRecipient recipient, | 329 UsbControlTransferRecipient recipient, |
330 uint8_t request, | 330 uint8_t request, |
331 uint16_t value, | 331 uint16_t value, |
332 uint16_t index, | 332 uint16_t index, |
333 scoped_refptr<net::IOBuffer> buffer, | 333 scoped_refptr<net::IOBuffer> buffer, |
334 size_t length, | 334 size_t length, |
335 unsigned int timeout, | 335 unsigned int timeout, |
336 const UsbDeviceHandle::TransferCallback& callback) { | 336 const UsbDeviceHandle::TransferCallback& callback) { |
337 if (direction == USB_DIRECTION_INBOUND) | 337 if (direction == UsbTransferDirection::INBOUND) |
338 InboundTransfer(callback); | 338 InboundTransfer(callback); |
339 else | 339 else |
340 OutboundTransfer(buffer, length, callback); | 340 OutboundTransfer(buffer, length, callback); |
341 } | 341 } |
342 | 342 |
343 void GenericTransfer(UsbEndpointDirection direction, | 343 void GenericTransfer(UsbTransferDirection direction, |
344 uint8_t endpoint, | 344 uint8_t endpoint, |
345 scoped_refptr<net::IOBuffer> buffer, | 345 scoped_refptr<net::IOBuffer> buffer, |
346 size_t length, | 346 size_t length, |
347 unsigned int timeout, | 347 unsigned int timeout, |
348 const UsbDeviceHandle::TransferCallback& callback) { | 348 const UsbDeviceHandle::TransferCallback& callback) { |
349 if (direction == USB_DIRECTION_INBOUND) | 349 if (direction == UsbTransferDirection::INBOUND) |
350 InboundTransfer(callback); | 350 InboundTransfer(callback); |
351 else | 351 else |
352 OutboundTransfer(buffer, length, callback); | 352 OutboundTransfer(buffer, length, callback); |
353 } | 353 } |
354 | 354 |
355 void IsochronousTransferIn( | 355 void IsochronousTransferIn( |
356 uint8_t endpoint_number, | 356 uint8_t endpoint_number, |
357 const std::vector<uint32_t>& packet_lengths, | 357 const std::vector<uint32_t>& packet_lengths, |
358 unsigned int timeout, | 358 unsigned int timeout, |
359 const UsbDeviceHandle::IsochronousTransferCallback& callback) { | 359 const UsbDeviceHandle::IsochronousTransferCallback& callback) { |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 } | 711 } |
712 | 712 |
713 std::vector<uint8_t> fake_data; | 713 std::vector<uint8_t> fake_data; |
714 fake_data.push_back(41); | 714 fake_data.push_back(41); |
715 fake_data.push_back(42); | 715 fake_data.push_back(42); |
716 fake_data.push_back(43); | 716 fake_data.push_back(43); |
717 | 717 |
718 AddMockInboundData(fake_data); | 718 AddMockInboundData(fake_data); |
719 | 719 |
720 EXPECT_CALL(mock_handle(), | 720 EXPECT_CALL(mock_handle(), |
721 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD, | 721 ControlTransfer(UsbTransferDirection::INBOUND, |
722 UsbDeviceHandle::DEVICE, 5, 6, 7, _, _, 0, _)); | 722 UsbControlTransferType::STANDARD, |
| 723 UsbControlTransferRecipient::DEVICE, 5, 6, 7, _, |
| 724 _, 0, _)); |
723 EXPECT_CALL(permission_provider(), HasConfigurationPermission(1, _)); | 725 EXPECT_CALL(permission_provider(), HasConfigurationPermission(1, _)); |
724 | 726 |
725 { | 727 { |
726 auto params = mojom::UsbControlTransferParams::New(); | 728 auto params = mojom::UsbControlTransferParams::New(); |
727 params->type = UsbControlTransferType::STANDARD; | 729 params->type = UsbControlTransferType::STANDARD; |
728 params->recipient = UsbControlTransferRecipient::DEVICE; | 730 params->recipient = UsbControlTransferRecipient::DEVICE; |
729 params->request = 5; | 731 params->request = 5; |
730 params->value = 6; | 732 params->value = 6; |
731 params->index = 7; | 733 params->index = 7; |
732 base::RunLoop loop; | 734 base::RunLoop loop; |
733 device->ControlTransferIn(std::move(params), | 735 device->ControlTransferIn(std::move(params), |
734 static_cast<uint32_t>(fake_data.size()), 0, | 736 static_cast<uint32_t>(fake_data.size()), 0, |
735 base::Bind(&ExpectTransferInAndThen, | 737 base::Bind(&ExpectTransferInAndThen, |
736 mojom::UsbTransferStatus::COMPLETED, | 738 mojom::UsbTransferStatus::COMPLETED, |
737 fake_data, loop.QuitClosure())); | 739 fake_data, loop.QuitClosure())); |
738 loop.Run(); | 740 loop.Run(); |
739 } | 741 } |
740 | 742 |
741 AddMockOutboundData(fake_data); | 743 AddMockOutboundData(fake_data); |
742 | 744 |
743 EXPECT_CALL(mock_handle(), | 745 EXPECT_CALL(mock_handle(), |
744 ControlTransfer(USB_DIRECTION_OUTBOUND, UsbDeviceHandle::STANDARD, | 746 ControlTransfer(UsbTransferDirection::OUTBOUND, |
745 UsbDeviceHandle::INTERFACE, 5, 6, 7, _, _, 0, _)); | 747 UsbControlTransferType::STANDARD, |
| 748 UsbControlTransferRecipient::INTERFACE, 5, 6, 7, |
| 749 _, _, 0, _)); |
746 EXPECT_CALL(permission_provider(), HasFunctionPermission(7, 1, _)); | 750 EXPECT_CALL(permission_provider(), HasFunctionPermission(7, 1, _)); |
747 | 751 |
748 { | 752 { |
749 auto params = mojom::UsbControlTransferParams::New(); | 753 auto params = mojom::UsbControlTransferParams::New(); |
750 params->type = UsbControlTransferType::STANDARD; | 754 params->type = UsbControlTransferType::STANDARD; |
751 params->recipient = UsbControlTransferRecipient::INTERFACE; | 755 params->recipient = UsbControlTransferRecipient::INTERFACE; |
752 params->request = 5; | 756 params->request = 5; |
753 params->value = 6; | 757 params->value = 6; |
754 params->index = 7; | 758 params->index = 7; |
755 base::RunLoop loop; | 759 base::RunLoop loop; |
(...skipping 24 matching lines...) Expand all Loading... |
780 std::copy(message1.begin(), message1.end(), fake_outbound_data.begin()); | 784 std::copy(message1.begin(), message1.end(), fake_outbound_data.begin()); |
781 | 785 |
782 std::string message2 = "hello world!"; | 786 std::string message2 = "hello world!"; |
783 std::vector<uint8_t> fake_inbound_data(message2.size()); | 787 std::vector<uint8_t> fake_inbound_data(message2.size()); |
784 std::copy(message2.begin(), message2.end(), fake_inbound_data.begin()); | 788 std::copy(message2.begin(), message2.end(), fake_inbound_data.begin()); |
785 | 789 |
786 AddMockConfig(ConfigBuilder(1).AddInterface(7, 0, 1, 2, 3)); | 790 AddMockConfig(ConfigBuilder(1).AddInterface(7, 0, 1, 2, 3)); |
787 AddMockOutboundData(fake_outbound_data); | 791 AddMockOutboundData(fake_outbound_data); |
788 AddMockInboundData(fake_inbound_data); | 792 AddMockInboundData(fake_inbound_data); |
789 | 793 |
790 EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_OUTBOUND, 0x01, _, | 794 EXPECT_CALL(mock_handle(), |
791 fake_outbound_data.size(), 0, _)); | 795 GenericTransfer(UsbTransferDirection::OUTBOUND, 0x01, _, |
| 796 fake_outbound_data.size(), 0, _)); |
792 | 797 |
793 { | 798 { |
794 base::RunLoop loop; | 799 base::RunLoop loop; |
795 device->GenericTransferOut( | 800 device->GenericTransferOut( |
796 1, fake_outbound_data, 0, | 801 1, fake_outbound_data, 0, |
797 base::Bind(&ExpectTransferStatusAndThen, | 802 base::Bind(&ExpectTransferStatusAndThen, |
798 mojom::UsbTransferStatus::COMPLETED, loop.QuitClosure())); | 803 mojom::UsbTransferStatus::COMPLETED, loop.QuitClosure())); |
799 loop.Run(); | 804 loop.Run(); |
800 } | 805 } |
801 | 806 |
802 EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_INBOUND, 0x81, _, | 807 EXPECT_CALL(mock_handle(), |
803 fake_inbound_data.size(), 0, _)); | 808 GenericTransfer(UsbTransferDirection::INBOUND, 0x81, _, |
| 809 fake_inbound_data.size(), 0, _)); |
804 | 810 |
805 { | 811 { |
806 base::RunLoop loop; | 812 base::RunLoop loop; |
807 device->GenericTransferIn( | 813 device->GenericTransferIn( |
808 1, static_cast<uint32_t>(fake_inbound_data.size()), 0, | 814 1, static_cast<uint32_t>(fake_inbound_data.size()), 0, |
809 base::Bind(&ExpectTransferInAndThen, | 815 base::Bind(&ExpectTransferInAndThen, |
810 mojom::UsbTransferStatus::COMPLETED, fake_inbound_data, | 816 mojom::UsbTransferStatus::COMPLETED, fake_inbound_data, |
811 loop.QuitClosure())); | 817 loop.QuitClosure())); |
812 loop.Run(); | 818 loop.Run(); |
813 } | 819 } |
(...skipping 10 matching lines...) Expand all Loading... |
824 base::RunLoop loop; | 830 base::RunLoop loop; |
825 device->Open(base::Bind(&ExpectOpenAndThen, mojom::UsbOpenDeviceError::OK, | 831 device->Open(base::Bind(&ExpectOpenAndThen, mojom::UsbOpenDeviceError::OK, |
826 loop.QuitClosure())); | 832 loop.QuitClosure())); |
827 loop.Run(); | 833 loop.Run(); |
828 } | 834 } |
829 | 835 |
830 std::vector<UsbDeviceHandle::IsochronousPacket> fake_packets(4); | 836 std::vector<UsbDeviceHandle::IsochronousPacket> fake_packets(4); |
831 for (size_t i = 0; i < fake_packets.size(); ++i) { | 837 for (size_t i = 0; i < fake_packets.size(); ++i) { |
832 fake_packets[i].length = 8; | 838 fake_packets[i].length = 8; |
833 fake_packets[i].transferred_length = 8; | 839 fake_packets[i].transferred_length = 8; |
834 fake_packets[i].status = USB_TRANSFER_COMPLETED; | 840 fake_packets[i].status = UsbTransferStatus::COMPLETED; |
835 } | 841 } |
836 std::vector<uint32_t> fake_packet_lengths(4, 8); | 842 std::vector<uint32_t> fake_packet_lengths(4, 8); |
837 | 843 |
838 std::vector<uint32_t> expected_transferred_lengths(4, 8); | 844 std::vector<uint32_t> expected_transferred_lengths(4, 8); |
839 | 845 |
840 std::string outbound_data = "aaaaaaaabbbbbbbbccccccccdddddddd"; | 846 std::string outbound_data = "aaaaaaaabbbbbbbbccccccccdddddddd"; |
841 std::vector<uint8_t> fake_outbound_data(outbound_data.size()); | 847 std::vector<uint8_t> fake_outbound_data(outbound_data.size()); |
842 std::copy(outbound_data.begin(), outbound_data.end(), | 848 std::copy(outbound_data.begin(), outbound_data.end(), |
843 fake_outbound_data.begin()); | 849 fake_outbound_data.begin()); |
844 | 850 |
(...skipping 28 matching lines...) Expand all Loading... |
873 base::Bind(&ExpectPacketsInAndThen, fake_inbound_data, | 879 base::Bind(&ExpectPacketsInAndThen, fake_inbound_data, |
874 expected_transferred_lengths, loop.QuitClosure())); | 880 expected_transferred_lengths, loop.QuitClosure())); |
875 loop.Run(); | 881 loop.Run(); |
876 } | 882 } |
877 | 883 |
878 EXPECT_CALL(mock_handle(), Close()); | 884 EXPECT_CALL(mock_handle(), Close()); |
879 } | 885 } |
880 | 886 |
881 } // namespace usb | 887 } // namespace usb |
882 } // namespace device | 888 } // namespace device |
OLD | NEW |