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 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, | |
| 777 last_gatt_error_code_); | |
| 775 } | 778 } |
| 776 #endif // defined(OS_ANDROID) | 779 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 777 | 780 |
| 778 #if defined(OS_ANDROID) | 781 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 779 // StartNotifySession fails if the characteristic is missing the Client | 782 // StartNotifySession fails if the characteristic is missing the Client |
| 780 // Characteristic Configuration descriptor. | 783 // Characteristic Configuration descriptor. |
| 781 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoConfigDescriptor) { | 784 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoConfigDescriptor) { |
| 782 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 785 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 783 /* properties: NOTIFY */ 0x10, | 786 /* properties: NOTIFY */ 0x10, |
| 784 /* expected_config_descriptor_value: NOTIFY */ 1, | 787 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 785 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); | 788 StartNotifySetupError::CONFIG_DESCRIPTOR_MISSING)); |
| 786 | 789 |
| 787 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 790 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 788 | 791 |
| 789 // The expected error callback is asynchronous: | 792 // The expected error callback is asynchronous: |
| 790 EXPECT_EQ(0, error_callback_count_); | 793 EXPECT_EQ(0, error_callback_count_); |
| 791 base::RunLoop().RunUntilIdle(); | 794 base::RunLoop().RunUntilIdle(); |
| 792 EXPECT_EQ(1, error_callback_count_); | 795 EXPECT_EQ(1, error_callback_count_); |
| 793 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, | 796 EXPECT_EQ(BluetoothGattService::GATT_ERROR_NOT_SUPPORTED, |
| 794 last_gatt_error_code_); | 797 last_gatt_error_code_); |
| 795 } | 798 } |
| 796 #endif // defined(OS_ANDROID) | 799 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 797 | 800 |
| 798 #if defined(OS_ANDROID) | 801 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 799 // StartNotifySession fails if the characteristic has multiple Client | 802 // StartNotifySession fails if the characteristic has multiple Client |
| 800 // Characteristic Configuration descriptors. | 803 // Characteristic Configuration descriptors. |
| 801 TEST_F(BluetoothGattCharacteristicTest, | 804 TEST_F(BluetoothGattCharacteristicTest, |
| 802 StartNotifySession_MultipleConfigDescriptor) { | 805 StartNotifySession_MultipleConfigDescriptor) { |
| 803 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 806 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 804 /* properties: NOTIFY */ 0x10, | 807 /* properties: NOTIFY */ 0x10, |
| 805 /* expected_config_descriptor_value: NOTIFY */ 1, | 808 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 806 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); | 809 StartNotifySetupError::CONFIG_DESCRIPTOR_DUPLICATE)); |
| 807 | 810 |
| 808 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 811 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 809 | 812 |
| 810 // The expected error callback is asynchronous: | 813 // The expected error callback is asynchronous: |
| 811 EXPECT_EQ(0, error_callback_count_); | 814 EXPECT_EQ(0, error_callback_count_); |
| 812 base::RunLoop().RunUntilIdle(); | 815 base::RunLoop().RunUntilIdle(); |
| 813 EXPECT_EQ(1, error_callback_count_); | 816 EXPECT_EQ(1, error_callback_count_); |
| 814 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); | 817 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); |
| 815 } | 818 } |
| 816 #endif // defined(OS_ANDROID) | 819 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 817 | 820 |
| 818 #if defined(OS_ANDROID) | 821 #if defined(OS_ANDROID) |
| 819 // StartNotifySession fails synchronously when failing to set a characteristic | 822 // StartNotifySession fails synchronously when failing to set a characteristic |
| 820 // to enable notifications. | 823 // to enable notifications. |
| 821 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. | 824 // Android: This is mBluetoothGatt.setCharacteristicNotification failing. |
| 825 // Windows: Characteristic notification is set to OS asynchronously. | |
|
scheib
2016/04/05 22:44:02
Windows: Synchronous Test Not Applicable: OS calls
gogerald1
2016/04/06 22:54:48
Done.
| |
| 822 TEST_F(BluetoothGattCharacteristicTest, | 826 TEST_F(BluetoothGattCharacteristicTest, |
| 823 StartNotifySession_FailToSetCharacteristicNotification) { | 827 StartNotifySession_FailToSetCharacteristicNotification) { |
| 824 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 828 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 825 /* properties: NOTIFY */ 0x10, | 829 /* properties: NOTIFY */ 0x10, |
| 826 /* expected_config_descriptor_value: NOTIFY */ 1, | 830 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 827 StartNotifySetupError::SET_NOTIFY)); | 831 StartNotifySetupError::SET_NOTIFY)); |
| 828 | 832 |
| 829 // The expected error callback is asynchronous: | 833 // The expected error callback is asynchronous: |
| 830 EXPECT_EQ(0, error_callback_count_); | 834 EXPECT_EQ(0, error_callback_count_); |
| 831 base::RunLoop().RunUntilIdle(); | 835 base::RunLoop().RunUntilIdle(); |
| 832 EXPECT_EQ(1, error_callback_count_); | 836 EXPECT_EQ(1, error_callback_count_); |
| 833 | 837 |
| 834 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); | 838 EXPECT_EQ(0, gatt_notify_characteristic_attempts_); |
| 835 ASSERT_EQ(0u, notify_sessions_.size()); | 839 ASSERT_EQ(0u, notify_sessions_.size()); |
| 836 } | 840 } |
| 837 #endif // defined(OS_ANDROID) | 841 #endif // defined(OS_ANDROID) |
| 838 | 842 |
| 839 #if defined(OS_ANDROID) | 843 #if defined(OS_ANDROID) |
| 840 // Tests StartNotifySession descriptor write synchronous failure. | 844 // Tests StartNotifySession descriptor write synchronous failure. |
| 845 // Windows: The Client Characteristic Configuration descriptor is written to OS | |
| 846 // asynchronously. | |
| 841 TEST_F(BluetoothGattCharacteristicTest, | 847 TEST_F(BluetoothGattCharacteristicTest, |
| 842 StartNotifySession_WriteDescriptorSynchronousError) { | 848 StartNotifySession_WriteDescriptorSynchronousError) { |
| 843 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 849 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 844 /* properties: NOTIFY */ 0x10, | 850 /* properties: NOTIFY */ 0x10, |
| 845 /* expected_config_descriptor_value: NOTIFY */ 1, | 851 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 846 StartNotifySetupError::WRITE_DESCRIPTOR)); | 852 StartNotifySetupError::WRITE_DESCRIPTOR)); |
| 847 | 853 |
| 848 // The expected error callback is asynchronous: | 854 // The expected error callback is asynchronous: |
| 849 EXPECT_EQ(0, error_callback_count_); | 855 EXPECT_EQ(0, error_callback_count_); |
| 850 base::RunLoop().RunUntilIdle(); | 856 base::RunLoop().RunUntilIdle(); |
| 851 EXPECT_EQ(1, error_callback_count_); | 857 EXPECT_EQ(1, error_callback_count_); |
| 852 | 858 |
| 853 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | 859 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); |
| 854 ASSERT_EQ(0u, notify_sessions_.size()); | 860 ASSERT_EQ(0u, notify_sessions_.size()); |
| 855 } | 861 } |
| 856 #endif // defined(OS_ANDROID) | 862 #endif // defined(OS_ANDROID) |
| 857 | 863 |
| 858 #if defined(OS_ANDROID) | 864 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 859 // Tests StartNotifySession success on a characteristic enabling Notify. | 865 // Tests StartNotifySession success on a characteristic enabling Notify. |
| 860 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) { | 866 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession) { |
| 861 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 867 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 862 /* properties: NOTIFY */ 0x10, | 868 /* properties: NOTIFY */ 0x10, |
| 863 /* expected_config_descriptor_value: NOTIFY */ 1)); | 869 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 864 } | 870 } |
| 865 #endif // defined(OS_ANDROID) | 871 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 866 | 872 |
| 867 #if defined(OS_ANDROID) | 873 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 868 // Tests StartNotifySession success on a characteristic enabling Indicate. | 874 // Tests StartNotifySession success on a characteristic enabling Indicate. |
| 869 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_OnIndicate) { | 875 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_OnIndicate) { |
| 870 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 876 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 871 /* properties: INDICATE */ 0x20, | 877 /* properties: INDICATE */ 0x20, |
| 872 /* expected_config_descriptor_value: INDICATE */ 2)); | 878 /* expected_config_descriptor_value: INDICATE */ 2)); |
| 873 } | 879 } |
| 874 #endif // defined(OS_ANDROID) | 880 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 875 | 881 |
| 876 #if defined(OS_ANDROID) | 882 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 877 // Tests StartNotifySession success on a characteristic enabling Notify & | 883 // Tests StartNotifySession success on a characteristic enabling Notify & |
| 878 // Indicate. | 884 // Indicate. |
| 879 TEST_F(BluetoothGattCharacteristicTest, | 885 TEST_F(BluetoothGattCharacteristicTest, |
| 880 StartNotifySession_OnNotifyAndIndicate) { | 886 StartNotifySession_OnNotifyAndIndicate) { |
| 881 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 887 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 882 /* properties: NOTIFY and INDICATE bits set */ 0x30, | 888 /* properties: NOTIFY and INDICATE bits set */ 0x30, |
| 883 /* expected_config_descriptor_value: NOTIFY */ 1)); | 889 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 884 } | 890 } |
| 885 #endif // defined(OS_ANDROID) | 891 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 886 | 892 |
| 887 #if defined(OS_ANDROID) | 893 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 888 // Tests multiple StartNotifySession success. | 894 // Tests multiple StartNotifySession success. |
| 889 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { | 895 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_Multiple) { |
| 890 ASSERT_NO_FATAL_FAILURE( | 896 ASSERT_NO_FATAL_FAILURE( |
| 891 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 897 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 892 SimulateGattDescriptor( | 898 SimulateGattDescriptor( |
| 893 characteristic1_, | 899 characteristic1_, |
| 894 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() | 900 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 895 .canonical_value()); | 901 .canonical_value()); |
| 896 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); | 902 ASSERT_EQ(1u, characteristic1_->GetDescriptors().size()); |
| 897 | 903 |
| 898 characteristic1_->StartNotifySession( | 904 characteristic1_->StartNotifySession( |
| 899 GetNotifyCallback(Call::EXPECTED), | 905 GetNotifyCallback(Call::EXPECTED), |
| 900 GetGattErrorCallback(Call::NOT_EXPECTED)); | 906 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 901 characteristic1_->StartNotifySession( | 907 characteristic1_->StartNotifySession( |
| 902 GetNotifyCallback(Call::EXPECTED), | 908 GetNotifyCallback(Call::EXPECTED), |
| 903 GetGattErrorCallback(Call::NOT_EXPECTED)); | 909 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 904 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 905 EXPECT_EQ(0, callback_count_); | 910 EXPECT_EQ(0, callback_count_); |
| 906 SimulateGattNotifySessionStarted(characteristic1_); | 911 SimulateGattNotifySessionStarted(characteristic1_); |
| 912 EXPECT_EQ(1, gatt_notify_characteristic_attempts_); | |
| 907 EXPECT_EQ(2, callback_count_); | 913 EXPECT_EQ(2, callback_count_); |
| 908 EXPECT_EQ(0, error_callback_count_); | 914 EXPECT_EQ(0, error_callback_count_); |
| 909 ASSERT_EQ(2u, notify_sessions_.size()); | 915 ASSERT_EQ(2u, notify_sessions_.size()); |
| 910 ASSERT_TRUE(notify_sessions_[0]); | 916 ASSERT_TRUE(notify_sessions_[0]); |
| 911 ASSERT_TRUE(notify_sessions_[1]); | 917 ASSERT_TRUE(notify_sessions_[1]); |
| 912 EXPECT_EQ(characteristic1_->GetIdentifier(), | 918 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 913 notify_sessions_[0]->GetCharacteristicIdentifier()); | 919 notify_sessions_[0]->GetCharacteristicIdentifier()); |
| 914 EXPECT_EQ(characteristic1_->GetIdentifier(), | 920 EXPECT_EQ(characteristic1_->GetIdentifier(), |
| 915 notify_sessions_[1]->GetCharacteristicIdentifier()); | 921 notify_sessions_[1]->GetCharacteristicIdentifier()); |
| 916 EXPECT_TRUE(notify_sessions_[0]->IsActive()); | 922 EXPECT_TRUE(notify_sessions_[0]->IsActive()); |
| 917 EXPECT_TRUE(notify_sessions_[1]->IsActive()); | 923 EXPECT_TRUE(notify_sessions_[1]->IsActive()); |
| 918 } | 924 } |
| 919 #endif // defined(OS_ANDROID) | 925 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 920 | 926 |
| 921 #if defined(OS_ANDROID) | 927 #if defined(OS_ANDROID) |
| 922 // Tests multiple StartNotifySessions pending and then an error. | 928 // Tests multiple StartNotifySessions pending and then an error. |
| 923 TEST_F(BluetoothGattCharacteristicTest, StartNotifySessionError_Multiple) { | 929 TEST_F(BluetoothGattCharacteristicTest, StartNotifySessionError_Multiple) { |
| 924 ASSERT_NO_FATAL_FAILURE( | 930 ASSERT_NO_FATAL_FAILURE( |
| 925 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); | 931 FakeCharacteristicBoilerplate(/* properties: NOTIFY */ 0x10)); |
| 926 SimulateGattDescriptor( | 932 SimulateGattDescriptor( |
| 927 characteristic1_, | 933 characteristic1_, |
| 928 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() | 934 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid() |
| 929 .canonical_value()); | 935 .canonical_value()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 965 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 971 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 966 | 972 |
| 967 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); | 973 SimulateGattNotifySessionStarted(/* use remembered characteristic */ nullptr); |
| 968 EXPECT_EQ(0, callback_count_); | 974 EXPECT_EQ(0, callback_count_); |
| 969 EXPECT_EQ(1, error_callback_count_); | 975 EXPECT_EQ(1, error_callback_count_); |
| 970 ASSERT_EQ(0u, notify_sessions_.size()); | 976 ASSERT_EQ(0u, notify_sessions_.size()); |
| 971 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); | 977 EXPECT_EQ(BluetoothGattService::GATT_ERROR_FAILED, last_gatt_error_code_); |
| 972 } | 978 } |
| 973 #endif // defined(OS_ANDROID) | 979 #endif // defined(OS_ANDROID) |
| 974 | 980 |
| 975 #if defined(OS_ANDROID) | 981 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 976 // Tests Characteristic Value changes during a Notify Session. | 982 // Tests Characteristic Value changes during a Notify Session. |
| 977 TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { | 983 TEST_F(BluetoothGattCharacteristicTest, GattCharacteristicValueChanged) { |
| 978 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 984 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 979 /* properties: NOTIFY */ 0x10, | 985 /* properties: NOTIFY */ 0x10, |
| 980 /* expected_config_descriptor_value: NOTIFY */ 1)); | 986 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 981 | 987 |
| 982 TestBluetoothAdapterObserver observer(adapter_); | 988 TestBluetoothAdapterObserver observer(adapter_); |
| 983 | 989 |
| 984 std::vector<uint8_t> test_vector1, test_vector2; | 990 std::vector<uint8_t> test_vector1, test_vector2; |
| 985 test_vector1.push_back(111); | 991 test_vector1.push_back(111); |
| 986 test_vector2.push_back(222); | 992 test_vector2.push_back(222); |
| 987 | 993 |
| 988 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); | 994 SimulateGattCharacteristicChanged(characteristic1_, test_vector1); |
| 989 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); | 995 EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count()); |
| 990 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); | 996 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| 991 | 997 |
| 992 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); | 998 SimulateGattCharacteristicChanged(characteristic1_, test_vector2); |
| 993 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); | 999 EXPECT_EQ(2, observer.gatt_characteristic_value_changed_count()); |
| 994 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); | 1000 EXPECT_EQ(test_vector2, characteristic1_->GetValue()); |
| 995 } | 1001 } |
| 996 #endif // defined(OS_ANDROID) | 1002 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 997 | 1003 |
| 998 #if defined(OS_ANDROID) | 1004 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 999 // Tests Characteristic Value changing after a Notify Session and objects being | 1005 // Tests Characteristic Value changing after a Notify Session and objects being |
| 1000 // destroyed. | 1006 // destroyed. |
| 1001 TEST_F(BluetoothGattCharacteristicTest, | 1007 TEST_F(BluetoothGattCharacteristicTest, |
| 1002 GattCharacteristicValueChanged_AfterDeleted) { | 1008 GattCharacteristicValueChanged_AfterDeleted) { |
| 1003 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 1009 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 1004 /* properties: NOTIFY */ 0x10, | 1010 /* properties: NOTIFY */ 0x10, |
| 1005 /* expected_config_descriptor_value: NOTIFY */ 1)); | 1011 /* expected_config_descriptor_value: NOTIFY */ 1)); |
| 1006 TestBluetoothAdapterObserver observer(adapter_); | 1012 TestBluetoothAdapterObserver observer(adapter_); |
| 1007 | 1013 |
| 1008 RememberCharacteristicForSubsequentAction(characteristic1_); | 1014 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 1009 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 1015 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 1010 | 1016 |
| 1011 std::vector<uint8_t> empty_vector; | 1017 std::vector<uint8_t> empty_vector; |
| 1012 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, | 1018 SimulateGattCharacteristicChanged(/* use remembered characteristic */ nullptr, |
| 1013 empty_vector); | 1019 empty_vector); |
| 1014 EXPECT_TRUE("Did not crash!"); | 1020 EXPECT_TRUE("Did not crash!"); |
| 1015 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); | 1021 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); |
| 1016 } | 1022 } |
| 1017 #endif // defined(OS_ANDROID) | 1023 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 1018 | 1024 |
| 1019 #if defined(OS_ANDROID) || defined(OS_WIN) | 1025 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 1020 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { | 1026 TEST_F(BluetoothGattCharacteristicTest, GetDescriptors_FindNone) { |
| 1021 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 1027 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
| 1022 | 1028 |
| 1023 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); | 1029 EXPECT_EQ(0u, characteristic1_->GetDescriptors().size()); |
| 1024 } | 1030 } |
| 1025 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 1031 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 1026 | 1032 |
| 1027 #if defined(OS_ANDROID) || defined(OS_WIN) | 1033 #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()); | 1099 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); |
| 1094 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); | 1100 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); |
| 1095 | 1101 |
| 1096 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); | 1102 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); |
| 1097 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); | 1103 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); |
| 1098 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); | 1104 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); |
| 1099 } | 1105 } |
| 1100 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 1106 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 1101 | 1107 |
| 1102 } // namespace device | 1108 } // namespace device |
| OLD | NEW |