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

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

Issue 2052513002: Read characteristic implementation on macOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@characteristicscan_servicescan_cleanup
Patch Set: Test not meant to be commited Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 284 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
285 return; 285 return;
286 } 286 }
287 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 287 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
288 288
289 EXPECT_EQ(service_, characteristic1_->GetService()); 289 EXPECT_EQ(service_, characteristic1_->GetService());
290 EXPECT_EQ(service_, characteristic2_->GetService()); 290 EXPECT_EQ(service_, characteristic2_->GetService());
291 } 291 }
292 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 292 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
293 293
294 #if defined(OS_ANDROID) || defined(OS_WIN) 294 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
295 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer. 295 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer.
296 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { 296 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Empty) {
297 if (!PlatformSupportsLowEnergy()) {
298 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
299 return;
300 }
297 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 301 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
298 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 302 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
299 303
300 characteristic1_->ReadRemoteCharacteristic( 304 characteristic1_->ReadRemoteCharacteristic(
301 GetReadValueCallback(Call::EXPECTED), 305 GetReadValueCallback(Call::EXPECTED),
302 GetGattErrorCallback(Call::NOT_EXPECTED)); 306 GetGattErrorCallback(Call::NOT_EXPECTED));
303 std::vector<uint8_t> empty_vector; 307 std::vector<uint8_t> empty_vector;
304 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 308 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
305 309
306 // Duplicate read reported from OS shouldn't cause a problem: 310 // Duplicate read reported from OS shouldn't cause a problem:
307 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 311 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
308 312
309 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 313 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
310 EXPECT_EQ(empty_vector, last_read_value_); 314 EXPECT_EQ(empty_vector, last_read_value_);
311 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); 315 EXPECT_EQ(empty_vector, characteristic1_->GetValue());
312 } 316 }
313 #endif // defined(OS_ANDROID) || defined(OS_WIN) 317 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
314 318
315 #if defined(OS_ANDROID) || defined(OS_WIN) 319 #if defined(OS_ANDROID) || defined(OS_WIN)
316 // Tests WriteRemoteCharacteristic with empty value buffer. 320 // Tests WriteRemoteCharacteristic with empty value buffer.
317 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { 321 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Empty) {
318 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 322 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
319 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 323 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
320 324
321 std::vector<uint8_t> empty_vector; 325 std::vector<uint8_t> empty_vector;
322 characteristic1_->WriteRemoteCharacteristic( 326 characteristic1_->WriteRemoteCharacteristic(
323 empty_vector, GetCallback(Call::EXPECTED), 327 empty_vector, GetCallback(Call::EXPECTED),
324 GetGattErrorCallback(Call::NOT_EXPECTED)); 328 GetGattErrorCallback(Call::NOT_EXPECTED));
325 SimulateGattCharacteristicWrite(characteristic1_); 329 SimulateGattCharacteristicWrite(characteristic1_);
326 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 330 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
327 331
328 // Duplicate write reported from OS shouldn't cause a problem: 332 // Duplicate write reported from OS shouldn't cause a problem:
329 SimulateGattCharacteristicWrite(characteristic1_); 333 SimulateGattCharacteristicWrite(characteristic1_);
330 334
331 EXPECT_EQ(empty_vector, last_write_value_); 335 EXPECT_EQ(empty_vector, last_write_value_);
332 } 336 }
333 #endif // defined(OS_ANDROID) || defined(OS_WIN) 337 #endif // defined(OS_ANDROID) || defined(OS_WIN)
334 338
335 #if defined(OS_ANDROID) || defined(OS_WIN) 339 #if defined(OS_ANDROID) || defined(OS_WIN)
336 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted. 340 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted.
341 // This test is not relevant for macOS. This can never happen if CBPeripheral
342 // delegate is set to nil.
337 TEST_F(BluetoothRemoteGattCharacteristicTest, 343 TEST_F(BluetoothRemoteGattCharacteristicTest,
338 ReadRemoteCharacteristic_AfterDeleted) { 344 ReadRemoteCharacteristic_AfterDeleted) {
345 if (!PlatformSupportsLowEnergy()) {
346 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
347 return;
348 }
339 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 349 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
340 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 350 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
341 351
342 characteristic1_->ReadRemoteCharacteristic( 352 characteristic1_->ReadRemoteCharacteristic(
343 GetReadValueCallback(Call::NOT_EXPECTED), 353 GetReadValueCallback(Call::NOT_EXPECTED),
344 GetGattErrorCallback(Call::NOT_EXPECTED)); 354 GetGattErrorCallback(Call::NOT_EXPECTED));
345 355
346 RememberCharacteristicForSubsequentAction(characteristic1_); 356 RememberCharacteristicForSubsequentAction(characteristic1_);
347 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 357 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
348 358
349 std::vector<uint8_t> empty_vector; 359 std::vector<uint8_t> empty_vector;
350 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, 360 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr,
351 empty_vector); 361 empty_vector);
352 EXPECT_TRUE("Did not crash!"); 362 EXPECT_TRUE("Did not crash!");
353 } 363 }
354 #endif // defined(OS_ANDROID) || defined(OS_WIN) 364 #endif // defined(OS_ANDROID) || defined(OS_WIN)
355 365
356 #if defined(OS_ANDROID) || defined(OS_WIN) 366 #if defined(OS_ANDROID) || defined(OS_WIN)
357 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. 367 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted.
368 // This test is not relevant for macOS. This can never happen if CBPeripheral
369 // delegate is set to nil.
358 TEST_F(BluetoothRemoteGattCharacteristicTest, 370 TEST_F(BluetoothRemoteGattCharacteristicTest,
359 WriteRemoteCharacteristic_AfterDeleted) { 371 WriteRemoteCharacteristic_AfterDeleted) {
360 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 372 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
361 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 373 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
362 374
363 std::vector<uint8_t> empty_vector; 375 std::vector<uint8_t> empty_vector;
364 characteristic1_->WriteRemoteCharacteristic( 376 characteristic1_->WriteRemoteCharacteristic(
365 empty_vector, GetCallback(Call::NOT_EXPECTED), 377 empty_vector, GetCallback(Call::NOT_EXPECTED),
366 GetGattErrorCallback(Call::NOT_EXPECTED)); 378 GetGattErrorCallback(Call::NOT_EXPECTED));
367 379
368 RememberCharacteristicForSubsequentAction(characteristic1_); 380 RememberCharacteristicForSubsequentAction(characteristic1_);
369 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 381 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
370 382
371 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); 383 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr);
372 EXPECT_TRUE("Did not crash!"); 384 EXPECT_TRUE("Did not crash!");
373 } 385 }
374 #endif // defined(OS_ANDROID) || defined(OS_WIN) 386 #endif // defined(OS_ANDROID) || defined(OS_WIN)
375 387
376 #if defined(OS_ANDROID) || defined(OS_WIN) 388 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
377 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. 389 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer.
378 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) { 390 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) {
391 if (!PlatformSupportsLowEnergy()) {
392 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
393 return;
394 }
379 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 395 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
380 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 396 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
381 397
382 characteristic1_->ReadRemoteCharacteristic( 398 characteristic1_->ReadRemoteCharacteristic(
383 GetReadValueCallback(Call::EXPECTED), 399 GetReadValueCallback(Call::EXPECTED),
384 GetGattErrorCallback(Call::NOT_EXPECTED)); 400 GetGattErrorCallback(Call::NOT_EXPECTED));
385 401
386 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 402 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
387 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 403 std::vector<uint8_t> test_vector(values, values + arraysize(values));
388 SimulateGattCharacteristicRead(characteristic1_, test_vector); 404 SimulateGattCharacteristicRead(characteristic1_, test_vector);
389 405
390 // Duplicate read reported from OS shouldn't cause a problem: 406 // Duplicate read reported from OS shouldn't cause a problem:
391 std::vector<uint8_t> empty_vector; 407 std::vector<uint8_t> empty_vector;
392 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 408 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
393 409
394 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 410 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
395 EXPECT_EQ(test_vector, last_read_value_); 411 EXPECT_EQ(test_vector, last_read_value_);
396 EXPECT_EQ(test_vector, characteristic1_->GetValue()); 412 EXPECT_EQ(test_vector, characteristic1_->GetValue());
397 } 413 }
398 #endif // defined(OS_ANDROID) || defined(OS_WIN) 414 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
399 415
400 #if defined(OS_ANDROID) || defined(OS_WIN) 416 #if defined(OS_ANDROID) || defined(OS_WIN)
401 // Tests WriteRemoteCharacteristic with non-empty value buffer. 417 // Tests WriteRemoteCharacteristic with non-empty value buffer.
402 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic) { 418 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic) {
403 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 419 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
404 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 420 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
405 421
406 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 422 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
407 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 423 std::vector<uint8_t> test_vector(values, values + arraysize(values));
408 characteristic1_->WriteRemoteCharacteristic( 424 characteristic1_->WriteRemoteCharacteristic(
409 test_vector, GetCallback(Call::EXPECTED), 425 test_vector, GetCallback(Call::EXPECTED),
410 GetGattErrorCallback(Call::NOT_EXPECTED)); 426 GetGattErrorCallback(Call::NOT_EXPECTED));
411 427
412 SimulateGattCharacteristicWrite(characteristic1_); 428 SimulateGattCharacteristicWrite(characteristic1_);
413 429
414 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 430 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
415 EXPECT_EQ(test_vector, last_write_value_); 431 EXPECT_EQ(test_vector, last_write_value_);
416 } 432 }
417 #endif // defined(OS_ANDROID) || defined(OS_WIN) 433 #endif // defined(OS_ANDROID) || defined(OS_WIN)
418 434
419 #if defined(OS_ANDROID) || defined(OS_WIN) 435 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
420 // Tests ReadRemoteCharacteristic and GetValue multiple times. 436 // Tests ReadRemoteCharacteristic and GetValue multiple times.
421 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { 437 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Twice) {
438 if (!PlatformSupportsLowEnergy()) {
439 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
440 return;
441 }
422 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 442 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
423 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 443 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
424 444
425 characteristic1_->ReadRemoteCharacteristic( 445 characteristic1_->ReadRemoteCharacteristic(
426 GetReadValueCallback(Call::EXPECTED), 446 GetReadValueCallback(Call::EXPECTED),
427 GetGattErrorCallback(Call::NOT_EXPECTED)); 447 GetGattErrorCallback(Call::NOT_EXPECTED));
428 448
429 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 449 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
430 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 450 std::vector<uint8_t> test_vector(values, values + arraysize(values));
431 SimulateGattCharacteristicRead(characteristic1_, test_vector); 451 SimulateGattCharacteristicRead(characteristic1_, test_vector);
432 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 452 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
433 EXPECT_EQ(1, callback_count_); 453 EXPECT_EQ(1, callback_count_);
434 EXPECT_EQ(0, error_callback_count_); 454 EXPECT_EQ(0, error_callback_count_);
435 EXPECT_EQ(test_vector, last_read_value_); 455 EXPECT_EQ(test_vector, last_read_value_);
436 EXPECT_EQ(test_vector, characteristic1_->GetValue()); 456 EXPECT_EQ(test_vector, characteristic1_->GetValue());
437 457
438 // Read again, with different value: 458 // Read again, with different value:
439 ResetEventCounts(); 459 ResetEventCounts();
440 characteristic1_->ReadRemoteCharacteristic( 460 characteristic1_->ReadRemoteCharacteristic(
441 GetReadValueCallback(Call::EXPECTED), 461 GetReadValueCallback(Call::EXPECTED),
442 GetGattErrorCallback(Call::NOT_EXPECTED)); 462 GetGattErrorCallback(Call::NOT_EXPECTED));
443 std::vector<uint8_t> empty_vector; 463 std::vector<uint8_t> empty_vector;
444 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 464 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
445 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 465 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
446 EXPECT_EQ(1, callback_count_); 466 EXPECT_EQ(1, callback_count_);
447 EXPECT_EQ(0, error_callback_count_); 467 EXPECT_EQ(0, error_callback_count_);
448 EXPECT_EQ(empty_vector, last_read_value_); 468 EXPECT_EQ(empty_vector, last_read_value_);
449 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); 469 EXPECT_EQ(empty_vector, characteristic1_->GetValue());
450 } 470 }
451 #endif // defined(OS_ANDROID) || defined(OS_WIN) 471 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
452 472
453 #if defined(OS_ANDROID) || defined(OS_WIN) 473 #if defined(OS_ANDROID) || defined(OS_WIN)
454 // Tests WriteRemoteCharacteristic multiple times. 474 // Tests WriteRemoteCharacteristic multiple times.
455 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { 475 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Twice) {
456 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 476 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
457 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 477 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
458 478
459 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 479 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
460 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 480 std::vector<uint8_t> test_vector(values, values + arraysize(values));
461 characteristic1_->WriteRemoteCharacteristic( 481 characteristic1_->WriteRemoteCharacteristic(
(...skipping 14 matching lines...) Expand all
476 GetGattErrorCallback(Call::NOT_EXPECTED)); 496 GetGattErrorCallback(Call::NOT_EXPECTED));
477 497
478 SimulateGattCharacteristicWrite(characteristic1_); 498 SimulateGattCharacteristicWrite(characteristic1_);
479 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 499 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
480 EXPECT_EQ(1, callback_count_); 500 EXPECT_EQ(1, callback_count_);
481 EXPECT_EQ(0, error_callback_count_); 501 EXPECT_EQ(0, error_callback_count_);
482 EXPECT_EQ(empty_vector, last_write_value_); 502 EXPECT_EQ(empty_vector, last_write_value_);
483 } 503 }
484 #endif // defined(OS_ANDROID) || defined(OS_WIN) 504 #endif // defined(OS_ANDROID) || defined(OS_WIN)
485 505
486 #if defined(OS_ANDROID) || defined(OS_WIN) 506 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
487 // Tests ReadRemoteCharacteristic on two characteristics. 507 // Tests ReadRemoteCharacteristic on two characteristics.
488 TEST_F(BluetoothRemoteGattCharacteristicTest, 508 TEST_F(BluetoothRemoteGattCharacteristicTest,
489 ReadRemoteCharacteristic_MultipleCharacteristics) { 509 ReadRemoteCharacteristic_MultipleCharacteristics) {
510 if (!PlatformSupportsLowEnergy()) {
511 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
512 return;
513 }
490 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 514 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
491 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 515 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
492 516
493 characteristic1_->ReadRemoteCharacteristic( 517 characteristic1_->ReadRemoteCharacteristic(
494 GetReadValueCallback(Call::EXPECTED), 518 GetReadValueCallback(Call::EXPECTED),
495 GetGattErrorCallback(Call::NOT_EXPECTED)); 519 GetGattErrorCallback(Call::NOT_EXPECTED));
496 characteristic2_->ReadRemoteCharacteristic( 520 characteristic2_->ReadRemoteCharacteristic(
497 GetReadValueCallback(Call::EXPECTED), 521 GetReadValueCallback(Call::EXPECTED),
498 GetGattErrorCallback(Call::NOT_EXPECTED)); 522 GetGattErrorCallback(Call::NOT_EXPECTED));
499 EXPECT_EQ(0, callback_count_); 523 EXPECT_EQ(0, callback_count_);
500 EXPECT_EQ(0, error_callback_count_); 524 EXPECT_EQ(0, error_callback_count_);
501 525
502 std::vector<uint8_t> test_vector1; 526 std::vector<uint8_t> test_vector1;
503 test_vector1.push_back(111); 527 test_vector1.push_back(111);
504 SimulateGattCharacteristicRead(characteristic1_, test_vector1); 528 SimulateGattCharacteristicRead(characteristic1_, test_vector1);
505 EXPECT_EQ(test_vector1, last_read_value_); 529 EXPECT_EQ(test_vector1, last_read_value_);
506 530
507 std::vector<uint8_t> test_vector2; 531 std::vector<uint8_t> test_vector2;
508 test_vector2.push_back(222); 532 test_vector2.push_back(222);
509 SimulateGattCharacteristicRead(characteristic2_, test_vector2); 533 SimulateGattCharacteristicRead(characteristic2_, test_vector2);
510 EXPECT_EQ(test_vector2, last_read_value_); 534 EXPECT_EQ(test_vector2, last_read_value_);
511 535
512 EXPECT_EQ(2, gatt_read_characteristic_attempts_); 536 EXPECT_EQ(2, gatt_read_characteristic_attempts_);
513 EXPECT_EQ(2, callback_count_); 537 EXPECT_EQ(2, callback_count_);
514 EXPECT_EQ(0, error_callback_count_); 538 EXPECT_EQ(0, error_callback_count_);
515 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); 539 EXPECT_EQ(test_vector1, characteristic1_->GetValue());
516 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); 540 EXPECT_EQ(test_vector2, characteristic2_->GetValue());
517 } 541 }
518 #endif // defined(OS_ANDROID) || defined(OS_WIN) 542 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
519 543
520 #if defined(OS_ANDROID) || defined(OS_WIN) 544 #if defined(OS_ANDROID) || defined(OS_WIN)
521 // Tests WriteRemoteCharacteristic on two characteristics. 545 // Tests WriteRemoteCharacteristic on two characteristics.
522 TEST_F(BluetoothRemoteGattCharacteristicTest, 546 TEST_F(BluetoothRemoteGattCharacteristicTest,
523 WriteRemoteCharacteristic_MultipleCharacteristics) { 547 WriteRemoteCharacteristic_MultipleCharacteristics) {
524 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 548 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
525 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 549 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
526 550
527 std::vector<uint8_t> test_vector1; 551 std::vector<uint8_t> test_vector1;
528 test_vector1.push_back(111); 552 test_vector1.push_back(111);
(...skipping 27 matching lines...) Expand all
556 #endif 580 #endif
557 581
558 EXPECT_EQ(2, gatt_write_characteristic_attempts_); 582 EXPECT_EQ(2, gatt_write_characteristic_attempts_);
559 EXPECT_EQ(2, callback_count_); 583 EXPECT_EQ(2, callback_count_);
560 EXPECT_EQ(0, error_callback_count_); 584 EXPECT_EQ(0, error_callback_count_);
561 585
562 // TODO(591740): Remove if define for OS_ANDROID in this test. 586 // TODO(591740): Remove if define for OS_ANDROID in this test.
563 } 587 }
564 #endif // defined(OS_ANDROID) || defined(OS_WIN) 588 #endif // defined(OS_ANDROID) || defined(OS_WIN)
565 589
566 #if defined(OS_ANDROID) || defined(OS_WIN) 590 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
567 // Tests ReadRemoteCharacteristic asynchronous error. 591 // Tests ReadRemoteCharacteristic asynchronous error.
568 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadError) { 592 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadError) {
593 if (!PlatformSupportsLowEnergy()) {
594 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
595 return;
596 }
569 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 597 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
570 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 598 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
571 599
600 TestBluetoothAdapterObserver observer(adapter_);
601
572 characteristic1_->ReadRemoteCharacteristic( 602 characteristic1_->ReadRemoteCharacteristic(
573 GetReadValueCallback(Call::NOT_EXPECTED), 603 GetReadValueCallback(Call::NOT_EXPECTED),
574 GetGattErrorCallback(Call::EXPECTED)); 604 GetGattErrorCallback(Call::EXPECTED));
575 SimulateGattCharacteristicReadError( 605 SimulateGattCharacteristicReadError(
576 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH); 606 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH);
577 SimulateGattCharacteristicReadError( 607 SimulateGattCharacteristicReadError(
578 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); 608 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
579 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH, 609 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH,
580 last_gatt_error_code_); 610 last_gatt_error_code_);
611 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
581 } 612 }
582 #endif // defined(OS_ANDROID) || defined(OS_WIN) 613 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
583 614
584 #if defined(OS_ANDROID) || defined(OS_WIN) 615 #if defined(OS_ANDROID) || defined(OS_WIN)
585 // Tests WriteRemoteCharacteristic asynchronous error. 616 // Tests WriteRemoteCharacteristic asynchronous error.
586 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteError) { 617 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteError) {
587 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 618 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
588 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 619 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
589 620
590 std::vector<uint8_t> empty_vector; 621 std::vector<uint8_t> empty_vector;
591 characteristic1_->WriteRemoteCharacteristic( 622 characteristic1_->WriteRemoteCharacteristic(
592 empty_vector, GetCallback(Call::NOT_EXPECTED), 623 empty_vector, GetCallback(Call::NOT_EXPECTED),
593 GetGattErrorCallback(Call::EXPECTED)); 624 GetGattErrorCallback(Call::EXPECTED));
594 SimulateGattCharacteristicWriteError( 625 SimulateGattCharacteristicWriteError(
595 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH); 626 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH);
596 SimulateGattCharacteristicWriteError( 627 SimulateGattCharacteristicWriteError(
597 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); 628 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
598 629
599 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH, 630 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH,
600 last_gatt_error_code_); 631 last_gatt_error_code_);
601 } 632 }
602 #endif // defined(OS_ANDROID) || defined(OS_WIN) 633 #endif // defined(OS_ANDROID) || defined(OS_WIN)
603 634
604 #if defined(OS_ANDROID) 635 #if defined(OS_ANDROID)
605 // Tests ReadRemoteCharacteristic synchronous error. 636 // Tests ReadRemoteCharacteristic synchronous error.
637 // Test not relevant for macOS since characteristic read cannot generate
638 // synchronous error.
606 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadSynchronousError) { 639 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadSynchronousError) {
607 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 640 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
608 641
609 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_); 642 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_);
610 characteristic1_->ReadRemoteCharacteristic( 643 characteristic1_->ReadRemoteCharacteristic(
611 GetReadValueCallback(Call::NOT_EXPECTED), 644 GetReadValueCallback(Call::NOT_EXPECTED),
612 GetGattErrorCallback(Call::EXPECTED)); 645 GetGattErrorCallback(Call::EXPECTED));
613 EXPECT_EQ(0, gatt_read_characteristic_attempts_); 646 EXPECT_EQ(0, gatt_read_characteristic_attempts_);
614 base::RunLoop().RunUntilIdle(); 647 base::RunLoop().RunUntilIdle();
615 EXPECT_EQ(0, callback_count_); 648 EXPECT_EQ(0, callback_count_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 characteristic1_->WriteRemoteCharacteristic( 685 characteristic1_->WriteRemoteCharacteristic(
653 empty_vector, GetCallback(Call::EXPECTED), 686 empty_vector, GetCallback(Call::EXPECTED),
654 GetGattErrorCallback(Call::NOT_EXPECTED)); 687 GetGattErrorCallback(Call::NOT_EXPECTED));
655 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 688 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
656 SimulateGattCharacteristicWrite(characteristic1_); 689 SimulateGattCharacteristicWrite(characteristic1_);
657 EXPECT_EQ(1, callback_count_); 690 EXPECT_EQ(1, callback_count_);
658 EXPECT_EQ(0, error_callback_count_); 691 EXPECT_EQ(0, error_callback_count_);
659 } 692 }
660 #endif // defined(OS_ANDROID) 693 #endif // defined(OS_ANDROID)
661 694
662 #if defined(OS_ANDROID) || defined(OS_WIN) 695 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
663 // Tests ReadRemoteCharacteristic error with a pending read operation. 696 // Tests ReadRemoteCharacteristic error with a pending read operation.
664 TEST_F(BluetoothRemoteGattCharacteristicTest, 697 TEST_F(BluetoothRemoteGattCharacteristicTest,
665 ReadRemoteCharacteristic_ReadPending) { 698 ReadRemoteCharacteristic_ReadPending) {
699 if (!PlatformSupportsLowEnergy()) {
700 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
701 return;
702 }
666 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 703 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
667 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 704 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
668 705
669 characteristic1_->ReadRemoteCharacteristic( 706 characteristic1_->ReadRemoteCharacteristic(
670 GetReadValueCallback(Call::EXPECTED), 707 GetReadValueCallback(Call::EXPECTED),
671 GetGattErrorCallback(Call::NOT_EXPECTED)); 708 GetGattErrorCallback(Call::NOT_EXPECTED));
672 characteristic1_->ReadRemoteCharacteristic( 709 characteristic1_->ReadRemoteCharacteristic(
673 GetReadValueCallback(Call::NOT_EXPECTED), 710 GetReadValueCallback(Call::NOT_EXPECTED),
674 GetGattErrorCallback(Call::EXPECTED)); 711 GetGattErrorCallback(Call::EXPECTED));
675 712
676 base::RunLoop().RunUntilIdle(); 713 base::RunLoop().RunUntilIdle();
677 714
678 EXPECT_EQ(0, callback_count_); 715 EXPECT_EQ(0, callback_count_);
679 EXPECT_EQ(1, error_callback_count_); 716 EXPECT_EQ(1, error_callback_count_);
680 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS, 717 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS,
681 last_gatt_error_code_); 718 last_gatt_error_code_);
682 719
683 // Initial read should still succeed: 720 // Initial read should still succeed:
684 ResetEventCounts(); 721 ResetEventCounts();
685 std::vector<uint8_t> empty_vector; 722 std::vector<uint8_t> empty_vector;
686 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 723 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
687 EXPECT_EQ(1, callback_count_); 724 EXPECT_EQ(1, callback_count_);
688 EXPECT_EQ(0, error_callback_count_); 725 EXPECT_EQ(0, error_callback_count_);
689 } 726 }
690 #endif // defined(OS_ANDROID) || defined(OS_WIN) 727 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
691 728
692 #if defined(OS_ANDROID) || defined(OS_WIN) 729 #if defined(OS_ANDROID) || defined(OS_WIN)
693 // Tests WriteRemoteCharacteristic error with a pending write operation. 730 // Tests WriteRemoteCharacteristic error with a pending write operation.
694 TEST_F(BluetoothRemoteGattCharacteristicTest, 731 TEST_F(BluetoothRemoteGattCharacteristicTest,
695 WriteRemoteCharacteristic_WritePending) { 732 WriteRemoteCharacteristic_WritePending) {
696 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 733 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
697 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 734 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
698 735
699 std::vector<uint8_t> empty_vector; 736 std::vector<uint8_t> empty_vector;
700 characteristic1_->WriteRemoteCharacteristic( 737 characteristic1_->WriteRemoteCharacteristic(
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 1277 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
1241 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 1278 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
1242 1279
1243 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 1280 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
1244 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 1281 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
1245 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 1282 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
1246 } 1283 }
1247 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1284 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1248 1285
1249 } // namespace device 1286 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698