Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "device/bluetooth/bluetooth_gatt_characteristic.h" | 5 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 characteristic1_->StartNotifySession( | 102 characteristic1_->StartNotifySession( |
| 103 GetNotifyCallback(Call::NOT_EXPECTED), | 103 GetNotifyCallback(Call::NOT_EXPECTED), |
| 104 GetGattErrorCallback(Call::EXPECTED)); | 104 GetGattErrorCallback(Call::EXPECTED)); |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 | 107 |
| 108 characteristic1_->StartNotifySession( | 108 characteristic1_->StartNotifySession( |
| 109 GetNotifyCallback(Call::EXPECTED), | 109 GetNotifyCallback(Call::EXPECTED), |
| 110 GetGattErrorCallback(Call::NOT_EXPECTED)); | 110 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 111 | 111 |
| 112 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 113 EXPECT_EQ(0, callback_count_); | 112 EXPECT_EQ(0, callback_count_); |
| 114 SimulateGattNotifySessionStarted(characteristic1_); | 113 SimulateGattNotifySessionStarted(characteristic1_); |
| 114 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 115 EXPECT_EQ(1, callback_count_); | 115 EXPECT_EQ(1, callback_count_); |
| 116 EXPECT_EQ(0, error_callback_count_); | 116 EXPECT_EQ(0, error_callback_count_); |
| 117 ASSERT_EQ(1u, notify_sessions_.size()); | 117 ASSERT_EQ(1u, notify_sessions_.size()); |
| 118 ASSERT_TRUE(notify_sessions_[0]); | 118 ASSERT_TRUE(notify_sessions_[0]); |
| 119 EXPECT_EQ(characteristic1_->GetIdentifier(), | 119 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 120 notify_sessions_[0]->GetCharacteristicIdentifier()); | 120 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 121 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 121 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 122 | 122 |
| 123 // Verify the Client Characteristic Configuration descriptor was written to. | 123 // Verify the Client Characteristic Configuration descriptor was written to. |
| 124 EXPECT_EQ(1, gatt_write_descriptor_attempts_); | 124 EXPECT_EQ(1, gatt_write_descriptor_attempts_); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 | 277 |
| 278 #if defined(OS_ANDROID) || defined(OS_WIN) | 278 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 279 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer. | 279 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer. |
| 280 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { | 280 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { |
| 281 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 281 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 282 BluetoothGattCharacteristic::PROPERTY_READ)); | 282 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 283 | 283 |
| 284 characteristic1_->ReadRemoteCharacteristic( | 284 characteristic1_->ReadRemoteCharacteristic( |
| 285 GetReadValueCallback(Call::EXPECTED), | 285 GetReadValueCallback(Call::EXPECTED), |
| 286 GetGattErrorCallback(Call::NOT_EXPECTED)); | 286 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 287 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | |
| 288 std::vector<uint8_t> empty_vector; | 287 std::vector<uint8_t> empty_vector; |
| 289 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 288 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 290 | 289 |
| 291 // Duplicate read reported from OS shouldn't cause a problem: | 290 // Duplicate read reported from OS shouldn't cause a problem: |
| 292 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 291 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 293 | 292 |
| 293 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | |
| 294 EXPECT_EQ(empty_vector, last_read_value_); | 294 EXPECT_EQ(empty_vector, last_read_value_); |
| 295 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); | 295 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); |
| 296 } | 296 } |
| 297 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 297 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 298 | 298 |
| 299 #if defined(OS_ANDROID) || defined(OS_WIN) | 299 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 300 // Tests WriteRemoteCharacteristic with empty value buffer. | 300 // Tests WriteRemoteCharacteristic with empty value buffer. |
| 301 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { | 301 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { |
| 302 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 302 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 303 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 303 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 304 | 304 |
| 305 std::vector<uint8_t> empty_vector; | 305 std::vector<uint8_t> empty_vector; |
| 306 characteristic1_->WriteRemoteCharacteristic( | 306 characteristic1_->WriteRemoteCharacteristic( |
| 307 empty_vector, GetCallback(Call::EXPECTED), | 307 empty_vector, GetCallback(Call::EXPECTED), |
| 308 GetGattErrorCallback(Call::NOT_EXPECTED)); | 308 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 309 SimulateGattCharacteristicWrite(characteristic1_); | |
| 309 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | 310 EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| 310 SimulateGattCharacteristicWrite(characteristic1_); | |
| 311 | 311 |
| 312 // Duplicate write reported from OS shouldn't cause a problem: | 312 // Duplicate write reported from OS shouldn't cause a problem: |
| 313 SimulateGattCharacteristicWrite(characteristic1_); | 313 SimulateGattCharacteristicWrite(characteristic1_); |
| 314 | 314 |
| 315 EXPECT_EQ(empty_vector, last_write_value_); | 315 EXPECT_EQ(empty_vector, last_write_value_); |
| 316 } | 316 } |
| 317 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 317 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 318 | 318 |
| 319 #if defined(OS_ANDROID) || defined(OS_WIN) | 319 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 320 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted. | 320 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 358 |
| 359 #if defined(OS_ANDROID) || defined(OS_WIN) | 359 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 360 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. | 360 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. |
| 361 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { | 361 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { |
| 362 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 362 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 363 BluetoothGattCharacteristic::PROPERTY_READ)); | 363 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 364 | 364 |
| 365 characteristic1_->ReadRemoteCharacteristic( | 365 characteristic1_->ReadRemoteCharacteristic( |
| 366 GetReadValueCallback(Call::EXPECTED), | 366 GetReadValueCallback(Call::EXPECTED), |
| 367 GetGattErrorCallback(Call::NOT_EXPECTED)); | 367 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 368 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | |
| 369 | 368 |
| 370 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; | 369 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| 371 std::vector<uint8_t> test_vector(values, values + arraysize(values)); | 370 std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| 372 SimulateGattCharacteristicRead(characteristic1_, test_vector); | 371 SimulateGattCharacteristicRead(characteristic1_, test_vector); |
| 373 | 372 |
| 374 // Duplicate read reported from OS shouldn't cause a problem: | 373 // Duplicate read reported from OS shouldn't cause a problem: |
| 375 std::vector<uint8_t> empty_vector; | 374 std::vector<uint8_t> empty_vector; |
| 376 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 375 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 377 | 376 |
| 377 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | |
| 378 EXPECT_EQ(test_vector, last_read_value_); | 378 EXPECT_EQ(test_vector, last_read_value_); |
| 379 EXPECT_EQ(test_vector, characteristic1_->GetValue()); | 379 EXPECT_EQ(test_vector, characteristic1_->GetValue()); |
| 380 } | 380 } |
| 381 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 381 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 382 | 382 |
| 383 #if defined(OS_ANDROID) || defined(OS_WIN) | 383 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 384 // Tests WriteRemoteCharacteristic with non-empty value buffer. | 384 // Tests WriteRemoteCharacteristic with non-empty value buffer. |
| 385 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic) { | 385 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic) { |
| 386 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 386 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 387 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 387 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 388 | 388 |
| 389 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; | 389 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| 390 std::vector<uint8_t> test_vector(values, values + arraysize(values)); | 390 std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| 391 characteristic1_->WriteRemoteCharacteristic( | 391 characteristic1_->WriteRemoteCharacteristic( |
| 392 test_vector, GetCallback(Call::EXPECTED), | 392 test_vector, GetCallback(Call::EXPECTED), |
| 393 GetGattErrorCallback(Call::NOT_EXPECTED)); | 393 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 394 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | |
| 395 | 394 |
| 396 SimulateGattCharacteristicWrite(characteristic1_); | 395 SimulateGattCharacteristicWrite(characteristic1_); |
| 397 | 396 |
| 397 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | |
| 398 EXPECT_EQ(test_vector, last_write_value_); | 398 EXPECT_EQ(test_vector, last_write_value_); |
| 399 } | 399 } |
| 400 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 400 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 401 | 401 |
| 402 #if defined(OS_ANDROID) || defined(OS_WIN) | 402 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 403 // Tests ReadRemoteCharacteristic and GetValue multiple times. | 403 // Tests ReadRemoteCharacteristic and GetValue multiple times. |
| 404 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { | 404 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { |
| 405 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 405 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 406 BluetoothGattCharacteristic::PROPERTY_READ)); | 406 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 407 | 407 |
| 408 characteristic1_->ReadRemoteCharacteristic( | 408 characteristic1_->ReadRemoteCharacteristic( |
| 409 GetReadValueCallback(Call::EXPECTED), | 409 GetReadValueCallback(Call::EXPECTED), |
| 410 GetGattErrorCallback(Call::NOT_EXPECTED)); | 410 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 411 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | |
| 412 | 411 |
| 413 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; | 412 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| 414 std::vector<uint8_t> test_vector(values, values + arraysize(values)); | 413 std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| 415 SimulateGattCharacteristicRead(characteristic1_, test_vector); | 414 SimulateGattCharacteristicRead(characteristic1_, test_vector); |
| 415 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | |
| 416 EXPECT_EQ(1, callback_count_); | 416 EXPECT_EQ(1, callback_count_); |
| 417 EXPECT_EQ(0, error_callback_count_); | 417 EXPECT_EQ(0, error_callback_count_); |
| 418 EXPECT_EQ(test_vector, last_read_value_); | 418 EXPECT_EQ(test_vector, last_read_value_); |
| 419 EXPECT_EQ(test_vector, characteristic1_->GetValue()); | 419 EXPECT_EQ(test_vector, characteristic1_->GetValue()); |
| 420 | 420 |
| 421 // Read again, with different value: | 421 // Read again, with different value: |
| 422 ResetEventCounts(); | 422 ResetEventCounts(); |
| 423 characteristic1_->ReadRemoteCharacteristic( | 423 characteristic1_->ReadRemoteCharacteristic( |
| 424 GetReadValueCallback(Call::EXPECTED), | 424 GetReadValueCallback(Call::EXPECTED), |
| 425 GetGattErrorCallback(Call::NOT_EXPECTED)); | 425 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 426 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | |
| 427 std::vector<uint8_t> empty_vector; | 426 std::vector<uint8_t> empty_vector; |
| 428 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 427 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 428 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | |
| 429 EXPECT_EQ(1, callback_count_); | 429 EXPECT_EQ(1, callback_count_); |
| 430 EXPECT_EQ(0, error_callback_count_); | 430 EXPECT_EQ(0, error_callback_count_); |
| 431 EXPECT_EQ(empty_vector, last_read_value_); | 431 EXPECT_EQ(empty_vector, last_read_value_); |
| 432 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); | 432 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); |
| 433 } | 433 } |
| 434 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 434 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 435 | 435 |
| 436 #if defined(OS_ANDROID) || defined(OS_WIN) | 436 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 437 // Tests WriteRemoteCharacteristic multiple times. | 437 // Tests WriteRemoteCharacteristic multiple times. |
| 438 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { | 438 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { |
| 439 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 439 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 440 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 440 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 441 | 441 |
| 442 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; | 442 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| 443 std::vector<uint8_t> test_vector(values, values + arraysize(values)); | 443 std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| 444 characteristic1_->WriteRemoteCharacteristic( | 444 characteristic1_->WriteRemoteCharacteristic( |
| 445 test_vector, GetCallback(Call::EXPECTED), | 445 test_vector, GetCallback(Call::EXPECTED), |
| 446 GetGattErrorCallback(Call::NOT_EXPECTED)); | 446 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 447 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | |
| 448 | 447 |
| 449 SimulateGattCharacteristicWrite(characteristic1_); | 448 SimulateGattCharacteristicWrite(characteristic1_); |
| 449 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | |
| 450 EXPECT_EQ(1, callback_count_); | 450 EXPECT_EQ(1, callback_count_); |
| 451 EXPECT_EQ(0, error_callback_count_); | 451 EXPECT_EQ(0, error_callback_count_); |
| 452 EXPECT_EQ(test_vector, last_write_value_); | 452 EXPECT_EQ(test_vector, last_write_value_); |
| 453 | 453 |
| 454 // Write again, with different value: | 454 // Write again, with different value: |
| 455 ResetEventCounts(); | 455 ResetEventCounts(); |
| 456 std::vector<uint8_t> empty_vector; | 456 std::vector<uint8_t> empty_vector; |
| 457 characteristic1_->WriteRemoteCharacteristic( | 457 characteristic1_->WriteRemoteCharacteristic( |
| 458 empty_vector, GetCallback(Call::EXPECTED), | 458 empty_vector, GetCallback(Call::EXPECTED), |
| 459 GetGattErrorCallback(Call::NOT_EXPECTED)); | 459 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 460 | |
| 461 SimulateGattCharacteristicWrite(characteristic1_); | |
| 460 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | 462 EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| 461 SimulateGattCharacteristicWrite(characteristic1_); | |
| 462 EXPECT_EQ(1, callback_count_); | 463 EXPECT_EQ(1, callback_count_); |
| 463 EXPECT_EQ(0, error_callback_count_); | 464 EXPECT_EQ(0, error_callback_count_); |
| 464 EXPECT_EQ(empty_vector, last_write_value_); | 465 EXPECT_EQ(empty_vector, last_write_value_); |
| 465 } | 466 } |
| 466 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 467 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 467 | 468 |
| 468 #if defined(OS_ANDROID) || defined(OS_WIN) | 469 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 469 // Tests ReadRemoteCharacteristic on two characteristics. | 470 // Tests ReadRemoteCharacteristic on two characteristics. |
| 470 TEST_F(BluetoothGattCharacteristicTest, | 471 TEST_F(BluetoothGattCharacteristicTest, |
| 471 ReadRemoteCharacteristic_MultipleCharacteristics) { | 472 ReadRemoteCharacteristic_MultipleCharacteristics) { |
| 472 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 473 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 473 BluetoothGattCharacteristic::PROPERTY_READ)); | 474 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 474 | 475 |
| 475 characteristic1_->ReadRemoteCharacteristic( | 476 characteristic1_->ReadRemoteCharacteristic( |
| 476 GetReadValueCallback(Call::EXPECTED), | 477 GetReadValueCallback(Call::EXPECTED), |
| 477 GetGattErrorCallback(Call::NOT_EXPECTED)); | 478 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 478 characteristic2_->ReadRemoteCharacteristic( | 479 characteristic2_->ReadRemoteCharacteristic( |
| 479 GetReadValueCallback(Call::EXPECTED), | 480 GetReadValueCallback(Call::EXPECTED), |
| 480 GetGattErrorCallback(Call::NOT_EXPECTED)); | 481 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 481 EXPECT_EQ(2, gatt_read_characteristic_attempts_); | |
| 482 EXPECT_EQ(0, callback_count_); | 482 EXPECT_EQ(0, callback_count_); |
| 483 EXPECT_EQ(0, error_callback_count_); | 483 EXPECT_EQ(0, error_callback_count_); |
| 484 | 484 |
| 485 std::vector<uint8_t> test_vector1; | 485 std::vector<uint8_t> test_vector1; |
| 486 test_vector1.push_back(111); | 486 test_vector1.push_back(111); |
| 487 SimulateGattCharacteristicRead(characteristic1_, test_vector1); | 487 SimulateGattCharacteristicRead(characteristic1_, test_vector1); |
| 488 EXPECT_EQ(test_vector1, last_read_value_); | 488 EXPECT_EQ(test_vector1, last_read_value_); |
| 489 | 489 |
| 490 std::vector<uint8_t> test_vector2; | 490 std::vector<uint8_t> test_vector2; |
| 491 test_vector2.push_back(222); | 491 test_vector2.push_back(222); |
| 492 SimulateGattCharacteristicRead(characteristic2_, test_vector2); | 492 SimulateGattCharacteristicRead(characteristic2_, test_vector2); |
| 493 EXPECT_EQ(test_vector2, last_read_value_); | 493 EXPECT_EQ(test_vector2, last_read_value_); |
| 494 | 494 |
| 495 EXPECT_EQ(2, gatt_read_characteristic_attempts_); | |
| 495 EXPECT_EQ(2, callback_count_); | 496 EXPECT_EQ(2, callback_count_); |
| 496 EXPECT_EQ(0, error_callback_count_); | 497 EXPECT_EQ(0, error_callback_count_); |
| 497 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); | 498 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| 498 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); | 499 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); |
| 499 } | 500 } |
| 500 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 501 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 501 | 502 |
| 502 #if defined(OS_ANDROID) || defined(OS_WIN) | 503 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 503 // Tests WriteRemoteCharacteristic on two characteristics. | 504 // Tests WriteRemoteCharacteristic on two characteristics. |
| 504 TEST_F(BluetoothGattCharacteristicTest, | 505 TEST_F(BluetoothGattCharacteristicTest, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 517 | 518 |
| 518 std::vector<uint8_t> test_vector2; | 519 std::vector<uint8_t> test_vector2; |
| 519 test_vector2.push_back(222); | 520 test_vector2.push_back(222); |
| 520 characteristic2_->WriteRemoteCharacteristic( | 521 characteristic2_->WriteRemoteCharacteristic( |
| 521 test_vector2, GetCallback(Call::EXPECTED), | 522 test_vector2, GetCallback(Call::EXPECTED), |
| 522 GetGattErrorCallback(Call::NOT_EXPECTED)); | 523 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 523 #ifdef OS_ANDROID | 524 #ifdef OS_ANDROID |
| 524 EXPECT_EQ(test_vector2, last_write_value_); | 525 EXPECT_EQ(test_vector2, last_write_value_); |
| 525 #endif | 526 #endif |
| 526 | 527 |
| 527 EXPECT_EQ(2, gatt_write_characteristic_attempts_); | |
| 528 EXPECT_EQ(0, callback_count_); | 528 EXPECT_EQ(0, callback_count_); |
| 529 EXPECT_EQ(0, error_callback_count_); | 529 EXPECT_EQ(0, error_callback_count_); |
| 530 | 530 |
| 531 SimulateGattCharacteristicWrite(characteristic1_); | 531 SimulateGattCharacteristicWrite(characteristic1_); |
| 532 #ifndef OS_ANDROID | 532 #ifndef OS_ANDROID |
| 533 EXPECT_EQ(test_vector1, last_write_value_); | 533 EXPECT_EQ(test_vector1, last_write_value_); |
| 534 #endif | 534 #endif |
| 535 | 535 |
| 536 SimulateGattCharacteristicWrite(characteristic2_); | 536 SimulateGattCharacteristicWrite(characteristic2_); |
| 537 #ifndef OS_ANDROID | 537 #ifndef OS_ANDROID |
| 538 EXPECT_EQ(test_vector2, last_write_value_); | 538 EXPECT_EQ(test_vector2, last_write_value_); |
| 539 #endif | 539 #endif |
| 540 | 540 |
| 541 EXPECT_EQ(2, gatt_write_characteristic_attempts_); | |
| 541 EXPECT_EQ(2, callback_count_); | 542 EXPECT_EQ(2, callback_count_); |
| 542 EXPECT_EQ(0, error_callback_count_); | 543 EXPECT_EQ(0, error_callback_count_); |
| 543 | 544 |
| 544 // TODO(591740): Remove if define for OS_ANDROID in this test. | 545 // TODO(591740): Remove if define for OS_ANDROID in this test. |
| 545 } | 546 } |
| 546 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 547 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 547 | 548 |
| 548 #if defined(OS_ANDROID) || defined(OS_WIN) | 549 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 549 // Tests ReadRemoteCharacteristic asynchronous error. | 550 // Tests ReadRemoteCharacteristic asynchronous error. |
| 550 TEST_F(BluetoothGattCharacteristicTest, ReadError) { | 551 TEST_F(BluetoothGattCharacteristicTest, ReadError) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 last_gatt_error_code_); | 751 last_gatt_error_code_); |
| 751 | 752 |
| 752 // Initial read should still succeed: | 753 // Initial read should still succeed: |
| 753 ResetEventCounts(); | 754 ResetEventCounts(); |
| 754 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 755 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 755 EXPECT_EQ(1, callback_count_); | 756 EXPECT_EQ(1, callback_count_); |
| 756 EXPECT_EQ(0, error_callback_count_); | 757 EXPECT_EQ(0, error_callback_count_); |
| 757 } | 758 } |
| 758 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 759 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 759 | 760 |
| 760 #if defined(OS_ANDROID) | 761 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 761 // StartNotifySession fails if characteristic doesn't have Notify or Indicate | 762 // StartNotifySession fails if characteristic doesn't have Notify or Indicate |
| 762 // property. | 763 // property. |
| 763 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) { | 764 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) { |
| 764 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 765 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 765 /* properties: NOTIFY */ 0x10, | 766 /* properties: NOTIFY */ 0x10, |
| 766 /* expected_config_descriptor_value: NOTIFY */ 1, | 767 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 767 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); | 768 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); |
| 768 | 769 |
| 769 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 770 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 770 | 771 |
| 771 // The expected error callback is asynchronous: | 772 // The expected error callback is asynchronous: |
| 772 EXPECT_EQ(0, error_callback_count_); | 773 EXPECT_EQ(0, error_callback_count_); |
| 773 base::RunLoop().RunUntilIdle(); | 774 base::RunLoop().RunUntilIdle(); |
| 774 EXPECT_EQ(1, error_callback_count_); | 775 EXPECT_EQ(1, error_callback_count_); |
| 776 // TODO(crbug.com/584369) Android doesn't return the correct errors. | |
| 777 #if !defined(OS_ANDROID) | |
|
ortuno
2016/03/30 22:34:23
You no longer need this #if.
gogerald1
2016/03/31 17:44:13
Done.
| |
| 778 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, | |
| 779 last_gatt_error_code_); | |
| 780 #endif // !defined(OS_ANDROID) | |
| 775 } | 781 } |
| 776 #endif // defined(OS_ANDROID) | 782 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 777 | 783 |
| 778 #if defined(OS_ANDROID) | 784 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 779 // StartNotifySession fails if the characteristic is missing the Client | 785 // StartNotifySession fails if the characteristic is missing the Client |
| 780 // Characteristic Configuration descriptor. | 786 // Characteristic Configuration descriptor. |
| 781 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoConfigDescriptor) { | 787 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoConfigDescriptor) { |
| 782 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 788 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 783 /* properties: NOTIFY */ 0x10, | 789 /* properties: NOTIFY */ 0x10, |
| 784 /* expected_config_descriptor_value: NOTIFY */ 1, | 790 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 785 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); | 791 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); |
| 786 | 792 |
| 787 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 793 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 788 | 794 |
| 789 // The expected error callback is asynchronous: | 795 // The expected error callback is asynchronous: |
| 790 EXPECT_EQ(0, error_callback_count_); | 796 EXPECT_EQ(0, error_callback_count_); |
| 791 base::RunLoop().RunUntilIdle(); | 797 base::RunLoop().RunUntilIdle(); |
| 792 EXPECT_EQ(1, error_callback_count_); | 798 EXPECT_EQ(1, error_callback_count_); |
| 793 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, | 799 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, |
| 794 last_gatt_error_code_); | 800 last_gatt_error_code_); |
| 795 } | 801 } |
| 796 #endif // defined(OS_ANDROID) | 802 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 797 | 803 |
| 798 #if defined(OS_ANDROID) | 804 #if defined(OS_ANDROID) |
|
ortuno
2016/03/30 22:34:23
See below. You can make this test pass if you use
gogerald1
2016/03/31 17:44:13
Done.
| |
| 799 // StartNotifySession fails if the characteristic has multiple Client | 805 // StartNotifySession fails if the characteristic has multiple Client |
| 800 // Characteristic Configuration descriptors. | 806 // Characteristic Configuration descriptors. |
| 801 TEST_F(BluetoothGattCharacteristicTest, | 807 TEST_F(BluetoothGattCharacteristicTest, |
| 802 StartNotifySession_MultipleConfigDescriptor) { | 808 StartNotifySession_MultipleConfigDescriptor) { |
| 803 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 809 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 804 /* properties: NOTIFY */ 0x10, | 810 /* properties: NOTIFY */ 0x10, |
| 805 /* expected_config_descriptor_value: NOTIFY */ 1, | 811 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 806 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); | 812 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); |
| 807 | 813 |
| 808 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 814 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 809 | 815 |
| 810 // The expected error callback is asynchronous: | 816 // The expected error callback is asynchronous: |
| 811 EXPECT_EQ(0, error_callback_count_); | 817 EXPECT_EQ(0, error_callback_count_); |
| 812 base::RunLoop().RunUntilIdle(); | 818 base::RunLoop().RunUntilIdle(); |
| 813 EXPECT_EQ(1, error_callback_count_); | 819 EXPECT_EQ(1, error_callback_count_); |
| 814 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); | 820 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); |
| 815 } | 821 } |
| 816 #endif // defined(OS_ANDROID) | 822 #endif // defined(OS_ANDROID) |
| 817 | 823 |
| 818 #if defined(OS_ANDROID) | 824 #if defined(OS_ANDROID) |
| 819 // StartNotifySession fails synchronously when failing to set a characteristic | 825 // StartNotifySession fails synchronously when failing to set a characteristic |
| 820 // to enable notifications. | 826 // to enable notifications. |
| 821 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. | 827 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. |
| 828 // Windows: Characteristic notification is set to OS asynchronously. | |
|
ortuno
2016/03/30 22:34:23
You need a test to make sure that an error from Re
gogerald1
2016/03/31 17:44:13
Postpone to follow up CL.
| |
| 822 TEST_F(BluetoothGattCharacteristicTest, | 829 TEST_F(BluetoothGattCharacteristicTest, |
| 823 StartNotifySession_FailToSetCharacteristicNotification) { | 830 StartNotifySession_FailToSetCharacteristicNotification) { |
| 824 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 831 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 825 /* properties: NOTIFY */ 0x10, | 832 /* properties: NOTIFY */ 0x10, |
| 826 /* expected_config_descriptor_value: NOTIFY */ 1, | 833 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 827 StartNotifySetupError::SET_NOTIFY)); | 834 StartNotifySetupError::SET_NOTIFY)); |
| 828 | 835 |
| 829 // The expected error callback is asynchronous: | 836 // The expected error callback is asynchronous: |
| 830 EXPECT_EQ(0, error_callback_count_); | 837 EXPECT_EQ(0, error_callback_count_); |
| 831 base::RunLoop().RunUntilIdle(); | 838 base::RunLoop().RunUntilIdle(); |
| 832 EXPECT_EQ(1, error_callback_count_); | 839 EXPECT_EQ(1, error_callback_count_); |
| 833 | 840 |
| 834 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 841 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 835 ASSERT_EQ(0u, notify_sessions_.size()); | 842 ASSERT_EQ(0u, notify_sessions_.size()); |
| 836 } | 843 } |
| 837 #endif // defined(OS_ANDROID) | 844 #endif // defined(OS_ANDROID) |
| 838 | 845 |
| 839 #if defined(OS_ANDROID) | 846 #if defined(OS_ANDROID) |
| 840 // Tests StartNotifySession descriptor write synchronous failure. | 847 // Tests StartNotifySession descriptor write synchronous failure. |
| 848 // Windows: The Client Characteristic Configuration descriptor is written to OS | |
| 849 // asynchronously. | |
| 841 TEST_F(BluetoothGattCharacteristicTest, | 850 TEST_F(BluetoothGattCharacteristicTest, |
| 842 StartNotifySession_WriteDescriptorSynchronousError) { | 851 StartNotifySession_WriteDescriptorSynchronousError) { |
| 843 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 852 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 844 /* properties: NOTIFY */ 0x10, | 853 /* properties: NOTIFY */ 0x10, |
| 845 /* expected_config_descriptor_value: NOTIFY */ 1, | 854 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 846 StartNotifySetupError::WRITE_DESCRIPTOR)); | 855 StartNotifySetupError::WRITE_DESCRIPTOR)); |
| 847 | 856 |
| 848 // The expected error callback is asynchronous: | 857 // The expected error callback is asynchronous: |
| 849 EXPECT_EQ(0, error_callback_count_); | 858 EXPECT_EQ(0, error_callback_count_); |
| 850 base::RunLoop().RunUntilIdle(); | 859 base::RunLoop().RunUntilIdle(); |
| 851 EXPECT_EQ(1, error_callback_count_); | 860 EXPECT_EQ(1, error_callback_count_); |
| 852 | 861 |
| 853 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 862 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 854 ASSERT_EQ(0u, notify_sessions_.size()); | 863 ASSERT_EQ(0u, notify_sessions_.size()); |
| 855 } | 864 } |
| 856 #endif // defined(OS_ANDROID) | 865 #endif // defined(OS_ANDROID) |
| 857 | 866 |
| 858 #if defined(OS_ANDROID) | 867 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 859 // Tests StartNotifySession success on a characteristic enabling Notify. | 868 // Tests StartNotifySession success on a characteristic enabling Notify. |
| 860 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) { | 869 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) { |
| 861 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 870 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 862 /* properties: NOTIFY */ 0x10, | 871 /* properties: NOTIFY */ 0x10, |
| 863 /* expected_config_descriptor_value: NOTIFY */ 1)); | 872 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 864 } | 873 } |
| 865 #endif // defined(OS_ANDROID) | 874 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 866 | 875 |
| 867 #if defined(OS_ANDROID) | 876 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 868 // Tests StartNotifySession success on a characteristic enabling Indicate. | 877 // Tests StartNotifySession success on a characteristic enabling Indicate. |
| 869 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_OnIndicate) { | 878 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_OnIndicate) { |
| 870 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 879 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 871 /* properties: INDICATE */ 0x20, | 880 /* properties: INDICATE */ 0x20, |
| 872 /* expected_config_descriptor_value: INDICATE */ 2)); | 881 /* expected_config_descriptor_value: INDICATE */ 2)); |
| 873 } | 882 } |
| 874 #endif // defined(OS_ANDROID) | 883 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 875 | 884 |
| 876 #if defined(OS_ANDROID) | 885 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 877 // Tests StartNotifySession success on a characteristic enabling Notify & | 886 // Tests StartNotifySession success on a characteristic enabling Notify & |
| 878 // Indicate. | 887 // Indicate. |
| 879 TEST_F(BluetoothGattCharacteristicTest, | 888 TEST_F(BluetoothGattCharacteristicTest, |
| 880 StartNotifySession_OnNotifyAndIndicate) { | 889 StartNotifySession_OnNotifyAndIndicate) { |
| 881 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 890 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 882 /* properties: NOTIFY and INDICATE bits set */ 0x30, | 891 /* properties: NOTIFY and INDICATE bits set */ 0x30, |
| 883 /* expected_config_descriptor_value: NOTIFY */ 1)); | 892 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 884 } | 893 } |
| 885 #endif // defined(OS_ANDROID) | 894 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 886 | 895 |
| 887 #if defined(OS_ANDROID) | 896 #if defined(OS_ANDROID) || defined(OS_WIN) |
|
ortuno
2016/03/30 22:34:23
We also need a test for when BluetoothGattSetDescr
gogerald1
2016/03/31 17:44:13
Postpone to follow up CL.
| |
| 888 // Tests multiple StartNotifySession success. | 897 // Tests multiple StartNotifySession success. |
| 889 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { | 898 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| 890 ASSERT_NO_FATAL_FAILURE( | 899 ASSERT_NO_FATAL_FAILURE( |
| 891 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 900 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 892 SimulateGattDescriptor( | 901 SimulateGattDescriptor( |
| 893 characteristic1_, | 902 characteristic1_, |
| 894 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() | 903 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 895 .canonical_value()); | 904 .canonical_value()); |
| 896 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 905 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 897 | 906 |
| 898 characteristic1_->StartNotifySession( | 907 characteristic1_->StartNotifySession( |
| 899 GetNotifyCallback(Call::EXPECTED), | 908 GetNotifyCallback(Call::EXPECTED), |
| 900 GetGattErrorCallback(Call::NOT_EXPECTED)); | 909 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 901 characteristic1_->StartNotifySession( | 910 characteristic1_->StartNotifySession( |
| 902 GetNotifyCallback(Call::EXPECTED), | 911 GetNotifyCallback(Call::EXPECTED), |
| 903 GetGattErrorCallback(Call::NOT_EXPECTED)); | 912 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 904 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 905 EXPECT_EQ(0, callback_count_); | 913 EXPECT_EQ(0, callback_count_); |
| 906 SimulateGattNotifySessionStarted(characteristic1_); | 914 SimulateGattNotifySessionStarted(characteristic1_); |
| 915 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 907 EXPECT_EQ(2, callback_count_); | 916 EXPECT_EQ(2, callback_count_); |
| 908 EXPECT_EQ(0, error_callback_count_); | 917 EXPECT_EQ(0, error_callback_count_); |
| 909 ASSERT_EQ(2u, notify_sessions_.size()); | 918 ASSERT_EQ(2u, notify_sessions_.size()); |
| 910 ASSERT_TRUE(notify_sessions_[0]); | 919 ASSERT_TRUE(notify_sessions_[0]); |
| 911 ASSERT_TRUE(notify_sessions_[1]); | 920 ASSERT_TRUE(notify_sessions_[1]); |
| 912 EXPECT_EQ(characteristic1_->GetIdentifier(), | 921 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 913 notify_sessions_[0]->GetCharacteristicIdentifier()); | 922 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 914 EXPECT_EQ(characteristic1_->GetIdentifier(), | 923 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 915 notify_sessions_[1]->GetCharacteristicIdentifier()); | 924 notify_sessions_[1]->GetCharacteristicIdentifier()); |
| 916 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 925 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 917 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 926 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 918 } | 927 } |
| 919 #endif // defined(OS_ANDROID) | 928 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 920 | 929 |
| 921 #if defined(OS_ANDROID) | 930 #if defined(OS_ANDROID) |
| 922 // Tests multiple StartNotifySessions pending and then an error. | 931 // Tests multiple StartNotifySessions pending and then an error. |
| 923 TEST_F(BluetoothGattCharacteristicTest, StartNotifySessionError_Multiple) { | 932 TEST_F(BluetoothGattCharacteristicTest, StartNotifySessionError_Multiple) { |
| 924 ASSERT_NO_FATAL_FAILURE( | 933 ASSERT_NO_FATAL_FAILURE( |
| 925 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 934 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 926 SimulateGattDescriptor( | 935 SimulateGattDescriptor( |
| 927 characteristic1_, | 936 characteristic1_, |
| 928 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() | 937 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 929 .canonical_value()); | 938 .canonical_value()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 965 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 974 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 966 | 975 |
| 967 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); | 976 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); |
| 968 EXPECT_EQ(0, callback_count_); | 977 EXPECT_EQ(0, callback_count_); |
| 969 EXPECT_EQ(1, error_callback_count_); | 978 EXPECT_EQ(1, error_callback_count_); |
| 970 ASSERT_EQ(0u, notify_sessions_.size()); | 979 ASSERT_EQ(0u, notify_sessions_.size()); |
| 971 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); | 980 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); |
| 972 } | 981 } |
| 973 #endif // defined(OS_ANDROID) | 982 #endif // defined(OS_ANDROID) |
| 974 | 983 |
| 975 #if defined(OS_ANDROID) | 984 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 976 // Tests Characteristic Value changes during a Notify Session. | 985 // Tests Characteristic Value changes during a Notify Session. |
| 977 TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { | 986 TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { |
| 978 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 987 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 979 /* properties: NOTIFY */ 0x10, | 988 /* properties: NOTIFY */ 0x10, |
| 980 /* expected_config_descriptor_value: NOTIFY */ 1)); | 989 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 981 | 990 |
| 982 TestBluetoothAdapterObserver observer(adapter_); | 991 TestBluetoothAdapterObserver observer(adapter_); |
| 983 | 992 |
| 984 std::vector<uint8_t> test_vector1, test_vector2; | 993 std::vector<uint8_t> test_vector1, test_vector2; |
| 985 test_vector1.push_back(111); | 994 test_vector1.push_back(111); |
| 986 test_vector2.push_back(222); | 995 test_vector2.push_back(222); |
| 987 | 996 |
| 988 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); | 997 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); |
| 989 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 998 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
| 990 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); | 999 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| 991 | 1000 |
| 992 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); | 1001 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); |
| 993 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); | 1002 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
| 994 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); | 1003 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); |
| 995 } | 1004 } |
| 996 #endif // defined(OS_ANDROID) | 1005 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 997 | 1006 |
| 998 #if defined(OS_ANDROID) | 1007 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 999 // Tests Characteristic Value changing after a Notify Session and objects being | 1008 // Tests Characteristic Value changing after a Notify Session and objects being |
| 1000 // destroyed. | 1009 // destroyed. |
| 1001 TEST_F(BluetoothGattCharacteristicTest, | 1010 TEST_F(BluetoothGattCharacteristicTest, |
| 1002 GattCharacteristicValueChanged_AfterDeleted) { | 1011 GattCharacteristicValueChanged_AfterDeleted) { |
| 1003 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1012 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1004 /* properties: NOTIFY */ 0x10, | 1013 /* properties: NOTIFY */ 0x10, |
| 1005 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1014 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 1006 TestBluetoothAdapterObserver observer(adapter_); | 1015 TestBluetoothAdapterObserver observer(adapter_); |
| 1007 | 1016 |
| 1008 RememberCharacteristicForSubsequentAction(characteristic1_); | 1017 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 1009 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1018 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1010 | 1019 |
| 1011 std::vector<uint8_t> empty_vector; | 1020 std::vector<uint8_t> empty_vector; |
| 1012 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, | 1021 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, |
| 1013 empty_vector); | 1022 empty_vector); |
| 1014 EXPECT_TRUE("Did not crash!"); | 1023 EXPECT_TRUE("Did not crash!"); |
| 1015 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 1024 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
| 1016 } | 1025 } |
| 1017 #endif // defined(OS_ANDROID) | 1026 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 1018 | 1027 |
| 1019 #if defined(OS_ANDROID) || defined(OS_WIN) | 1028 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 1020 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { | 1029 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { |
| 1021 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 1030 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
| 1022 | 1031 |
| 1023 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); | 1032 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); |
| 1024 } | 1033 } |
| 1025 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 1034 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 1026 | 1035 |
| 1027 #if defined(OS_ANDROID) || defined(OS_WIN) | 1036 #if defined(OS_ANDROID) || defined(OS_WIN) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); | 1102 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); |
| 1094 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); | 1103 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); |
| 1095 | 1104 |
| 1096 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); | 1105 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); |
| 1097 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); | 1106 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); |
| 1098 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); | 1107 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); |
| 1099 } | 1108 } |
| 1100 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 1109 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 1101 | 1110 |
| 1102 } // namespace device | 1111 } // namespace device |
| OLD | NEW |