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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 options->filters = mojo::Array<DeviceFilterPtr>::New(1); | 144 options->filters = mojo::Array<DeviceFilterPtr>::New(1); |
145 options->filters[0] = DeviceFilter::New(); | 145 options->filters[0] = DeviceFilter::New(); |
146 options->filters[0]->has_vendor_id = true; | 146 options->filters[0]->has_vendor_id = true; |
147 options->filters[0]->vendor_id = 0x1234; | 147 options->filters[0]->vendor_id = 0x1234; |
148 | 148 |
149 std::set<std::string> guids; | 149 std::set<std::string> guids; |
150 guids.insert(device0->guid()); | 150 guids.insert(device0->guid()); |
151 guids.insert(device1->guid()); | 151 guids.insert(device1->guid()); |
152 guids.insert(device2->guid()); | 152 guids.insert(device2->guid()); |
153 | 153 |
154 // One call to GetConfiguration for each device during enumeration. | 154 // One call to GetActiveConfiguration for each device during enumeration. |
155 EXPECT_CALL(*device0.get(), GetConfiguration()); | 155 EXPECT_CALL(*device0.get(), GetActiveConfiguration()); |
156 EXPECT_CALL(*device1.get(), GetConfiguration()); | 156 EXPECT_CALL(*device1.get(), GetActiveConfiguration()); |
157 EXPECT_CALL(*device2.get(), GetConfiguration()); | 157 EXPECT_CALL(*device2.get(), GetActiveConfiguration()); |
158 | 158 |
159 base::RunLoop loop; | 159 base::RunLoop loop; |
160 device_manager->GetDevices( | 160 device_manager->GetDevices( |
161 options.Pass(), | 161 options.Pass(), |
162 base::Bind(&ExpectDevicesAndThen, guids, loop.QuitClosure())); | 162 base::Bind(&ExpectDevicesAndThen, guids, loop.QuitClosure())); |
163 loop.Run(); | 163 loop.Run(); |
164 } | 164 } |
165 | 165 |
166 // Test requesting a single Device by GUID. | 166 // Test requesting a single Device by GUID. |
167 TEST_F(USBDeviceManagerImplTest, OpenDevice) { | 167 TEST_F(USBDeviceManagerImplTest, OpenDevice) { |
168 scoped_refptr<MockUsbDevice> mock_device = | 168 scoped_refptr<MockUsbDevice> mock_device = |
169 new MockUsbDevice(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF"); | 169 new MockUsbDevice(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF"); |
170 | 170 |
171 mock_usb_service().AddDevice(mock_device); | 171 mock_usb_service().AddDevice(mock_device); |
172 | 172 |
173 DeviceManagerPtr device_manager = ConnectToDeviceManager(); | 173 DeviceManagerPtr device_manager = ConnectToDeviceManager(); |
174 | 174 |
175 // Should be called on the mock as a result of OpenDevice() below. | 175 // Should be called on the mock as a result of OpenDevice() below. |
176 EXPECT_CALL(*mock_device.get(), Open(_)); | 176 EXPECT_CALL(*mock_device.get(), Open(_)); |
177 | 177 |
178 MockOpenCallback open_callback(mock_device.get()); | 178 MockOpenCallback open_callback(mock_device.get()); |
179 ON_CALL(*mock_device.get(), Open(_)) | 179 ON_CALL(*mock_device.get(), Open(_)) |
180 .WillByDefault(Invoke(&open_callback, &MockOpenCallback::Open)); | 180 .WillByDefault(Invoke(&open_callback, &MockOpenCallback::Open)); |
181 | 181 |
182 // Should be called on the mock as a result of GetDeviceInfo() below. | 182 // Should be called on the mock as a result of GetDeviceInfo() below. |
183 EXPECT_CALL(*mock_device.get(), GetConfiguration()); | 183 EXPECT_CALL(*mock_device.get(), GetActiveConfiguration()); |
184 | 184 |
185 { | 185 { |
186 base::RunLoop loop; | 186 base::RunLoop loop; |
187 DevicePtr device; | 187 DevicePtr device; |
188 device_manager->OpenDevice( | 188 device_manager->OpenDevice( |
189 mock_device->guid(), mojo::GetProxy(&device), | 189 mock_device->guid(), mojo::GetProxy(&device), |
190 base::Bind(&ExpectOpenDeviceError, OPEN_DEVICE_ERROR_OK)); | 190 base::Bind(&ExpectOpenDeviceError, OPEN_DEVICE_ERROR_OK)); |
191 device->GetDeviceInfo(base::Bind(&ExpectDeviceInfoAndThen, | 191 device->GetDeviceInfo(base::Bind(&ExpectDeviceInfoAndThen, |
192 mock_device->guid(), loop.QuitClosure())); | 192 mock_device->guid(), loop.QuitClosure())); |
193 loop.Run(); | 193 loop.Run(); |
(...skipping 11 matching lines...) Expand all Loading... |
205 { | 205 { |
206 base::RunLoop loop; | 206 base::RunLoop loop; |
207 bad_device.set_connection_error_handler(loop.QuitClosure()); | 207 bad_device.set_connection_error_handler(loop.QuitClosure()); |
208 bad_device->GetDeviceInfo(base::Bind(&FailOnGetDeviceInfoResponse)); | 208 bad_device->GetDeviceInfo(base::Bind(&FailOnGetDeviceInfoResponse)); |
209 loop.Run(); | 209 loop.Run(); |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 } // namespace usb | 213 } // namespace usb |
214 } // namespace device | 214 } // namespace device |
OLD | NEW |