Chromium Code Reviews| 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_manager_impl.h" | 5 #include "device/usb/mojo/device_manager_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 void OnDeviceRemoved(DeviceInfoPtr device_info) { | 78 void OnDeviceRemoved(DeviceInfoPtr device_info) { |
| 79 DoOnDeviceRemoved(device_info.get()); | 79 DoOnDeviceRemoved(device_info.get()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 mojo::Binding<DeviceManagerClient> m_binding; | 83 mojo::Binding<DeviceManagerClient> m_binding; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 void ExpectDevicesAndThen(const std::set<std::string>& expected_guids, | 86 void ExpectDevicesAndThen(const std::set<std::string>& expected_guids, |
| 87 const base::Closure& continuation, | 87 const base::Closure& continuation, |
| 88 mojo::Array<DeviceInfoPtr> results) { | 88 std::vector<DeviceInfoPtr> results) { |
| 89 EXPECT_EQ(expected_guids.size(), results.size()); | 89 EXPECT_EQ(expected_guids.size(), results.size()); |
| 90 std::set<std::string> actual_guids; | 90 std::set<std::string> actual_guids; |
| 91 for (size_t i = 0; i < results.size(); ++i) | 91 for (size_t i = 0; i < results.size(); ++i) |
| 92 actual_guids.insert(results[i]->guid); | 92 actual_guids.insert(results[i]->guid); |
| 93 EXPECT_EQ(expected_guids, actual_guids); | 93 EXPECT_EQ(expected_guids, actual_guids); |
| 94 continuation.Run(); | 94 continuation.Run(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ExpectDeviceInfoAndThen(const std::string& expected_guid, | 97 void ExpectDeviceInfoAndThen(const std::string& expected_guid, |
| 98 const base::Closure& continuation, | 98 const base::Closure& continuation, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 114 scoped_refptr<MockUsbDevice> device2 = | 114 scoped_refptr<MockUsbDevice> device2 = |
| 115 new MockUsbDevice(0x1234, 0x567a, "ACME", "Frobinator Mk II", "MNOPQR"); | 115 new MockUsbDevice(0x1234, 0x567a, "ACME", "Frobinator Mk II", "MNOPQR"); |
| 116 | 116 |
| 117 device_client_.usb_service()->AddDevice(device0); | 117 device_client_.usb_service()->AddDevice(device0); |
| 118 device_client_.usb_service()->AddDevice(device1); | 118 device_client_.usb_service()->AddDevice(device1); |
| 119 device_client_.usb_service()->AddDevice(device2); | 119 device_client_.usb_service()->AddDevice(device2); |
| 120 | 120 |
| 121 DeviceManagerPtr device_manager = ConnectToDeviceManager(); | 121 DeviceManagerPtr device_manager = ConnectToDeviceManager(); |
| 122 | 122 |
| 123 EnumerationOptionsPtr options = EnumerationOptions::New(); | 123 EnumerationOptionsPtr options = EnumerationOptions::New(); |
| 124 options->filters = mojo::Array<DeviceFilterPtr>::New(1); | 124 auto filter = DeviceFilter::New(); |
| 125 options->filters[0] = DeviceFilter::New(); | 125 filter->has_vendor_id = true; |
| 126 options->filters[0]->has_vendor_id = true; | 126 filter->vendor_id = 0x1234; |
| 127 options->filters[0]->vendor_id = 0x1234; | 127 options->filters.emplace(); |
|
dcheng
2016/08/15 18:18:15
?
Isn't option->filters a vector here? How does a
Reilly Grant (use Gerrit)
2016/08/15 21:39:02
option->filters is a base::Optional<std::vector<>>
| |
| 128 options->filters->push_back(std::move(filter)); | |
| 128 | 129 |
| 129 std::set<std::string> guids; | 130 std::set<std::string> guids; |
| 130 guids.insert(device0->guid()); | 131 guids.insert(device0->guid()); |
| 131 guids.insert(device1->guid()); | 132 guids.insert(device1->guid()); |
| 132 guids.insert(device2->guid()); | 133 guids.insert(device2->guid()); |
| 133 | 134 |
| 134 base::RunLoop loop; | 135 base::RunLoop loop; |
| 135 device_manager->GetDevices( | 136 device_manager->GetDevices( |
| 136 std::move(options), | 137 std::move(options), |
| 137 base::Bind(&ExpectDevicesAndThen, guids, loop.QuitClosure())); | 138 base::Bind(&ExpectDevicesAndThen, guids, loop.QuitClosure())); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 .WillOnce(ExpectGuidAndThen(device0->guid(), barrier)) | 214 .WillOnce(ExpectGuidAndThen(device0->guid(), barrier)) |
| 214 .WillOnce(ExpectGuidAndThen(device2->guid(), barrier)); | 215 .WillOnce(ExpectGuidAndThen(device2->guid(), barrier)); |
| 215 EXPECT_CALL(mock_client, DoOnDeviceAdded(_)) | 216 EXPECT_CALL(mock_client, DoOnDeviceAdded(_)) |
| 216 .WillOnce(ExpectGuidAndThen(device3->guid(), barrier)); | 217 .WillOnce(ExpectGuidAndThen(device3->guid(), barrier)); |
| 217 loop.Run(); | 218 loop.Run(); |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 | 221 |
| 221 } // namespace usb | 222 } // namespace usb |
| 222 } // namespace device | 223 } // namespace device |
| OLD | NEW |