| 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 | 10 |
| (...skipping 241 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 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 EXPECT_EQ(0, error_callback_count_); | 1426 EXPECT_EQ(0, error_callback_count_); |
| 1427 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1427 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
| 1428 EXPECT_EQ(3U, update_sessions_.size()); | 1428 EXPECT_EQ(3U, update_sessions_.size()); |
| 1429 | 1429 |
| 1430 // Notifications should be getting sent regularly now. | 1430 // Notifications should be getting sent regularly now. |
| 1431 base::RunLoop().Run(); | 1431 base::RunLoop().Run(); |
| 1432 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); | 1432 EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); |
| 1433 | 1433 |
| 1434 // Stop one of the sessions. The session should become inactive but the | 1434 // Stop one of the sessions. The session should become inactive but the |
| 1435 // characteristic should still be notifying. | 1435 // characteristic should still be notifying. |
| 1436 BluetoothGattNotifySession* session = update_sessions_[0]; | 1436 BluetoothGattNotifySession* session = update_sessions_[0].get(); |
| 1437 EXPECT_TRUE(session->IsActive()); | 1437 EXPECT_TRUE(session->IsActive()); |
| 1438 session->Stop(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, | 1438 session->Stop(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |
| 1439 base::Unretained(this))); | 1439 base::Unretained(this))); |
| 1440 EXPECT_EQ(4, success_callback_count_); | 1440 EXPECT_EQ(4, success_callback_count_); |
| 1441 EXPECT_EQ(0, error_callback_count_); | 1441 EXPECT_EQ(0, error_callback_count_); |
| 1442 EXPECT_FALSE(session->IsActive()); | 1442 EXPECT_FALSE(session->IsActive()); |
| 1443 EXPECT_EQ(characteristic->GetIdentifier(), | 1443 EXPECT_EQ(characteristic->GetIdentifier(), |
| 1444 session->GetCharacteristicIdentifier()); | 1444 session->GetCharacteristicIdentifier()); |
| 1445 EXPECT_TRUE(characteristic->IsNotifying()); | 1445 EXPECT_TRUE(characteristic->IsNotifying()); |
| 1446 | 1446 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 | 1617 |
| 1618 EXPECT_EQ(1, success_callback_count_); | 1618 EXPECT_EQ(1, success_callback_count_); |
| 1619 EXPECT_EQ(0, error_callback_count_); | 1619 EXPECT_EQ(0, error_callback_count_); |
| 1620 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 1620 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
| 1621 EXPECT_TRUE(characteristic->IsNotifying()); | 1621 EXPECT_TRUE(characteristic->IsNotifying()); |
| 1622 EXPECT_EQ(1U, update_sessions_.size()); | 1622 EXPECT_EQ(1U, update_sessions_.size()); |
| 1623 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1623 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
| 1624 } | 1624 } |
| 1625 | 1625 |
| 1626 } // namespace bluez | 1626 } // namespace bluez |
| OLD | NEW |