Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc

Issue 2728623004: Fix getting notified twice after subscribe to notifications and call readValue (Closed)
Patch Set: address comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <vector>
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 characteristic->WriteRemoteCharacteristic( 1094 characteristic->WriteRemoteCharacteristic(
1095 invalid_write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback, 1095 invalid_write_value, base::Bind(&BluetoothGattBlueZTest::SuccessCallback,
1096 base::Unretained(this)), 1096 base::Unretained(this)),
1097 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, 1097 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1098 base::Unretained(this))); 1098 base::Unretained(this)));
1099 EXPECT_EQ(1, success_callback_count_); 1099 EXPECT_EQ(1, success_callback_count_);
1100 EXPECT_EQ(4, error_callback_count_); 1100 EXPECT_EQ(4, error_callback_count_);
1101 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, last_service_error_); 1101 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, last_service_error_);
1102 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 1102 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
1103 1103
1104 // Issue a read request. A successful read results in a 1104 // Issue a read request. A successful read results in a
ortuno 2017/03/06 09:15:37 Fix comment.
juncai 2017/03/08 23:20:39 Done.
1105 // CharacteristicValueChanged notification. 1105 // CharacteristicValueChanged notification.
1106 characteristic = service->GetCharacteristic( 1106 characteristic = service->GetCharacteristic(
1107 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() 1107 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
1108 .value()); 1108 .value());
1109 ASSERT_TRUE(characteristic); 1109 ASSERT_TRUE(characteristic);
1110 EXPECT_EQ( 1110 EXPECT_EQ(
1111 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() 1111 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
1112 .value(), 1112 .value(),
1113 characteristic->GetIdentifier()); 1113 characteristic->GetIdentifier());
1114 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); 1114 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID());
1115 characteristic->ReadRemoteCharacteristic( 1115 characteristic->ReadRemoteCharacteristic(
1116 base::Bind(&BluetoothGattBlueZTest::ValueCallback, 1116 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
1117 base::Unretained(this)), 1117 base::Unretained(this)),
1118 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, 1118 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1119 base::Unretained(this))); 1119 base::Unretained(this)));
1120 EXPECT_EQ(2, success_callback_count_); 1120 EXPECT_EQ(2, success_callback_count_);
1121 EXPECT_EQ(4, error_callback_count_); 1121 EXPECT_EQ(4, error_callback_count_);
1122 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1122 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
1123 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); 1123 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_));
1124 1124
1125 // Test long-running actions. 1125 // Test long-running actions.
1126 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(1); 1126 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(1);
1127 characteristic = service->GetCharacteristic( 1127 characteristic = service->GetCharacteristic(
1128 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() 1128 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
1129 .value()); 1129 .value());
1130 ASSERT_TRUE(characteristic); 1130 ASSERT_TRUE(characteristic);
1131 EXPECT_EQ( 1131 EXPECT_EQ(
1132 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath() 1132 fake_bluetooth_gatt_characteristic_client_->GetBodySensorLocationPath()
1133 .value(), 1133 .value(),
1134 characteristic->GetIdentifier()); 1134 characteristic->GetIdentifier());
1135 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID()); 1135 EXPECT_EQ(kBodySensorLocationUUID, characteristic->GetUUID());
1136 characteristic->ReadRemoteCharacteristic( 1136 characteristic->ReadRemoteCharacteristic(
1137 base::Bind(&BluetoothGattBlueZTest::ValueCallback, 1137 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
1138 base::Unretained(this)), 1138 base::Unretained(this)),
1139 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, 1139 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1140 base::Unretained(this))); 1140 base::Unretained(this)));
1141 1141
1142 // Callback counts shouldn't change, this one will be delayed until after 1142 // Callback counts shouldn't change, this one will be delayed until after
1143 // tne next one. 1143 // tne next one.
1144 EXPECT_EQ(2, success_callback_count_); 1144 EXPECT_EQ(2, success_callback_count_);
1145 EXPECT_EQ(4, error_callback_count_); 1145 EXPECT_EQ(4, error_callback_count_);
1146 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); 1146 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
1147 1147
1148 // Next read should error because IN_PROGRESS 1148 // Next read should error because IN_PROGRESS
1149 characteristic->ReadRemoteCharacteristic( 1149 characteristic->ReadRemoteCharacteristic(
1150 base::Bind(&BluetoothGattBlueZTest::ValueCallback, 1150 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
1151 base::Unretained(this)), 1151 base::Unretained(this)),
1152 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, 1152 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1153 base::Unretained(this))); 1153 base::Unretained(this)));
1154 EXPECT_EQ(5, error_callback_count_); 1154 EXPECT_EQ(5, error_callback_count_);
1155 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS, 1155 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS,
1156 last_service_error_); 1156 last_service_error_);
1157 1157
1158 // But previous call finished. 1158 // But previous call finished.
1159 EXPECT_EQ(3, success_callback_count_); 1159 EXPECT_EQ(3, success_callback_count_);
1160 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); 1160 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
ortuno 2017/03/06 09:15:37 Please spend some time trying to understand tests
juncai 2017/03/08 23:20:39 Done.
1161 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_)); 1161 EXPECT_TRUE(ValuesEqual(characteristic->GetValue(), last_read_value_));
1162 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(0); 1162 fake_bluetooth_gatt_characteristic_client_->SetExtraProcessing(0);
1163 1163
1164 // Test unauthorized actions. 1164 // Test unauthorized actions.
1165 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(false); 1165 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(false);
1166 characteristic->ReadRemoteCharacteristic( 1166 characteristic->ReadRemoteCharacteristic(
1167 base::Bind(&BluetoothGattBlueZTest::ValueCallback, 1167 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
1168 base::Unretained(this)), 1168 base::Unretained(this)),
1169 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, 1169 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1170 base::Unretained(this))); 1170 base::Unretained(this)));
1171 EXPECT_EQ(3, success_callback_count_); 1171 EXPECT_EQ(3, success_callback_count_);
1172 EXPECT_EQ(6, error_callback_count_); 1172 EXPECT_EQ(6, error_callback_count_);
1173 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_AUTHORIZED, 1173 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_AUTHORIZED,
1174 last_service_error_); 1174 last_service_error_);
1175 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); 1175 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1176 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(true); 1176 fake_bluetooth_gatt_characteristic_client_->SetAuthorized(true);
1177 1177
1178 // Test unauthenticated / needs login. 1178 // Test unauthenticated / needs login.
1179 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(false); 1179 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(false);
1180 characteristic->ReadRemoteCharacteristic( 1180 characteristic->ReadRemoteCharacteristic(
1181 base::Bind(&BluetoothGattBlueZTest::ValueCallback, 1181 base::Bind(&BluetoothGattBlueZTest::ValueCallback,
1182 base::Unretained(this)), 1182 base::Unretained(this)),
1183 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback, 1183 base::Bind(&BluetoothGattBlueZTest::ServiceErrorCallback,
1184 base::Unretained(this))); 1184 base::Unretained(this)));
1185 EXPECT_EQ(3, success_callback_count_); 1185 EXPECT_EQ(3, success_callback_count_);
1186 EXPECT_EQ(7, error_callback_count_); 1186 EXPECT_EQ(7, error_callback_count_);
1187 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_PAIRED, 1187 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_NOT_PAIRED,
1188 last_service_error_); 1188 last_service_error_);
1189 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); 1189 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
1190 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(true); 1190 fake_bluetooth_gatt_characteristic_client_->SetAuthenticated(true);
1191 } 1191 }
1192 1192
1193 TEST_F(BluetoothGattBlueZTest, GattCharacteristicProperties) { 1193 TEST_F(BluetoothGattBlueZTest, GattCharacteristicProperties) {
1194 fake_bluetooth_device_client_->CreateDevice( 1194 fake_bluetooth_device_client_->CreateDevice(
1195 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 1195 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
1196 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath)); 1196 dbus::ObjectPath(bluez::FakeBluetoothDeviceClient::kLowEnergyPath));
1197 BluetoothDevice* device = 1197 BluetoothDevice* device =
1198 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress); 1198 adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
1199 ASSERT_TRUE(device); 1199 ASSERT_TRUE(device);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698