| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   116   void TearDown() override { |   116   void TearDown() override { | 
|   117     adapter_ = NULL; |   117     adapter_ = NULL; | 
|   118     update_sessions_.clear(); |   118     update_sessions_.clear(); | 
|   119     gatt_conn_.reset(); |   119     gatt_conn_.reset(); | 
|   120     bluez::BluezDBusManager::Shutdown(); |   120     bluez::BluezDBusManager::Shutdown(); | 
|   121   } |   121   } | 
|   122  |   122  | 
|   123   void GetAdapter() { |   123   void GetAdapter() { | 
|   124     device::BluetoothAdapterFactory::GetAdapter(base::Bind( |   124     device::BluetoothAdapterFactory::GetAdapter(base::Bind( | 
|   125         &BluetoothGattBlueZTest::AdapterCallback, base::Unretained(this))); |   125         &BluetoothGattBlueZTest::AdapterCallback, base::Unretained(this))); | 
|   126     base::MessageLoop::current()->Run(); |   126     base::RunLoop().Run(); | 
|   127     ASSERT_TRUE(adapter_.get() != NULL); |   127     ASSERT_TRUE(adapter_.get() != NULL); | 
|   128     ASSERT_TRUE(adapter_->IsInitialized()); |   128     ASSERT_TRUE(adapter_->IsInitialized()); | 
|   129     ASSERT_TRUE(adapter_->IsPresent()); |   129     ASSERT_TRUE(adapter_->IsPresent()); | 
|   130   } |   130   } | 
|   131  |   131  | 
|   132   void BatteryServiceShouldBeComplete(BluetoothDevice* device) { |   132   void BatteryServiceShouldBeComplete(BluetoothDevice* device) { | 
|   133     ASSERT_TRUE(device); |   133     ASSERT_TRUE(device); | 
|   134     ASSERT_GE(device->GetGattServices().size(), 1u); |   134     ASSERT_GE(device->GetGattServices().size(), 1u); | 
|   135  |   135  | 
|   136     BluetoothRemoteGattService* service = device->GetGattService( |   136     BluetoothRemoteGattService* service = device->GetGattService( | 
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   480           dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |   480           dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 
|   481  |   481  | 
|   482   ASSERT_TRUE(device); |   482   ASSERT_TRUE(device); | 
|   483  |   483  | 
|   484   TestBluetoothAdapterObserver observer(adapter_); |   484   TestBluetoothAdapterObserver observer(adapter_); | 
|   485  |   485  | 
|   486   // Expose the fake Heart Rate Service. |   486   // Expose the fake Heart Rate Service. | 
|   487   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |   487   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 
|   488       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |   488       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 
|   489   // Run the message loop so that the characteristics/descriptors appear. |   489   // Run the message loop so that the characteristics/descriptors appear. | 
|   490   base::MessageLoop::current()->Run(); |   490   base::RunLoop().Run(); | 
|   491   properties->services_resolved.ReplaceValue(true); |   491   properties->services_resolved.ReplaceValue(true); | 
|   492  |   492  | 
|   493   EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |   493   EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | 
|   494   EXPECT_EQ(1u, device->GetGattServices().size()); |   494   EXPECT_EQ(1u, device->GetGattServices().size()); | 
|   495   EXPECT_EQ(device, observer.last_device()); |   495   EXPECT_EQ(device, observer.last_device()); | 
|   496   EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, |   496   EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress, | 
|   497             observer.last_device_address()); |   497             observer.last_device_address()); | 
|   498  |   498  | 
|   499   // Disconnect from the device: |   499   // Disconnect from the device: | 
|   500   device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |   500   device->Disconnect(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|   515                  base::Unretained(this)), |   515                  base::Unretained(this)), | 
|   516       base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback, |   516       base::Bind(&BluetoothGattBlueZTest::ConnectErrorCallback, | 
|   517                  base::Unretained(this))); |   517                  base::Unretained(this))); | 
|   518   properties->connected.ReplaceValue(true); |   518   properties->connected.ReplaceValue(true); | 
|   519   EXPECT_TRUE(device->IsConnected()); |   519   EXPECT_TRUE(device->IsConnected()); | 
|   520  |   520  | 
|   521   // Verify that service discovery can be done again: |   521   // Verify that service discovery can be done again: | 
|   522   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |   522   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 
|   523       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |   523       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 
|   524   // Run the message loop so that the characteristics/descriptors appear. |   524   // Run the message loop so that the characteristics/descriptors appear. | 
|   525   base::MessageLoop::current()->Run(); |   525   base::RunLoop().Run(); | 
|   526   properties->services_resolved.ReplaceValue(true); |   526   properties->services_resolved.ReplaceValue(true); | 
|   527  |   527  | 
|   528   EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |   528   EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | 
|   529   EXPECT_EQ(1u, device->GetGattServices().size()); |   529   EXPECT_EQ(1u, device->GetGattServices().size()); | 
|   530 } |   530 } | 
|   531  |   531  | 
|   532 TEST_F(BluetoothGattBlueZTest, DiscoverCachedServices) { |   532 TEST_F(BluetoothGattBlueZTest, DiscoverCachedServices) { | 
|   533   // This unit test tests that all remote GATT objects are created for D-Bus |   533   // This unit test tests that all remote GATT objects are created for D-Bus | 
|   534   // objects that were already exposed and all relevant events have been |   534   // objects that were already exposed and all relevant events have been | 
|   535   // dispatched. |   535   // dispatched. | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   697       device->GetGattService(observer.last_gatt_service_id()); |   697       device->GetGattService(observer.last_gatt_service_id()); | 
|   698  |   698  | 
|   699   EXPECT_EQ(0, observer.gatt_service_changed_count()); |   699   EXPECT_EQ(0, observer.gatt_service_changed_count()); | 
|   700   EXPECT_EQ(0, observer.gatt_discovery_complete_count()); |   700   EXPECT_EQ(0, observer.gatt_discovery_complete_count()); | 
|   701   EXPECT_EQ(0, observer.gatt_characteristic_added_count()); |   701   EXPECT_EQ(0, observer.gatt_characteristic_added_count()); | 
|   702   EXPECT_EQ(0, observer.gatt_characteristic_removed_count()); |   702   EXPECT_EQ(0, observer.gatt_characteristic_removed_count()); | 
|   703   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |   703   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 
|   704   EXPECT_TRUE(service->GetCharacteristics().empty()); |   704   EXPECT_TRUE(service->GetCharacteristics().empty()); | 
|   705  |   705  | 
|   706   // Run the message loop so that the characteristics appear. |   706   // Run the message loop so that the characteristics appear. | 
|   707   base::MessageLoop::current()->Run(); |   707   base::RunLoop().Run(); | 
|   708  |   708  | 
|   709   // 3 characteristics should appear. Only 1 of the characteristics sends |   709   // 3 characteristics should appear. Only 1 of the characteristics sends | 
|   710   // value changed signals. Service changed should be fired once for |   710   // value changed signals. Service changed should be fired once for | 
|   711   // descriptor added. |   711   // descriptor added. | 
|   712   EXPECT_EQ(0, observer.gatt_service_changed_count()); |   712   EXPECT_EQ(0, observer.gatt_service_changed_count()); | 
|   713   EXPECT_EQ(3, observer.gatt_characteristic_added_count()); |   713   EXPECT_EQ(3, observer.gatt_characteristic_added_count()); | 
|   714   EXPECT_EQ(0, observer.gatt_characteristic_removed_count()); |   714   EXPECT_EQ(0, observer.gatt_characteristic_removed_count()); | 
|   715   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |   715   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 
|   716   EXPECT_EQ(3U, service->GetCharacteristics().size()); |   716   EXPECT_EQ(3U, service->GetCharacteristics().size()); | 
|   717  |   717  | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   763       device->GetGattService(observer.last_gatt_service_id()); |   763       device->GetGattService(observer.last_gatt_service_id()); | 
|   764  |   764  | 
|   765   EXPECT_EQ(0, observer.gatt_service_changed_count()); |   765   EXPECT_EQ(0, observer.gatt_service_changed_count()); | 
|   766   EXPECT_EQ(0, observer.gatt_descriptor_added_count()); |   766   EXPECT_EQ(0, observer.gatt_descriptor_added_count()); | 
|   767   EXPECT_EQ(0, observer.gatt_descriptor_removed_count()); |   767   EXPECT_EQ(0, observer.gatt_descriptor_removed_count()); | 
|   768   EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |   768   EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 
|   769  |   769  | 
|   770   EXPECT_TRUE(service->GetCharacteristics().empty()); |   770   EXPECT_TRUE(service->GetCharacteristics().empty()); | 
|   771  |   771  | 
|   772   // Run the message loop so that the characteristics appear. |   772   // Run the message loop so that the characteristics appear. | 
|   773   base::MessageLoop::current()->Run(); |   773   base::RunLoop().Run(); | 
|   774   EXPECT_EQ(0, observer.gatt_service_changed_count()); |   774   EXPECT_EQ(0, observer.gatt_service_changed_count()); | 
|   775  |   775  | 
|   776   // Only the Heart Rate Measurement characteristic has a descriptor. |   776   // Only the Heart Rate Measurement characteristic has a descriptor. | 
|   777   EXPECT_EQ(1, observer.gatt_descriptor_added_count()); |   777   EXPECT_EQ(1, observer.gatt_descriptor_added_count()); | 
|   778   EXPECT_EQ(0, observer.gatt_descriptor_removed_count()); |   778   EXPECT_EQ(0, observer.gatt_descriptor_removed_count()); | 
|   779   EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |   779   EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 
|   780  |   780  | 
|   781   BluetoothRemoteGattCharacteristic* characteristic = |   781   BluetoothRemoteGattCharacteristic* characteristic = | 
|   782       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ |   782       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ | 
|   783                                      ->GetBodySensorLocationPath() |   783                                      ->GetBodySensorLocationPath() | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   850   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |   850   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 
|   851       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |   851       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 
|   852   ASSERT_EQ(1, observer.gatt_service_added_count()); |   852   ASSERT_EQ(1, observer.gatt_service_added_count()); | 
|   853  |   853  | 
|   854   BluetoothRemoteGattService* service = |   854   BluetoothRemoteGattService* service = | 
|   855       device->GetGattService(observer.last_gatt_service_id()); |   855       device->GetGattService(observer.last_gatt_service_id()); | 
|   856  |   856  | 
|   857   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |   857   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 
|   858  |   858  | 
|   859   // Run the message loop so that the characteristics appear. |   859   // Run the message loop so that the characteristics appear. | 
|   860   base::MessageLoop::current()->Run(); |   860   base::RunLoop().Run(); | 
|   861  |   861  | 
|   862   // Issue write request to non-writable characteristics. |   862   // Issue write request to non-writable characteristics. | 
|   863   observer.Reset(); |   863   observer.Reset(); | 
|   864  |   864  | 
|   865   std::vector<uint8_t> write_value; |   865   std::vector<uint8_t> write_value; | 
|   866   write_value.push_back(0x01); |   866   write_value.push_back(0x01); | 
|   867   BluetoothRemoteGattCharacteristic* characteristic = |   867   BluetoothRemoteGattCharacteristic* characteristic = | 
|   868       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ |   868       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ | 
|   869                                      ->GetHeartRateMeasurementPath() |   869                                      ->GetHeartRateMeasurementPath() | 
|   870                                      .value()); |   870                                      .value()); | 
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1066   // characteristics. |  1066   // characteristics. | 
|  1067   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |  1067   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 
|  1068       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |  1068       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 
|  1069  |  1069  | 
|  1070   BluetoothRemoteGattService* service = |  1070   BluetoothRemoteGattService* service = | 
|  1071       device->GetGattService(observer.last_gatt_service_id()); |  1071       device->GetGattService(observer.last_gatt_service_id()); | 
|  1072  |  1072  | 
|  1073   EXPECT_TRUE(service->GetCharacteristics().empty()); |  1073   EXPECT_TRUE(service->GetCharacteristics().empty()); | 
|  1074  |  1074  | 
|  1075   // Run the message loop so that the characteristics appear. |  1075   // Run the message loop so that the characteristics appear. | 
|  1076   base::MessageLoop::current()->Run(); |  1076   base::RunLoop().Run(); | 
|  1077  |  1077  | 
|  1078   BluetoothRemoteGattCharacteristic* characteristic = |  1078   BluetoothRemoteGattCharacteristic* characteristic = | 
|  1079       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ |  1079       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ | 
|  1080                                      ->GetBodySensorLocationPath() |  1080                                      ->GetBodySensorLocationPath() | 
|  1081                                      .value()); |  1081                                      .value()); | 
|  1082   EXPECT_EQ(BluetoothRemoteGattCharacteristic::PROPERTY_READ, |  1082   EXPECT_EQ(BluetoothRemoteGattCharacteristic::PROPERTY_READ, | 
|  1083             characteristic->GetProperties()); |  1083             characteristic->GetProperties()); | 
|  1084  |  1084  | 
|  1085   characteristic = service->GetCharacteristic( |  1085   characteristic = service->GetCharacteristic( | 
|  1086       fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath() |  1086       fake_bluetooth_gatt_characteristic_client_->GetHeartRateControlPointPath() | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  1112   ASSERT_EQ(1, observer.gatt_service_added_count()); |  1112   ASSERT_EQ(1, observer.gatt_service_added_count()); | 
|  1113  |  1113  | 
|  1114   BluetoothRemoteGattService* service = |  1114   BluetoothRemoteGattService* service = | 
|  1115       device->GetGattService(observer.last_gatt_service_id()); |  1115       device->GetGattService(observer.last_gatt_service_id()); | 
|  1116  |  1116  | 
|  1117   EXPECT_EQ(0, observer.gatt_service_changed_count()); |  1117   EXPECT_EQ(0, observer.gatt_service_changed_count()); | 
|  1118   EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); |  1118   EXPECT_EQ(0, observer.gatt_descriptor_value_changed_count()); | 
|  1119   EXPECT_TRUE(service->GetCharacteristics().empty()); |  1119   EXPECT_TRUE(service->GetCharacteristics().empty()); | 
|  1120  |  1120  | 
|  1121   // Run the message loop so that the characteristics appear. |  1121   // Run the message loop so that the characteristics appear. | 
|  1122   base::MessageLoop::current()->Run(); |  1122   base::RunLoop().Run(); | 
|  1123   EXPECT_EQ(0, observer.gatt_service_changed_count()); |  1123   EXPECT_EQ(0, observer.gatt_service_changed_count()); | 
|  1124  |  1124  | 
|  1125   // Only the Heart Rate Measurement characteristic has a descriptor. |  1125   // Only the Heart Rate Measurement characteristic has a descriptor. | 
|  1126   BluetoothRemoteGattCharacteristic* characteristic = |  1126   BluetoothRemoteGattCharacteristic* characteristic = | 
|  1127       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ |  1127       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ | 
|  1128                                      ->GetHeartRateMeasurementPath() |  1128                                      ->GetHeartRateMeasurementPath() | 
|  1129                                      .value()); |  1129                                      .value()); | 
|  1130   ASSERT_TRUE(characteristic); |  1130   ASSERT_TRUE(characteristic); | 
|  1131   EXPECT_EQ(1U, characteristic->GetDescriptors().size()); |  1131   EXPECT_EQ(1U, characteristic->GetDescriptors().size()); | 
|  1132   EXPECT_FALSE(characteristic->IsNotifying()); |  1132   EXPECT_FALSE(characteristic->IsNotifying()); | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1190   EXPECT_EQ(0, observer.gatt_service_changed_count()); |  1190   EXPECT_EQ(0, observer.gatt_service_changed_count()); | 
|  1191   EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); |  1191   EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count()); | 
|  1192  |  1192  | 
|  1193   // Start notifications on the descriptor's characteristic. The descriptor |  1193   // Start notifications on the descriptor's characteristic. The descriptor | 
|  1194   // value should change. |  1194   // value should change. | 
|  1195   characteristic->StartNotifySession( |  1195   characteristic->StartNotifySession( | 
|  1196       base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |  1196       base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, | 
|  1197                  base::Unretained(this)), |  1197                  base::Unretained(this)), | 
|  1198       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |  1198       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, | 
|  1199                  base::Unretained(this))); |  1199                  base::Unretained(this))); | 
|  1200   base::MessageLoop::current()->Run(); |  1200   base::RunLoop().Run(); | 
|  1201   EXPECT_EQ(3, success_callback_count_); |  1201   EXPECT_EQ(3, success_callback_count_); | 
|  1202   EXPECT_EQ(1, error_callback_count_); |  1202   EXPECT_EQ(1, error_callback_count_); | 
|  1203   EXPECT_EQ(1U, update_sessions_.size()); |  1203   EXPECT_EQ(1U, update_sessions_.size()); | 
|  1204   EXPECT_TRUE(characteristic->IsNotifying()); |  1204   EXPECT_TRUE(characteristic->IsNotifying()); | 
|  1205  |  1205  | 
|  1206   // Read the new descriptor value. We should receive a value updated event. |  1206   // Read the new descriptor value. We should receive a value updated event. | 
|  1207   descriptor->ReadRemoteDescriptor( |  1207   descriptor->ReadRemoteDescriptor( | 
|  1208       base::Bind(&BluetoothGattBlueZTest::ValueCallback, |  1208       base::Bind(&BluetoothGattBlueZTest::ValueCallback, | 
|  1209                  base::Unretained(this)), |  1209                  base::Unretained(this)), | 
|  1210       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |  1210       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
|  1232   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |  1232   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 
|  1233       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |  1233       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 
|  1234   ASSERT_EQ(1, observer.gatt_service_added_count()); |  1234   ASSERT_EQ(1, observer.gatt_service_added_count()); | 
|  1235  |  1235  | 
|  1236   BluetoothRemoteGattService* service = |  1236   BluetoothRemoteGattService* service = | 
|  1237       device->GetGattService(observer.last_gatt_service_id()); |  1237       device->GetGattService(observer.last_gatt_service_id()); | 
|  1238  |  1238  | 
|  1239   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |  1239   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 
|  1240  |  1240  | 
|  1241   // Run the message loop so that the characteristics appear. |  1241   // Run the message loop so that the characteristics appear. | 
|  1242   base::MessageLoop::current()->Run(); |  1242   base::RunLoop().Run(); | 
|  1243  |  1243  | 
|  1244   BluetoothRemoteGattCharacteristic* characteristic = |  1244   BluetoothRemoteGattCharacteristic* characteristic = | 
|  1245       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ |  1245       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ | 
|  1246                                      ->GetHeartRateMeasurementPath() |  1246                                      ->GetHeartRateMeasurementPath() | 
|  1247                                      .value()); |  1247                                      .value()); | 
|  1248   ASSERT_TRUE(characteristic); |  1248   ASSERT_TRUE(characteristic); | 
|  1249   EXPECT_FALSE(characteristic->IsNotifying()); |  1249   EXPECT_FALSE(characteristic->IsNotifying()); | 
|  1250   EXPECT_TRUE(update_sessions_.empty()); |  1250   EXPECT_TRUE(update_sessions_.empty()); | 
|  1251  |  1251  | 
|  1252   // Request to start notifications. |  1252   // Request to start notifications. | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|  1275       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |  1275       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, | 
|  1276                  base::Unretained(this))); |  1276                  base::Unretained(this))); | 
|  1277   EXPECT_EQ(0, success_callback_count_); |  1277   EXPECT_EQ(0, success_callback_count_); | 
|  1278   EXPECT_EQ(0, error_callback_count_); |  1278   EXPECT_EQ(0, error_callback_count_); | 
|  1279   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |  1279   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 
|  1280   EXPECT_TRUE(update_sessions_.empty()); |  1280   EXPECT_TRUE(update_sessions_.empty()); | 
|  1281   EXPECT_TRUE(characteristic->IsNotifying()); |  1281   EXPECT_TRUE(characteristic->IsNotifying()); | 
|  1282  |  1282  | 
|  1283   // Run the main loop. The initial call should complete. The queued call should |  1283   // Run the main loop. The initial call should complete. The queued call should | 
|  1284   // succeed immediately. |  1284   // succeed immediately. | 
|  1285   base::MessageLoop::current()->Run(); |  1285   base::RunLoop().Run(); | 
|  1286  |  1286  | 
|  1287   EXPECT_EQ(3, success_callback_count_); |  1287   EXPECT_EQ(3, success_callback_count_); | 
|  1288   EXPECT_EQ(0, error_callback_count_); |  1288   EXPECT_EQ(0, error_callback_count_); | 
|  1289   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |  1289   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 
|  1290   EXPECT_EQ(3U, update_sessions_.size()); |  1290   EXPECT_EQ(3U, update_sessions_.size()); | 
|  1291  |  1291  | 
|  1292   // Notifications should be getting sent regularly now. |  1292   // Notifications should be getting sent regularly now. | 
|  1293   base::MessageLoop::current()->Run(); |  1293   base::RunLoop().Run(); | 
|  1294   EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); |  1294   EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); | 
|  1295  |  1295  | 
|  1296   // Stop one of the sessions. The session should become inactive but the |  1296   // Stop one of the sessions. The session should become inactive but the | 
|  1297   // characteristic should still be notifying. |  1297   // characteristic should still be notifying. | 
|  1298   BluetoothGattNotifySession* session = update_sessions_[0]; |  1298   BluetoothGattNotifySession* session = update_sessions_[0]; | 
|  1299   EXPECT_TRUE(session->IsActive()); |  1299   EXPECT_TRUE(session->IsActive()); | 
|  1300   session->Stop(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, |  1300   session->Stop(base::Bind(&BluetoothGattBlueZTest::SuccessCallback, | 
|  1301                            base::Unretained(this))); |  1301                            base::Unretained(this))); | 
|  1302   EXPECT_EQ(4, success_callback_count_); |  1302   EXPECT_EQ(4, success_callback_count_); | 
|  1303   EXPECT_EQ(0, error_callback_count_); |  1303   EXPECT_EQ(0, error_callback_count_); | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  1327                  base::Unretained(this)), |  1327                  base::Unretained(this)), | 
|  1328       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |  1328       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, | 
|  1329                  base::Unretained(this))); |  1329                  base::Unretained(this))); | 
|  1330   EXPECT_EQ(0, success_callback_count_); |  1330   EXPECT_EQ(0, success_callback_count_); | 
|  1331   EXPECT_EQ(0, error_callback_count_); |  1331   EXPECT_EQ(0, error_callback_count_); | 
|  1332   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |  1332   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 
|  1333   EXPECT_TRUE(update_sessions_.empty()); |  1333   EXPECT_TRUE(update_sessions_.empty()); | 
|  1334   EXPECT_TRUE(characteristic->IsNotifying()); |  1334   EXPECT_TRUE(characteristic->IsNotifying()); | 
|  1335  |  1335  | 
|  1336   // Run the message loop. Notifications should begin. |  1336   // Run the message loop. Notifications should begin. | 
|  1337   base::MessageLoop::current()->Run(); |  1337   base::RunLoop().Run(); | 
|  1338  |  1338  | 
|  1339   EXPECT_EQ(1, success_callback_count_); |  1339   EXPECT_EQ(1, success_callback_count_); | 
|  1340   EXPECT_EQ(0, error_callback_count_); |  1340   EXPECT_EQ(0, error_callback_count_); | 
|  1341   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |  1341   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 
|  1342   EXPECT_EQ(1U, update_sessions_.size()); |  1342   EXPECT_EQ(1U, update_sessions_.size()); | 
|  1343   EXPECT_TRUE(update_sessions_[0]->IsActive()); |  1343   EXPECT_TRUE(update_sessions_[0]->IsActive()); | 
|  1344   EXPECT_TRUE(characteristic->IsNotifying()); |  1344   EXPECT_TRUE(characteristic->IsNotifying()); | 
|  1345  |  1345  | 
|  1346   // Check that notifications are happening. |  1346   // Check that notifications are happening. | 
|  1347   base::MessageLoop::current()->Run(); |  1347   base::RunLoop().Run(); | 
|  1348   EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); |  1348   EXPECT_GT(observer.gatt_characteristic_value_changed_count(), 1); | 
|  1349  |  1349  | 
|  1350   // Request another session. This should return immediately. |  1350   // Request another session. This should return immediately. | 
|  1351   characteristic->StartNotifySession( |  1351   characteristic->StartNotifySession( | 
|  1352       base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, |  1352       base::Bind(&BluetoothGattBlueZTest::NotifySessionCallback, | 
|  1353                  base::Unretained(this)), |  1353                  base::Unretained(this)), | 
|  1354       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |  1354       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, | 
|  1355                  base::Unretained(this))); |  1355                  base::Unretained(this))); | 
|  1356   EXPECT_EQ(2, success_callback_count_); |  1356   EXPECT_EQ(2, success_callback_count_); | 
|  1357   EXPECT_EQ(0, error_callback_count_); |  1357   EXPECT_EQ(0, error_callback_count_); | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  1382   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( |  1382   fake_bluetooth_gatt_service_client_->ExposeHeartRateService( | 
|  1383       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); |  1383       dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); | 
|  1384   ASSERT_EQ(1, observer.gatt_service_added_count()); |  1384   ASSERT_EQ(1, observer.gatt_service_added_count()); | 
|  1385  |  1385  | 
|  1386   BluetoothRemoteGattService* service = |  1386   BluetoothRemoteGattService* service = | 
|  1387       device->GetGattService(observer.last_gatt_service_id()); |  1387       device->GetGattService(observer.last_gatt_service_id()); | 
|  1388  |  1388  | 
|  1389   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |  1389   EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 
|  1390  |  1390  | 
|  1391   // Run the message loop so that the characteristics appear. |  1391   // Run the message loop so that the characteristics appear. | 
|  1392   base::MessageLoop::current()->Run(); |  1392   base::RunLoop().Run(); | 
|  1393  |  1393  | 
|  1394   BluetoothRemoteGattCharacteristic* characteristic = |  1394   BluetoothRemoteGattCharacteristic* characteristic = | 
|  1395       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ |  1395       service->GetCharacteristic(fake_bluetooth_gatt_characteristic_client_ | 
|  1396                                      ->GetHeartRateMeasurementPath() |  1396                                      ->GetHeartRateMeasurementPath() | 
|  1397                                      .value()); |  1397                                      .value()); | 
|  1398   ASSERT_TRUE(characteristic); |  1398   ASSERT_TRUE(characteristic); | 
|  1399   EXPECT_FALSE(characteristic->IsNotifying()); |  1399   EXPECT_FALSE(characteristic->IsNotifying()); | 
|  1400   EXPECT_TRUE(update_sessions_.empty()); |  1400   EXPECT_TRUE(update_sessions_.empty()); | 
|  1401  |  1401  | 
|  1402   // Send several requests to start notifications. |  1402   // Send several requests to start notifications. | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
|  1424   // The operation still hasn't completed but we should have received the first |  1424   // The operation still hasn't completed but we should have received the first | 
|  1425   // notification. |  1425   // notification. | 
|  1426   EXPECT_EQ(0, success_callback_count_); |  1426   EXPECT_EQ(0, success_callback_count_); | 
|  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_TRUE(characteristic->IsNotifying()); |  1429   EXPECT_TRUE(characteristic->IsNotifying()); | 
|  1430   EXPECT_TRUE(update_sessions_.empty()); |  1430   EXPECT_TRUE(update_sessions_.empty()); | 
|  1431  |  1431  | 
|  1432   // Run the main loop. The initial call should complete. The queued calls |  1432   // Run the main loop. The initial call should complete. The queued calls | 
|  1433   // should succeed immediately. |  1433   // should succeed immediately. | 
|  1434   base::MessageLoop::current()->Run(); |  1434   base::RunLoop().Run(); | 
|  1435  |  1435  | 
|  1436   EXPECT_EQ(4, success_callback_count_); |  1436   EXPECT_EQ(4, success_callback_count_); | 
|  1437   EXPECT_EQ(0, error_callback_count_); |  1437   EXPECT_EQ(0, error_callback_count_); | 
|  1438   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |  1438   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 
|  1439   EXPECT_TRUE(characteristic->IsNotifying()); |  1439   EXPECT_TRUE(characteristic->IsNotifying()); | 
|  1440   EXPECT_EQ(4U, update_sessions_.size()); |  1440   EXPECT_EQ(4U, update_sessions_.size()); | 
|  1441  |  1441  | 
|  1442   for (int i = 0; i < 4; i++) |  1442   for (int i = 0; i < 4; i++) | 
|  1443     EXPECT_TRUE(update_sessions_[0]->IsActive()); |  1443     EXPECT_TRUE(update_sessions_[0]->IsActive()); | 
|  1444  |  1444  | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  1468                  base::Unretained(this)), |  1468                  base::Unretained(this)), | 
|  1469       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, |  1469       base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, | 
|  1470                  base::Unretained(this))); |  1470                  base::Unretained(this))); | 
|  1471  |  1471  | 
|  1472   EXPECT_EQ(0, success_callback_count_); |  1472   EXPECT_EQ(0, success_callback_count_); | 
|  1473   EXPECT_EQ(0, error_callback_count_); |  1473   EXPECT_EQ(0, error_callback_count_); | 
|  1474   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |  1474   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 
|  1475   EXPECT_TRUE(characteristic->IsNotifying()); |  1475   EXPECT_TRUE(characteristic->IsNotifying()); | 
|  1476   EXPECT_TRUE(update_sessions_.empty()); |  1476   EXPECT_TRUE(update_sessions_.empty()); | 
|  1477  |  1477  | 
|  1478   base::MessageLoop::current()->Run(); |  1478   base::RunLoop().Run(); | 
|  1479  |  1479  | 
|  1480   EXPECT_EQ(1, success_callback_count_); |  1480   EXPECT_EQ(1, success_callback_count_); | 
|  1481   EXPECT_EQ(0, error_callback_count_); |  1481   EXPECT_EQ(0, error_callback_count_); | 
|  1482   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |  1482   EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 
|  1483   EXPECT_TRUE(characteristic->IsNotifying()); |  1483   EXPECT_TRUE(characteristic->IsNotifying()); | 
|  1484   EXPECT_EQ(1U, update_sessions_.size()); |  1484   EXPECT_EQ(1U, update_sessions_.size()); | 
|  1485   EXPECT_TRUE(update_sessions_[0]->IsActive()); |  1485   EXPECT_TRUE(update_sessions_[0]->IsActive()); | 
|  1486 } |  1486 } | 
|  1487  |  1487  | 
|  1488 }  // namespace bluez |  1488 }  // namespace bluez | 
| OLD | NEW |