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

Side by Side Diff: device/devices_app/usb/device_impl_unittest.cc

Issue 1544323002: Convert Pass()→std::move() in //device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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/usb/device_impl.cc ('k') | device/devices_app/usb/device_manager_impl.cc » ('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 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/devices_app/usb/device_impl.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 #include <stdint.h> 8 #include <stdint.h>
7
8 #include <map> 9 #include <map>
9 #include <queue> 10 #include <queue>
10 #include <set> 11 #include <set>
12 #include <utility>
11 #include <vector> 13 #include <vector>
12 14
13 #include "base/bind.h" 15 #include "base/bind.h"
14 #include "base/macros.h" 16 #include "base/macros.h"
15 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 18 #include "base/run_loop.h"
17 #include "base/stl_util.h" 19 #include "base/stl_util.h"
18 #include "device/devices_app/usb/device_impl.h"
19 #include "device/devices_app/usb/fake_permission_provider.h" 20 #include "device/devices_app/usb/fake_permission_provider.h"
20 #include "device/usb/mock_usb_device.h" 21 #include "device/usb/mock_usb_device.h"
21 #include "device/usb/mock_usb_device_handle.h" 22 #include "device/usb/mock_usb_device_handle.h"
22 #include "mojo/public/cpp/bindings/interface_request.h" 23 #include "mojo/public/cpp/bindings/interface_request.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 using ::testing::Invoke; 26 using ::testing::Invoke;
26 using ::testing::_; 27 using ::testing::_;
27 28
28 namespace device { 29 namespace device {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 const std::string& manufacturer, 151 const std::string& manufacturer,
151 const std::string& product, 152 const std::string& product,
152 const std::string& serial) { 153 const std::string& serial) {
153 mock_device_ = 154 mock_device_ =
154 new MockUsbDevice(vendor_id, product_id, manufacturer, product, serial); 155 new MockUsbDevice(vendor_id, product_id, manufacturer, product, serial);
155 mock_handle_ = new MockUsbDeviceHandle(mock_device_.get()); 156 mock_handle_ = new MockUsbDeviceHandle(mock_device_.get());
156 157
157 PermissionProviderPtr permission_provider; 158 PermissionProviderPtr permission_provider;
158 permission_provider_.Bind(mojo::GetProxy(&permission_provider)); 159 permission_provider_.Bind(mojo::GetProxy(&permission_provider));
159 DevicePtr proxy; 160 DevicePtr proxy;
160 new DeviceImpl(mock_device_, permission_provider.Pass(), 161 new DeviceImpl(mock_device_, std::move(permission_provider),
161 mojo::GetProxy(&proxy)); 162 mojo::GetProxy(&proxy));
162 163
163 // Set up mock handle calls to respond based on mock device configs 164 // Set up mock handle calls to respond based on mock device configs
164 // established by the test. 165 // established by the test.
165 ON_CALL(mock_device(), Open(_)) 166 ON_CALL(mock_device(), Open(_))
166 .WillByDefault(Invoke(this, &USBDeviceImplTest::OpenMockHandle)); 167 .WillByDefault(Invoke(this, &USBDeviceImplTest::OpenMockHandle));
167 ON_CALL(mock_device(), GetActiveConfiguration()) 168 ON_CALL(mock_device(), GetActiveConfiguration())
168 .WillByDefault( 169 .WillByDefault(
169 Invoke(this, &USBDeviceImplTest::GetActiveConfiguration)); 170 Invoke(this, &USBDeviceImplTest::GetActiveConfiguration));
170 ON_CALL(mock_handle(), Close()) 171 ON_CALL(mock_handle(), Close())
171 .WillByDefault(Invoke(this, &USBDeviceImplTest::CloseMockHandle)); 172 .WillByDefault(Invoke(this, &USBDeviceImplTest::CloseMockHandle));
172 ON_CALL(mock_handle(), SetConfiguration(_, _)) 173 ON_CALL(mock_handle(), SetConfiguration(_, _))
173 .WillByDefault(Invoke(this, &USBDeviceImplTest::SetConfiguration)); 174 .WillByDefault(Invoke(this, &USBDeviceImplTest::SetConfiguration));
174 ON_CALL(mock_handle(), ClaimInterface(_, _)) 175 ON_CALL(mock_handle(), ClaimInterface(_, _))
175 .WillByDefault(Invoke(this, &USBDeviceImplTest::ClaimInterface)); 176 .WillByDefault(Invoke(this, &USBDeviceImplTest::ClaimInterface));
176 ON_CALL(mock_handle(), ReleaseInterface(_)) 177 ON_CALL(mock_handle(), ReleaseInterface(_))
177 .WillByDefault(Invoke(this, &USBDeviceImplTest::ReleaseInterface)); 178 .WillByDefault(Invoke(this, &USBDeviceImplTest::ReleaseInterface));
178 ON_CALL(mock_handle(), SetInterfaceAlternateSetting(_, _, _)) 179 ON_CALL(mock_handle(), SetInterfaceAlternateSetting(_, _, _))
179 .WillByDefault( 180 .WillByDefault(
180 Invoke(this, &USBDeviceImplTest::SetInterfaceAlternateSetting)); 181 Invoke(this, &USBDeviceImplTest::SetInterfaceAlternateSetting));
181 ON_CALL(mock_handle(), ResetDevice(_)) 182 ON_CALL(mock_handle(), ResetDevice(_))
182 .WillByDefault(Invoke(this, &USBDeviceImplTest::ResetDevice)); 183 .WillByDefault(Invoke(this, &USBDeviceImplTest::ResetDevice));
183 ON_CALL(mock_handle(), ControlTransfer(_, _, _, _, _, _, _, _, _, _)) 184 ON_CALL(mock_handle(), ControlTransfer(_, _, _, _, _, _, _, _, _, _))
184 .WillByDefault(Invoke(this, &USBDeviceImplTest::ControlTransfer)); 185 .WillByDefault(Invoke(this, &USBDeviceImplTest::ControlTransfer));
185 ON_CALL(mock_handle(), GenericTransfer(_, _, _, _, _, _)) 186 ON_CALL(mock_handle(), GenericTransfer(_, _, _, _, _, _))
186 .WillByDefault(Invoke(this, &USBDeviceImplTest::GenericTransfer)); 187 .WillByDefault(Invoke(this, &USBDeviceImplTest::GenericTransfer));
187 ON_CALL(mock_handle(), IsochronousTransfer(_, _, _, _, _, _, _, _)) 188 ON_CALL(mock_handle(), IsochronousTransfer(_, _, _, _, _, _, _, _))
188 .WillByDefault(Invoke(this, &USBDeviceImplTest::IsochronousTransfer)); 189 .WillByDefault(Invoke(this, &USBDeviceImplTest::IsochronousTransfer));
189 190
190 return proxy.Pass(); 191 return proxy;
191 } 192 }
192 193
193 DevicePtr GetMockDeviceProxy() { 194 DevicePtr GetMockDeviceProxy() {
194 return GetMockDeviceProxy(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF"); 195 return GetMockDeviceProxy(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF");
195 } 196 }
196 197
197 void AddMockConfig(const ConfigBuilder& builder) { 198 void AddMockConfig(const ConfigBuilder& builder) {
198 const UsbConfigDescriptor& config = builder.config(); 199 const UsbConfigDescriptor& config = builder.config();
199 DCHECK(!ContainsKey(mock_configs_, config.configuration_value)); 200 DCHECK(!ContainsKey(mock_configs_, config.configuration_value));
200 mock_configs_[config.configuration_value] = config; 201 mock_configs_[config.configuration_value] = config;
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 656
656 { 657 {
657 auto params = ControlTransferParams::New(); 658 auto params = ControlTransferParams::New();
658 params->type = CONTROL_TRANSFER_TYPE_STANDARD; 659 params->type = CONTROL_TRANSFER_TYPE_STANDARD;
659 params->recipient = CONTROL_TRANSFER_RECIPIENT_DEVICE; 660 params->recipient = CONTROL_TRANSFER_RECIPIENT_DEVICE;
660 params->request = 5; 661 params->request = 5;
661 params->value = 6; 662 params->value = 6;
662 params->index = 7; 663 params->index = 7;
663 base::RunLoop loop; 664 base::RunLoop loop;
664 device->ControlTransferIn( 665 device->ControlTransferIn(
665 params.Pass(), static_cast<uint32_t>(fake_data.size()), 0, 666 std::move(params), static_cast<uint32_t>(fake_data.size()), 0,
666 base::Bind(&ExpectTransferInAndThen, TRANSFER_STATUS_COMPLETED, 667 base::Bind(&ExpectTransferInAndThen, TRANSFER_STATUS_COMPLETED,
667 fake_data, loop.QuitClosure())); 668 fake_data, loop.QuitClosure()));
668 loop.Run(); 669 loop.Run();
669 } 670 }
670 671
671 AddMockOutboundData(fake_data); 672 AddMockOutboundData(fake_data);
672 673
673 EXPECT_CALL(mock_device(), GetActiveConfiguration()); 674 EXPECT_CALL(mock_device(), GetActiveConfiguration());
674 EXPECT_CALL(mock_handle(), 675 EXPECT_CALL(mock_handle(),
675 ControlTransfer(USB_DIRECTION_OUTBOUND, UsbDeviceHandle::STANDARD, 676 ControlTransfer(USB_DIRECTION_OUTBOUND, UsbDeviceHandle::STANDARD,
676 UsbDeviceHandle::INTERFACE, 5, 6, 7, _, _, 0, _)); 677 UsbDeviceHandle::INTERFACE, 5, 6, 7, _, _, 0, _));
677 678
678 { 679 {
679 auto params = ControlTransferParams::New(); 680 auto params = ControlTransferParams::New();
680 params->type = CONTROL_TRANSFER_TYPE_STANDARD; 681 params->type = CONTROL_TRANSFER_TYPE_STANDARD;
681 params->recipient = CONTROL_TRANSFER_RECIPIENT_INTERFACE; 682 params->recipient = CONTROL_TRANSFER_RECIPIENT_INTERFACE;
682 params->request = 5; 683 params->request = 5;
683 params->value = 6; 684 params->value = 6;
684 params->index = 7; 685 params->index = 7;
685 base::RunLoop loop; 686 base::RunLoop loop;
686 device->ControlTransferOut( 687 device->ControlTransferOut(
687 params.Pass(), mojo::Array<uint8_t>::From(fake_data), 0, 688 std::move(params), mojo::Array<uint8_t>::From(fake_data), 0,
688 base::Bind(&ExpectTransferStatusAndThen, TRANSFER_STATUS_COMPLETED, 689 base::Bind(&ExpectTransferStatusAndThen, TRANSFER_STATUS_COMPLETED,
689 loop.QuitClosure())); 690 loop.QuitClosure()));
690 loop.Run(); 691 loop.Run();
691 } 692 }
692 693
693 EXPECT_CALL(mock_handle(), Close()); 694 EXPECT_CALL(mock_handle(), Close());
694 } 695 }
695 696
696 TEST_F(USBDeviceImplTest, GenericTransfer) { 697 TEST_F(USBDeviceImplTest, GenericTransfer) {
697 DevicePtr device = GetMockDeviceProxy(); 698 DevicePtr device = GetMockDeviceProxy();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 base::RunLoop loop; 779 base::RunLoop loop;
779 mojo::Array<mojo::Array<uint8_t>> packets = 780 mojo::Array<mojo::Array<uint8_t>> packets =
780 mojo::Array<mojo::Array<uint8_t>>::New(4); 781 mojo::Array<mojo::Array<uint8_t>>::New(4);
781 for (size_t i = 0; i < 4; ++i) { 782 for (size_t i = 0; i < 4; ++i) {
782 std::vector<uint8_t> bytes(8); 783 std::vector<uint8_t> bytes(8);
783 std::copy(outbound_packet_data.begin() + i * 8, 784 std::copy(outbound_packet_data.begin() + i * 8,
784 outbound_packet_data.begin() + i * 8 + 8, bytes.begin()); 785 outbound_packet_data.begin() + i * 8 + 8, bytes.begin());
785 packets[i].Swap(&bytes); 786 packets[i].Swap(&bytes);
786 } 787 }
787 device->IsochronousTransferOut( 788 device->IsochronousTransferOut(
788 1, packets.Pass(), 0, 789 1, std::move(packets), 0,
789 base::Bind(&ExpectTransferStatusAndThen, TRANSFER_STATUS_COMPLETED, 790 base::Bind(&ExpectTransferStatusAndThen, TRANSFER_STATUS_COMPLETED,
790 loop.QuitClosure())); 791 loop.QuitClosure()));
791 loop.Run(); 792 loop.Run();
792 } 793 }
793 794
794 EXPECT_CALL(mock_handle(), 795 EXPECT_CALL(mock_handle(),
795 IsochronousTransfer(USB_DIRECTION_INBOUND, 0x81, _, 796 IsochronousTransfer(USB_DIRECTION_INBOUND, 0x81, _,
796 fake_inbound_packets.size(), 4, 8, 0, _)); 797 fake_inbound_packets.size(), 4, 8, 0, _));
797 798
798 { 799 {
799 base::RunLoop loop; 800 base::RunLoop loop;
800 std::vector<std::vector<uint8_t>> packets(4); 801 std::vector<std::vector<uint8_t>> packets(4);
801 for (size_t i = 0; i < 4; ++i) { 802 for (size_t i = 0; i < 4; ++i) {
802 packets[i].resize(8); 803 packets[i].resize(8);
803 std::copy(inbound_packet_data.begin() + i * 8, 804 std::copy(inbound_packet_data.begin() + i * 8,
804 inbound_packet_data.begin() + i * 8 + 8, packets[i].begin()); 805 inbound_packet_data.begin() + i * 8 + 8, packets[i].begin());
805 } 806 }
806 device->IsochronousTransferIn( 807 device->IsochronousTransferIn(
807 1, 4, 8, 0, base::Bind(&ExpectPacketsAndThen, TRANSFER_STATUS_COMPLETED, 808 1, 4, 8, 0, base::Bind(&ExpectPacketsAndThen, TRANSFER_STATUS_COMPLETED,
808 packets, loop.QuitClosure())); 809 packets, loop.QuitClosure()));
809 loop.Run(); 810 loop.Run();
810 } 811 }
811 812
812 EXPECT_CALL(mock_handle(), Close()); 813 EXPECT_CALL(mock_handle(), Close());
813 } 814 }
814 815
815 } // namespace usb 816 } // namespace usb
816 } // namespace device 817 } // namespace device
OLDNEW
« no previous file with comments | « device/devices_app/usb/device_impl.cc ('k') | device/devices_app/usb/device_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698