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" | |
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | |
10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | |
11 #include "chromeos/dbus/fake_bluetooth_device_client.h" | |
12 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" | |
13 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h" | |
14 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" | |
15 #include "chromeos/dbus/fake_bluetooth_input_client.h" | |
16 #include "dbus/object_path.h" | 8 #include "dbus/object_path.h" |
17 #include "device/bluetooth/bluetooth_adapter.h" | 9 #include "device/bluetooth/bluetooth_adapter.h" |
18 #include "device/bluetooth/bluetooth_adapter_factory.h" | 10 #include "device/bluetooth/bluetooth_adapter_factory.h" |
19 #include "device/bluetooth/bluetooth_device.h" | 11 #include "device/bluetooth/bluetooth_device.h" |
20 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 12 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
21 #include "device/bluetooth/bluetooth_gatt_connection.h" | 13 #include "device/bluetooth/bluetooth_gatt_connection.h" |
22 #include "device/bluetooth/bluetooth_gatt_descriptor.h" | 14 #include "device/bluetooth/bluetooth_gatt_descriptor.h" |
23 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 15 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
24 #include "device/bluetooth/bluetooth_gatt_service.h" | 16 #include "device/bluetooth/bluetooth_gatt_service.h" |
25 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
| 18 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 19 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
| 20 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" |
| 21 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
| 22 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_client.h" |
| 23 #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_client.h" |
| 24 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" |
| 25 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" |
26 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 26 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 | 28 |
29 using device::BluetoothAdapter; | 29 using device::BluetoothAdapter; |
30 using device::BluetoothDevice; | 30 using device::BluetoothDevice; |
31 using device::BluetoothGattCharacteristic; | 31 using device::BluetoothGattCharacteristic; |
32 using device::BluetoothGattConnection; | 32 using device::BluetoothGattConnection; |
33 using device::BluetoothGattDescriptor; | 33 using device::BluetoothGattDescriptor; |
34 using device::BluetoothGattService; | 34 using device::BluetoothGattService; |
35 using device::BluetoothGattNotifySession; | 35 using device::BluetoothGattNotifySession; |
36 using device::BluetoothUUID; | 36 using device::BluetoothUUID; |
37 using device::TestBluetoothAdapterObserver; | 37 using device::TestBluetoothAdapterObserver; |
38 | 38 |
39 namespace chromeos { | 39 namespace chromeos { |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 const BluetoothUUID kHeartRateMeasurementUUID( | 43 const BluetoothUUID kHeartRateMeasurementUUID( |
44 FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID); | 44 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID); |
45 const BluetoothUUID kBodySensorLocationUUID( | 45 const BluetoothUUID kBodySensorLocationUUID( |
46 FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID); | 46 bluez::FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID); |
47 const BluetoothUUID kHeartRateControlPointUUID( | 47 const BluetoothUUID kHeartRateControlPointUUID( |
48 FakeBluetoothGattCharacteristicClient::kHeartRateControlPointUUID); | 48 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateControlPointUUID); |
49 | 49 |
50 // Compares GATT characteristic/descriptor values. Returns true, if the values | 50 // Compares GATT characteristic/descriptor values. Returns true, if the values |
51 // are equal. | 51 // are equal. |
52 bool ValuesEqual(const std::vector<uint8>& value0, | 52 bool ValuesEqual(const std::vector<uint8>& value0, |
53 const std::vector<uint8>& value1) { | 53 const std::vector<uint8>& value1) { |
54 if (value0.size() != value1.size()) | 54 if (value0.size() != value1.size()) |
55 return false; | 55 return false; |
56 for (size_t i = 0; i < value0.size(); ++i) | 56 for (size_t i = 0; i < value0.size(); ++i) |
57 if (value0[i] != value1[i]) | 57 if (value0[i] != value1[i]) |
58 return false; | 58 return false; |
59 return true; | 59 return true; |
60 } | 60 } |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
64 class BluetoothGattChromeOSTest : public testing::Test { | 64 class BluetoothGattChromeOSTest : public testing::Test { |
65 public: | 65 public: |
66 BluetoothGattChromeOSTest() | 66 BluetoothGattChromeOSTest() |
67 : fake_bluetooth_gatt_service_client_(NULL), | 67 : fake_bluetooth_gatt_service_client_(NULL), |
68 success_callback_count_(0), | 68 success_callback_count_(0), |
69 error_callback_count_(0) { | 69 error_callback_count_(0) { |
70 } | 70 } |
71 | 71 |
72 void SetUp() override { | 72 void SetUp() override { |
73 scoped_ptr<DBusThreadManagerSetter> dbus_setter = | 73 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = |
74 chromeos::DBusThreadManager::GetSetterForTesting(); | 74 bluez::BluezDBusManager::GetSetterForTesting(); |
75 fake_bluetooth_device_client_ = new FakeBluetoothDeviceClient; | 75 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; |
76 fake_bluetooth_gatt_service_client_ = | 76 fake_bluetooth_gatt_service_client_ = |
77 new FakeBluetoothGattServiceClient; | 77 new bluez::FakeBluetoothGattServiceClient; |
78 fake_bluetooth_gatt_characteristic_client_ = | 78 fake_bluetooth_gatt_characteristic_client_ = |
79 new FakeBluetoothGattCharacteristicClient; | 79 new bluez::FakeBluetoothGattCharacteristicClient; |
80 fake_bluetooth_gatt_descriptor_client_ = | 80 fake_bluetooth_gatt_descriptor_client_ = |
81 new FakeBluetoothGattDescriptorClient; | 81 new bluez::FakeBluetoothGattDescriptorClient; |
82 dbus_setter->SetBluetoothDeviceClient( | 82 dbus_setter->SetBluetoothDeviceClient( |
83 scoped_ptr<BluetoothDeviceClient>( | 83 scoped_ptr<bluez::BluetoothDeviceClient>( |
84 fake_bluetooth_device_client_)); | 84 fake_bluetooth_device_client_)); |
85 dbus_setter->SetBluetoothGattServiceClient( | 85 dbus_setter->SetBluetoothGattServiceClient( |
86 scoped_ptr<BluetoothGattServiceClient>( | 86 scoped_ptr<bluez::BluetoothGattServiceClient>( |
87 fake_bluetooth_gatt_service_client_)); | 87 fake_bluetooth_gatt_service_client_)); |
88 dbus_setter->SetBluetoothGattCharacteristicClient( | 88 dbus_setter->SetBluetoothGattCharacteristicClient( |
89 scoped_ptr<BluetoothGattCharacteristicClient>( | 89 scoped_ptr<bluez::BluetoothGattCharacteristicClient>( |
90 fake_bluetooth_gatt_characteristic_client_)); | 90 fake_bluetooth_gatt_characteristic_client_)); |
91 dbus_setter->SetBluetoothGattDescriptorClient( | 91 dbus_setter->SetBluetoothGattDescriptorClient( |
92 scoped_ptr<BluetoothGattDescriptorClient>( | 92 scoped_ptr<bluez::BluetoothGattDescriptorClient>( |
93 fake_bluetooth_gatt_descriptor_client_)); | 93 fake_bluetooth_gatt_descriptor_client_)); |
94 dbus_setter->SetBluetoothAdapterClient( | 94 dbus_setter->SetBluetoothAdapterClient( |
95 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient)); | 95 scoped_ptr<bluez::BluetoothAdapterClient>( |
| 96 new bluez::FakeBluetoothAdapterClient)); |
96 dbus_setter->SetBluetoothInputClient( | 97 dbus_setter->SetBluetoothInputClient( |
97 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient)); | 98 scoped_ptr<bluez::BluetoothInputClient>( |
| 99 new bluez::FakeBluetoothInputClient)); |
98 dbus_setter->SetBluetoothAgentManagerClient( | 100 dbus_setter->SetBluetoothAgentManagerClient( |
99 scoped_ptr<BluetoothAgentManagerClient>( | 101 scoped_ptr<bluez::BluetoothAgentManagerClient>( |
100 new FakeBluetoothAgentManagerClient)); | 102 new bluez::FakeBluetoothAgentManagerClient)); |
101 | 103 |
102 GetAdapter(); | 104 GetAdapter(); |
103 | 105 |
104 adapter_->SetPowered( | 106 adapter_->SetPowered( |
105 true, | 107 true, |
106 base::Bind(&base::DoNothing), | 108 base::Bind(&base::DoNothing), |
107 base::Bind(&base::DoNothing)); | 109 base::Bind(&base::DoNothing)); |
108 ASSERT_TRUE(adapter_->IsPowered()); | 110 ASSERT_TRUE(adapter_->IsPowered()); |
109 } | 111 } |
110 | 112 |
111 void TearDown() override { | 113 void TearDown() override { |
112 adapter_ = NULL; | 114 adapter_ = NULL; |
113 update_sessions_.clear(); | 115 update_sessions_.clear(); |
114 gatt_conn_.reset(); | 116 gatt_conn_.reset(); |
115 DBusThreadManager::Shutdown(); | 117 bluez::BluezDBusManager::Shutdown(); |
116 } | 118 } |
117 | 119 |
118 void GetAdapter() { | 120 void GetAdapter() { |
119 device::BluetoothAdapterFactory::GetAdapter( | 121 device::BluetoothAdapterFactory::GetAdapter( |
120 base::Bind(&BluetoothGattChromeOSTest::AdapterCallback, | 122 base::Bind(&BluetoothGattChromeOSTest::AdapterCallback, |
121 base::Unretained(this))); | 123 base::Unretained(this))); |
122 ASSERT_TRUE(adapter_.get() != NULL); | 124 ASSERT_TRUE(adapter_.get() != NULL); |
123 ASSERT_TRUE(adapter_->IsInitialized()); | 125 ASSERT_TRUE(adapter_->IsInitialized()); |
124 ASSERT_TRUE(adapter_->IsPresent()); | 126 ASSERT_TRUE(adapter_->IsPresent()); |
125 } | 127 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 170 |
169 protected: | 171 protected: |
170 void QuitMessageLoop() { | 172 void QuitMessageLoop() { |
171 if (base::MessageLoop::current() && | 173 if (base::MessageLoop::current() && |
172 base::MessageLoop::current()->is_running()) | 174 base::MessageLoop::current()->is_running()) |
173 base::MessageLoop::current()->Quit(); | 175 base::MessageLoop::current()->Quit(); |
174 } | 176 } |
175 | 177 |
176 base::MessageLoop message_loop_; | 178 base::MessageLoop message_loop_; |
177 | 179 |
178 FakeBluetoothDeviceClient* fake_bluetooth_device_client_; | 180 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; |
179 FakeBluetoothGattServiceClient* fake_bluetooth_gatt_service_client_; | 181 bluez::FakeBluetoothGattServiceClient* fake_bluetooth_gatt_service_client_; |
180 FakeBluetoothGattCharacteristicClient* | 182 bluez::FakeBluetoothGattCharacteristicClient* |
181 fake_bluetooth_gatt_characteristic_client_; | 183 fake_bluetooth_gatt_characteristic_client_; |
182 FakeBluetoothGattDescriptorClient* fake_bluetooth_gatt_descriptor_client_; | 184 bluez::FakeBluetoothGattDescriptorClient* |
| 185 fake_bluetooth_gatt_descriptor_client_; |
183 scoped_ptr<device::BluetoothGattConnection> gatt_conn_; | 186 scoped_ptr<device::BluetoothGattConnection> gatt_conn_; |
184 ScopedVector<BluetoothGattNotifySession> update_sessions_; | 187 ScopedVector<BluetoothGattNotifySession> update_sessions_; |
185 scoped_refptr<BluetoothAdapter> adapter_; | 188 scoped_refptr<BluetoothAdapter> adapter_; |
186 | 189 |
187 int success_callback_count_; | 190 int success_callback_count_; |
188 int error_callback_count_; | 191 int error_callback_count_; |
189 std::vector<uint8> last_read_value_; | 192 std::vector<uint8> last_read_value_; |
190 BluetoothGattService::GattErrorCode last_service_error_; | 193 BluetoothGattService::GattErrorCode last_service_error_; |
191 }; | 194 }; |
192 | 195 |
193 TEST_F(BluetoothGattChromeOSTest, GattConnection) { | 196 TEST_F(BluetoothGattChromeOSTest, GattConnection) { |
194 fake_bluetooth_device_client_->CreateDevice( | 197 fake_bluetooth_device_client_->CreateDevice( |
195 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 198 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
196 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 199 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
197 BluetoothDevice* device = adapter_->GetDevice( | 200 BluetoothDevice* device = |
198 FakeBluetoothDeviceClient::kLowEnergyAddress); | 201 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
199 ASSERT_TRUE(device); | 202 ASSERT_TRUE(device); |
200 ASSERT_FALSE(device->IsConnected()); | 203 ASSERT_FALSE(device->IsConnected()); |
201 ASSERT_FALSE(gatt_conn_.get()); | 204 ASSERT_FALSE(gatt_conn_.get()); |
202 ASSERT_EQ(0, success_callback_count_); | 205 ASSERT_EQ(0, success_callback_count_); |
203 ASSERT_EQ(0, error_callback_count_); | 206 ASSERT_EQ(0, error_callback_count_); |
204 | 207 |
205 device->CreateGattConnection( | 208 device->CreateGattConnection( |
206 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, | 209 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
207 base::Unretained(this)), | 210 base::Unretained(this)), |
208 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, | 211 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
209 base::Unretained(this))); | 212 base::Unretained(this))); |
210 | 213 |
211 EXPECT_EQ(1, success_callback_count_); | 214 EXPECT_EQ(1, success_callback_count_); |
212 EXPECT_EQ(0, error_callback_count_); | 215 EXPECT_EQ(0, error_callback_count_); |
213 EXPECT_TRUE(device->IsConnected()); | 216 EXPECT_TRUE(device->IsConnected()); |
214 ASSERT_TRUE(gatt_conn_.get()); | 217 ASSERT_TRUE(gatt_conn_.get()); |
215 EXPECT_TRUE(gatt_conn_->IsConnected()); | 218 EXPECT_TRUE(gatt_conn_->IsConnected()); |
216 EXPECT_EQ(FakeBluetoothDeviceClient::kLowEnergyAddress, | 219 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, |
217 gatt_conn_->GetDeviceAddress()); | 220 gatt_conn_->GetDeviceAddress()); |
218 | 221 |
219 gatt_conn_->Disconnect(); | 222 gatt_conn_->Disconnect(); |
220 EXPECT_TRUE(device->IsConnected()); | 223 EXPECT_TRUE(device->IsConnected()); |
221 EXPECT_FALSE(gatt_conn_->IsConnected()); | 224 EXPECT_FALSE(gatt_conn_->IsConnected()); |
222 | 225 |
223 device->CreateGattConnection( | 226 device->CreateGattConnection( |
224 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, | 227 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, |
225 base::Unretained(this)), | 228 base::Unretained(this)), |
226 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, | 229 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
(...skipping 21 matching lines...) Expand all Loading... |
248 base::Unretained(this)), | 251 base::Unretained(this)), |
249 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, | 252 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, |
250 base::Unretained(this))); | 253 base::Unretained(this))); |
251 | 254 |
252 EXPECT_EQ(4, success_callback_count_); | 255 EXPECT_EQ(4, success_callback_count_); |
253 EXPECT_EQ(0, error_callback_count_); | 256 EXPECT_EQ(0, error_callback_count_); |
254 EXPECT_TRUE(device->IsConnected()); | 257 EXPECT_TRUE(device->IsConnected()); |
255 EXPECT_TRUE(gatt_conn_->IsConnected()); | 258 EXPECT_TRUE(gatt_conn_->IsConnected()); |
256 | 259 |
257 fake_bluetooth_device_client_->RemoveDevice( | 260 fake_bluetooth_device_client_->RemoveDevice( |
258 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 261 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
259 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 262 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
260 ASSERT_TRUE(gatt_conn_.get()); | 263 ASSERT_TRUE(gatt_conn_.get()); |
261 EXPECT_FALSE(gatt_conn_->IsConnected()); | 264 EXPECT_FALSE(gatt_conn_->IsConnected()); |
262 } | 265 } |
263 | 266 |
264 TEST_F(BluetoothGattChromeOSTest, GattServiceAddedAndRemoved) { | 267 TEST_F(BluetoothGattChromeOSTest, GattServiceAddedAndRemoved) { |
265 // Create a fake LE device. We store the device pointer here because this is a | 268 // Create a fake LE device. We store the device pointer here because this is a |
266 // test. It's unsafe to do this in production as the device might get deleted. | 269 // test. It's unsafe to do this in production as the device might get deleted. |
267 fake_bluetooth_device_client_->CreateDevice( | 270 fake_bluetooth_device_client_->CreateDevice( |
268 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 271 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
269 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 272 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
270 BluetoothDevice* device = adapter_->GetDevice( | 273 BluetoothDevice* device = |
271 FakeBluetoothDeviceClient::kLowEnergyAddress); | 274 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
272 ASSERT_TRUE(device); | 275 ASSERT_TRUE(device); |
273 | 276 |
274 TestBluetoothAdapterObserver observer(adapter_); | 277 TestBluetoothAdapterObserver observer(adapter_); |
275 | 278 |
276 EXPECT_EQ(0, observer.gatt_service_added_count()); | 279 EXPECT_EQ(0, observer.gatt_service_added_count()); |
277 EXPECT_EQ(0, observer.gatt_service_removed_count()); | 280 EXPECT_EQ(0, observer.gatt_service_removed_count()); |
278 EXPECT_TRUE(observer.last_gatt_service_id().empty()); | 281 EXPECT_TRUE(observer.last_gatt_service_id().empty()); |
279 EXPECT_FALSE(observer.last_gatt_service_uuid().IsValid()); | 282 EXPECT_FALSE(observer.last_gatt_service_uuid().IsValid()); |
280 EXPECT_TRUE(device->GetGattServices().empty()); | 283 EXPECT_TRUE(device->GetGattServices().empty()); |
281 | 284 |
282 // Expose the fake Heart Rate Service. | 285 // Expose the fake Heart Rate Service. |
283 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 286 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
284 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 287 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
285 EXPECT_EQ(1, observer.gatt_service_added_count()); | 288 EXPECT_EQ(1, observer.gatt_service_added_count()); |
286 EXPECT_EQ(0, observer.gatt_service_removed_count()); | 289 EXPECT_EQ(0, observer.gatt_service_removed_count()); |
287 EXPECT_FALSE(observer.last_gatt_service_id().empty()); | 290 EXPECT_FALSE(observer.last_gatt_service_id().empty()); |
288 EXPECT_EQ(1U, device->GetGattServices().size()); | 291 EXPECT_EQ(1U, device->GetGattServices().size()); |
289 EXPECT_EQ( | 292 EXPECT_EQ(BluetoothUUID( |
290 BluetoothUUID(FakeBluetoothGattServiceClient::kHeartRateServiceUUID), | 293 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), |
291 observer.last_gatt_service_uuid()); | 294 observer.last_gatt_service_uuid()); |
292 | 295 |
293 BluetoothGattService* service = | 296 BluetoothGattService* service = |
294 device->GetGattService(observer.last_gatt_service_id()); | 297 device->GetGattService(observer.last_gatt_service_id()); |
295 EXPECT_FALSE(service->IsLocal()); | 298 EXPECT_FALSE(service->IsLocal()); |
296 EXPECT_TRUE(service->IsPrimary()); | 299 EXPECT_TRUE(service->IsPrimary()); |
297 EXPECT_EQ(service, device->GetGattServices()[0]); | 300 EXPECT_EQ(service, device->GetGattServices()[0]); |
298 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier())); | 301 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier())); |
299 | 302 |
300 EXPECT_EQ(observer.last_gatt_service_uuid(), service->GetUUID()); | 303 EXPECT_EQ(observer.last_gatt_service_uuid(), service->GetUUID()); |
301 | 304 |
302 // Hide the service. | 305 // Hide the service. |
303 observer.last_gatt_service_uuid() = BluetoothUUID(); | 306 observer.last_gatt_service_uuid() = BluetoothUUID(); |
304 observer.last_gatt_service_id().clear(); | 307 observer.last_gatt_service_id().clear(); |
305 fake_bluetooth_gatt_service_client_->HideHeartRateService(); | 308 fake_bluetooth_gatt_service_client_->HideHeartRateService(); |
306 | 309 |
307 EXPECT_EQ(1, observer.gatt_service_added_count()); | 310 EXPECT_EQ(1, observer.gatt_service_added_count()); |
308 EXPECT_EQ(1, observer.gatt_service_removed_count()); | 311 EXPECT_EQ(1, observer.gatt_service_removed_count()); |
309 EXPECT_FALSE(observer.last_gatt_service_id().empty()); | 312 EXPECT_FALSE(observer.last_gatt_service_id().empty()); |
310 EXPECT_TRUE(device->GetGattServices().empty()); | 313 EXPECT_TRUE(device->GetGattServices().empty()); |
311 EXPECT_EQ( | 314 EXPECT_EQ(BluetoothUUID( |
312 BluetoothUUID(FakeBluetoothGattServiceClient::kHeartRateServiceUUID), | 315 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), |
313 observer.last_gatt_service_uuid()); | 316 observer.last_gatt_service_uuid()); |
314 | 317 |
315 EXPECT_EQ(NULL, device->GetGattService(observer.last_gatt_service_id())); | 318 EXPECT_EQ(NULL, device->GetGattService(observer.last_gatt_service_id())); |
316 | 319 |
317 // Expose the service again. | 320 // Expose the service again. |
318 observer.last_gatt_service_uuid() = BluetoothUUID(); | 321 observer.last_gatt_service_uuid() = BluetoothUUID(); |
319 observer.last_gatt_service_id().clear(); | 322 observer.last_gatt_service_id().clear(); |
320 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 323 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
321 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 324 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
322 EXPECT_EQ(2, observer.gatt_service_added_count()); | 325 EXPECT_EQ(2, observer.gatt_service_added_count()); |
323 EXPECT_EQ(1, observer.gatt_service_removed_count()); | 326 EXPECT_EQ(1, observer.gatt_service_removed_count()); |
324 EXPECT_FALSE(observer.last_gatt_service_id().empty()); | 327 EXPECT_FALSE(observer.last_gatt_service_id().empty()); |
325 EXPECT_EQ(1U, device->GetGattServices().size()); | 328 EXPECT_EQ(1U, device->GetGattServices().size()); |
326 EXPECT_EQ( | 329 EXPECT_EQ(BluetoothUUID( |
327 BluetoothUUID(FakeBluetoothGattServiceClient::kHeartRateServiceUUID), | 330 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), |
328 observer.last_gatt_service_uuid()); | 331 observer.last_gatt_service_uuid()); |
329 | 332 |
330 // The object |service| points to should have been deallocated. |device| | 333 // The object |service| points to should have been deallocated. |device| |
331 // should contain a brand new instance. | 334 // should contain a brand new instance. |
332 service = device->GetGattService(observer.last_gatt_service_id()); | 335 service = device->GetGattService(observer.last_gatt_service_id()); |
333 EXPECT_EQ(service, device->GetGattServices()[0]); | 336 EXPECT_EQ(service, device->GetGattServices()[0]); |
334 EXPECT_FALSE(service->IsLocal()); | 337 EXPECT_FALSE(service->IsLocal()); |
335 EXPECT_TRUE(service->IsPrimary()); | 338 EXPECT_TRUE(service->IsPrimary()); |
336 | 339 |
337 EXPECT_EQ(observer.last_gatt_service_uuid(), service->GetUUID()); | 340 EXPECT_EQ(observer.last_gatt_service_uuid(), service->GetUUID()); |
338 | 341 |
339 // Remove the device. The observer should be notified of the removed service. | 342 // Remove the device. The observer should be notified of the removed service. |
340 // |device| becomes invalid after this. | 343 // |device| becomes invalid after this. |
341 observer.last_gatt_service_uuid() = BluetoothUUID(); | 344 observer.last_gatt_service_uuid() = BluetoothUUID(); |
342 observer.last_gatt_service_id().clear(); | 345 observer.last_gatt_service_id().clear(); |
343 fake_bluetooth_device_client_->RemoveDevice( | 346 fake_bluetooth_device_client_->RemoveDevice( |
344 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 347 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
345 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 348 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
346 | 349 |
347 EXPECT_EQ(2, observer.gatt_service_added_count()); | 350 EXPECT_EQ(2, observer.gatt_service_added_count()); |
348 EXPECT_EQ(2, observer.gatt_service_removed_count()); | 351 EXPECT_EQ(2, observer.gatt_service_removed_count()); |
349 EXPECT_FALSE(observer.last_gatt_service_id().empty()); | 352 EXPECT_FALSE(observer.last_gatt_service_id().empty()); |
350 EXPECT_EQ( | 353 EXPECT_EQ(BluetoothUUID( |
351 BluetoothUUID(FakeBluetoothGattServiceClient::kHeartRateServiceUUID), | 354 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), |
352 observer.last_gatt_service_uuid()); | 355 observer.last_gatt_service_uuid()); |
353 EXPECT_EQ( | 356 EXPECT_EQ(NULL, adapter_->GetDevice( |
354 NULL, adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress)); | 357 bluez::FakeBluetoothDeviceClient::kLowEnergyAddress)); |
355 } | 358 } |
356 | 359 |
357 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) { | 360 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) { |
358 fake_bluetooth_device_client_->CreateDevice( | 361 fake_bluetooth_device_client_->CreateDevice( |
359 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 362 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
360 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 363 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
361 BluetoothDevice* device = adapter_->GetDevice( | 364 BluetoothDevice* device = |
362 FakeBluetoothDeviceClient::kLowEnergyAddress); | 365 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
363 ASSERT_TRUE(device); | 366 ASSERT_TRUE(device); |
364 | 367 |
365 TestBluetoothAdapterObserver observer(adapter_); | 368 TestBluetoothAdapterObserver observer(adapter_); |
366 | 369 |
367 // Expose the fake Heart Rate service. This will asynchronously expose | 370 // Expose the fake Heart Rate service. This will asynchronously expose |
368 // characteristics. | 371 // characteristics. |
369 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 372 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
370 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 373 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
371 ASSERT_EQ(1, observer.gatt_service_added_count()); | 374 ASSERT_EQ(1, observer.gatt_service_added_count()); |
372 | 375 |
373 BluetoothGattService* service = | 376 BluetoothGattService* service = |
374 device->GetGattService(observer.last_gatt_service_id()); | 377 device->GetGattService(observer.last_gatt_service_id()); |
375 | 378 |
376 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 379 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
377 EXPECT_EQ(0, observer.gatt_discovery_complete_count()); | 380 EXPECT_EQ(0, observer.gatt_discovery_complete_count()); |
378 EXPECT_EQ(0, observer.gatt_characteristic_added_count()); | 381 EXPECT_EQ(0, observer.gatt_characteristic_added_count()); |
379 EXPECT_EQ(0, observer.gatt_characteristic_removed_count()); | 382 EXPECT_EQ(0, observer.gatt_characteristic_removed_count()); |
380 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 383 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 // Hide the service. All characteristics should disappear. | 420 // Hide the service. All characteristics should disappear. |
418 fake_bluetooth_gatt_service_client_->HideHeartRateService(); | 421 fake_bluetooth_gatt_service_client_->HideHeartRateService(); |
419 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 422 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
420 EXPECT_EQ(6, observer.gatt_characteristic_added_count()); | 423 EXPECT_EQ(6, observer.gatt_characteristic_added_count()); |
421 EXPECT_EQ(6, observer.gatt_characteristic_removed_count()); | 424 EXPECT_EQ(6, observer.gatt_characteristic_removed_count()); |
422 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 425 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
423 } | 426 } |
424 | 427 |
425 TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) { | 428 TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) { |
426 fake_bluetooth_device_client_->CreateDevice( | 429 fake_bluetooth_device_client_->CreateDevice( |
427 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 430 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
428 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 431 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
429 BluetoothDevice* device = adapter_->GetDevice( | 432 BluetoothDevice* device = |
430 FakeBluetoothDeviceClient::kLowEnergyAddress); | 433 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
431 ASSERT_TRUE(device); | 434 ASSERT_TRUE(device); |
432 | 435 |
433 TestBluetoothAdapterObserver observer(adapter_); | 436 TestBluetoothAdapterObserver observer(adapter_); |
434 | 437 |
435 // Expose the fake Heart Rate service. This will asynchronously expose | 438 // Expose the fake Heart Rate service. This will asynchronously expose |
436 // characteristics. | 439 // characteristics. |
437 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 440 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
438 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 441 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
439 ASSERT_EQ(1, observer.gatt_service_added_count()); | 442 ASSERT_EQ(1, observer.gatt_service_added_count()); |
440 | 443 |
441 BluetoothGattService* service = | 444 BluetoothGattService* service = |
442 device->GetGattService(observer.last_gatt_service_id()); | 445 device->GetGattService(observer.last_gatt_service_id()); |
443 | 446 |
444 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 447 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
445 EXPECT_EQ(0, observer.gatt_descriptor_added_count()); | 448 EXPECT_EQ(0, observer.gatt_descriptor_added_count()); |
446 EXPECT_EQ(0, observer.gatt_descriptor_removed_count()); | 449 EXPECT_EQ(0, observer.gatt_descriptor_removed_count()); |
447 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 450 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |
448 | 451 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 492 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
490 EXPECT_EQ(1, observer.gatt_descriptor_added_count()); | 493 EXPECT_EQ(1, observer.gatt_descriptor_added_count()); |
491 EXPECT_EQ(1, observer.gatt_descriptor_removed_count()); | 494 EXPECT_EQ(1, observer.gatt_descriptor_removed_count()); |
492 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 495 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |
493 | 496 |
494 // Expose the descriptor again. | 497 // Expose the descriptor again. |
495 observer.last_gatt_descriptor_id().clear(); | 498 observer.last_gatt_descriptor_id().clear(); |
496 observer.last_gatt_descriptor_uuid() = BluetoothUUID(); | 499 observer.last_gatt_descriptor_uuid() = BluetoothUUID(); |
497 fake_bluetooth_gatt_descriptor_client_->ExposeDescriptor( | 500 fake_bluetooth_gatt_descriptor_client_->ExposeDescriptor( |
498 dbus::ObjectPath(characteristic->GetIdentifier()), | 501 dbus::ObjectPath(characteristic->GetIdentifier()), |
499 FakeBluetoothGattDescriptorClient:: | 502 bluez::FakeBluetoothGattDescriptorClient:: |
500 kClientCharacteristicConfigurationUUID); | 503 kClientCharacteristicConfigurationUUID); |
501 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 504 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
502 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); | 505 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); |
503 EXPECT_EQ(2, observer.gatt_descriptor_added_count()); | 506 EXPECT_EQ(2, observer.gatt_descriptor_added_count()); |
504 EXPECT_EQ(1, observer.gatt_descriptor_removed_count()); | 507 EXPECT_EQ(1, observer.gatt_descriptor_removed_count()); |
505 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 508 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |
506 | 509 |
507 descriptor = characteristic->GetDescriptors()[0]; | 510 descriptor = characteristic->GetDescriptors()[0]; |
508 EXPECT_FALSE(descriptor->IsLocal()); | 511 EXPECT_FALSE(descriptor->IsLocal()); |
509 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), | 512 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), |
510 descriptor->GetUUID()); | 513 descriptor->GetUUID()); |
511 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); | 514 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); |
512 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); | 515 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); |
513 } | 516 } |
514 | 517 |
515 TEST_F(BluetoothGattChromeOSTest, AdapterAddedAfterGattService) { | 518 TEST_F(BluetoothGattChromeOSTest, AdapterAddedAfterGattService) { |
516 // This unit test tests that all remote GATT objects are created for D-Bus | 519 // This unit test tests that all remote GATT objects are created for D-Bus |
517 // objects that were already exposed. | 520 // objects that were already exposed. |
518 adapter_ = NULL; | 521 adapter_ = NULL; |
519 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting()); | 522 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting()); |
520 | 523 |
521 // Create the fake D-Bus objects. | 524 // Create the fake D-Bus objects. |
522 fake_bluetooth_device_client_->CreateDevice( | 525 fake_bluetooth_device_client_->CreateDevice( |
523 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 526 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
524 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 527 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
525 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 528 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
526 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 529 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
527 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible()) | 530 while (!fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible()) |
528 base::RunLoop().RunUntilIdle(); | 531 base::RunLoop().RunUntilIdle(); |
529 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible()); | 532 ASSERT_TRUE(fake_bluetooth_gatt_service_client_->IsHeartRateVisible()); |
530 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible()); | 533 ASSERT_TRUE(fake_bluetooth_gatt_characteristic_client_->IsHeartRateVisible()); |
531 | 534 |
532 // Create the adapter. This should create all the GATT objects. | 535 // Create the adapter. This should create all the GATT objects. |
533 GetAdapter(); | 536 GetAdapter(); |
534 BluetoothDevice* device = adapter_->GetDevice( | 537 BluetoothDevice* device = |
535 FakeBluetoothDeviceClient::kLowEnergyAddress); | 538 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
536 ASSERT_TRUE(device); | 539 ASSERT_TRUE(device); |
537 EXPECT_EQ(1U, device->GetGattServices().size()); | 540 EXPECT_EQ(1U, device->GetGattServices().size()); |
538 | 541 |
539 BluetoothGattService* service = device->GetGattServices()[0]; | 542 BluetoothGattService* service = device->GetGattServices()[0]; |
540 ASSERT_TRUE(service); | 543 ASSERT_TRUE(service); |
541 EXPECT_FALSE(service->IsLocal()); | 544 EXPECT_FALSE(service->IsLocal()); |
542 EXPECT_TRUE(service->IsPrimary()); | 545 EXPECT_TRUE(service->IsPrimary()); |
543 EXPECT_EQ( | 546 EXPECT_EQ(BluetoothUUID( |
544 BluetoothUUID(FakeBluetoothGattServiceClient::kHeartRateServiceUUID), | 547 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), |
545 service->GetUUID()); | 548 service->GetUUID()); |
546 EXPECT_EQ(service, device->GetGattServices()[0]); | 549 EXPECT_EQ(service, device->GetGattServices()[0]); |
547 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier())); | 550 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier())); |
548 EXPECT_FALSE(service->IsLocal()); | 551 EXPECT_FALSE(service->IsLocal()); |
549 EXPECT_EQ(3U, service->GetCharacteristics().size()); | 552 EXPECT_EQ(3U, service->GetCharacteristics().size()); |
550 | 553 |
551 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( | 554 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( |
552 fake_bluetooth_gatt_characteristic_client_-> | 555 fake_bluetooth_gatt_characteristic_client_-> |
553 GetBodySensorLocationPath().value()); | 556 GetBodySensorLocationPath().value()); |
554 ASSERT_TRUE(characteristic); | 557 ASSERT_TRUE(characteristic); |
555 EXPECT_EQ( | 558 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: |
556 BluetoothUUID(FakeBluetoothGattCharacteristicClient:: | 559 kBodySensorLocationUUID), |
557 kBodySensorLocationUUID), | 560 characteristic->GetUUID()); |
558 characteristic->GetUUID()); | |
559 EXPECT_FALSE(characteristic->IsLocal()); | 561 EXPECT_FALSE(characteristic->IsLocal()); |
560 EXPECT_TRUE(characteristic->GetDescriptors().empty()); | 562 EXPECT_TRUE(characteristic->GetDescriptors().empty()); |
561 | 563 |
562 characteristic = service->GetCharacteristic( | 564 characteristic = service->GetCharacteristic( |
563 fake_bluetooth_gatt_characteristic_client_-> | 565 fake_bluetooth_gatt_characteristic_client_-> |
564 GetHeartRateControlPointPath().value()); | 566 GetHeartRateControlPointPath().value()); |
565 ASSERT_TRUE(characteristic); | 567 ASSERT_TRUE(characteristic); |
566 EXPECT_EQ( | 568 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: |
567 BluetoothUUID(FakeBluetoothGattCharacteristicClient:: | 569 kHeartRateControlPointUUID), |
568 kHeartRateControlPointUUID), | 570 characteristic->GetUUID()); |
569 characteristic->GetUUID()); | |
570 EXPECT_FALSE(characteristic->IsLocal()); | 571 EXPECT_FALSE(characteristic->IsLocal()); |
571 EXPECT_TRUE(characteristic->GetDescriptors().empty()); | 572 EXPECT_TRUE(characteristic->GetDescriptors().empty()); |
572 | 573 |
573 characteristic = service->GetCharacteristic( | 574 characteristic = service->GetCharacteristic( |
574 fake_bluetooth_gatt_characteristic_client_-> | 575 fake_bluetooth_gatt_characteristic_client_-> |
575 GetHeartRateMeasurementPath().value()); | 576 GetHeartRateMeasurementPath().value()); |
576 ASSERT_TRUE(characteristic); | 577 ASSERT_TRUE(characteristic); |
577 EXPECT_EQ( | 578 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: |
578 BluetoothUUID(FakeBluetoothGattCharacteristicClient:: | 579 kHeartRateMeasurementUUID), |
579 kHeartRateMeasurementUUID), | 580 characteristic->GetUUID()); |
580 characteristic->GetUUID()); | |
581 EXPECT_FALSE(characteristic->IsLocal()); | 581 EXPECT_FALSE(characteristic->IsLocal()); |
582 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); | 582 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); |
583 | 583 |
584 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; | 584 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; |
585 ASSERT_TRUE(descriptor); | 585 ASSERT_TRUE(descriptor); |
586 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), | 586 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), |
587 descriptor->GetUUID()); | 587 descriptor->GetUUID()); |
588 EXPECT_FALSE(descriptor->IsLocal()); | 588 EXPECT_FALSE(descriptor->IsLocal()); |
589 } | 589 } |
590 | 590 |
591 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { | 591 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { |
592 fake_bluetooth_device_client_->CreateDevice( | 592 fake_bluetooth_device_client_->CreateDevice( |
593 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 593 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
594 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 594 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
595 BluetoothDevice* device = adapter_->GetDevice( | 595 BluetoothDevice* device = |
596 FakeBluetoothDeviceClient::kLowEnergyAddress); | 596 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
597 ASSERT_TRUE(device); | 597 ASSERT_TRUE(device); |
598 | 598 |
599 TestBluetoothAdapterObserver observer(adapter_); | 599 TestBluetoothAdapterObserver observer(adapter_); |
600 | 600 |
601 // Expose the fake Heart Rate service. This will asynchronously expose | 601 // Expose the fake Heart Rate service. This will asynchronously expose |
602 // characteristics. | 602 // characteristics. |
603 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 603 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
604 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 604 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
605 ASSERT_EQ(1, observer.gatt_service_added_count()); | 605 ASSERT_EQ(1, observer.gatt_service_added_count()); |
606 | 606 |
607 BluetoothGattService* service = | 607 BluetoothGattService* service = |
608 device->GetGattService(observer.last_gatt_service_id()); | 608 device->GetGattService(observer.last_gatt_service_id()); |
609 | 609 |
610 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 610 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
611 | 611 |
612 // Run the message loop so that the characteristics appear. | 612 // Run the message loop so that the characteristics appear. |
613 base::MessageLoop::current()->Run(); | 613 base::MessageLoop::current()->Run(); |
614 | 614 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 base::Unretained(this))); | 798 base::Unretained(this))); |
799 EXPECT_EQ(3, success_callback_count_); | 799 EXPECT_EQ(3, success_callback_count_); |
800 EXPECT_EQ(7, error_callback_count_); | 800 EXPECT_EQ(7, error_callback_count_); |
801 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PAIRED, last_service_error_); | 801 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PAIRED, last_service_error_); |
802 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); | 802 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
803 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(true); | 803 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(true); |
804 } | 804 } |
805 | 805 |
806 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) { | 806 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) { |
807 fake_bluetooth_device_client_->CreateDevice( | 807 fake_bluetooth_device_client_->CreateDevice( |
808 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 808 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
809 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 809 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
810 BluetoothDevice* device = adapter_->GetDevice( | 810 BluetoothDevice* device = |
811 FakeBluetoothDeviceClient::kLowEnergyAddress); | 811 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
812 ASSERT_TRUE(device); | 812 ASSERT_TRUE(device); |
813 | 813 |
814 TestBluetoothAdapterObserver observer(adapter_); | 814 TestBluetoothAdapterObserver observer(adapter_); |
815 | 815 |
816 // Expose the fake Heart Rate service. This will asynchronously expose | 816 // Expose the fake Heart Rate service. This will asynchronously expose |
817 // characteristics. | 817 // characteristics. |
818 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 818 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
819 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 819 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
820 | 820 |
821 BluetoothGattService* service = | 821 BluetoothGattService* service = |
822 device->GetGattService(observer.last_gatt_service_id()); | 822 device->GetGattService(observer.last_gatt_service_id()); |
823 | 823 |
824 EXPECT_TRUE(service->GetCharacteristics().empty()); | 824 EXPECT_TRUE(service->GetCharacteristics().empty()); |
825 | 825 |
826 // Run the message loop so that the characteristics appear. | 826 // Run the message loop so that the characteristics appear. |
827 base::MessageLoop::current()->Run(); | 827 base::MessageLoop::current()->Run(); |
828 | 828 |
829 BluetoothGattCharacteristic *characteristic = service->GetCharacteristic( | 829 BluetoothGattCharacteristic *characteristic = service->GetCharacteristic( |
(...skipping 10 matching lines...) Expand all Loading... |
840 | 840 |
841 characteristic = service->GetCharacteristic( | 841 characteristic = service->GetCharacteristic( |
842 fake_bluetooth_gatt_characteristic_client_-> | 842 fake_bluetooth_gatt_characteristic_client_-> |
843 GetHeartRateMeasurementPath().value()); | 843 GetHeartRateMeasurementPath().value()); |
844 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_NOTIFY, | 844 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_NOTIFY, |
845 characteristic->GetProperties()); | 845 characteristic->GetProperties()); |
846 } | 846 } |
847 | 847 |
848 TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { | 848 TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { |
849 fake_bluetooth_device_client_->CreateDevice( | 849 fake_bluetooth_device_client_->CreateDevice( |
850 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 850 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
851 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 851 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
852 BluetoothDevice* device = adapter_->GetDevice( | 852 BluetoothDevice* device = |
853 FakeBluetoothDeviceClient::kLowEnergyAddress); | 853 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
854 ASSERT_TRUE(device); | 854 ASSERT_TRUE(device); |
855 | 855 |
856 TestBluetoothAdapterObserver observer(adapter_); | 856 TestBluetoothAdapterObserver observer(adapter_); |
857 | 857 |
858 // Expose the fake Heart Rate service. This will asynchronously expose | 858 // Expose the fake Heart Rate service. This will asynchronously expose |
859 // characteristics. | 859 // characteristics. |
860 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 860 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
861 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 861 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
862 ASSERT_EQ(1, observer.gatt_service_added_count()); | 862 ASSERT_EQ(1, observer.gatt_service_added_count()); |
863 | 863 |
864 BluetoothGattService* service = | 864 BluetoothGattService* service = |
865 device->GetGattService(observer.last_gatt_service_id()); | 865 device->GetGattService(observer.last_gatt_service_id()); |
866 | 866 |
867 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 867 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
868 EXPECT_EQ(0, observer.gatt_discovery_complete_count()); | 868 EXPECT_EQ(0, observer.gatt_discovery_complete_count()); |
869 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 869 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |
870 EXPECT_TRUE(service->GetCharacteristics().empty()); | 870 EXPECT_TRUE(service->GetCharacteristics().empty()); |
871 | 871 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 EXPECT_EQ(4, success_callback_count_); | 963 EXPECT_EQ(4, success_callback_count_); |
964 EXPECT_EQ(1, error_callback_count_); | 964 EXPECT_EQ(1, error_callback_count_); |
965 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 965 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
966 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); | 966 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
967 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 967 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
968 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count()); | 968 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count()); |
969 } | 969 } |
970 | 970 |
971 TEST_F(BluetoothGattChromeOSTest, NotifySessions) { | 971 TEST_F(BluetoothGattChromeOSTest, NotifySessions) { |
972 fake_bluetooth_device_client_->CreateDevice( | 972 fake_bluetooth_device_client_->CreateDevice( |
973 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 973 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
974 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 974 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
975 BluetoothDevice* device = | 975 BluetoothDevice* device = |
976 adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress); | 976 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
977 ASSERT_TRUE(device); | 977 ASSERT_TRUE(device); |
978 | 978 |
979 TestBluetoothAdapterObserver observer(adapter_); | 979 TestBluetoothAdapterObserver observer(adapter_); |
980 | 980 |
981 // Expose the fake Heart Rate service. This will asynchronously expose | 981 // Expose the fake Heart Rate service. This will asynchronously expose |
982 // characteristics. | 982 // characteristics. |
983 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 983 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
984 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 984 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
985 ASSERT_EQ(1, observer.gatt_service_added_count()); | 985 ASSERT_EQ(1, observer.gatt_service_added_count()); |
986 | 986 |
987 BluetoothGattService* service = | 987 BluetoothGattService* service = |
988 device->GetGattService(observer.last_gatt_service_id()); | 988 device->GetGattService(observer.last_gatt_service_id()); |
989 | 989 |
990 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 990 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
991 | 991 |
992 // Run the message loop so that the characteristics appear. | 992 // Run the message loop so that the characteristics appear. |
993 base::MessageLoop::current()->Run(); | 993 base::MessageLoop::current()->Run(); |
994 | 994 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 | 1112 |
1113 // Hide the characteristic. The sessions should become inactive. | 1113 // Hide the characteristic. The sessions should become inactive. |
1114 fake_bluetooth_gatt_characteristic_client_->HideHeartRateCharacteristics(); | 1114 fake_bluetooth_gatt_characteristic_client_->HideHeartRateCharacteristics(); |
1115 EXPECT_EQ(2U, update_sessions_.size()); | 1115 EXPECT_EQ(2U, update_sessions_.size()); |
1116 EXPECT_FALSE(update_sessions_[0]->IsActive()); | 1116 EXPECT_FALSE(update_sessions_[0]->IsActive()); |
1117 EXPECT_FALSE(update_sessions_[1]->IsActive()); | 1117 EXPECT_FALSE(update_sessions_[1]->IsActive()); |
1118 } | 1118 } |
1119 | 1119 |
1120 TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { | 1120 TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { |
1121 fake_bluetooth_device_client_->CreateDevice( | 1121 fake_bluetooth_device_client_->CreateDevice( |
1122 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 1122 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
1123 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 1123 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
1124 BluetoothDevice* device = | 1124 BluetoothDevice* device = |
1125 adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress); | 1125 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
1126 ASSERT_TRUE(device); | 1126 ASSERT_TRUE(device); |
1127 | 1127 |
1128 TestBluetoothAdapterObserver observer(adapter_); | 1128 TestBluetoothAdapterObserver observer(adapter_); |
1129 | 1129 |
1130 // Expose the fake Heart Rate service. This will asynchronously expose | 1130 // Expose the fake Heart Rate service. This will asynchronously expose |
1131 // characteristics. | 1131 // characteristics. |
1132 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 1132 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
1133 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 1133 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
1134 ASSERT_EQ(1, observer.gatt_service_added_count()); | 1134 ASSERT_EQ(1, observer.gatt_service_added_count()); |
1135 | 1135 |
1136 BluetoothGattService* service = | 1136 BluetoothGattService* service = |
1137 device->GetGattService(observer.last_gatt_service_id()); | 1137 device->GetGattService(observer.last_gatt_service_id()); |
1138 | 1138 |
1139 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 1139 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
1140 | 1140 |
1141 // Run the message loop so that the characteristics appear. | 1141 // Run the message loop so that the characteristics appear. |
1142 base::MessageLoop::current()->Run(); | 1142 base::MessageLoop::current()->Run(); |
1143 | 1143 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 | 1228 |
1229 EXPECT_EQ(1, success_callback_count_); | 1229 EXPECT_EQ(1, success_callback_count_); |
1230 EXPECT_EQ(0, error_callback_count_); | 1230 EXPECT_EQ(0, error_callback_count_); |
1231 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1231 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1232 EXPECT_TRUE(characteristic->IsNotifying()); | 1232 EXPECT_TRUE(characteristic->IsNotifying()); |
1233 EXPECT_EQ(1U, update_sessions_.size()); | 1233 EXPECT_EQ(1U, update_sessions_.size()); |
1234 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1234 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
1235 } | 1235 } |
1236 | 1236 |
1237 } // namespace chromeos | 1237 } // namespace chromeos |
OLD | NEW |