| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 adapter_->AddObserver(this); | 74 adapter_->AddObserver(this); |
| 75 } | 75 } |
| 76 | 76 |
| 77 virtual ~TestObserver() { | 77 virtual ~TestObserver() { |
| 78 adapter_->RemoveObserver(this); | 78 adapter_->RemoveObserver(this); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // BluetoothAdapter::Observer overrides. | 81 // BluetoothAdapter::Observer overrides. |
| 82 virtual void GattServiceAdded(BluetoothAdapter* adapter, | 82 virtual void GattServiceAdded(BluetoothAdapter* adapter, |
| 83 BluetoothDevice* device, | 83 BluetoothDevice* device, |
| 84 BluetoothGattService* service) OVERRIDE { | 84 BluetoothGattService* service) override { |
| 85 ASSERT_EQ(adapter_.get(), adapter); | 85 ASSERT_EQ(adapter_.get(), adapter); |
| 86 ASSERT_EQ(service->GetDevice(), device); | 86 ASSERT_EQ(service->GetDevice(), device); |
| 87 | 87 |
| 88 ++gatt_service_added_count_; | 88 ++gatt_service_added_count_; |
| 89 last_gatt_service_id_ = service->GetIdentifier(); | 89 last_gatt_service_id_ = service->GetIdentifier(); |
| 90 last_gatt_service_uuid_ = service->GetUUID(); | 90 last_gatt_service_uuid_ = service->GetUUID(); |
| 91 | 91 |
| 92 EXPECT_FALSE(service->IsLocal()); | 92 EXPECT_FALSE(service->IsLocal()); |
| 93 EXPECT_TRUE(service->IsPrimary()); | 93 EXPECT_TRUE(service->IsPrimary()); |
| 94 | 94 |
| 95 EXPECT_EQ(device->GetGattService(last_gatt_service_id_), service); | 95 EXPECT_EQ(device->GetGattService(last_gatt_service_id_), service); |
| 96 | 96 |
| 97 QuitMessageLoop(); | 97 QuitMessageLoop(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 virtual void GattServiceRemoved(BluetoothAdapter* adapter, | 100 virtual void GattServiceRemoved(BluetoothAdapter* adapter, |
| 101 BluetoothDevice* device, | 101 BluetoothDevice* device, |
| 102 BluetoothGattService* service) OVERRIDE { | 102 BluetoothGattService* service) override { |
| 103 ASSERT_EQ(adapter_.get(), adapter); | 103 ASSERT_EQ(adapter_.get(), adapter); |
| 104 ASSERT_EQ(service->GetDevice(), device); | 104 ASSERT_EQ(service->GetDevice(), device); |
| 105 | 105 |
| 106 ++gatt_service_removed_count_; | 106 ++gatt_service_removed_count_; |
| 107 last_gatt_service_id_ = service->GetIdentifier(); | 107 last_gatt_service_id_ = service->GetIdentifier(); |
| 108 last_gatt_service_uuid_ = service->GetUUID(); | 108 last_gatt_service_uuid_ = service->GetUUID(); |
| 109 | 109 |
| 110 EXPECT_FALSE(service->IsLocal()); | 110 EXPECT_FALSE(service->IsLocal()); |
| 111 EXPECT_TRUE(service->IsPrimary()); | 111 EXPECT_TRUE(service->IsPrimary()); |
| 112 | 112 |
| 113 // The device should return NULL for this service. | 113 // The device should return NULL for this service. |
| 114 EXPECT_FALSE(device->GetGattService(last_gatt_service_id_)); | 114 EXPECT_FALSE(device->GetGattService(last_gatt_service_id_)); |
| 115 | 115 |
| 116 QuitMessageLoop(); | 116 QuitMessageLoop(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 virtual void GattDiscoveryCompleteForService( | 119 virtual void GattDiscoveryCompleteForService( |
| 120 BluetoothAdapter* adapter, | 120 BluetoothAdapter* adapter, |
| 121 BluetoothGattService* service) OVERRIDE { | 121 BluetoothGattService* service) override { |
| 122 ASSERT_EQ(adapter_.get(), adapter); | 122 ASSERT_EQ(adapter_.get(), adapter); |
| 123 ++gatt_discovery_complete_count_; | 123 ++gatt_discovery_complete_count_; |
| 124 | 124 |
| 125 QuitMessageLoop(); | 125 QuitMessageLoop(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 virtual void GattServiceChanged(BluetoothAdapter* adapter, | 128 virtual void GattServiceChanged(BluetoothAdapter* adapter, |
| 129 BluetoothGattService* service) OVERRIDE { | 129 BluetoothGattService* service) override { |
| 130 ASSERT_EQ(adapter_.get(), adapter); | 130 ASSERT_EQ(adapter_.get(), adapter); |
| 131 ++gatt_service_changed_count_; | 131 ++gatt_service_changed_count_; |
| 132 | 132 |
| 133 QuitMessageLoop(); | 133 QuitMessageLoop(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 virtual void GattCharacteristicAdded( | 136 virtual void GattCharacteristicAdded( |
| 137 BluetoothAdapter* adapter, | 137 BluetoothAdapter* adapter, |
| 138 BluetoothGattCharacteristic* characteristic) OVERRIDE { | 138 BluetoothGattCharacteristic* characteristic) override { |
| 139 ASSERT_EQ(adapter_.get(), adapter); | 139 ASSERT_EQ(adapter_.get(), adapter); |
| 140 | 140 |
| 141 ++gatt_characteristic_added_count_; | 141 ++gatt_characteristic_added_count_; |
| 142 last_gatt_characteristic_id_ = characteristic->GetIdentifier(); | 142 last_gatt_characteristic_id_ = characteristic->GetIdentifier(); |
| 143 last_gatt_characteristic_uuid_ = characteristic->GetUUID(); | 143 last_gatt_characteristic_uuid_ = characteristic->GetUUID(); |
| 144 | 144 |
| 145 ASSERT_TRUE(characteristic->GetService()); | 145 ASSERT_TRUE(characteristic->GetService()); |
| 146 EXPECT_EQ(characteristic->GetService()->GetCharacteristic( | 146 EXPECT_EQ(characteristic->GetService()->GetCharacteristic( |
| 147 last_gatt_characteristic_id_), | 147 last_gatt_characteristic_id_), |
| 148 characteristic); | 148 characteristic); |
| 149 | 149 |
| 150 QuitMessageLoop(); | 150 QuitMessageLoop(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 virtual void GattCharacteristicRemoved( | 153 virtual void GattCharacteristicRemoved( |
| 154 BluetoothAdapter* adapter, | 154 BluetoothAdapter* adapter, |
| 155 BluetoothGattCharacteristic* characteristic) OVERRIDE { | 155 BluetoothGattCharacteristic* characteristic) override { |
| 156 ASSERT_EQ(adapter_.get(), adapter); | 156 ASSERT_EQ(adapter_.get(), adapter); |
| 157 | 157 |
| 158 ++gatt_characteristic_removed_count_; | 158 ++gatt_characteristic_removed_count_; |
| 159 last_gatt_characteristic_id_ = characteristic->GetIdentifier(); | 159 last_gatt_characteristic_id_ = characteristic->GetIdentifier(); |
| 160 last_gatt_characteristic_uuid_ = characteristic->GetUUID(); | 160 last_gatt_characteristic_uuid_ = characteristic->GetUUID(); |
| 161 | 161 |
| 162 // The service should return NULL for this characteristic. | 162 // The service should return NULL for this characteristic. |
| 163 ASSERT_TRUE(characteristic->GetService()); | 163 ASSERT_TRUE(characteristic->GetService()); |
| 164 EXPECT_FALSE(characteristic->GetService()->GetCharacteristic( | 164 EXPECT_FALSE(characteristic->GetService()->GetCharacteristic( |
| 165 last_gatt_characteristic_id_)); | 165 last_gatt_characteristic_id_)); |
| 166 | 166 |
| 167 QuitMessageLoop(); | 167 QuitMessageLoop(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 virtual void GattCharacteristicValueChanged( | 170 virtual void GattCharacteristicValueChanged( |
| 171 BluetoothAdapter* adapter, | 171 BluetoothAdapter* adapter, |
| 172 BluetoothGattCharacteristic* characteristic, | 172 BluetoothGattCharacteristic* characteristic, |
| 173 const std::vector<uint8>& value) OVERRIDE { | 173 const std::vector<uint8>& value) override { |
| 174 ASSERT_EQ(adapter_.get(), adapter); | 174 ASSERT_EQ(adapter_.get(), adapter); |
| 175 | 175 |
| 176 ++gatt_characteristic_value_changed_count_; | 176 ++gatt_characteristic_value_changed_count_; |
| 177 last_gatt_characteristic_id_ = characteristic->GetIdentifier(); | 177 last_gatt_characteristic_id_ = characteristic->GetIdentifier(); |
| 178 last_gatt_characteristic_uuid_ = characteristic->GetUUID(); | 178 last_gatt_characteristic_uuid_ = characteristic->GetUUID(); |
| 179 last_changed_characteristic_value_ = value; | 179 last_changed_characteristic_value_ = value; |
| 180 | 180 |
| 181 ASSERT_TRUE(characteristic->GetService()); | 181 ASSERT_TRUE(characteristic->GetService()); |
| 182 EXPECT_EQ(characteristic->GetService()->GetCharacteristic( | 182 EXPECT_EQ(characteristic->GetService()->GetCharacteristic( |
| 183 last_gatt_characteristic_id_), | 183 last_gatt_characteristic_id_), |
| 184 characteristic); | 184 characteristic); |
| 185 | 185 |
| 186 QuitMessageLoop(); | 186 QuitMessageLoop(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 virtual void GattDescriptorAdded( | 189 virtual void GattDescriptorAdded( |
| 190 BluetoothAdapter* adapter, | 190 BluetoothAdapter* adapter, |
| 191 BluetoothGattDescriptor* descriptor) OVERRIDE { | 191 BluetoothGattDescriptor* descriptor) override { |
| 192 ASSERT_EQ(adapter_.get(), adapter); | 192 ASSERT_EQ(adapter_.get(), adapter); |
| 193 | 193 |
| 194 ++gatt_descriptor_added_count_; | 194 ++gatt_descriptor_added_count_; |
| 195 last_gatt_descriptor_id_ = descriptor->GetIdentifier(); | 195 last_gatt_descriptor_id_ = descriptor->GetIdentifier(); |
| 196 last_gatt_descriptor_uuid_ = descriptor->GetUUID(); | 196 last_gatt_descriptor_uuid_ = descriptor->GetUUID(); |
| 197 | 197 |
| 198 ASSERT_TRUE(descriptor->GetCharacteristic()); | 198 ASSERT_TRUE(descriptor->GetCharacteristic()); |
| 199 EXPECT_EQ(descriptor->GetCharacteristic()->GetDescriptor( | 199 EXPECT_EQ(descriptor->GetCharacteristic()->GetDescriptor( |
| 200 last_gatt_descriptor_id_), | 200 last_gatt_descriptor_id_), |
| 201 descriptor); | 201 descriptor); |
| 202 | 202 |
| 203 QuitMessageLoop(); | 203 QuitMessageLoop(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 virtual void GattDescriptorRemoved( | 206 virtual void GattDescriptorRemoved( |
| 207 BluetoothAdapter* adapter, | 207 BluetoothAdapter* adapter, |
| 208 BluetoothGattDescriptor* descriptor) OVERRIDE { | 208 BluetoothGattDescriptor* descriptor) override { |
| 209 ASSERT_EQ(adapter_.get(), adapter); | 209 ASSERT_EQ(adapter_.get(), adapter); |
| 210 | 210 |
| 211 ++gatt_descriptor_removed_count_; | 211 ++gatt_descriptor_removed_count_; |
| 212 last_gatt_descriptor_id_ = descriptor->GetIdentifier(); | 212 last_gatt_descriptor_id_ = descriptor->GetIdentifier(); |
| 213 last_gatt_descriptor_uuid_ = descriptor->GetUUID(); | 213 last_gatt_descriptor_uuid_ = descriptor->GetUUID(); |
| 214 | 214 |
| 215 // The characteristic should return NULL for this descriptor.. | 215 // The characteristic should return NULL for this descriptor.. |
| 216 ASSERT_TRUE(descriptor->GetCharacteristic()); | 216 ASSERT_TRUE(descriptor->GetCharacteristic()); |
| 217 EXPECT_FALSE(descriptor->GetCharacteristic()->GetDescriptor( | 217 EXPECT_FALSE(descriptor->GetCharacteristic()->GetDescriptor( |
| 218 last_gatt_descriptor_id_)); | 218 last_gatt_descriptor_id_)); |
| 219 | 219 |
| 220 QuitMessageLoop(); | 220 QuitMessageLoop(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 virtual void GattDescriptorValueChanged( | 223 virtual void GattDescriptorValueChanged( |
| 224 BluetoothAdapter* adapter, | 224 BluetoothAdapter* adapter, |
| 225 BluetoothGattDescriptor* descriptor, | 225 BluetoothGattDescriptor* descriptor, |
| 226 const std::vector<uint8>& value) OVERRIDE { | 226 const std::vector<uint8>& value) override { |
| 227 ASSERT_EQ(adapter_.get(), adapter); | 227 ASSERT_EQ(adapter_.get(), adapter); |
| 228 | 228 |
| 229 ++gatt_descriptor_value_changed_count_; | 229 ++gatt_descriptor_value_changed_count_; |
| 230 last_gatt_descriptor_id_ = descriptor->GetIdentifier(); | 230 last_gatt_descriptor_id_ = descriptor->GetIdentifier(); |
| 231 last_gatt_descriptor_uuid_ = descriptor->GetUUID(); | 231 last_gatt_descriptor_uuid_ = descriptor->GetUUID(); |
| 232 last_changed_descriptor_value_ = value; | 232 last_changed_descriptor_value_ = value; |
| 233 | 233 |
| 234 ASSERT_TRUE(descriptor->GetCharacteristic()); | 234 ASSERT_TRUE(descriptor->GetCharacteristic()); |
| 235 EXPECT_EQ(descriptor->GetCharacteristic()->GetDescriptor( | 235 EXPECT_EQ(descriptor->GetCharacteristic()->GetDescriptor( |
| 236 last_gatt_descriptor_id_), | 236 last_gatt_descriptor_id_), |
| (...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 | 1419 |
| 1420 EXPECT_EQ(1, success_callback_count_); | 1420 EXPECT_EQ(1, success_callback_count_); |
| 1421 EXPECT_EQ(0, error_callback_count_); | 1421 EXPECT_EQ(0, error_callback_count_); |
| 1422 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); | 1422 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); |
| 1423 EXPECT_TRUE(characteristic->IsNotifying()); | 1423 EXPECT_TRUE(characteristic->IsNotifying()); |
| 1424 EXPECT_EQ(1U, update_sessions_.size()); | 1424 EXPECT_EQ(1U, update_sessions_.size()); |
| 1425 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1425 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
| 1426 } | 1426 } |
| 1427 | 1427 |
| 1428 } // namespace chromeos | 1428 } // namespace chromeos |
| OLD | NEW |