| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_vector.h" | 5 #include "base/memory/scoped_vector.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| (...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 base::MessageLoop::current()->Run(); | 1083 base::MessageLoop::current()->Run(); |
| 1084 EXPECT_EQ(0, observer.gatt_service_changed_count_); | 1084 EXPECT_EQ(0, observer.gatt_service_changed_count_); |
| 1085 EXPECT_EQ(1, observer.gatt_discovery_complete_count_); | 1085 EXPECT_EQ(1, observer.gatt_discovery_complete_count_); |
| 1086 | 1086 |
| 1087 // Only the Heart Rate Measurement characteristic has a descriptor. | 1087 // Only the Heart Rate Measurement characteristic has a descriptor. |
| 1088 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( | 1088 BluetoothGattCharacteristic* characteristic = service->GetCharacteristic( |
| 1089 fake_bluetooth_gatt_characteristic_client_-> | 1089 fake_bluetooth_gatt_characteristic_client_-> |
| 1090 GetHeartRateMeasurementPath().value()); | 1090 GetHeartRateMeasurementPath().value()); |
| 1091 ASSERT_TRUE(characteristic); | 1091 ASSERT_TRUE(characteristic); |
| 1092 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); | 1092 EXPECT_EQ(1U, characteristic->GetDescriptors().size()); |
| 1093 EXPECT_FALSE(characteristic->IsNotifying()); |
| 1093 | 1094 |
| 1094 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; | 1095 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptors()[0]; |
| 1095 EXPECT_FALSE(descriptor->IsLocal()); | 1096 EXPECT_FALSE(descriptor->IsLocal()); |
| 1096 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), | 1097 EXPECT_EQ(BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid(), |
| 1097 descriptor->GetUUID()); | 1098 descriptor->GetUUID()); |
| 1098 | 1099 |
| 1099 std::vector<uint8> desc_value; | 1100 std::vector<uint8_t> desc_value = {0x00, 0x00}; |
| 1100 desc_value.push_back(1); | |
| 1101 desc_value.push_back(0); | |
| 1102 | 1101 |
| 1103 /* The cached value will be empty until the first read request */ | 1102 /* The cached value will be empty until the first read request */ |
| 1104 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); | 1103 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
| 1105 EXPECT_TRUE(descriptor->GetValue().empty()); | 1104 EXPECT_TRUE(descriptor->GetValue().empty()); |
| 1106 | 1105 |
| 1107 EXPECT_EQ(0, success_callback_count_); | 1106 EXPECT_EQ(0, success_callback_count_); |
| 1108 EXPECT_EQ(0, error_callback_count_); | 1107 EXPECT_EQ(0, error_callback_count_); |
| 1109 EXPECT_TRUE(last_read_value_.empty()); | 1108 EXPECT_TRUE(last_read_value_.empty()); |
| 1110 | 1109 |
| 1111 // Read value. GattDescriptorValueChanged event will be sent after a | 1110 // Read value. GattDescriptorValueChanged event will be sent after a |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1132 base::Unretained(this))); | 1131 base::Unretained(this))); |
| 1133 EXPECT_EQ(1, success_callback_count_); | 1132 EXPECT_EQ(1, success_callback_count_); |
| 1134 EXPECT_EQ(1, error_callback_count_); | 1133 EXPECT_EQ(1, error_callback_count_); |
| 1135 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED, | 1134 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_PERMITTED, |
| 1136 last_service_error_); | 1135 last_service_error_); |
| 1137 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 1136 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
| 1138 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); | 1137 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
| 1139 EXPECT_EQ(0, observer.gatt_service_changed_count_); | 1138 EXPECT_EQ(0, observer.gatt_service_changed_count_); |
| 1140 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_); | 1139 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_); |
| 1141 | 1140 |
| 1142 // Read new value. | 1141 // Read value. The value should remain unchanged. |
| 1143 descriptor->ReadRemoteDescriptor( | 1142 descriptor->ReadRemoteDescriptor( |
| 1144 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, | 1143 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, |
| 1145 base::Unretained(this)), | 1144 base::Unretained(this)), |
| 1146 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, | 1145 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, |
| 1147 base::Unretained(this))); | 1146 base::Unretained(this))); |
| 1148 EXPECT_EQ(2, success_callback_count_); | 1147 EXPECT_EQ(2, success_callback_count_); |
| 1149 EXPECT_EQ(1, error_callback_count_); | 1148 EXPECT_EQ(1, error_callback_count_); |
| 1150 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); | 1149 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
| 1151 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); | 1150 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
| 1152 EXPECT_EQ(0, observer.gatt_service_changed_count_); | 1151 EXPECT_EQ(0, observer.gatt_service_changed_count_); |
| 1152 EXPECT_EQ(1, observer.gatt_descriptor_value_changed_count_); |
| 1153 |
| 1154 // Start notifications on the descriptor's characteristic. The descriptor |
| 1155 // value should change. |
| 1156 characteristic->StartNotifySession( |
| 1157 base::Bind(&BluetoothGattChromeOSTest::NotifySessionCallback, |
| 1158 base::Unretained(this)), |
| 1159 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, |
| 1160 base::Unretained(this))); |
| 1161 base::MessageLoop::current()->Run(); |
| 1162 EXPECT_EQ(3, success_callback_count_); |
| 1163 EXPECT_EQ(1, error_callback_count_); |
| 1164 EXPECT_EQ(1U, update_sessions_.size()); |
| 1165 EXPECT_TRUE(characteristic->IsNotifying()); |
| 1166 |
| 1167 // Read the new descriptor value. We should receive a value updated event. |
| 1168 descriptor->ReadRemoteDescriptor( |
| 1169 base::Bind(&BluetoothGattChromeOSTest::ValueCallback, |
| 1170 base::Unretained(this)), |
| 1171 base::Bind(&BluetoothGattChromeOSTest::ServiceErrorCallback, |
| 1172 base::Unretained(this))); |
| 1173 EXPECT_EQ(4, success_callback_count_); |
| 1174 EXPECT_EQ(1, error_callback_count_); |
| 1175 EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); |
| 1176 EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); |
| 1177 EXPECT_EQ(0, observer.gatt_service_changed_count_); |
| 1153 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count_); | 1178 EXPECT_EQ(2, observer.gatt_descriptor_value_changed_count_); |
| 1154 } | 1179 } |
| 1155 | 1180 |
| 1156 TEST_F(BluetoothGattChromeOSTest, NotifySessions) { | 1181 TEST_F(BluetoothGattChromeOSTest, NotifySessions) { |
| 1157 fake_bluetooth_device_client_->CreateDevice( | 1182 fake_bluetooth_device_client_->CreateDevice( |
| 1158 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 1183 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 1159 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); | 1184 dbus::ObjectPath(FakeBluetoothDeviceClient::kLowEnergyPath)); |
| 1160 BluetoothDevice* device = | 1185 BluetoothDevice* device = |
| 1161 adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress); | 1186 adapter_->GetDevice(FakeBluetoothDeviceClient::kLowEnergyAddress); |
| 1162 ASSERT_TRUE(device); | 1187 ASSERT_TRUE(device); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 | 1438 |
| 1414 EXPECT_EQ(1, success_callback_count_); | 1439 EXPECT_EQ(1, success_callback_count_); |
| 1415 EXPECT_EQ(0, error_callback_count_); | 1440 EXPECT_EQ(0, error_callback_count_); |
| 1416 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); | 1441 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count_); |
| 1417 EXPECT_TRUE(characteristic->IsNotifying()); | 1442 EXPECT_TRUE(characteristic->IsNotifying()); |
| 1418 EXPECT_EQ(1U, update_sessions_.size()); | 1443 EXPECT_EQ(1U, update_sessions_.size()); |
| 1419 EXPECT_TRUE(update_sessions_[0]->IsActive()); | 1444 EXPECT_TRUE(update_sessions_[0]->IsActive()); |
| 1420 } | 1445 } |
| 1421 | 1446 |
| 1422 } // namespace chromeos | 1447 } // namespace chromeos |
| OLD | NEW |