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.
5 #include "device/usb/mock_usb_service.h"
7 #include "device/usb/usb_device.h"
11 MockUsbService::MockUsbService() {
14 MockUsbService::~MockUsbService() {
17 void MockUsbService::AddDevice(scoped_refptr
<UsbDevice
> device
) {
18 devices_
[device
->unique_id()] = device
;
19 NotifyDeviceAdded(device
);
22 void MockUsbService::RemoveDevice(scoped_refptr
<UsbDevice
> device
) {
23 devices_
.erase(device
->unique_id());
24 UsbService::NotifyDeviceRemoved(device
);
27 scoped_refptr
<UsbDevice
> MockUsbService::GetDeviceById(uint32 unique_id
) {
28 auto it
= devices_
.find(unique_id
);
29 EXPECT_TRUE(it
!= devices_
.end());
33 void MockUsbService::GetDevices(const GetDevicesCallback
& callback
) {
34 std::vector
<scoped_refptr
<UsbDevice
>> devices
;
35 for (const auto& map_entry
: devices_
) {
36 devices
.push_back(map_entry
.second
);
38 callback
.Run(devices
);