OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> |
10 | 11 |
11 #include "base/memory/scoped_vector.h" | |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
15 #include "device/bluetooth/bluetooth_adapter.h" | 15 #include "device/bluetooth/bluetooth_adapter.h" |
16 #include "device/bluetooth/bluetooth_adapter_factory.h" | 16 #include "device/bluetooth/bluetooth_adapter_factory.h" |
17 #include "device/bluetooth/bluetooth_device.h" | 17 #include "device/bluetooth/bluetooth_device.h" |
18 #include "device/bluetooth/bluetooth_discovery_filter.h" | 18 #include "device/bluetooth/bluetooth_discovery_filter.h" |
19 #include "device/bluetooth/bluetooth_gatt_connection.h" | 19 #include "device/bluetooth/bluetooth_gatt_connection.h" |
20 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 20 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
21 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 21 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 | 253 |
254 void GattConnectionCallback(std::unique_ptr<BluetoothGattConnection> conn) { | 254 void GattConnectionCallback(std::unique_ptr<BluetoothGattConnection> conn) { |
255 ++success_callback_count_; | 255 ++success_callback_count_; |
256 gatt_conn_ = std::move(conn); | 256 gatt_conn_ = std::move(conn); |
257 } | 257 } |
258 | 258 |
259 void NotifySessionCallback( | 259 void NotifySessionCallback( |
260 std::unique_ptr<BluetoothGattNotifySession> session) { | 260 std::unique_ptr<BluetoothGattNotifySession> session) { |
261 ++success_callback_count_; | 261 ++success_callback_count_; |
262 update_sessions_.push_back(session.release()); | 262 update_sessions_.push_back(std::move(session)); |
263 QuitMessageLoop(); | 263 QuitMessageLoop(); |
264 } | 264 } |
265 | 265 |
266 void ServiceErrorCallback(BluetoothRemoteGattService::GattErrorCode err) { | 266 void ServiceErrorCallback(BluetoothRemoteGattService::GattErrorCode err) { |
267 ++error_callback_count_; | 267 ++error_callback_count_; |
268 last_service_error_ = err; | 268 last_service_error_ = err; |
269 } | 269 } |
270 | 270 |
271 void ErrorCallback() { ++error_callback_count_; } | 271 void ErrorCallback() { ++error_callback_count_; } |
272 | 272 |
(...skipping 15 matching lines...) Expand all Loading... |
288 | 288 |
289 base::MessageLoop message_loop_; | 289 base::MessageLoop message_loop_; |
290 | 290 |
291 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; | 291 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client_; |
292 bluez::FakeBluetoothGattServiceClient* fake_bluetooth_gatt_service_client_; | 292 bluez::FakeBluetoothGattServiceClient* fake_bluetooth_gatt_service_client_; |
293 bluez::FakeBluetoothGattCharacteristicClient* | 293 bluez::FakeBluetoothGattCharacteristicClient* |
294 fake_bluetooth_gatt_characteristic_client_; | 294 fake_bluetooth_gatt_characteristic_client_; |
295 bluez::FakeBluetoothGattDescriptorClient* | 295 bluez::FakeBluetoothGattDescriptorClient* |
296 fake_bluetooth_gatt_descriptor_client_; | 296 fake_bluetooth_gatt_descriptor_client_; |
297 std::unique_ptr<device::BluetoothGattConnection> gatt_conn_; | 297 std::unique_ptr<device::BluetoothGattConnection> gatt_conn_; |
298 ScopedVector<BluetoothGattNotifySession> update_sessions_; | 298 std::vector<std::unique_ptr<BluetoothGattNotifySession>> update_sessions_; |
299 scoped_refptr<BluetoothAdapter> adapter_; | 299 scoped_refptr<BluetoothAdapter> adapter_; |
300 | 300 |
301 int success_callback_count_; | 301 int success_callback_count_; |
302 int error_callback_count_; | 302 int error_callback_count_; |
303 std::vector<uint8_t> last_read_value_; | 303 std::vector<uint8_t> last_read_value_; |
304 BluetoothRemoteGattService::GattErrorCode last_service_error_; | 304 BluetoothRemoteGattService::GattErrorCode last_service_error_; |
305 }; | 305 }; |
306 | 306 |
307 TEST_F(BluetoothGattBlueZTest, | 307 TEST_F(BluetoothGattBlueZTest, |
308 RetrieveGattConnectedDevicesWithDiscoveryFilter_NoFilter) { | 308 RetrieveGattConnectedDevicesWithDiscoveryFilter_NoFilter) { |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 EXPECT_EQ(0, error_callback_count_); | 1427 EXPECT_EQ(0, error_callback_count_); |
1428 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1428 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1429 EXPECT_EQ(3U, update_sessions_.size()); | 1429 EXPECT_EQ(3U, update_sessions_.size()); |
1430 | 1430 |
1431 // Notifications should be getting sent regularly now. | 1431 // Notifications should be getting sent regularly now. |
1432 base::RunLoop().Run(); | 1432 base::RunLoop().Run(); |
1433 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); | 1433 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); |
1434 | 1434 |
1435 // Stop one of the sessions. The session should become inactive but the | 1435 // Stop one of the sessions. The session should become inactive but the |
1436 // characteristic should still be notifying. | 1436 // characteristic should still be notifying. |
1437 BluetoothGattNotifySession* session = update_sessions_[0]; | 1437 BluetoothGattNotifySession* session = update_sessions_[0].get(); |
1438 EXPECT_TRUE(session->IsActive()); | 1438 EXPECT_TRUE(session->IsActive()); |
1439 session->Stop(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, | 1439 session->Stop(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
1440 base::Unretained(this))); | 1440 base::Unretained(this))); |
1441 | 1441 |
1442 // Run message loop to stop the notify session. | 1442 // Run message loop to stop the notify session. |
1443 base::RunLoop().Run(); | 1443 base::RunLoop().Run(); |
1444 | 1444 |
1445 EXPECT_EQ(4, success_callback_count_); | 1445 EXPECT_EQ(4, success_callback_count_); |
1446 EXPECT_EQ(0, error_callback_count_); | 1446 EXPECT_EQ(0, error_callback_count_); |
1447 EXPECT_FALSE(session->IsActive()); | 1447 EXPECT_FALSE(session->IsActive()); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 | 1637 |
1638 EXPECT_EQ(1, success_callback_count_); | 1638 EXPECT_EQ(1, success_callback_count_); |
1639 EXPECT_EQ(0, error_callback_count_); | 1639 EXPECT_EQ(0, error_callback_count_); |
1640 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1640 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
1641 EXPECT_TRUE(characteristic->IsNotifying()); | 1641 EXPECT_TRUE(characteristic->IsNotifying()); |
1642 EXPECT_EQ(1U, update_sessions_.size()); | 1642 EXPECT_EQ(1U, update_sessions_.size()); |
1643 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1643 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
1644 } | 1644 } |
1645 | 1645 |
1646 } // namespace bluez | 1646 } // namespace bluez |
OLD | NEW |