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

Side by Side Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 1380883003: bluetooth: Refactor BluetoothTest member names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt-hold-connections-
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "device/bluetooth/bluetooth_device.h" 5 #include "device/bluetooth/bluetooth_device.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 #if defined(OS_ANDROID) 115 #if defined(OS_ANDROID)
116 // Basic CreateGattConnection test. 116 // Basic CreateGattConnection test.
117 TEST_F(BluetoothTest, CreateGattConnection) { 117 TEST_F(BluetoothTest, CreateGattConnection) {
118 InitWithFakeAdapter(); 118 InitWithFakeAdapter();
119 StartDiscoverySession(); 119 StartDiscoverySession();
120 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 120 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
121 121
122 ResetEventCounts(); 122 ResetEventCounts();
123 device->CreateGattConnection(GetGattConnectionCallback(), 123 device->CreateGattConnection(GetGattConnectionCallback(),
124 GetConnectErrorCallback()); 124 GetConnectErrorCallback());
125 CompleteGattConnection(device); 125 SimulateGattConnection(device);
126 EXPECT_EQ(1, callback_count_); 126 EXPECT_EQ(1, callback_count_);
127 EXPECT_EQ(0, error_callback_count_); 127 EXPECT_EQ(0, error_callback_count_);
128 ASSERT_EQ(1u, gatt_connections_.size()); 128 ASSERT_EQ(1u, gatt_connections_.size());
129 EXPECT_TRUE(device->IsGattConnected()); 129 EXPECT_TRUE(device->IsGattConnected());
130 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); 130 EXPECT_TRUE(gatt_connections_[0]->IsConnected());
131 } 131 }
132 #endif // defined(OS_ANDROID) 132 #endif // defined(OS_ANDROID)
133 133
134 #if defined(OS_ANDROID) 134 #if defined(OS_ANDROID)
135 // Creates BluetoothGattConnection instances and tests that the interface 135 // Creates BluetoothGattConnection instances and tests that the interface
136 // functions even when some Disconnect and the BluetoothDevice is destroyed. 136 // functions even when some Disconnect and the BluetoothDevice is destroyed.
137 TEST_F(BluetoothTest, BluetoothGattConnection) { 137 TEST_F(BluetoothTest, BluetoothGattConnection) {
138 InitWithFakeAdapter(); 138 InitWithFakeAdapter();
139 StartDiscoverySession(); 139 StartDiscoverySession();
140 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 140 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
141 std::string device_address = device->GetAddress(); 141 std::string device_address = device->GetAddress();
142 142
143 // CreateGattConnection 143 // CreateGattConnection
144 ResetEventCounts(); 144 ResetEventCounts();
145 device->CreateGattConnection(GetGattConnectionCallback(), 145 device->CreateGattConnection(GetGattConnectionCallback(),
146 GetConnectErrorCallback()); 146 GetConnectErrorCallback());
147 EXPECT_EQ(1, gatt_connection_attempt_count_); 147 EXPECT_EQ(1, gatt_connection_attempts_);
148 CompleteGattConnection(device); 148 SimulateGattConnection(device);
149 EXPECT_EQ(1, callback_count_); 149 EXPECT_EQ(1, callback_count_);
150 EXPECT_EQ(0, error_callback_count_); 150 EXPECT_EQ(0, error_callback_count_);
151 ASSERT_EQ(1u, gatt_connections_.size()); 151 ASSERT_EQ(1u, gatt_connections_.size());
152 EXPECT_TRUE(device->IsGattConnected()); 152 EXPECT_TRUE(device->IsGattConnected());
153 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); 153 EXPECT_TRUE(gatt_connections_[0]->IsConnected());
154 154
155 // Connect again once already connected. 155 // Connect again once already connected.
156 ResetEventCounts(); 156 ResetEventCounts();
157 device->CreateGattConnection(GetGattConnectionCallback(), 157 device->CreateGattConnection(GetGattConnectionCallback(),
158 GetConnectErrorCallback()); 158 GetConnectErrorCallback());
159 device->CreateGattConnection(GetGattConnectionCallback(), 159 device->CreateGattConnection(GetGattConnectionCallback(),
160 GetConnectErrorCallback()); 160 GetConnectErrorCallback());
161 EXPECT_EQ(0, gatt_connection_attempt_count_); 161 EXPECT_EQ(0, gatt_connection_attempts_);
162 EXPECT_EQ(2, callback_count_); 162 EXPECT_EQ(2, callback_count_);
163 EXPECT_EQ(0, error_callback_count_); 163 EXPECT_EQ(0, error_callback_count_);
164 ASSERT_EQ(3u, gatt_connections_.size()); 164 ASSERT_EQ(3u, gatt_connections_.size());
165 165
166 // Test GetDeviceAddress 166 // Test GetDeviceAddress
167 EXPECT_EQ(device_address, gatt_connections_[0]->GetDeviceAddress()); 167 EXPECT_EQ(device_address, gatt_connections_[0]->GetDeviceAddress());
168 168
169 // Test IsConnected 169 // Test IsConnected
170 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); 170 EXPECT_TRUE(gatt_connections_[0]->IsConnected());
171 EXPECT_TRUE(gatt_connections_[1]->IsConnected()); 171 EXPECT_TRUE(gatt_connections_[1]->IsConnected());
172 EXPECT_TRUE(gatt_connections_[2]->IsConnected()); 172 EXPECT_TRUE(gatt_connections_[2]->IsConnected());
173 173
174 // Disconnect & Delete connection objects. Device stays connected. 174 // Disconnect & Delete connection objects. Device stays connected.
175 gatt_connections_[0]->Disconnect(); // Disconnect first. 175 gatt_connections_[0]->Disconnect(); // Disconnect first.
176 gatt_connections_.pop_back(); // Delete last. 176 gatt_connections_.pop_back(); // Delete last.
177 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); 177 EXPECT_FALSE(gatt_connections_[0]->IsConnected());
178 EXPECT_TRUE(gatt_connections_[1]->IsConnected()); 178 EXPECT_TRUE(gatt_connections_[1]->IsConnected());
179 EXPECT_TRUE(device->IsGattConnected()); 179 EXPECT_TRUE(device->IsGattConnected());
180 EXPECT_EQ(0, gatt_disconnection_attempt_count_); 180 EXPECT_EQ(0, gatt_disconnection_attempts_);
181 181
182 // Delete device, connection objects should all be disconnected. 182 // Delete device, connection objects should all be disconnected.
183 gatt_disconnection_attempt_count_ = 0; 183 gatt_disconnection_attempts_ = 0;
184 DeleteDevice(device); 184 DeleteDevice(device);
185 EXPECT_EQ(1, gatt_disconnection_attempt_count_); 185 EXPECT_EQ(1, gatt_disconnection_attempts_);
186 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); 186 EXPECT_FALSE(gatt_connections_[0]->IsConnected());
187 EXPECT_FALSE(gatt_connections_[1]->IsConnected()); 187 EXPECT_FALSE(gatt_connections_[1]->IsConnected());
188 188
189 // Test GetDeviceAddress after device deleted. 189 // Test GetDeviceAddress after device deleted.
190 EXPECT_EQ(device_address, gatt_connections_[0]->GetDeviceAddress()); 190 EXPECT_EQ(device_address, gatt_connections_[0]->GetDeviceAddress());
191 EXPECT_EQ(device_address, gatt_connections_[1]->GetDeviceAddress()); 191 EXPECT_EQ(device_address, gatt_connections_[1]->GetDeviceAddress());
192 } 192 }
193 #endif // defined(OS_ANDROID) 193 #endif // defined(OS_ANDROID)
194 194
195 #if defined(OS_ANDROID) 195 #if defined(OS_ANDROID)
196 // Calls CreateGattConnection then simulates multiple connections from platform. 196 // Calls CreateGattConnection then simulates multiple connections from platform.
197 TEST_F(BluetoothTest, 197 TEST_F(BluetoothTest,
198 BluetoothGattConnection_ConnectWithMultipleOSConnections) { 198 BluetoothGattConnection_ConnectWithMultipleOSConnections) {
199 InitWithFakeAdapter(); 199 InitWithFakeAdapter();
200 StartDiscoverySession(); 200 StartDiscoverySession();
201 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 201 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
202 202
203 // CreateGattConnection, & multiple connections from platform only invoke 203 // CreateGattConnection, & multiple connections from platform only invoke
204 // callbacks once: 204 // callbacks once:
205 ResetEventCounts(); 205 ResetEventCounts();
206 device->CreateGattConnection(GetGattConnectionCallback(), 206 device->CreateGattConnection(GetGattConnectionCallback(),
207 GetConnectErrorCallback()); 207 GetConnectErrorCallback());
208 CompleteGattConnection(device); 208 SimulateGattConnection(device);
209 CompleteGattConnection(device); 209 SimulateGattConnection(device);
210 EXPECT_EQ(1, gatt_connection_attempt_count_); 210 EXPECT_EQ(1, gatt_connection_attempts_);
211 EXPECT_EQ(1, callback_count_); 211 EXPECT_EQ(1, callback_count_);
212 EXPECT_EQ(0, error_callback_count_); 212 EXPECT_EQ(0, error_callback_count_);
213 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); 213 EXPECT_TRUE(gatt_connections_[0]->IsConnected());
214 214
215 // Become disconnected: 215 // Become disconnected:
216 ResetEventCounts(); 216 ResetEventCounts();
217 CompleteGattDisconnection(device); 217 SimulateGattDisconnection(device);
218 EXPECT_EQ(0, callback_count_); 218 EXPECT_EQ(0, callback_count_);
219 EXPECT_EQ(0, error_callback_count_); 219 EXPECT_EQ(0, error_callback_count_);
220 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); 220 EXPECT_FALSE(gatt_connections_[0]->IsConnected());
221 } 221 }
222 #endif // defined(OS_ANDROID) 222 #endif // defined(OS_ANDROID)
223 223
224 #if defined(OS_ANDROID) 224 #if defined(OS_ANDROID)
225 // Calls CreateGattConnection after already connected. 225 // Calls CreateGattConnection after already connected.
226 TEST_F(BluetoothTest, BluetoothGattConnection_AlreadyConnected) { 226 TEST_F(BluetoothTest, BluetoothGattConnection_AlreadyConnected) {
227 InitWithFakeAdapter(); 227 InitWithFakeAdapter();
228 StartDiscoverySession(); 228 StartDiscoverySession();
229 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 229 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
230 230
231 // Be already connected: 231 // Be already connected:
232 device->CreateGattConnection(GetGattConnectionCallback(), 232 device->CreateGattConnection(GetGattConnectionCallback(),
233 GetConnectErrorCallback()); 233 GetConnectErrorCallback());
234 CompleteGattConnection(device); 234 SimulateGattConnection(device);
235 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); 235 EXPECT_TRUE(gatt_connections_[0]->IsConnected());
236 236
237 // Then CreateGattConnection: 237 // Then CreateGattConnection:
238 ResetEventCounts(); 238 ResetEventCounts();
239 device->CreateGattConnection(GetGattConnectionCallback(), 239 device->CreateGattConnection(GetGattConnectionCallback(),
240 GetConnectErrorCallback()); 240 GetConnectErrorCallback());
241 EXPECT_EQ(0, gatt_connection_attempt_count_); 241 EXPECT_EQ(0, gatt_connection_attempts_);
242 EXPECT_EQ(1, callback_count_); 242 EXPECT_EQ(1, callback_count_);
243 EXPECT_EQ(0, error_callback_count_); 243 EXPECT_EQ(0, error_callback_count_);
244 EXPECT_TRUE(gatt_connections_[1]->IsConnected()); 244 EXPECT_TRUE(gatt_connections_[1]->IsConnected());
245 } 245 }
246 #endif // defined(OS_ANDROID) 246 #endif // defined(OS_ANDROID)
247 247
248 #if defined(OS_ANDROID) 248 #if defined(OS_ANDROID)
249 // Creates BluetoothGattConnection after one exists that has disconnected. 249 // Creates BluetoothGattConnection after one exists that has disconnected.
250 TEST_F(BluetoothTest, 250 TEST_F(BluetoothTest,
251 BluetoothGattConnection_NewConnectionLeavesPreviousDisconnected) { 251 BluetoothGattConnection_NewConnectionLeavesPreviousDisconnected) {
252 InitWithFakeAdapter(); 252 InitWithFakeAdapter();
253 StartDiscoverySession(); 253 StartDiscoverySession();
254 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 254 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
255 255
256 // Create connection: 256 // Create connection:
257 device->CreateGattConnection(GetGattConnectionCallback(), 257 device->CreateGattConnection(GetGattConnectionCallback(),
258 GetConnectErrorCallback()); 258 GetConnectErrorCallback());
259 CompleteGattConnection(device); 259 SimulateGattConnection(device);
260 260
261 // Disconnect connection: 261 // Disconnect connection:
262 gatt_connections_[0]->Disconnect(); 262 gatt_connections_[0]->Disconnect();
263 CompleteGattDisconnection(device); 263 SimulateGattDisconnection(device);
264 264
265 // Create 2nd connection: 265 // Create 2nd connection:
266 device->CreateGattConnection(GetGattConnectionCallback(), 266 device->CreateGattConnection(GetGattConnectionCallback(),
267 GetConnectErrorCallback()); 267 GetConnectErrorCallback());
268 CompleteGattConnection(device); 268 SimulateGattConnection(device);
269 269
270 EXPECT_FALSE(gatt_connections_[0]->IsConnected()) 270 EXPECT_FALSE(gatt_connections_[0]->IsConnected())
271 << "The disconnected connection shouldn't become connected when another " 271 << "The disconnected connection shouldn't become connected when another "
272 "connection is created."; 272 "connection is created.";
273 EXPECT_TRUE(gatt_connections_[1]->IsConnected()); 273 EXPECT_TRUE(gatt_connections_[1]->IsConnected());
274 } 274 }
275 #endif // defined(OS_ANDROID) 275 #endif // defined(OS_ANDROID)
276 276
277 #if defined(OS_ANDROID) 277 #if defined(OS_ANDROID)
278 // Deletes BluetoothGattConnection causing disconnection. 278 // Deletes BluetoothGattConnection causing disconnection.
279 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectWhenObjectsDestroyed) { 279 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectWhenObjectsDestroyed) {
280 InitWithFakeAdapter(); 280 InitWithFakeAdapter();
281 StartDiscoverySession(); 281 StartDiscoverySession();
282 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 282 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
283 283
284 // Create multiple connections and simulate connection complete: 284 // Create multiple connections and simulate connection complete:
285 device->CreateGattConnection(GetGattConnectionCallback(), 285 device->CreateGattConnection(GetGattConnectionCallback(),
286 GetConnectErrorCallback()); 286 GetConnectErrorCallback());
287 device->CreateGattConnection(GetGattConnectionCallback(), 287 device->CreateGattConnection(GetGattConnectionCallback(),
288 GetConnectErrorCallback()); 288 GetConnectErrorCallback());
289 CompleteGattConnection(device); 289 SimulateGattConnection(device);
290 290
291 // Delete all CreateGattConnection objects, observe disconnection: 291 // Delete all CreateGattConnection objects, observe disconnection:
292 ResetEventCounts(); 292 ResetEventCounts();
293 gatt_connections_.clear(); 293 gatt_connections_.clear();
294 EXPECT_EQ(1, gatt_disconnection_attempt_count_); 294 EXPECT_EQ(1, gatt_disconnection_attempts_);
295 } 295 }
296 #endif // defined(OS_ANDROID) 296 #endif // defined(OS_ANDROID)
297 297
298 #if defined(OS_ANDROID) 298 #if defined(OS_ANDROID)
299 // Starts process of disconnecting and then calls BluetoothGattConnection. 299 // Starts process of disconnecting and then calls BluetoothGattConnection.
300 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectInProgress) { 300 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectInProgress) {
301 InitWithFakeAdapter(); 301 InitWithFakeAdapter();
302 StartDiscoverySession(); 302 StartDiscoverySession();
303 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 303 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
304 304
305 // Create multiple connections and simulate connection complete: 305 // Create multiple connections and simulate connection complete:
306 device->CreateGattConnection(GetGattConnectionCallback(), 306 device->CreateGattConnection(GetGattConnectionCallback(),
307 GetConnectErrorCallback()); 307 GetConnectErrorCallback());
308 device->CreateGattConnection(GetGattConnectionCallback(), 308 device->CreateGattConnection(GetGattConnectionCallback(),
309 GetConnectErrorCallback()); 309 GetConnectErrorCallback());
310 CompleteGattConnection(device); 310 SimulateGattConnection(device);
311 311
312 // Disconnect all CreateGattConnection objects & create a new connection. 312 // Disconnect all CreateGattConnection objects & create a new connection.
313 // But, don't yet simulate the device disconnecting: 313 // But, don't yet simulate the device disconnecting:
314 ResetEventCounts(); 314 ResetEventCounts();
315 for (BluetoothGattConnection* connection : gatt_connections_) 315 for (BluetoothGattConnection* connection : gatt_connections_)
316 connection->Disconnect(); 316 connection->Disconnect();
317 EXPECT_EQ(1, gatt_disconnection_attempt_count_); 317 EXPECT_EQ(1, gatt_disconnection_attempts_);
318 318
319 // Create a connection. 319 // Create a connection.
320 device->CreateGattConnection(GetGattConnectionCallback(), 320 device->CreateGattConnection(GetGattConnectionCallback(),
321 GetConnectErrorCallback()); 321 GetConnectErrorCallback());
322 EXPECT_EQ(0, gatt_connection_attempt_count_); // No connection attempt. 322 EXPECT_EQ(0, gatt_connection_attempts_); // No connection attempt.
323 EXPECT_EQ(1, callback_count_); // Device is assumed still connected. 323 EXPECT_EQ(1, callback_count_); // Device is assumed still connected.
324 EXPECT_EQ(0, error_callback_count_); 324 EXPECT_EQ(0, error_callback_count_);
325 EXPECT_FALSE(gatt_connections_.front()->IsConnected()); 325 EXPECT_FALSE(gatt_connections_.front()->IsConnected());
326 EXPECT_TRUE(gatt_connections_.back()->IsConnected()); 326 EXPECT_TRUE(gatt_connections_.back()->IsConnected());
327 327
328 // Actually disconnect: 328 // Actually disconnect:
329 ResetEventCounts(); 329 ResetEventCounts();
330 CompleteGattDisconnection(device); 330 SimulateGattDisconnection(device);
331 EXPECT_EQ(0, callback_count_); 331 EXPECT_EQ(0, callback_count_);
332 EXPECT_EQ(0, error_callback_count_); 332 EXPECT_EQ(0, error_callback_count_);
333 for (BluetoothGattConnection* connection : gatt_connections_) 333 for (BluetoothGattConnection* connection : gatt_connections_)
334 EXPECT_FALSE(connection->IsConnected()); 334 EXPECT_FALSE(connection->IsConnected());
335 } 335 }
336 #endif // defined(OS_ANDROID) 336 #endif // defined(OS_ANDROID)
337 337
338 #if defined(OS_ANDROID) 338 #if defined(OS_ANDROID)
339 // Calls CreateGattConnection but receives notice that the device disconnected 339 // Calls CreateGattConnection but receives notice that the device disconnected
340 // before it ever connects. 340 // before it ever connects.
341 TEST_F(BluetoothTest, BluetoothGattConnection_SimulateDisconnect) { 341 TEST_F(BluetoothTest, BluetoothGattConnection_SimulateDisconnect) {
342 InitWithFakeAdapter(); 342 InitWithFakeAdapter();
343 StartDiscoverySession(); 343 StartDiscoverySession();
344 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 344 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
345 345
346 ResetEventCounts(); 346 ResetEventCounts();
347 device->CreateGattConnection(GetGattConnectionCallback(), 347 device->CreateGattConnection(GetGattConnectionCallback(),
348 GetConnectErrorCallback()); 348 GetConnectErrorCallback());
349 EXPECT_EQ(1, gatt_connection_attempt_count_); 349 EXPECT_EQ(1, gatt_connection_attempts_);
350 CompleteGattDisconnection(device); 350 SimulateGattDisconnection(device);
351 EXPECT_EQ(0, callback_count_); 351 EXPECT_EQ(0, callback_count_);
352 EXPECT_EQ(1, error_callback_count_); 352 EXPECT_EQ(1, error_callback_count_);
353 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); 353 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_);
354 for (BluetoothGattConnection* connection : gatt_connections_) 354 for (BluetoothGattConnection* connection : gatt_connections_)
355 EXPECT_FALSE(connection->IsConnected()); 355 EXPECT_FALSE(connection->IsConnected());
356 } 356 }
357 #endif // defined(OS_ANDROID) 357 #endif // defined(OS_ANDROID)
358 358
359 #if defined(OS_ANDROID) 359 #if defined(OS_ANDROID)
360 // Calls CreateGattConnection & DisconnectGatt, then simulates connection. 360 // Calls CreateGattConnection & DisconnectGatt, then simulates connection.
361 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_SimulateConnect) { 361 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_SimulateConnect) {
362 InitWithFakeAdapter(); 362 InitWithFakeAdapter();
363 StartDiscoverySession(); 363 StartDiscoverySession();
364 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 364 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
365 365
366 ResetEventCounts(); 366 ResetEventCounts();
367 device->CreateGattConnection(GetGattConnectionCallback(), 367 device->CreateGattConnection(GetGattConnectionCallback(),
368 GetConnectErrorCallback()); 368 GetConnectErrorCallback());
369 device->DisconnectGatt(); 369 device->DisconnectGatt();
370 EXPECT_EQ(1, gatt_connection_attempt_count_); 370 EXPECT_EQ(1, gatt_connection_attempts_);
371 EXPECT_EQ(1, gatt_disconnection_attempt_count_); 371 EXPECT_EQ(1, gatt_disconnection_attempts_);
372 CompleteGattConnection(device); 372 SimulateGattConnection(device);
373 EXPECT_EQ(1, callback_count_); 373 EXPECT_EQ(1, callback_count_);
374 EXPECT_EQ(0, error_callback_count_); 374 EXPECT_EQ(0, error_callback_count_);
375 EXPECT_TRUE(gatt_connections_.back()->IsConnected()); 375 EXPECT_TRUE(gatt_connections_.back()->IsConnected());
376 ResetEventCounts(); 376 ResetEventCounts();
377 CompleteGattDisconnection(device); 377 SimulateGattDisconnection(device);
378 EXPECT_EQ(0, callback_count_); 378 EXPECT_EQ(0, callback_count_);
379 EXPECT_EQ(0, error_callback_count_); 379 EXPECT_EQ(0, error_callback_count_);
380 } 380 }
381 #endif // defined(OS_ANDROID) 381 #endif // defined(OS_ANDROID)
382 382
383 #if defined(OS_ANDROID) 383 #if defined(OS_ANDROID)
384 // Calls CreateGattConnection & DisconnectGatt, then simulates disconnection. 384 // Calls CreateGattConnection & DisconnectGatt, then simulates disconnection.
385 TEST_F(BluetoothTest, 385 TEST_F(BluetoothTest,
386 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect) { 386 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect) {
387 InitWithFakeAdapter(); 387 InitWithFakeAdapter();
388 StartDiscoverySession(); 388 StartDiscoverySession();
389 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 389 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
390 390
391 ResetEventCounts(); 391 ResetEventCounts();
392 device->CreateGattConnection(GetGattConnectionCallback(), 392 device->CreateGattConnection(GetGattConnectionCallback(),
393 GetConnectErrorCallback()); 393 GetConnectErrorCallback());
394 device->DisconnectGatt(); 394 device->DisconnectGatt();
395 EXPECT_EQ(1, gatt_connection_attempt_count_); 395 EXPECT_EQ(1, gatt_connection_attempts_);
396 EXPECT_EQ(1, gatt_disconnection_attempt_count_); 396 EXPECT_EQ(1, gatt_disconnection_attempts_);
397 CompleteGattDisconnection(device); 397 SimulateGattDisconnection(device);
398 EXPECT_EQ(0, callback_count_); 398 EXPECT_EQ(0, callback_count_);
399 EXPECT_EQ(1, error_callback_count_); 399 EXPECT_EQ(1, error_callback_count_);
400 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); 400 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_);
401 for (BluetoothGattConnection* connection : gatt_connections_) 401 for (BluetoothGattConnection* connection : gatt_connections_)
402 EXPECT_FALSE(connection->IsConnected()); 402 EXPECT_FALSE(connection->IsConnected());
403 } 403 }
404 #endif // defined(OS_ANDROID) 404 #endif // defined(OS_ANDROID)
405 405
406 #if defined(OS_ANDROID) 406 #if defined(OS_ANDROID)
407 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies 407 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies
408 // multiple errors should only invoke callbacks once. 408 // multiple errors should only invoke callbacks once.
409 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) { 409 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) {
410 InitWithFakeAdapter(); 410 InitWithFakeAdapter();
411 StartDiscoverySession(); 411 StartDiscoverySession();
412 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 412 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
413 413
414 ResetEventCounts(); 414 ResetEventCounts();
415 device->CreateGattConnection(GetGattConnectionCallback(), 415 device->CreateGattConnection(GetGattConnectionCallback(),
416 GetConnectErrorCallback()); 416 GetConnectErrorCallback());
417 EXPECT_EQ(1, gatt_connection_attempt_count_); 417 EXPECT_EQ(1, gatt_connection_attempts_);
418 FailGattConnection(device, BluetoothDevice::ERROR_AUTH_FAILED); 418 SimulateGattConnectionError(device, BluetoothDevice::ERROR_AUTH_FAILED);
419 FailGattConnection(device, BluetoothDevice::ERROR_FAILED); 419 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED);
420 EXPECT_EQ(0, callback_count_); 420 EXPECT_EQ(0, callback_count_);
421 EXPECT_EQ(1, error_callback_count_); 421 EXPECT_EQ(1, error_callback_count_);
422 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_); 422 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_);
423 for (BluetoothGattConnection* connection : gatt_connections_) 423 for (BluetoothGattConnection* connection : gatt_connections_)
424 EXPECT_FALSE(connection->IsConnected()); 424 EXPECT_FALSE(connection->IsConnected());
425 } 425 }
426 #endif // defined(OS_ANDROID) 426 #endif // defined(OS_ANDROID)
427 427
428 } // namespace device 428 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698