| 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 19 matching lines...) Expand all Loading... |
| 30 using ::testing::Invoke; | 30 using ::testing::Invoke; |
| 31 using ::testing::_; | 31 using ::testing::_; |
| 32 | 32 |
| 33 namespace device { | 33 namespace device { |
| 34 namespace usb { | 34 namespace usb { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 class ConfigBuilder { | 38 class ConfigBuilder { |
| 39 public: | 39 public: |
| 40 explicit ConfigBuilder(uint8_t value) { config_.configuration_value = value; } | 40 explicit ConfigBuilder(uint8_t value) : config_(value, false, false, 0) {} |
| 41 | 41 |
| 42 ConfigBuilder& AddInterface(uint8_t interface_number, | 42 ConfigBuilder& AddInterface(uint8_t interface_number, |
| 43 uint8_t alternate_setting, | 43 uint8_t alternate_setting, |
| 44 uint8_t class_code, | 44 uint8_t class_code, |
| 45 uint8_t subclass_code, | 45 uint8_t subclass_code, |
| 46 uint8_t protocol_code) { | 46 uint8_t protocol_code) { |
| 47 UsbInterfaceDescriptor interface; | 47 config_.interfaces.emplace_back(interface_number, alternate_setting, |
| 48 interface.interface_number = interface_number; | 48 class_code, subclass_code, protocol_code); |
| 49 interface.alternate_setting = alternate_setting; | |
| 50 interface.interface_class = class_code; | |
| 51 interface.interface_subclass = subclass_code; | |
| 52 interface.interface_protocol = protocol_code; | |
| 53 config_.interfaces.push_back(interface); | |
| 54 return *this; | 49 return *this; |
| 55 } | 50 } |
| 56 | 51 |
| 57 const UsbConfigDescriptor& config() const { return config_; } | 52 const UsbConfigDescriptor& config() const { return config_; } |
| 58 | 53 |
| 59 private: | 54 private: |
| 60 UsbConfigDescriptor config_; | 55 UsbConfigDescriptor config_; |
| 61 }; | 56 }; |
| 62 | 57 |
| 63 void ExpectOpenAndThen(OpenDeviceError expected, | 58 void ExpectOpenAndThen(OpenDeviceError expected, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return proxy; | 207 return proxy; |
| 213 } | 208 } |
| 214 | 209 |
| 215 DevicePtr GetMockDeviceProxy() { | 210 DevicePtr GetMockDeviceProxy() { |
| 216 return GetMockDeviceProxy(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF"); | 211 return GetMockDeviceProxy(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF"); |
| 217 } | 212 } |
| 218 | 213 |
| 219 void AddMockConfig(const ConfigBuilder& builder) { | 214 void AddMockConfig(const ConfigBuilder& builder) { |
| 220 const UsbConfigDescriptor& config = builder.config(); | 215 const UsbConfigDescriptor& config = builder.config(); |
| 221 DCHECK(!ContainsKey(mock_configs_, config.configuration_value)); | 216 DCHECK(!ContainsKey(mock_configs_, config.configuration_value)); |
| 222 mock_configs_[config.configuration_value] = config; | 217 mock_configs_.insert(std::make_pair(config.configuration_value, config)); |
| 223 } | 218 } |
| 224 | 219 |
| 225 void AddMockInboundData(const std::vector<uint8_t>& data) { | 220 void AddMockInboundData(const std::vector<uint8_t>& data) { |
| 226 mock_inbound_data_.push(data); | 221 mock_inbound_data_.push(data); |
| 227 } | 222 } |
| 228 | 223 |
| 229 void AddMockInboundPackets( | 224 void AddMockInboundPackets( |
| 230 const std::vector<uint8_t>& data, | 225 const std::vector<uint8_t>& data, |
| 231 const std::vector<UsbDeviceHandle::IsochronousPacket>& packets) { | 226 const std::vector<UsbDeviceHandle::IsochronousPacket>& packets) { |
| 232 mock_inbound_data_.push(data); | 227 mock_inbound_data_.push(data); |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 base::Bind(&ExpectPacketsInAndThen, fake_inbound_data, | 881 base::Bind(&ExpectPacketsInAndThen, fake_inbound_data, |
| 887 expected_transferred_lengths, loop.QuitClosure())); | 882 expected_transferred_lengths, loop.QuitClosure())); |
| 888 loop.Run(); | 883 loop.Run(); |
| 889 } | 884 } |
| 890 | 885 |
| 891 EXPECT_CALL(mock_handle(), Close()); | 886 EXPECT_CALL(mock_handle(), Close()); |
| 892 } | 887 } |
| 893 | 888 |
| 894 } // namespace usb | 889 } // namespace usb |
| 895 } // namespace device | 890 } // namespace device |
| OLD | NEW |