OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" |
| 8 #include "device/usb/device_impl.h" |
| 9 #include "device/usb/mock_usb_device.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
| 12 |
| 13 namespace device { |
| 14 namespace usb { |
| 15 |
| 16 namespace { |
| 17 |
| 18 using DeviceImplTest = testing::Test; |
| 19 |
| 20 void ExpectDeviceInfoAndThen(uint16_t vendor_id, |
| 21 uint16_t product_id, |
| 22 const std::string& manufacturer, |
| 23 const std::string& product, |
| 24 const std::string& serial_number, |
| 25 const base::Closure& continuation, |
| 26 DeviceInfoPtr device_info) { |
| 27 EXPECT_EQ(vendor_id, device_info->vendor_id); |
| 28 EXPECT_EQ(product_id, device_info->product_id); |
| 29 EXPECT_EQ(manufacturer, device_info->manufacturer); |
| 30 EXPECT_EQ(product, device_info->product); |
| 31 EXPECT_EQ(serial_number, device_info->serial_number); |
| 32 continuation.Run(); |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 // Test that the information returned via the Device::GetDeviceInfo matches that |
| 38 // of the underlying device. |
| 39 TEST_F(DeviceImplTest, GetDeviceInfo) { |
| 40 base::MessageLoop message_loop; |
| 41 scoped_refptr<MockUsbDevice> fake_device = |
| 42 new MockUsbDevice(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF"); |
| 43 DevicePtr device; |
| 44 EXPECT_CALL(*fake_device.get(), GetConfiguration()); |
| 45 new DeviceImpl(fake_device, mojo::GetProxy(&device)); |
| 46 |
| 47 base::RunLoop run_loop; |
| 48 device->GetDeviceInfo(base::Bind(&ExpectDeviceInfoAndThen, 0x1234, 0x5678, |
| 49 "ACME", "Frobinator", "ABCDEF", |
| 50 run_loop.QuitClosure())); |
| 51 run_loop.Run(); |
| 52 } |
| 53 |
| 54 } // namespace usb |
| 55 } // namespace device |
OLD | NEW |