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 "dbus/object_path.h" | 8 #include "dbus/object_path.h" |
9 #include "device/bluetooth/bluetooth_adapter.h" | 9 #include "device/bluetooth/bluetooth_adapter.h" |
10 #include "device/bluetooth/bluetooth_adapter_factory.h" | 10 #include "device/bluetooth/bluetooth_adapter_factory.h" |
(...skipping 18 matching lines...) Expand all Loading... |
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 bluez { |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 const BluetoothUUID kHeartRateMeasurementUUID( | 43 const BluetoothUUID kHeartRateMeasurementUUID( |
44 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID); | 44 bluez::FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID); |
45 const BluetoothUUID kBodySensorLocationUUID( | 45 const BluetoothUUID kBodySensorLocationUUID( |
46 bluez::FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID); | 46 bluez::FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID); |
47 const BluetoothUUID kHeartRateControlPointUUID( | 47 const BluetoothUUID kHeartRateControlPointUUID( |
48 bluez::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 BluetoothGattBlueZTest : public testing::Test { |
65 public: | 65 public: |
66 BluetoothGattChromeOSTest() | 66 BluetoothGattBlueZTest() |
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 } | |
71 | 70 |
72 void SetUp() override { | 71 void SetUp() override { |
73 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = | 72 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = |
74 bluez::BluezDBusManager::GetSetterForTesting(); | 73 bluez::BluezDBusManager::GetSetterForTesting(); |
75 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; | 74 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; |
76 fake_bluetooth_gatt_service_client_ = | 75 fake_bluetooth_gatt_service_client_ = |
77 new bluez::FakeBluetoothGattServiceClient; | 76 new bluez::FakeBluetoothGattServiceClient; |
78 fake_bluetooth_gatt_characteristic_client_ = | 77 fake_bluetooth_gatt_characteristic_client_ = |
79 new bluez::FakeBluetoothGattCharacteristicClient; | 78 new bluez::FakeBluetoothGattCharacteristicClient; |
80 fake_bluetooth_gatt_descriptor_client_ = | 79 fake_bluetooth_gatt_descriptor_client_ = |
(...skipping 15 matching lines...) Expand all Loading... |
96 new bluez::FakeBluetoothAdapterClient)); | 95 new bluez::FakeBluetoothAdapterClient)); |
97 dbus_setter->SetBluetoothInputClient( | 96 dbus_setter->SetBluetoothInputClient( |
98 scoped_ptr<bluez::BluetoothInputClient>( | 97 scoped_ptr<bluez::BluetoothInputClient>( |
99 new bluez::FakeBluetoothInputClient)); | 98 new bluez::FakeBluetoothInputClient)); |
100 dbus_setter->SetBluetoothAgentManagerClient( | 99 dbus_setter->SetBluetoothAgentManagerClient( |
101 scoped_ptr<bluez::BluetoothAgentManagerClient>( | 100 scoped_ptr<bluez::BluetoothAgentManagerClient>( |
102 new bluez::FakeBluetoothAgentManagerClient)); | 101 new bluez::FakeBluetoothAgentManagerClient)); |
103 | 102 |
104 GetAdapter(); | 103 GetAdapter(); |
105 | 104 |
106 adapter_->SetPowered( | 105 adapter_->SetPowered(true, base::Bind(&base::DoNothing), |
107 true, | 106 base::Bind(&base::DoNothing)); |
108 base::Bind(&base::DoNothing), | |
109 base::Bind(&base::DoNothing)); | |
110 ASSERT_TRUE(adapter_->IsPowered()); | 107 ASSERT_TRUE(adapter_->IsPowered()); |
111 } | 108 } |
112 | 109 |
113 void TearDown() override { | 110 void TearDown() override { |
114 adapter_ = NULL; | 111 adapter_ = NULL; |
115 update_sessions_.clear(); | 112 update_sessions_.clear(); |
116 gatt_conn_.reset(); | 113 gatt_conn_.reset(); |
117 bluez::BluezDBusManager::Shutdown(); | 114 bluez::BluezDBusManager::Shutdown(); |
118 } | 115 } |
119 | 116 |
120 void GetAdapter() { | 117 void GetAdapter() { |
121 device::BluetoothAdapterFactory::GetAdapter( | 118 device::BluetoothAdapterFactory::GetAdapter(base::Bind( |
122 base::Bind(&BluetoothGattChromeOSTest::AdapterCallback, | 119 &BluetoothGattBlueZTest::AdapterCallback, base::Unretained(this))); |
123 base::Unretained(this))); | |
124 ASSERT_TRUE(adapter_.get() != NULL); | 120 ASSERT_TRUE(adapter_.get() != NULL); |
125 ASSERT_TRUE(adapter_->IsInitialized()); | 121 ASSERT_TRUE(adapter_->IsInitialized()); |
126 ASSERT_TRUE(adapter_->IsPresent()); | 122 ASSERT_TRUE(adapter_->IsPresent()); |
127 } | 123 } |
128 | 124 |
129 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { | 125 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { |
130 adapter_ = adapter; | 126 adapter_ = adapter; |
131 } | 127 } |
132 | 128 |
133 void SuccessCallback() { | 129 void SuccessCallback() { ++success_callback_count_; } |
134 ++success_callback_count_; | |
135 } | |
136 | 130 |
137 void ValueCallback(const std::vector<uint8>& value) { | 131 void ValueCallback(const std::vector<uint8>& value) { |
138 ++success_callback_count_; | 132 ++success_callback_count_; |
139 last_read_value_ = value; | 133 last_read_value_ = value; |
140 } | 134 } |
141 | 135 |
142 void GattConnectionCallback(scoped_ptr<BluetoothGattConnection> conn) { | 136 void GattConnectionCallback(scoped_ptr<BluetoothGattConnection> conn) { |
143 ++success_callback_count_; | 137 ++success_callback_count_; |
144 gatt_conn_ = conn.Pass(); | 138 gatt_conn_ = conn.Pass(); |
145 } | 139 } |
146 | 140 |
147 void NotifySessionCallback(scoped_ptr<BluetoothGattNotifySession> session) { | 141 void NotifySessionCallback(scoped_ptr<BluetoothGattNotifySession> session) { |
148 ++success_callback_count_; | 142 ++success_callback_count_; |
149 update_sessions_.push_back(session.release()); | 143 update_sessions_.push_back(session.release()); |
150 QuitMessageLoop(); | 144 QuitMessageLoop(); |
151 } | 145 } |
152 | 146 |
153 void ServiceErrorCallback(BluetoothGattService::GattErrorCode err) { | 147 void ServiceErrorCallback(BluetoothGattService::GattErrorCode err) { |
154 ++error_callback_count_; | 148 ++error_callback_count_; |
155 last_service_error_ = err; | 149 last_service_error_ = err; |
156 } | 150 } |
157 | 151 |
158 void ErrorCallback() { | 152 void ErrorCallback() { ++error_callback_count_; } |
159 ++error_callback_count_; | |
160 } | |
161 | 153 |
162 void DBusErrorCallback(const std::string& error_name, | 154 void DBusErrorCallback(const std::string& error_name, |
163 const std::string& error_message) { | 155 const std::string& error_message) { |
164 ++error_callback_count_; | 156 ++error_callback_count_; |
165 } | 157 } |
166 | 158 |
167 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { | 159 void ConnectErrorCallback(BluetoothDevice::ConnectErrorCode error) { |
168 ++error_callback_count_; | 160 ++error_callback_count_; |
169 } | 161 } |
170 | 162 |
(...skipping 15 matching lines...) Expand all Loading... |
186 scoped_ptr<device::BluetoothGattConnection> gatt_conn_; | 178 scoped_ptr<device::BluetoothGattConnection> gatt_conn_; |
187 ScopedVector<BluetoothGattNotifySession> update_sessions_; | 179 ScopedVector<BluetoothGattNotifySession> update_sessions_; |
188 scoped_refptr<BluetoothAdapter> adapter_; | 180 scoped_refptr<BluetoothAdapter> adapter_; |
189 | 181 |
190 int success_callback_count_; | 182 int success_callback_count_; |
191 int error_callback_count_; | 183 int error_callback_count_; |
192 std::vector<uint8> last_read_value_; | 184 std::vector<uint8> last_read_value_; |
193 BluetoothGattService::GattErrorCode last_service_error_; | 185 BluetoothGattService::GattErrorCode last_service_error_; |
194 }; | 186 }; |
195 | 187 |
196 TEST_F(BluetoothGattChromeOSTest, GattConnection) { | 188 TEST_F(BluetoothGattBlueZTest, GattConnection) { |
197 fake_bluetooth_device_client_->CreateDevice( | 189 fake_bluetooth_device_client_->CreateDevice( |
198 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 190 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
199 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 191 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
200 BluetoothDevice* device = | 192 BluetoothDevice* device = |
201 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 193 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
202 ASSERT_TRUE(device); | 194 ASSERT_TRUE(device); |
203 ASSERT_FALSE(device->IsConnected()); | 195 ASSERT_FALSE(device->IsConnected()); |
204 ASSERT_FALSE(gatt_conn_.get()); | 196 ASSERT_FALSE(gatt_conn_.get()); |
205 ASSERT_EQ(0, success_callback_count_); | 197 ASSERT_EQ(0, success_callback_count_); |
206 ASSERT_EQ(0, error_callback_count_); | 198 ASSERT_EQ(0, error_callback_count_); |
207 | 199 |
208 device->CreateGattConnection( | 200 device->CreateGattConnection( |
209 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, | 201 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback, |
210 base::Unretained(this)), | 202 base::Unretained(this)), |
211 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, | 203 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback, |
212 base::Unretained(this))); | 204 base::Unretained(this))); |
213 | 205 |
214 EXPECT_EQ(1, success_callback_count_); | 206 EXPECT_EQ(1, success_callback_count_); |
215 EXPECT_EQ(0, error_callback_count_); | 207 EXPECT_EQ(0, error_callback_count_); |
216 EXPECT_TRUE(device->IsConnected()); | 208 EXPECT_TRUE(device->IsConnected()); |
217 ASSERT_TRUE(gatt_conn_.get()); | 209 ASSERT_TRUE(gatt_conn_.get()); |
218 EXPECT_TRUE(gatt_conn_->IsConnected()); | 210 EXPECT_TRUE(gatt_conn_->IsConnected()); |
219 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, | 211 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, |
220 gatt_conn_->GetDeviceAddress()); | 212 gatt_conn_->GetDeviceAddress()); |
221 | 213 |
222 gatt_conn_->Disconnect(); | 214 gatt_conn_->Disconnect(); |
223 EXPECT_TRUE(device->IsConnected()); | 215 EXPECT_TRUE(device->IsConnected()); |
224 EXPECT_FALSE(gatt_conn_->IsConnected()); | 216 EXPECT_FALSE(gatt_conn_->IsConnected()); |
225 | 217 |
226 device->CreateGattConnection( | 218 device->CreateGattConnection( |
227 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, | 219 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback, |
228 base::Unretained(this)), | 220 base::Unretained(this)), |
229 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, | 221 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback, |
230 base::Unretained(this))); | 222 base::Unretained(this))); |
231 | 223 |
232 EXPECT_EQ(2, success_callback_count_); | 224 EXPECT_EQ(2, success_callback_count_); |
233 EXPECT_EQ(0, error_callback_count_); | 225 EXPECT_EQ(0, error_callback_count_); |
234 EXPECT_TRUE(device->IsConnected()); | 226 EXPECT_TRUE(device->IsConnected()); |
235 ASSERT_TRUE(gatt_conn_.get()); | 227 ASSERT_TRUE(gatt_conn_.get()); |
236 EXPECT_TRUE(gatt_conn_->IsConnected()); | 228 EXPECT_TRUE(gatt_conn_->IsConnected()); |
237 | 229 |
238 device->Disconnect( | 230 device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
239 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 231 base::Unretained(this)), |
240 base::Unretained(this)), | 232 base::Bind(&BluetoothGattBlueZTest::ErrorCallback, |
241 base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, | 233 base::Unretained(this))); |
242 base::Unretained(this))); | |
243 | 234 |
244 EXPECT_EQ(3, success_callback_count_); | 235 EXPECT_EQ(3, success_callback_count_); |
245 EXPECT_EQ(0, error_callback_count_); | 236 EXPECT_EQ(0, error_callback_count_); |
246 ASSERT_TRUE(gatt_conn_.get()); | 237 ASSERT_TRUE(gatt_conn_.get()); |
247 EXPECT_FALSE(gatt_conn_->IsConnected()); | 238 EXPECT_FALSE(gatt_conn_->IsConnected()); |
248 | 239 |
249 device->CreateGattConnection( | 240 device->CreateGattConnection( |
250 base::Bind(&BluetoothGattChromeOSTest::GattConnectionCallback, | 241 base::Bind(&BluetoothGattBlueZTest::GattConnectionCallback, |
251 base::Unretained(this)), | 242 base::Unretained(this)), |
252 base::Bind(&BluetoothGattChromeOSTest::ConnectErrorCallback, | 243 base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback, |
253 base::Unretained(this))); | 244 base::Unretained(this))); |
254 | 245 |
255 EXPECT_EQ(4, success_callback_count_); | 246 EXPECT_EQ(4, success_callback_count_); |
256 EXPECT_EQ(0, error_callback_count_); | 247 EXPECT_EQ(0, error_callback_count_); |
257 EXPECT_TRUE(device->IsConnected()); | 248 EXPECT_TRUE(device->IsConnected()); |
258 EXPECT_TRUE(gatt_conn_->IsConnected()); | 249 EXPECT_TRUE(gatt_conn_->IsConnected()); |
259 | 250 |
260 fake_bluetooth_device_client_->RemoveDevice( | 251 fake_bluetooth_device_client_->RemoveDevice( |
261 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 252 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
262 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 253 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
263 ASSERT_TRUE(gatt_conn_.get()); | 254 ASSERT_TRUE(gatt_conn_.get()); |
264 EXPECT_FALSE(gatt_conn_->IsConnected()); | 255 EXPECT_FALSE(gatt_conn_->IsConnected()); |
265 } | 256 } |
266 | 257 |
267 TEST_F(BluetoothGattChromeOSTest, GattServiceAddedAndRemoved) { | 258 TEST_F(BluetoothGattBlueZTest, GattServiceAddedAndRemoved) { |
268 // Create a fake LE device. We store the device pointer here because this is a | 259 // Create a fake LE device. We store the device pointer here because this is a |
269 // test. It's unsafe to do this in production as the device might get deleted. | 260 // test. It's unsafe to do this in production as the device might get deleted. |
270 fake_bluetooth_device_client_->CreateDevice( | 261 fake_bluetooth_device_client_->CreateDevice( |
271 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 262 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
272 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 263 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
273 BluetoothDevice* device = | 264 BluetoothDevice* device = |
274 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 265 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
275 ASSERT_TRUE(device); | 266 ASSERT_TRUE(device); |
276 | 267 |
277 TestBluetoothAdapterObserver observer(adapter_); | 268 TestBluetoothAdapterObserver observer(adapter_); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 EXPECT_EQ(2, observer.gatt_service_added_count()); | 341 EXPECT_EQ(2, observer.gatt_service_added_count()); |
351 EXPECT_EQ(2, observer.gatt_service_removed_count()); | 342 EXPECT_EQ(2, observer.gatt_service_removed_count()); |
352 EXPECT_FALSE(observer.last_gatt_service_id().empty()); | 343 EXPECT_FALSE(observer.last_gatt_service_id().empty()); |
353 EXPECT_EQ(BluetoothUUID( | 344 EXPECT_EQ(BluetoothUUID( |
354 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), | 345 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), |
355 observer.last_gatt_service_uuid()); | 346 observer.last_gatt_service_uuid()); |
356 EXPECT_EQ(NULL, adapter_->GetDevice( | 347 EXPECT_EQ(NULL, adapter_->GetDevice( |
357 bluez::FakeBluetoothDeviceClient::kLowEnergyAddress)); | 348 bluez::FakeBluetoothDeviceClient::kLowEnergyAddress)); |
358 } | 349 } |
359 | 350 |
360 TEST_F(BluetoothGattChromeOSTest, ServicesDiscovered) { | 351 TEST_F(BluetoothGattBlueZTest, ServicesDiscovered) { |
361 // Create a fake LE device. We store the device pointer here because this is a | 352 // Create a fake LE device. We store the device pointer here because this is a |
362 // test. It's unsafe to do this in production as the device might get deleted. | 353 // test. It's unsafe to do this in production as the device might get deleted. |
363 fake_bluetooth_device_client_->CreateDevice( | 354 fake_bluetooth_device_client_->CreateDevice( |
364 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 355 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
365 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 356 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
366 BluetoothDevice* device = | 357 BluetoothDevice* device = |
367 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 358 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
368 bluez::FakeBluetoothDeviceClient::Properties* properties = | 359 bluez::FakeBluetoothDeviceClient::Properties* properties = |
369 fake_bluetooth_device_client_->GetProperties( | 360 fake_bluetooth_device_client_->GetProperties( |
370 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 361 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
(...skipping 10 matching lines...) Expand all Loading... |
381 // Notify that all services have been discovered. | 372 // Notify that all services have been discovered. |
382 properties->gatt_services.ReplaceValue( | 373 properties->gatt_services.ReplaceValue( |
383 fake_bluetooth_gatt_service_client_->GetServices()); | 374 fake_bluetooth_gatt_service_client_->GetServices()); |
384 | 375 |
385 EXPECT_EQ(1, observer.gatt_services_discovered_count()); | 376 EXPECT_EQ(1, observer.gatt_services_discovered_count()); |
386 EXPECT_EQ(device, observer.last_device()); | 377 EXPECT_EQ(device, observer.last_device()); |
387 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, | 378 EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, |
388 observer.last_device_address()); | 379 observer.last_device_address()); |
389 } | 380 } |
390 | 381 |
391 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicAddedAndRemoved) { | 382 TEST_F(BluetoothGattBlueZTest, GattCharacteristicAddedAndRemoved) { |
392 fake_bluetooth_device_client_->CreateDevice( | 383 fake_bluetooth_device_client_->CreateDevice( |
393 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 384 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
394 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 385 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
395 BluetoothDevice* device = | 386 BluetoothDevice* device = |
396 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 387 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
397 ASSERT_TRUE(device); | 388 ASSERT_TRUE(device); |
398 | 389 |
399 TestBluetoothAdapterObserver observer(adapter_); | 390 TestBluetoothAdapterObserver observer(adapter_); |
400 | 391 |
401 // Expose the fake Heart Rate service. This will asynchronously expose | 392 // Expose the fake Heart Rate service. This will asynchronously expose |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 EXPECT_EQ(3U, service->GetCharacteristics().size()); | 440 EXPECT_EQ(3U, service->GetCharacteristics().size()); |
450 | 441 |
451 // Hide the service. All characteristics should disappear. | 442 // Hide the service. All characteristics should disappear. |
452 fake_bluetooth_gatt_service_client_->HideHeartRateService(); | 443 fake_bluetooth_gatt_service_client_->HideHeartRateService(); |
453 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 444 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
454 EXPECT_EQ(6, observer.gatt_characteristic_added_count()); | 445 EXPECT_EQ(6, observer.gatt_characteristic_added_count()); |
455 EXPECT_EQ(6, observer.gatt_characteristic_removed_count()); | 446 EXPECT_EQ(6, observer.gatt_characteristic_removed_count()); |
456 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 447 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
457 } | 448 } |
458 | 449 |
459 TEST_F(BluetoothGattChromeOSTest, GattDescriptorAddedAndRemoved) { | 450 TEST_F(BluetoothGattBlueZTest, GattDescriptorAddedAndRemoved) { |
460 fake_bluetooth_device_client_->CreateDevice( | 451 fake_bluetooth_device_client_->CreateDevice( |
461 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 452 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
462 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 453 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
463 BluetoothDevice* device = | 454 BluetoothDevice* device = |
464 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 455 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
465 ASSERT_TRUE(device); | 456 ASSERT_TRUE(device); |
466 | 457 |
467 TestBluetoothAdapterObserver observer(adapter_); | 458 TestBluetoothAdapterObserver observer(adapter_); |
468 | 459 |
469 // Expose the fake Heart Rate service. This will asynchronously expose | 460 // Expose the fake Heart Rate service. This will asynchronously expose |
(...skipping 15 matching lines...) Expand all Loading... |
485 // Run the message loop so that the characteristics appear. | 476 // Run the message loop so that the characteristics appear. |
486 base::MessageLoop::current()->Run(); | 477 base::MessageLoop::current()->Run(); |
487 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 478 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
488 | 479 |
489 // Only the Heart Rate Measurement characteristic has a descriptor. | 480 // Only the Heart Rate Measurement characteristic has a descriptor. |
490 EXPECT_EQ(1, observer.gatt_descriptor_added_count()); | 481 EXPECT_EQ(1, observer.gatt_descriptor_added_count()); |
491 EXPECT_EQ(0, observer.gatt_descriptor_removed_count()); | 482 EXPECT_EQ(0, observer.gatt_descriptor_removed_count()); |
492 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 483 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |
493 | 484 |
494 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( | 485 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( |
495 fake_bluetooth_gatt_characteristic_client_-> | 486 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() |
496 GetBodySensorLocationPath().value()); | 487 .value()); |
497 ASSERT_TRUE(characteristic); | 488 ASSERT_TRUE(characteristic); |
498 EXPECT_TRUE(characteristic->GetDescriptors().empty()); | 489 EXPECT_TRUE(characteristic->GetDescriptors().empty()); |
499 | 490 |
500 characteristic = service->GetCharacteristic( | 491 characteristic = service->GetCharacteristic( |
501 fake_bluetooth_gatt_characteristic_client_-> | 492 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath() |
502 GetHeartRateControlPointPath().value()); | 493 .value()); |
503 ASSERT_TRUE(characteristic); | 494 ASSERT_TRUE(characteristic); |
504 EXPECT_TRUE(characteristic->GetDescriptors().empty()); | 495 EXPECT_TRUE(characteristic->GetDescriptors().empty()); |
505 | 496 |
506 characteristic = service->GetCharacteristic( | 497 characteristic = service->GetCharacteristic( |
507 fake_bluetooth_gatt_characteristic_client_-> | 498 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() |
508 GetHeartRateMeasurementPath().value()); | 499 .value()); |
509 ASSERT_TRUE(characteristic); | 500 ASSERT_TRUE(characteristic); |
510 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); | 501 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); |
511 | 502 |
512 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; | 503 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; |
513 EXPECT_FALSE(descriptor->IsLocal()); | 504 EXPECT_FALSE(descriptor->IsLocal()); |
514 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), | 505 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), |
515 descriptor->GetUUID()); | 506 descriptor->GetUUID()); |
516 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); | 507 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); |
517 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); | 508 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); |
518 | 509 |
(...skipping 20 matching lines...) Expand all Loading... |
539 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 530 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |
540 | 531 |
541 descriptor = characteristic->GetDescriptors()[0]; | 532 descriptor = characteristic->GetDescriptors()[0]; |
542 EXPECT_FALSE(descriptor->IsLocal()); | 533 EXPECT_FALSE(descriptor->IsLocal()); |
543 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), | 534 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), |
544 descriptor->GetUUID()); | 535 descriptor->GetUUID()); |
545 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); | 536 EXPECT_EQ(descriptor->GetUUID(), observer.last_gatt_descriptor_uuid()); |
546 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); | 537 EXPECT_EQ(descriptor->GetIdentifier(), observer.last_gatt_descriptor_id()); |
547 } | 538 } |
548 | 539 |
549 TEST_F(BluetoothGattChromeOSTest, AdapterAddedAfterGattService) { | 540 TEST_F(BluetoothGattBlueZTest, AdapterAddedAfterGattService) { |
550 // This unit test tests that all remote GATT objects are created for D-Bus | 541 // This unit test tests that all remote GATT objects are created for D-Bus |
551 // objects that were already exposed. | 542 // objects that were already exposed. |
552 adapter_ = NULL; | 543 adapter_ = NULL; |
553 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting()); | 544 ASSERT_FALSE(device::BluetoothAdapterFactory::HasSharedInstanceForTesting()); |
554 | 545 |
555 // Create the fake D-Bus objects. | 546 // Create the fake D-Bus objects. |
556 fake_bluetooth_device_client_->CreateDevice( | 547 fake_bluetooth_device_client_->CreateDevice( |
557 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 548 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
558 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 549 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
559 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 550 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
(...skipping 16 matching lines...) Expand all Loading... |
576 EXPECT_TRUE(service->IsPrimary()); | 567 EXPECT_TRUE(service->IsPrimary()); |
577 EXPECT_EQ(BluetoothUUID( | 568 EXPECT_EQ(BluetoothUUID( |
578 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), | 569 bluez::FakeBluetoothGattServiceClient::kHeartRateServiceUUID), |
579 service->GetUUID()); | 570 service->GetUUID()); |
580 EXPECT_EQ(service, device->GetGattServices()[0]); | 571 EXPECT_EQ(service, device->GetGattServices()[0]); |
581 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier())); | 572 EXPECT_EQ(service, device->GetGattService(service->GetIdentifier())); |
582 EXPECT_FALSE(service->IsLocal()); | 573 EXPECT_FALSE(service->IsLocal()); |
583 EXPECT_EQ(3U, service->GetCharacteristics().size()); | 574 EXPECT_EQ(3U, service->GetCharacteristics().size()); |
584 | 575 |
585 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( | 576 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( |
586 fake_bluetooth_gatt_characteristic_client_-> | 577 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() |
587 GetBodySensorLocationPath().value()); | 578 .value()); |
588 ASSERT_TRUE(characteristic); | 579 ASSERT_TRUE(characteristic); |
589 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: | 580 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: |
590 kBodySensorLocationUUID), | 581 kBodySensorLocationUUID), |
591 characteristic->GetUUID()); | 582 characteristic->GetUUID()); |
592 EXPECT_FALSE(characteristic->IsLocal()); | 583 EXPECT_FALSE(characteristic->IsLocal()); |
593 EXPECT_TRUE(characteristic->GetDescriptors().empty()); | 584 EXPECT_TRUE(characteristic->GetDescriptors().empty()); |
594 | 585 |
595 characteristic = service->GetCharacteristic( | 586 characteristic = service->GetCharacteristic( |
596 fake_bluetooth_gatt_characteristic_client_-> | 587 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath() |
597 GetHeartRateControlPointPath().value()); | 588 .value()); |
598 ASSERT_TRUE(characteristic); | 589 ASSERT_TRUE(characteristic); |
599 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: | 590 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: |
600 kHeartRateControlPointUUID), | 591 kHeartRateControlPointUUID), |
601 characteristic->GetUUID()); | 592 characteristic->GetUUID()); |
602 EXPECT_FALSE(characteristic->IsLocal()); | 593 EXPECT_FALSE(characteristic->IsLocal()); |
603 EXPECT_TRUE(characteristic->GetDescriptors().empty()); | 594 EXPECT_TRUE(characteristic->GetDescriptors().empty()); |
604 | 595 |
605 characteristic = service->GetCharacteristic( | 596 characteristic = service->GetCharacteristic( |
606 fake_bluetooth_gatt_characteristic_client_-> | 597 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() |
607 GetHeartRateMeasurementPath().value()); | 598 .value()); |
608 ASSERT_TRUE(characteristic); | 599 ASSERT_TRUE(characteristic); |
609 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: | 600 EXPECT_EQ(BluetoothUUID(bluez::FakeBluetoothGattCharacteristicClient:: |
610 kHeartRateMeasurementUUID), | 601 kHeartRateMeasurementUUID), |
611 characteristic->GetUUID()); | 602 characteristic->GetUUID()); |
612 EXPECT_FALSE(characteristic->IsLocal()); | 603 EXPECT_FALSE(characteristic->IsLocal()); |
613 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); | 604 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); |
614 | 605 |
615 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; | 606 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; |
616 ASSERT_TRUE(descriptor); | 607 ASSERT_TRUE(descriptor); |
617 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), | 608 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), |
618 descriptor->GetUUID()); | 609 descriptor->GetUUID()); |
619 EXPECT_FALSE(descriptor->IsLocal()); | 610 EXPECT_FALSE(descriptor->IsLocal()); |
620 } | 611 } |
621 | 612 |
622 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicValue) { | 613 TEST_F(BluetoothGattBlueZTest, GattCharacteristicValue) { |
623 fake_bluetooth_device_client_->CreateDevice( | 614 fake_bluetooth_device_client_->CreateDevice( |
624 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 615 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
625 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 616 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
626 BluetoothDevice* device = | 617 BluetoothDevice* device = |
627 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 618 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
628 ASSERT_TRUE(device); | 619 ASSERT_TRUE(device); |
629 | 620 |
630 TestBluetoothAdapterObserver observer(adapter_); | 621 TestBluetoothAdapterObserver observer(adapter_); |
631 | 622 |
632 // Expose the fake Heart Rate service. This will asynchronously expose | 623 // Expose the fake Heart Rate service. This will asynchronously expose |
633 // characteristics. | 624 // characteristics. |
634 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 625 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
635 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 626 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
636 ASSERT_EQ(1, observer.gatt_service_added_count()); | 627 ASSERT_EQ(1, observer.gatt_service_added_count()); |
637 | 628 |
638 BluetoothGattService* service = | 629 BluetoothGattService* service = |
639 device->GetGattService(observer.last_gatt_service_id()); | 630 device->GetGattService(observer.last_gatt_service_id()); |
640 | 631 |
641 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 632 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
642 | 633 |
643 // Run the message loop so that the characteristics appear. | 634 // Run the message loop so that the characteristics appear. |
644 base::MessageLoop::current()->Run(); | 635 base::MessageLoop::current()->Run(); |
645 | 636 |
646 // Issue write request to non-writable characteristics. | 637 // Issue write request to non-writable characteristics. |
647 observer.Reset(); | 638 observer.Reset(); |
648 | 639 |
649 std::vector<uint8> write_value; | 640 std::vector<uint8> write_value; |
650 write_value.push_back(0x01); | 641 write_value.push_back(0x01); |
651 BluetoothGattCharacteristic* characteristic = | 642 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( |
652 service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_-> | 643 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() |
653 GetHeartRateMeasurementPath().value()); | 644 .value()); |
654 ASSERT_TRUE(characteristic); | 645 ASSERT_TRUE(characteristic); |
655 EXPECT_FALSE(characteristic->IsNotifying()); | 646 EXPECT_FALSE(characteristic->IsNotifying()); |
656 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> | 647 EXPECT_EQ( |
657 GetHeartRateMeasurementPath().value(), | 648 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() |
658 characteristic->GetIdentifier()); | 649 .value(), |
| 650 characteristic->GetIdentifier()); |
659 EXPECT_EQ(kHeartRateMeasurementUUID, characteristic->GetUUID()); | 651 EXPECT_EQ(kHeartRateMeasurementUUID, characteristic->GetUUID()); |
660 characteristic->WriteRemoteCharacteristic( | 652 characteristic->WriteRemoteCharacteristic( |
661 write_value, | 653 write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
662 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 654 base::Unretained(this)), |
663 base::Unretained(this)), | 655 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
664 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | |
665 base::Unretained(this))); | 656 base::Unretained(this))); |
666 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); | 657 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); |
667 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); | 658 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); |
668 EXPECT_EQ(0, success_callback_count_); | 659 EXPECT_EQ(0, success_callback_count_); |
669 EXPECT_EQ(1, error_callback_count_); | 660 EXPECT_EQ(1, error_callback_count_); |
670 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, | 661 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, |
671 last_service_error_); | 662 last_service_error_); |
672 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 663 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
673 | 664 |
674 characteristic = service->GetCharacteristic( | 665 characteristic = service->GetCharacteristic( |
675 fake_bluetooth_gatt_characteristic_client_-> | 666 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() |
676 GetBodySensorLocationPath().value()); | 667 .value()); |
677 ASSERT_TRUE(characteristic); | 668 ASSERT_TRUE(characteristic); |
678 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> | 669 EXPECT_EQ( |
679 GetBodySensorLocationPath().value(), | 670 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() |
680 characteristic->GetIdentifier()); | 671 .value(), |
| 672 characteristic->GetIdentifier()); |
681 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); | 673 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); |
682 characteristic->WriteRemoteCharacteristic( | 674 characteristic->WriteRemoteCharacteristic( |
683 write_value, | 675 write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
684 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 676 base::Unretained(this)), |
685 base::Unretained(this)), | 677 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
686 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | |
687 base::Unretained(this))); | 678 base::Unretained(this))); |
688 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); | 679 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); |
689 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); | 680 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); |
690 EXPECT_EQ(0, success_callback_count_); | 681 EXPECT_EQ(0, success_callback_count_); |
691 EXPECT_EQ(2, error_callback_count_); | 682 EXPECT_EQ(2, error_callback_count_); |
692 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED, | 683 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED, |
693 last_service_error_); | 684 last_service_error_); |
694 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 685 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
695 | 686 |
696 // Issue write request to writable characteristic. The "Body Sensor Location" | 687 // Issue write request to writable characteristic. The "Body Sensor Location" |
697 // characteristic does not send notifications and WriteValue does not result | 688 // characteristic does not send notifications and WriteValue does not result |
698 // in a CharacteristicValueChanged event, thus no such event should be | 689 // in a CharacteristicValueChanged event, thus no such event should be |
699 // received. | 690 // received. |
700 characteristic = service->GetCharacteristic( | 691 characteristic = service->GetCharacteristic( |
701 fake_bluetooth_gatt_characteristic_client_-> | 692 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath() |
702 GetHeartRateControlPointPath().value()); | 693 .value()); |
703 ASSERT_TRUE(characteristic); | 694 ASSERT_TRUE(characteristic); |
704 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> | 695 EXPECT_EQ( |
705 GetHeartRateControlPointPath().value(), | 696 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath() |
706 characteristic->GetIdentifier()); | 697 .value(), |
| 698 characteristic->GetIdentifier()); |
707 EXPECT_EQ(kHeartRateControlPointUUID, characteristic->GetUUID()); | 699 EXPECT_EQ(kHeartRateControlPointUUID, characteristic->GetUUID()); |
708 characteristic->WriteRemoteCharacteristic( | 700 characteristic->WriteRemoteCharacteristic( |
709 write_value, | 701 write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
710 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 702 base::Unretained(this)), |
711 base::Unretained(this)), | 703 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
712 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | |
713 base::Unretained(this))); | 704 base::Unretained(this))); |
714 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); | 705 EXPECT_TRUE(observer.last_gatt_characteristic_id().empty()); |
715 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); | 706 EXPECT_FALSE(observer.last_gatt_characteristic_uuid().IsValid()); |
716 EXPECT_EQ(1, success_callback_count_); | 707 EXPECT_EQ(1, success_callback_count_); |
717 EXPECT_EQ(2, error_callback_count_); | 708 EXPECT_EQ(2, error_callback_count_); |
718 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 709 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
719 | 710 |
720 // Issue some invalid write requests to the characteristic. | 711 // Issue some invalid write requests to the characteristic. |
721 // The value should still not change. | 712 // The value should still not change. |
722 | 713 |
723 std::vector<uint8> invalid_write_length; | 714 std::vector<uint8> invalid_write_length; |
724 invalid_write_length.push_back(0x01); | 715 invalid_write_length.push_back(0x01); |
725 invalid_write_length.push_back(0x00); | 716 invalid_write_length.push_back(0x00); |
726 characteristic->WriteRemoteCharacteristic( | 717 characteristic->WriteRemoteCharacteristic( |
727 invalid_write_length, | 718 invalid_write_length, base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
728 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 719 base::Unretained(this)), |
729 base::Unretained(this)), | 720 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
730 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | |
731 base::Unretained(this))); | 721 base::Unretained(this))); |
732 EXPECT_EQ(1, success_callback_count_); | 722 EXPECT_EQ(1, success_callback_count_); |
733 EXPECT_EQ(3, error_callback_count_); | 723 EXPECT_EQ(3, error_callback_count_); |
734 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, | 724 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, |
735 last_service_error_); | 725 last_service_error_); |
736 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 726 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
737 | 727 |
738 std::vector<uint8> invalid_write_value; | 728 std::vector<uint8> invalid_write_value; |
739 invalid_write_value.push_back(0x02); | 729 invalid_write_value.push_back(0x02); |
740 characteristic->WriteRemoteCharacteristic( | 730 characteristic->WriteRemoteCharacteristic( |
741 invalid_write_value, | 731 invalid_write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
742 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 732 base::Unretained(this)), |
743 base::Unretained(this)), | 733 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
744 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | |
745 base::Unretained(this))); | 734 base::Unretained(this))); |
746 EXPECT_EQ(1, success_callback_count_); | 735 EXPECT_EQ(1, success_callback_count_); |
747 EXPECT_EQ(4, error_callback_count_); | 736 EXPECT_EQ(4, error_callback_count_); |
748 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_service_error_); | 737 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_service_error_); |
749 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 738 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
750 | 739 |
751 // Issue a read request. A successful read results in a | 740 // Issue a read request. A successful read results in a |
752 // CharacteristicValueChanged notification. | 741 // CharacteristicValueChanged notification. |
753 characteristic = service->GetCharacteristic( | 742 characteristic = service->GetCharacteristic( |
754 fake_bluetooth_gatt_characteristic_client_-> | 743 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() |
755 GetBodySensorLocationPath().value()); | 744 .value()); |
756 ASSERT_TRUE(characteristic); | 745 ASSERT_TRUE(characteristic); |
757 EXPECT_EQ(fake_bluetooth_gatt_characteristic_client_-> | 746 EXPECT_EQ( |
758 GetBodySensorLocationPath().value(), | 747 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() |
759 characteristic->GetIdentifier()); | 748 .value(), |
| 749 characteristic->GetIdentifier()); |
760 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); | 750 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); |
761 characteristic->ReadRemoteCharacteristic( | 751 characteristic->ReadRemoteCharacteristic( |
762 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 752 base::Bind(&BluetoothGattBlueZTest::ValueCallback, |
763 base::Unretained(this)), | 753 base::Unretained(this)), |
764 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 754 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
765 base::Unretained(this))); | 755 base::Unretained(this))); |
766 EXPECT_EQ(2, success_callback_count_); | 756 EXPECT_EQ(2, success_callback_count_); |
767 EXPECT_EQ(4, error_callback_count_); | 757 EXPECT_EQ(4, error_callback_count_); |
768 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 758 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
769 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); | 759 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); |
770 | 760 |
771 // Test long-running actions. | 761 // Test long-running actions. |
772 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(1); | 762 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(1); |
773 characteristic = service->GetCharacteristic( | 763 characteristic = service->GetCharacteristic( |
774 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() | 764 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() |
775 .value()); | 765 .value()); |
776 ASSERT_TRUE(characteristic); | 766 ASSERT_TRUE(characteristic); |
777 EXPECT_EQ( | 767 EXPECT_EQ( |
778 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() | 768 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() |
779 .value(), | 769 .value(), |
780 characteristic->GetIdentifier()); | 770 characteristic->GetIdentifier()); |
781 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); | 771 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); |
782 characteristic->ReadRemoteCharacteristic( | 772 characteristic->ReadRemoteCharacteristic( |
783 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 773 base::Bind(&BluetoothGattBlueZTest::ValueCallback, |
784 base::Unretained(this)), | 774 base::Unretained(this)), |
785 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 775 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
786 base::Unretained(this))); | 776 base::Unretained(this))); |
787 | 777 |
788 // Callback counts shouldn't change, this one will be delayed until after | 778 // Callback counts shouldn't change, this one will be delayed until after |
789 // tne next one. | 779 // tne next one. |
790 EXPECT_EQ(2, success_callback_count_); | 780 EXPECT_EQ(2, success_callback_count_); |
791 EXPECT_EQ(4, error_callback_count_); | 781 EXPECT_EQ(4, error_callback_count_); |
792 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 782 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
793 | 783 |
794 // Next read should error because IN_PROGRESS | 784 // Next read should error because IN_PROGRESS |
795 characteristic->ReadRemoteCharacteristic( | 785 characteristic->ReadRemoteCharacteristic( |
796 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 786 base::Bind(&BluetoothGattBlueZTest::ValueCallback, |
797 base::Unretained(this)), | 787 base::Unretained(this)), |
798 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 788 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
799 base::Unretained(this))); | 789 base::Unretained(this))); |
800 EXPECT_EQ(5, error_callback_count_); | 790 EXPECT_EQ(5, error_callback_count_); |
801 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, last_service_error_); | 791 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, last_service_error_); |
802 | 792 |
803 // But previous call finished. | 793 // But previous call finished. |
804 EXPECT_EQ(3, success_callback_count_); | 794 EXPECT_EQ(3, success_callback_count_); |
805 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); | 795 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
806 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); | 796 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); |
807 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(0); | 797 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(0); |
808 | 798 |
809 // Test unauthorized actions. | 799 // Test unauthorized actions. |
810 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(false); | 800 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(false); |
811 characteristic->ReadRemoteCharacteristic( | 801 characteristic->ReadRemoteCharacteristic( |
812 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 802 base::Bind(&BluetoothGattBlueZTest::ValueCallback, |
813 base::Unretained(this)), | 803 base::Unretained(this)), |
814 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 804 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
815 base::Unretained(this))); | 805 base::Unretained(this))); |
816 EXPECT_EQ(3, success_callback_count_); | 806 EXPECT_EQ(3, success_callback_count_); |
817 EXPECT_EQ(6, error_callback_count_); | 807 EXPECT_EQ(6, error_callback_count_); |
818 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED, | 808 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED, |
819 last_service_error_); | 809 last_service_error_); |
820 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); | 810 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
821 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(true); | 811 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(true); |
822 | 812 |
823 // Test unauthenticated / needs login. | 813 // Test unauthenticated / needs login. |
824 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(false); | 814 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(false); |
825 characteristic->ReadRemoteCharacteristic( | 815 characteristic->ReadRemoteCharacteristic( |
826 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 816 base::Bind(&BluetoothGattBlueZTest::ValueCallback, |
827 base::Unretained(this)), | 817 base::Unretained(this)), |
828 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 818 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
829 base::Unretained(this))); | 819 base::Unretained(this))); |
830 EXPECT_EQ(3, success_callback_count_); | 820 EXPECT_EQ(3, success_callback_count_); |
831 EXPECT_EQ(7, error_callback_count_); | 821 EXPECT_EQ(7, error_callback_count_); |
832 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PAIRED, last_service_error_); | 822 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PAIRED, last_service_error_); |
833 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); | 823 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
834 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(true); | 824 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(true); |
835 } | 825 } |
836 | 826 |
837 TEST_F(BluetoothGattChromeOSTest, GattCharacteristicProperties) { | 827 TEST_F(BluetoothGattBlueZTest, GattCharacteristicProperties) { |
838 fake_bluetooth_device_client_->CreateDevice( | 828 fake_bluetooth_device_client_->CreateDevice( |
839 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 829 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
840 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 830 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
841 BluetoothDevice* device = | 831 BluetoothDevice* device = |
842 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 832 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
843 ASSERT_TRUE(device); | 833 ASSERT_TRUE(device); |
844 | 834 |
845 TestBluetoothAdapterObserver observer(adapter_); | 835 TestBluetoothAdapterObserver observer(adapter_); |
846 | 836 |
847 // Expose the fake Heart Rate service. This will asynchronously expose | 837 // Expose the fake Heart Rate service. This will asynchronously expose |
848 // characteristics. | 838 // characteristics. |
849 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 839 fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |
850 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 840 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
851 | 841 |
852 BluetoothGattService* service = | 842 BluetoothGattService* service = |
853 device->GetGattService(observer.last_gatt_service_id()); | 843 device->GetGattService(observer.last_gatt_service_id()); |
854 | 844 |
855 EXPECT_TRUE(service->GetCharacteristics().empty()); | 845 EXPECT_TRUE(service->GetCharacteristics().empty()); |
856 | 846 |
857 // Run the message loop so that the characteristics appear. | 847 // Run the message loop so that the characteristics appear. |
858 base::MessageLoop::current()->Run(); | 848 base::MessageLoop::current()->Run(); |
859 | 849 |
860 BluetoothGattCharacteristic *characteristic = service->GetCharacteristic( | 850 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( |
861 fake_bluetooth_gatt_characteristic_client_-> | 851 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() |
862 GetBodySensorLocationPath().value()); | 852 .value()); |
863 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_READ, | 853 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_READ, |
864 characteristic->GetProperties()); | 854 characteristic->GetProperties()); |
865 | 855 |
866 characteristic = service->GetCharacteristic( | 856 characteristic = service->GetCharacteristic( |
867 fake_bluetooth_gatt_characteristic_client_-> | 857 fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath() |
868 GetHeartRateControlPointPath().value()); | 858 .value()); |
869 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_WRITE, | 859 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_WRITE, |
870 characteristic->GetProperties()); | 860 characteristic->GetProperties()); |
871 | 861 |
872 characteristic = service->GetCharacteristic( | 862 characteristic = service->GetCharacteristic( |
873 fake_bluetooth_gatt_characteristic_client_-> | 863 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() |
874 GetHeartRateMeasurementPath().value()); | 864 .value()); |
875 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_NOTIFY, | 865 EXPECT_EQ(BluetoothGattCharacteristic::PROPERTY_NOTIFY, |
876 characteristic->GetProperties()); | 866 characteristic->GetProperties()); |
877 } | 867 } |
878 | 868 |
879 TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { | 869 TEST_F(BluetoothGattBlueZTest, GattDescriptorValue) { |
880 fake_bluetooth_device_client_->CreateDevice( | 870 fake_bluetooth_device_client_->CreateDevice( |
881 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 871 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
882 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 872 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
883 BluetoothDevice* device = | 873 BluetoothDevice* device = |
884 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 874 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
885 ASSERT_TRUE(device); | 875 ASSERT_TRUE(device); |
886 | 876 |
887 TestBluetoothAdapterObserver observer(adapter_); | 877 TestBluetoothAdapterObserver observer(adapter_); |
888 | 878 |
889 // Expose the fake Heart Rate service. This will asynchronously expose | 879 // Expose the fake Heart Rate service. This will asynchronously expose |
(...skipping 10 matching lines...) Expand all Loading... |
900 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 890 EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |
901 EXPECT_TRUE(service->GetCharacteristics().empty()); | 891 EXPECT_TRUE(service->GetCharacteristics().empty()); |
902 | 892 |
903 // Run the message loop so that the characteristics appear. | 893 // Run the message loop so that the characteristics appear. |
904 base::MessageLoop::current()->Run(); | 894 base::MessageLoop::current()->Run(); |
905 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 895 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
906 EXPECT_EQ(1, observer.gatt_discovery_complete_count()); | 896 EXPECT_EQ(1, observer.gatt_discovery_complete_count()); |
907 | 897 |
908 // Only the Heart Rate Measurement characteristic has a descriptor. | 898 // Only the Heart Rate Measurement characteristic has a descriptor. |
909 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( | 899 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( |
910 fake_bluetooth_gatt_characteristic_client_-> | 900 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() |
911 GetHeartRateMeasurementPath().value()); | 901 .value()); |
912 ASSERT_TRUE(characteristic); | 902 ASSERT_TRUE(characteristic); |
913 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); | 903 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); |
914 EXPECT_FALSE(characteristic->IsNotifying()); | 904 EXPECT_FALSE(characteristic->IsNotifying()); |
915 | 905 |
916 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; | 906 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; |
917 EXPECT_FALSE(descriptor->IsLocal()); | 907 EXPECT_FALSE(descriptor->IsLocal()); |
918 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), | 908 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), |
919 descriptor->GetUUID()); | 909 descriptor->GetUUID()); |
920 | 910 |
921 std::vector<uint8_t> desc_value = {0x00, 0x00}; | 911 std::vector<uint8_t> desc_value = {0x00, 0x00}; |
922 | 912 |
923 /* The cached value will be empty until the first read request */ | 913 /* The cached value will be empty until the first read request */ |
924 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); | 914 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
925 EXPECT_TRUE(descriptor->GetValue().empty()); | 915 EXPECT_TRUE(descriptor->GetValue().empty()); |
926 | 916 |
927 EXPECT_EQ(0, success_callback_count_); | 917 EXPECT_EQ(0, success_callback_count_); |
928 EXPECT_EQ(0, error_callback_count_); | 918 EXPECT_EQ(0, error_callback_count_); |
929 EXPECT_TRUE(last_read_value_.empty()); | 919 EXPECT_TRUE(last_read_value_.empty()); |
930 | 920 |
931 // Read value. GattDescriptorValueChanged event will be sent after a | 921 // Read value. GattDescriptorValueChanged event will be sent after a |
932 // successful read. | 922 // successful read. |
933 descriptor->ReadRemoteDescriptor( | 923 descriptor->ReadRemoteDescriptor( |
934 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 924 base::Bind(&BluetoothGattBlueZTest::ValueCallback, |
935 base::Unretained(this)), | 925 base::Unretained(this)), |
936 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 926 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
937 base::Unretained(this))); | 927 base::Unretained(this))); |
938 EXPECT_EQ(1, success_callback_count_); | 928 EXPECT_EQ(1, success_callback_count_); |
939 EXPECT_EQ(0, error_callback_count_); | 929 EXPECT_EQ(0, error_callback_count_); |
940 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 930 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
941 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); | 931 EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); |
942 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 932 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
943 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); | 933 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); |
944 | 934 |
945 // Write value. Writes to this descriptor will fail. | 935 // Write value. Writes to this descriptor will fail. |
946 desc_value[0] = 0x03; | 936 desc_value[0] = 0x03; |
947 descriptor->WriteRemoteDescriptor( | 937 descriptor->WriteRemoteDescriptor( |
948 desc_value, | 938 desc_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
949 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 939 base::Unretained(this)), |
950 base::Unretained(this)), | 940 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
951 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | |
952 base::Unretained(this))); | 941 base::Unretained(this))); |
953 EXPECT_EQ(1, success_callback_count_); | 942 EXPECT_EQ(1, success_callback_count_); |
954 EXPECT_EQ(1, error_callback_count_); | 943 EXPECT_EQ(1, error_callback_count_); |
955 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED, | 944 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED, |
956 last_service_error_); | 945 last_service_error_); |
957 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 946 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
958 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); | 947 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
959 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 948 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
960 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); | 949 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); |
961 | 950 |
962 // Read value. The value should remain unchanged. | 951 // Read value. The value should remain unchanged. |
963 descriptor->ReadRemoteDescriptor( | 952 descriptor->ReadRemoteDescriptor( |
964 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 953 base::Bind(&BluetoothGattBlueZTest::ValueCallback, |
965 base::Unretained(this)), | 954 base::Unretained(this)), |
966 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 955 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
967 base::Unretained(this))); | 956 base::Unretained(this))); |
968 EXPECT_EQ(2, success_callback_count_); | 957 EXPECT_EQ(2, success_callback_count_); |
969 EXPECT_EQ(1, error_callback_count_); | 958 EXPECT_EQ(1, error_callback_count_); |
970 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 959 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
971 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); | 960 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
972 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 961 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
973 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); | 962 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); |
974 | 963 |
975 // Start notifications on the descriptor's characteristic. The descriptor | 964 // Start notifications on the descriptor's characteristic. The descriptor |
976 // value should change. | 965 // value should change. |
977 characteristic->StartNotifySession( | 966 characteristic->StartNotifySession( |
978 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 967 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
979 base::Unretained(this)), | 968 base::Unretained(this)), |
980 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 969 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
981 base::Unretained(this))); | 970 base::Unretained(this))); |
982 base::MessageLoop::current()->Run(); | 971 base::MessageLoop::current()->Run(); |
983 EXPECT_EQ(3, success_callback_count_); | 972 EXPECT_EQ(3, success_callback_count_); |
984 EXPECT_EQ(1, error_callback_count_); | 973 EXPECT_EQ(1, error_callback_count_); |
985 EXPECT_EQ(1U, update_sessions_.size()); | 974 EXPECT_EQ(1U, update_sessions_.size()); |
986 EXPECT_TRUE(characteristic->IsNotifying()); | 975 EXPECT_TRUE(characteristic->IsNotifying()); |
987 | 976 |
988 // Read the new descriptor value. We should receive a value updated event. | 977 // Read the new descriptor value. We should receive a value updated event. |
989 descriptor->ReadRemoteDescriptor( | 978 descriptor->ReadRemoteDescriptor( |
990 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 979 base::Bind(&BluetoothGattBlueZTest::ValueCallback, |
991 base::Unretained(this)), | 980 base::Unretained(this)), |
992 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 981 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
993 base::Unretained(this))); | 982 base::Unretained(this))); |
994 EXPECT_EQ(4, success_callback_count_); | 983 EXPECT_EQ(4, success_callback_count_); |
995 EXPECT_EQ(1, error_callback_count_); | 984 EXPECT_EQ(1, error_callback_count_); |
996 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 985 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
997 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); | 986 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
998 EXPECT_EQ(0, observer.gatt_service_changed_count()); | 987 EXPECT_EQ(0, observer.gatt_service_changed_count()); |
999 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count()); | 988 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count()); |
1000 } | 989 } |
1001 | 990 |
1002 TEST_F(BluetoothGattChromeOSTest, NotifySessions) { | 991 TEST_F(BluetoothGattBlueZTest, NotifySessions) { |
1003 fake_bluetooth_device_client_->CreateDevice( | 992 fake_bluetooth_device_client_->CreateDevice( |
1004 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 993 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
1005 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 994 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
1006 BluetoothDevice* device = | 995 BluetoothDevice* device = |
1007 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 996 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
1008 ASSERT_TRUE(device); | 997 ASSERT_TRUE(device); |
1009 | 998 |
1010 TestBluetoothAdapterObserver observer(adapter_); | 999 TestBluetoothAdapterObserver observer(adapter_); |
1011 | 1000 |
1012 // Expose the fake Heart Rate service. This will asynchronously expose | 1001 // Expose the fake Heart Rate service. This will asynchronously expose |
(...skipping 12 matching lines...) Expand all Loading... |
1025 | 1014 |
1026 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( | 1015 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( |
1027 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() | 1016 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() |
1028 .value()); | 1017 .value()); |
1029 ASSERT_TRUE(characteristic); | 1018 ASSERT_TRUE(characteristic); |
1030 EXPECT_FALSE(characteristic->IsNotifying()); | 1019 EXPECT_FALSE(characteristic->IsNotifying()); |
1031 EXPECT_TRUE(update_sessions_.empty()); | 1020 EXPECT_TRUE(update_sessions_.empty()); |
1032 | 1021 |
1033 // Request to start notifications. | 1022 // Request to start notifications. |
1034 characteristic->StartNotifySession( | 1023 characteristic->StartNotifySession( |
1035 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1024 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1036 base::Unretained(this)), | 1025 base::Unretained(this)), |
1037 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1026 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1038 base::Unretained(this))); | 1027 base::Unretained(this))); |
1039 | 1028 |
1040 // The operation still hasn't completed but we should have received the first | 1029 // The operation still hasn't completed but we should have received the first |
1041 // notification. | 1030 // notification. |
1042 EXPECT_EQ(0, success_callback_count_); | 1031 EXPECT_EQ(0, success_callback_count_); |
1043 EXPECT_EQ(0, error_callback_count_); | 1032 EXPECT_EQ(0, error_callback_count_); |
1044 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1033 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1045 EXPECT_TRUE(update_sessions_.empty()); | 1034 EXPECT_TRUE(update_sessions_.empty()); |
1046 | 1035 |
1047 // Send a two more requests, which should get queued. | 1036 // Send a two more requests, which should get queued. |
1048 characteristic->StartNotifySession( | 1037 characteristic->StartNotifySession( |
1049 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1038 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1050 base::Unretained(this)), | 1039 base::Unretained(this)), |
1051 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1040 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1052 base::Unretained(this))); | 1041 base::Unretained(this))); |
1053 characteristic->StartNotifySession( | 1042 characteristic->StartNotifySession( |
1054 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1043 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1055 base::Unretained(this)), | 1044 base::Unretained(this)), |
1056 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1045 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1057 base::Unretained(this))); | 1046 base::Unretained(this))); |
1058 EXPECT_EQ(0, success_callback_count_); | 1047 EXPECT_EQ(0, success_callback_count_); |
1059 EXPECT_EQ(0, error_callback_count_); | 1048 EXPECT_EQ(0, error_callback_count_); |
1060 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1049 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1061 EXPECT_TRUE(update_sessions_.empty()); | 1050 EXPECT_TRUE(update_sessions_.empty()); |
1062 EXPECT_TRUE(characteristic->IsNotifying()); | 1051 EXPECT_TRUE(characteristic->IsNotifying()); |
1063 | 1052 |
1064 // Run the main loop. The initial call should complete. The queued call should | 1053 // Run the main loop. The initial call should complete. The queued call should |
1065 // succeed immediately. | 1054 // succeed immediately. |
1066 base::MessageLoop::current()->Run(); | 1055 base::MessageLoop::current()->Run(); |
1067 | 1056 |
1068 EXPECT_EQ(3, success_callback_count_); | 1057 EXPECT_EQ(3, success_callback_count_); |
1069 EXPECT_EQ(0, error_callback_count_); | 1058 EXPECT_EQ(0, error_callback_count_); |
1070 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1059 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1071 EXPECT_EQ(3U, update_sessions_.size()); | 1060 EXPECT_EQ(3U, update_sessions_.size()); |
1072 | 1061 |
1073 // Notifications should be getting sent regularly now. | 1062 // Notifications should be getting sent regularly now. |
1074 base::MessageLoop::current()->Run(); | 1063 base::MessageLoop::current()->Run(); |
1075 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); | 1064 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); |
1076 | 1065 |
1077 // Stop one of the sessions. The session should become inactive but the | 1066 // Stop one of the sessions. The session should become inactive but the |
1078 // characteristic should still be notifying. | 1067 // characteristic should still be notifying. |
1079 BluetoothGattNotifySession* session = update_sessions_[0]; | 1068 BluetoothGattNotifySession* session = update_sessions_[0]; |
1080 EXPECT_TRUE(session->IsActive()); | 1069 EXPECT_TRUE(session->IsActive()); |
1081 session->Stop(base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 1070 session->Stop(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
1082 base::Unretained(this))); | 1071 base::Unretained(this))); |
1083 EXPECT_EQ(4, success_callback_count_); | 1072 EXPECT_EQ(4, success_callback_count_); |
1084 EXPECT_EQ(0, error_callback_count_); | 1073 EXPECT_EQ(0, error_callback_count_); |
1085 EXPECT_FALSE(session->IsActive()); | 1074 EXPECT_FALSE(session->IsActive()); |
1086 EXPECT_EQ(characteristic->GetIdentifier(), | 1075 EXPECT_EQ(characteristic->GetIdentifier(), |
1087 session->GetCharacteristicIdentifier()); | 1076 session->GetCharacteristicIdentifier()); |
1088 EXPECT_TRUE(characteristic->IsNotifying()); | 1077 EXPECT_TRUE(characteristic->IsNotifying()); |
1089 | 1078 |
1090 // Delete another session. Characteristic should still be notifying. | 1079 // Delete another session. Characteristic should still be notifying. |
1091 update_sessions_.pop_back(); | 1080 update_sessions_.pop_back(); |
1092 EXPECT_EQ(2U, update_sessions_.size()); | 1081 EXPECT_EQ(2U, update_sessions_.size()); |
1093 EXPECT_TRUE(characteristic->IsNotifying()); | 1082 EXPECT_TRUE(characteristic->IsNotifying()); |
1094 EXPECT_FALSE(update_sessions_[0]->IsActive()); | 1083 EXPECT_FALSE(update_sessions_[0]->IsActive()); |
1095 EXPECT_TRUE(update_sessions_[1]->IsActive()); | 1084 EXPECT_TRUE(update_sessions_[1]->IsActive()); |
1096 | 1085 |
1097 // Clear the last session. | 1086 // Clear the last session. |
1098 update_sessions_.clear(); | 1087 update_sessions_.clear(); |
1099 EXPECT_TRUE(update_sessions_.empty()); | 1088 EXPECT_TRUE(update_sessions_.empty()); |
1100 EXPECT_FALSE(characteristic->IsNotifying()); | 1089 EXPECT_FALSE(characteristic->IsNotifying()); |
1101 | 1090 |
1102 success_callback_count_ = 0; | 1091 success_callback_count_ = 0; |
1103 observer.Reset(); | 1092 observer.Reset(); |
1104 | 1093 |
1105 // Enable notifications again. | 1094 // Enable notifications again. |
1106 characteristic->StartNotifySession( | 1095 characteristic->StartNotifySession( |
1107 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1096 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1108 base::Unretained(this)), | 1097 base::Unretained(this)), |
1109 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1098 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1110 base::Unretained(this))); | 1099 base::Unretained(this))); |
1111 EXPECT_EQ(0, success_callback_count_); | 1100 EXPECT_EQ(0, success_callback_count_); |
1112 EXPECT_EQ(0, error_callback_count_); | 1101 EXPECT_EQ(0, error_callback_count_); |
1113 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1102 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1114 EXPECT_TRUE(update_sessions_.empty()); | 1103 EXPECT_TRUE(update_sessions_.empty()); |
1115 EXPECT_TRUE(characteristic->IsNotifying()); | 1104 EXPECT_TRUE(characteristic->IsNotifying()); |
1116 | 1105 |
1117 // Run the message loop. Notifications should begin. | 1106 // Run the message loop. Notifications should begin. |
1118 base::MessageLoop::current()->Run(); | 1107 base::MessageLoop::current()->Run(); |
1119 | 1108 |
1120 EXPECT_EQ(1, success_callback_count_); | 1109 EXPECT_EQ(1, success_callback_count_); |
1121 EXPECT_EQ(0, error_callback_count_); | 1110 EXPECT_EQ(0, error_callback_count_); |
1122 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1111 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1123 EXPECT_EQ(1U, update_sessions_.size()); | 1112 EXPECT_EQ(1U, update_sessions_.size()); |
1124 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1113 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
1125 EXPECT_TRUE(characteristic->IsNotifying()); | 1114 EXPECT_TRUE(characteristic->IsNotifying()); |
1126 | 1115 |
1127 // Check that notifications are happening. | 1116 // Check that notifications are happening. |
1128 base::MessageLoop::current()->Run(); | 1117 base::MessageLoop::current()->Run(); |
1129 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); | 1118 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); |
1130 | 1119 |
1131 // Request another session. This should return immediately. | 1120 // Request another session. This should return immediately. |
1132 characteristic->StartNotifySession( | 1121 characteristic->StartNotifySession( |
1133 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1122 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1134 base::Unretained(this)), | 1123 base::Unretained(this)), |
1135 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1124 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1136 base::Unretained(this))); | 1125 base::Unretained(this))); |
1137 EXPECT_EQ(2, success_callback_count_); | 1126 EXPECT_EQ(2, success_callback_count_); |
1138 EXPECT_EQ(0, error_callback_count_); | 1127 EXPECT_EQ(0, error_callback_count_); |
1139 EXPECT_EQ(2U, update_sessions_.size()); | 1128 EXPECT_EQ(2U, update_sessions_.size()); |
1140 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1129 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
1141 EXPECT_TRUE(update_sessions_[1]->IsActive()); | 1130 EXPECT_TRUE(update_sessions_[1]->IsActive()); |
1142 EXPECT_TRUE(characteristic->IsNotifying()); | 1131 EXPECT_TRUE(characteristic->IsNotifying()); |
1143 | 1132 |
1144 // Hide the characteristic. The sessions should become inactive. | 1133 // Hide the characteristic. The sessions should become inactive. |
1145 fake_bluetooth_gatt_characteristic_client_->HideHeartRateCharacteristics(); | 1134 fake_bluetooth_gatt_characteristic_client_->HideHeartRateCharacteristics(); |
1146 EXPECT_EQ(2U, update_sessions_.size()); | 1135 EXPECT_EQ(2U, update_sessions_.size()); |
1147 EXPECT_FALSE(update_sessions_[0]->IsActive()); | 1136 EXPECT_FALSE(update_sessions_[0]->IsActive()); |
1148 EXPECT_FALSE(update_sessions_[1]->IsActive()); | 1137 EXPECT_FALSE(update_sessions_[1]->IsActive()); |
1149 } | 1138 } |
1150 | 1139 |
1151 TEST_F(BluetoothGattChromeOSTest, NotifySessionsMadeInactive) { | 1140 TEST_F(BluetoothGattBlueZTest, NotifySessionsMadeInactive) { |
1152 fake_bluetooth_device_client_->CreateDevice( | 1141 fake_bluetooth_device_client_->CreateDevice( |
1153 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), | 1142 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
1154 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 1143 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |
1155 BluetoothDevice* device = | 1144 BluetoothDevice* device = |
1156 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); | 1145 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); |
1157 ASSERT_TRUE(device); | 1146 ASSERT_TRUE(device); |
1158 | 1147 |
1159 TestBluetoothAdapterObserver observer(adapter_); | 1148 TestBluetoothAdapterObserver observer(adapter_); |
1160 | 1149 |
1161 // Expose the fake Heart Rate service. This will asynchronously expose | 1150 // Expose the fake Heart Rate service. This will asynchronously expose |
(...skipping 12 matching lines...) Expand all Loading... |
1174 | 1163 |
1175 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( | 1164 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( |
1176 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() | 1165 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath() |
1177 .value()); | 1166 .value()); |
1178 ASSERT_TRUE(characteristic); | 1167 ASSERT_TRUE(characteristic); |
1179 EXPECT_FALSE(characteristic->IsNotifying()); | 1168 EXPECT_FALSE(characteristic->IsNotifying()); |
1180 EXPECT_TRUE(update_sessions_.empty()); | 1169 EXPECT_TRUE(update_sessions_.empty()); |
1181 | 1170 |
1182 // Send several requests to start notifications. | 1171 // Send several requests to start notifications. |
1183 characteristic->StartNotifySession( | 1172 characteristic->StartNotifySession( |
1184 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1173 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1185 base::Unretained(this)), | 1174 base::Unretained(this)), |
1186 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1175 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1187 base::Unretained(this))); | 1176 base::Unretained(this))); |
1188 characteristic->StartNotifySession( | 1177 characteristic->StartNotifySession( |
1189 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1178 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1190 base::Unretained(this)), | 1179 base::Unretained(this)), |
1191 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1180 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1192 base::Unretained(this))); | 1181 base::Unretained(this))); |
1193 characteristic->StartNotifySession( | 1182 characteristic->StartNotifySession( |
1194 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1183 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1195 base::Unretained(this)), | 1184 base::Unretained(this)), |
1196 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1185 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1197 base::Unretained(this))); | 1186 base::Unretained(this))); |
1198 characteristic->StartNotifySession( | 1187 characteristic->StartNotifySession( |
1199 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1188 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1200 base::Unretained(this)), | 1189 base::Unretained(this)), |
1201 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1190 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1202 base::Unretained(this))); | 1191 base::Unretained(this))); |
1203 | 1192 |
1204 // The operation still hasn't completed but we should have received the first | 1193 // The operation still hasn't completed but we should have received the first |
1205 // notification. | 1194 // notification. |
1206 EXPECT_EQ(0, success_callback_count_); | 1195 EXPECT_EQ(0, success_callback_count_); |
1207 EXPECT_EQ(0, error_callback_count_); | 1196 EXPECT_EQ(0, error_callback_count_); |
1208 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1197 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1209 EXPECT_TRUE(characteristic->IsNotifying()); | 1198 EXPECT_TRUE(characteristic->IsNotifying()); |
1210 EXPECT_TRUE(update_sessions_.empty()); | 1199 EXPECT_TRUE(update_sessions_.empty()); |
1211 | 1200 |
1212 // Run the main loop. The initial call should complete. The queued calls | 1201 // Run the main loop. The initial call should complete. The queued calls |
1213 // should succeed immediately. | 1202 // should succeed immediately. |
1214 base::MessageLoop::current()->Run(); | 1203 base::MessageLoop::current()->Run(); |
1215 | 1204 |
1216 EXPECT_EQ(4, success_callback_count_); | 1205 EXPECT_EQ(4, success_callback_count_); |
1217 EXPECT_EQ(0, error_callback_count_); | 1206 EXPECT_EQ(0, error_callback_count_); |
1218 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1207 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1219 EXPECT_TRUE(characteristic->IsNotifying()); | 1208 EXPECT_TRUE(characteristic->IsNotifying()); |
1220 EXPECT_EQ(4U, update_sessions_.size()); | 1209 EXPECT_EQ(4U, update_sessions_.size()); |
1221 | 1210 |
1222 for (int i = 0; i < 4; i++) | 1211 for (int i = 0; i < 4; i++) |
1223 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1212 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
1224 | 1213 |
1225 // Stop notifications directly through the client. The sessions should get | 1214 // Stop notifications directly through the client. The sessions should get |
1226 // marked as inactive. | 1215 // marked as inactive. |
1227 fake_bluetooth_gatt_characteristic_client_->StopNotify( | 1216 fake_bluetooth_gatt_characteristic_client_->StopNotify( |
1228 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath(), | 1217 fake_bluetooth_gatt_characteristic_client_->GetHeartRateMeasurementPath(), |
1229 base::Bind(&BluetoothGattChromeOSTest::SuccessCallback, | 1218 base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
1230 base::Unretained(this)), | 1219 base::Unretained(this)), |
1231 base::Bind(&BluetoothGattChromeOSTest::DBusErrorCallback, | 1220 base::Bind(&BluetoothGattBlueZTest::DBusErrorCallback, |
1232 base::Unretained(this))); | 1221 base::Unretained(this))); |
1233 EXPECT_EQ(5, success_callback_count_); | 1222 EXPECT_EQ(5, success_callback_count_); |
1234 EXPECT_EQ(0, error_callback_count_); | 1223 EXPECT_EQ(0, error_callback_count_); |
1235 EXPECT_FALSE(characteristic->IsNotifying()); | 1224 EXPECT_FALSE(characteristic->IsNotifying()); |
1236 EXPECT_EQ(4U, update_sessions_.size()); | 1225 EXPECT_EQ(4U, update_sessions_.size()); |
1237 | 1226 |
1238 for (int i = 0; i < 4; i++) | 1227 for (int i = 0; i < 4; i++) |
1239 EXPECT_FALSE(update_sessions_[0]->IsActive()); | 1228 EXPECT_FALSE(update_sessions_[0]->IsActive()); |
1240 | 1229 |
1241 // It should be possible to restart notifications and the call should reset | 1230 // It should be possible to restart notifications and the call should reset |
1242 // the session count and make a request through the client. | 1231 // the session count and make a request through the client. |
1243 update_sessions_.clear(); | 1232 update_sessions_.clear(); |
1244 success_callback_count_ = 0; | 1233 success_callback_count_ = 0; |
1245 observer.Reset(); | 1234 observer.Reset(); |
1246 characteristic->StartNotifySession( | 1235 characteristic->StartNotifySession( |
1247 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, | 1236 base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |
1248 base::Unretained(this)), | 1237 base::Unretained(this)), |
1249 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1238 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |
1250 base::Unretained(this))); | 1239 base::Unretained(this))); |
1251 | 1240 |
1252 EXPECT_EQ(0, success_callback_count_); | 1241 EXPECT_EQ(0, success_callback_count_); |
1253 EXPECT_EQ(0, error_callback_count_); | 1242 EXPECT_EQ(0, error_callback_count_); |
1254 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1243 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1255 EXPECT_TRUE(characteristic->IsNotifying()); | 1244 EXPECT_TRUE(characteristic->IsNotifying()); |
1256 EXPECT_TRUE(update_sessions_.empty()); | 1245 EXPECT_TRUE(update_sessions_.empty()); |
1257 | 1246 |
1258 base::MessageLoop::current()->Run(); | 1247 base::MessageLoop::current()->Run(); |
1259 | 1248 |
1260 EXPECT_EQ(1, success_callback_count_); | 1249 EXPECT_EQ(1, success_callback_count_); |
1261 EXPECT_EQ(0, error_callback_count_); | 1250 EXPECT_EQ(0, error_callback_count_); |
1262 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1251 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1263 EXPECT_TRUE(characteristic->IsNotifying()); | 1252 EXPECT_TRUE(characteristic->IsNotifying()); |
1264 EXPECT_EQ(1U, update_sessions_.size()); | 1253 EXPECT_EQ(1U, update_sessions_.size()); |
1265 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1254 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
1266 } | 1255 } |
1267 | 1256 |
1268 } // namespace chromeos | 1257 } // namespace bluez |
OLD | NEW |