| OLD | NEW |
| 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 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/containers/scoped_ptr_hash_map.h" | 10 #include "base/containers/scoped_ptr_hash_map.h" |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 }; | 393 }; |
| 394 | 394 |
| 395 template <class T> | 395 template <class T> |
| 396 class MockUsbDevice : public UsbDevice { | 396 class MockUsbDevice : public UsbDevice { |
| 397 public: | 397 public: |
| 398 MockUsbDevice() | 398 MockUsbDevice() |
| 399 : UsbDevice(0, | 399 : UsbDevice(0, |
| 400 0, | 400 0, |
| 401 base::UTF8ToUTF16(kDeviceManufacturer), | 401 base::UTF8ToUTF16(kDeviceManufacturer), |
| 402 base::UTF8ToUTF16(kDeviceModel), | 402 base::UTF8ToUTF16(kDeviceModel), |
| 403 base::UTF8ToUTF16(kDeviceSerial)) { | 403 base::UTF8ToUTF16(kDeviceSerial)), |
| 404 UsbEndpointDescriptor bulk_in; | 404 config_desc_(1, false, false, 0) { |
| 405 bulk_in.address = 0x81; | 405 UsbInterfaceDescriptor interface_desc(0, 0, T::kClass, T::kSubclass, |
| 406 bulk_in.direction = device::USB_DIRECTION_INBOUND; | 406 T::kProtocol); |
| 407 bulk_in.maximum_packet_size = 512; | 407 interface_desc.endpoints.emplace_back(0x81, device::USB_DIRECTION_INBOUND, |
| 408 bulk_in.transfer_type = device::USB_TRANSFER_BULK; | 408 512, device::USB_SYNCHRONIZATION_NONE, |
| 409 | 409 device::USB_TRANSFER_BULK, |
| 410 UsbEndpointDescriptor bulk_out; | 410 device::USB_USAGE_DATA, 0); |
| 411 bulk_out.address = 0x01; | 411 interface_desc.endpoints.emplace_back(0x01, device::USB_DIRECTION_OUTBOUND, |
| 412 bulk_out.direction = device::USB_DIRECTION_OUTBOUND; | 412 512, device::USB_SYNCHRONIZATION_NONE, |
| 413 bulk_out.maximum_packet_size = 512; | 413 device::USB_TRANSFER_BULK, |
| 414 bulk_out.transfer_type = device::USB_TRANSFER_BULK; | 414 device::USB_USAGE_DATA, 0); |
| 415 | |
| 416 UsbInterfaceDescriptor interface_desc; | |
| 417 interface_desc.interface_number = 0; | |
| 418 interface_desc.alternate_setting = 0; | |
| 419 interface_desc.interface_class = T::kClass; | |
| 420 interface_desc.interface_subclass = T::kSubclass; | |
| 421 interface_desc.interface_protocol = T::kProtocol; | |
| 422 interface_desc.endpoints.push_back(bulk_in); | |
| 423 interface_desc.endpoints.push_back(bulk_out); | |
| 424 | |
| 425 config_desc_.interfaces.push_back(interface_desc); | 415 config_desc_.interfaces.push_back(interface_desc); |
| 426 } | 416 } |
| 427 | 417 |
| 428 void Open(const OpenCallback& callback) override { | 418 void Open(const OpenCallback& callback) override { |
| 429 base::ThreadTaskRunnerHandle::Get()->PostTask( | 419 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 430 FROM_HERE, base::Bind(callback, make_scoped_refptr( | 420 FROM_HERE, base::Bind(callback, make_scoped_refptr( |
| 431 new MockUsbDeviceHandle<T>(this)))); | 421 new MockUsbDeviceHandle<T>(this)))); |
| 432 } | 422 } |
| 433 | 423 |
| 434 const UsbConfigDescriptor* GetActiveConfiguration() override { | 424 const UsbConfigDescriptor* GetActiveConfiguration() override { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 EXPECT_EQ(2, listener.invoked_); | 793 EXPECT_EQ(2, listener.invoked_); |
| 804 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); | 794 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); |
| 805 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 795 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 806 } | 796 } |
| 807 | 797 |
| 808 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { | 798 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { |
| 809 MockCountListenerForCheckingTraits listener(adb_bridge_); | 799 MockCountListenerForCheckingTraits listener(adb_bridge_); |
| 810 adb_bridge_->AddDeviceCountListener(&listener); | 800 adb_bridge_->AddDeviceCountListener(&listener); |
| 811 runner_->Run(); | 801 runner_->Run(); |
| 812 } | 802 } |
| OLD | NEW |