Roll src/third_party/WebKit 787a07c:716df21 (svn 201034:201036)
[chromium-blink-merge.git] / device / bluetooth / test / test_bluetooth_adapter_observer.h
blobf3a9cf879de0e6a5e78971fa6df6b716eecba83e
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 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_ADAPTER_OBSERVER_H_
6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_ADAPTER_OBSERVER_H_
8 #include "device/bluetooth/bluetooth_adapter.h"
10 namespace device {
12 // Test implementation of BluetoothAdapter::Observer counting method calls and
13 // caching last reported values.
14 class TestBluetoothAdapterObserver : public BluetoothAdapter::Observer {
15 public:
16 TestBluetoothAdapterObserver(scoped_refptr<BluetoothAdapter> adapter);
17 ~TestBluetoothAdapterObserver() override;
19 // Reset counters and cached values.
20 void Reset();
22 // BluetoothAdapter::Observer
23 void AdapterPresentChanged(BluetoothAdapter* adapter, bool present) override;
24 void AdapterPoweredChanged(BluetoothAdapter* adapter, bool powered) override;
25 void AdapterDiscoverableChanged(BluetoothAdapter* adapter,
26 bool discoverable) override;
27 void AdapterDiscoveringChanged(BluetoothAdapter* adapter,
28 bool discovering) override;
29 void DeviceAdded(BluetoothAdapter* adapter, BluetoothDevice* device) override;
30 void DeviceChanged(BluetoothAdapter* adapter,
31 BluetoothDevice* device) override;
32 void DeviceRemoved(BluetoothAdapter* adapter,
33 BluetoothDevice* device) override;
34 void GattServiceAdded(BluetoothAdapter* adapter,
35 BluetoothDevice* device,
36 BluetoothGattService* service) override;
37 void GattServiceRemoved(BluetoothAdapter* adapter,
38 BluetoothDevice* device,
39 BluetoothGattService* service) override;
40 void GattDiscoveryCompleteForService(BluetoothAdapter* adapter,
41 BluetoothGattService* service) override;
42 void GattServiceChanged(BluetoothAdapter* adapter,
43 BluetoothGattService* service) override;
44 void GattCharacteristicAdded(
45 BluetoothAdapter* adapter,
46 BluetoothGattCharacteristic* characteristic) override;
47 void GattCharacteristicRemoved(
48 BluetoothAdapter* adapter,
49 BluetoothGattCharacteristic* characteristic) override;
50 void GattDescriptorAdded(BluetoothAdapter* adapter,
51 BluetoothGattDescriptor* descriptor) override;
52 void GattDescriptorRemoved(BluetoothAdapter* adapter,
53 BluetoothGattDescriptor* descriptor) override;
54 void GattCharacteristicValueChanged(
55 BluetoothAdapter* adapter,
56 BluetoothGattCharacteristic* characteristic,
57 const std::vector<uint8>& value) override;
58 void GattDescriptorValueChanged(BluetoothAdapter* adapter,
59 BluetoothGattDescriptor* descriptor,
60 const std::vector<uint8>& value) override;
62 // Adapter related:
63 int present_changed_count() { return present_changed_count_; }
64 int powered_changed_count() { return powered_changed_count_; }
65 int discoverable_changed_count() { return discoverable_changed_count_; }
66 int discovering_changed_count() { return discovering_changed_count_; }
67 bool last_present() { return last_present_; }
68 bool last_powered() { return last_powered_; }
69 bool last_discovering() { return last_discovering_; }
71 // Device related:
72 int device_added_count() { return device_added_count_; }
73 int device_changed_count() { return device_changed_count_; }
74 int device_removed_count() { return device_removed_count_; }
75 BluetoothDevice* last_device() { return last_device_; }
76 std::string last_device_address() { return last_device_address_; }
78 // GATT related:
79 int gatt_service_added_count() { return gatt_service_added_count_; }
80 int gatt_service_removed_count() { return gatt_service_removed_count_; }
81 int gatt_service_changed_count() { return gatt_service_changed_count_; }
82 int gatt_discovery_complete_count() { return gatt_discovery_complete_count_; }
83 int gatt_characteristic_added_count() {
84 return gatt_characteristic_added_count_;
86 int gatt_characteristic_removed_count() {
87 return gatt_characteristic_removed_count_;
89 int gatt_characteristic_value_changed_count() {
90 return gatt_characteristic_value_changed_count_;
92 int gatt_descriptor_added_count() { return gatt_descriptor_added_count_; }
93 int gatt_descriptor_removed_count() { return gatt_descriptor_removed_count_; }
94 int gatt_descriptor_value_changed_count() {
95 return gatt_descriptor_value_changed_count_;
97 std::string last_gatt_service_id() { return last_gatt_service_id_; }
98 BluetoothUUID last_gatt_service_uuid() { return last_gatt_service_uuid_; }
99 std::string last_gatt_characteristic_id() {
100 return last_gatt_characteristic_id_;
102 BluetoothUUID last_gatt_characteristic_uuid() {
103 return last_gatt_characteristic_uuid_;
105 std::vector<uint8> last_changed_characteristic_value() {
106 return last_changed_characteristic_value_;
108 std::string last_gatt_descriptor_id() { return last_gatt_descriptor_id_; }
109 BluetoothUUID last_gatt_descriptor_uuid() {
110 return last_gatt_descriptor_uuid_;
112 std::vector<uint8> last_changed_descriptor_value() {
113 return last_changed_descriptor_value_;
116 private:
117 // Some tests use a message loop since background processing is simulated;
118 // break out of those loops.
119 void QuitMessageLoop();
121 scoped_refptr<BluetoothAdapter> adapter_;
123 // Adapter related:
124 int present_changed_count_;
125 int powered_changed_count_;
126 int discoverable_changed_count_;
127 int discovering_changed_count_;
128 bool last_present_;
129 bool last_powered_;
130 bool last_discovering_;
132 // Device related:
133 int device_added_count_;
134 int device_changed_count_;
135 int device_removed_count_;
136 BluetoothDevice* last_device_;
137 std::string last_device_address_;
139 // GATT related:
140 int gatt_service_added_count_;
141 int gatt_service_removed_count_;
142 int gatt_service_changed_count_;
143 int gatt_discovery_complete_count_;
144 int gatt_characteristic_added_count_;
145 int gatt_characteristic_removed_count_;
146 int gatt_characteristic_value_changed_count_;
147 int gatt_descriptor_added_count_;
148 int gatt_descriptor_removed_count_;
149 int gatt_descriptor_value_changed_count_;
150 std::string last_gatt_service_id_;
151 BluetoothUUID last_gatt_service_uuid_;
152 std::string last_gatt_characteristic_id_;
153 BluetoothUUID last_gatt_characteristic_uuid_;
154 std::vector<uint8> last_changed_characteristic_value_;
155 std::string last_gatt_descriptor_id_;
156 BluetoothUUID last_gatt_descriptor_uuid_;
157 std::vector<uint8> last_changed_descriptor_value_;
159 DISALLOW_COPY_AND_ASSIGN(TestBluetoothAdapterObserver);
162 } // namespace device
164 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_ADAPTER_OBSERVER_H_