1 // Copyright (c) 2012 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 #ifndef DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_ADAPTER_H_
6 #define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_ADAPTER_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_vector.h"
12 #include "device/bluetooth/bluetooth_adapter.h"
13 #include "device/bluetooth/bluetooth_audio_sink.h"
14 #include "device/bluetooth/bluetooth_device.h"
15 #include "device/bluetooth/bluetooth_discovery_session.h"
16 #include "device/bluetooth/test/mock_bluetooth_device.h"
17 #include "testing/gmock/include/gmock/gmock.h"
21 class MockBluetoothAdapter
: public BluetoothAdapter
{
23 class Observer
: public BluetoothAdapter::Observer
{
28 MOCK_METHOD2(AdapterPresentChanged
, void(BluetoothAdapter
*, bool));
29 MOCK_METHOD2(AdapterPoweredChanged
, void(BluetoothAdapter
*, bool));
30 MOCK_METHOD2(AdapterDiscoveringChanged
, void(BluetoothAdapter
*, bool));
31 MOCK_METHOD2(DeviceAdded
, void(BluetoothAdapter
*, BluetoothDevice
*));
32 MOCK_METHOD2(DeviceChanged
, void(BluetoothAdapter
*, BluetoothDevice
*));
33 MOCK_METHOD2(DeviceRemoved
, void(BluetoothAdapter
*, BluetoothDevice
*));
36 MockBluetoothAdapter();
38 virtual bool IsInitialized() const { return true; }
40 #if defined(OS_CHROMEOS)
41 void Shutdown() override
;
43 MOCK_METHOD1(AddObserver
, void(BluetoothAdapter::Observer
*));
44 MOCK_METHOD1(RemoveObserver
, void(BluetoothAdapter::Observer
*));
45 MOCK_CONST_METHOD0(GetAddress
, std::string());
46 MOCK_CONST_METHOD0(GetName
, std::string());
48 void(const std::string
& name
,
49 const base::Closure
& callback
,
50 const ErrorCallback
& error_callback
));
51 MOCK_CONST_METHOD0(IsPresent
, bool());
52 MOCK_CONST_METHOD0(IsPowered
, bool());
53 MOCK_METHOD3(SetPowered
,
55 const base::Closure
& callback
,
56 const ErrorCallback
& error_callback
));
57 MOCK_CONST_METHOD0(IsDiscoverable
, bool());
58 MOCK_METHOD3(SetDiscoverable
,
59 void(bool discoverable
,
60 const base::Closure
& callback
,
61 const ErrorCallback
& error_callback
));
62 MOCK_CONST_METHOD0(IsDiscovering
, bool());
63 MOCK_METHOD2(StartDiscoverySession
,
64 void(const DiscoverySessionCallback
& callback
,
65 const ErrorCallback
& error_callback
));
66 MOCK_METHOD3(StartDiscoverySessionWithFilterRaw
,
67 void(const BluetoothDiscoveryFilter
*,
68 const DiscoverySessionCallback
& callback
,
69 const ErrorCallback
& error_callback
));
70 MOCK_METHOD3(SetDiscoveryFilterRaw
,
71 void(const BluetoothDiscoveryFilter
*,
72 const base::Closure
& callback
,
73 const DiscoverySessionErrorCallback
& error_callback
));
74 MOCK_CONST_METHOD0(GetDevices
, BluetoothAdapter::ConstDeviceList());
75 MOCK_METHOD1(GetDevice
, BluetoothDevice
*(const std::string
& address
));
76 MOCK_CONST_METHOD1(GetDevice
,
77 const BluetoothDevice
*(const std::string
& address
));
78 MOCK_METHOD2(AddPairingDelegate
,
79 void(BluetoothDevice::PairingDelegate
* pairing_delegate
,
80 enum PairingDelegatePriority priority
));
81 MOCK_METHOD1(RemovePairingDelegate
,
82 void(BluetoothDevice::PairingDelegate
* pairing_delegate
));
83 MOCK_METHOD0(DefaultPairingDelegate
, BluetoothDevice::PairingDelegate
*());
84 MOCK_METHOD4(CreateRfcommService
,
85 void(const BluetoothUUID
& uuid
,
86 const ServiceOptions
& options
,
87 const CreateServiceCallback
& callback
,
88 const CreateServiceErrorCallback
& error_callback
));
89 MOCK_METHOD4(CreateL2capService
,
90 void(const BluetoothUUID
& uuid
,
91 const ServiceOptions
& options
,
92 const CreateServiceCallback
& callback
,
93 const CreateServiceErrorCallback
& error_callback
));
94 MOCK_METHOD3(RegisterAudioSink
,
95 void(const BluetoothAudioSink::Options
& options
,
96 const AcquiredCallback
& callback
,
97 const BluetoothAudioSink::ErrorCallback
& error_callback
));
99 void StartDiscoverySessionWithFilter(
100 scoped_ptr
<BluetoothDiscoveryFilter
> discovery_filter
,
101 const DiscoverySessionCallback
& callback
,
102 const ErrorCallback
& error_callback
);
104 // BluetoothAdapter is supposed to manage the lifetime of BluetoothDevices.
105 // This method takes ownership of the MockBluetoothDevice. This is only for
106 // convenience as far testing is concerned and it's possible to write test
107 // cases without using these functions.
108 void AddMockDevice(scoped_ptr
<MockBluetoothDevice
> mock_device
);
109 BluetoothAdapter::ConstDeviceList
GetConstMockDevices();
110 BluetoothAdapter::DeviceList
GetMockDevices();
113 void AddDiscoverySession(
114 BluetoothDiscoveryFilter
* discovery_filter
,
115 const base::Closure
& callback
,
116 const DiscoverySessionErrorCallback
& error_callback
) override
;
117 void RemoveDiscoverySession(
118 BluetoothDiscoveryFilter
* discovery_filter
,
119 const base::Closure
& callback
,
120 const DiscoverySessionErrorCallback
& error_callback
) override
;
121 void SetDiscoveryFilter(
122 scoped_ptr
<BluetoothDiscoveryFilter
> discovery_filter
,
123 const base::Closure
& callback
,
124 const DiscoverySessionErrorCallback
& error_callback
) override
;
125 void RegisterAdvertisement(
126 scoped_ptr
<BluetoothAdvertisement::Data
> advertisement_data
,
127 const CreateAdvertisementCallback
& callback
,
128 const CreateAdvertisementErrorCallback
& error_callback
) override
;
129 virtual ~MockBluetoothAdapter();
131 MOCK_METHOD1(RemovePairingDelegateInternal
,
132 void(BluetoothDevice::PairingDelegate
* pairing_delegate
));
134 ScopedVector
<MockBluetoothDevice
> mock_devices_
;
137 } // namespace device
139 #endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_ADAPTER_H_