| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 #if defined(OS_ANDROID) || defined(OS_WIN) | 257 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 258 // Tests GetService. | 258 // Tests GetService. |
| 259 TEST_F(BluetoothGattCharacteristicTest, GetService) { | 259 TEST_F(BluetoothGattCharacteristicTest, GetService) { |
| 260 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 260 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
| 261 | 261 |
| 262 EXPECT_EQ(service_, characteristic1_->GetService()); | 262 EXPECT_EQ(service_, characteristic1_->GetService()); |
| 263 EXPECT_EQ(service_, characteristic2_->GetService()); | 263 EXPECT_EQ(service_, characteristic2_->GetService()); |
| 264 } | 264 } |
| 265 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 265 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 266 | 266 |
| 267 #if defined(OS_ANDROID) | 267 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 268 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer. | 268 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer. |
| 269 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { | 269 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { |
| 270 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 270 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 271 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 271 | 272 |
| 272 characteristic1_->ReadRemoteCharacteristic( | 273 characteristic1_->ReadRemoteCharacteristic( |
| 273 GetReadValueCallback(Call::EXPECTED), | 274 GetReadValueCallback(Call::EXPECTED), |
| 274 GetGattErrorCallback(Call::NOT_EXPECTED)); | 275 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 275 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | 276 EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| 276 std::vector<uint8_t> empty_vector; | 277 std::vector<uint8_t> empty_vector; |
| 277 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 278 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 278 | 279 |
| 279 // Duplicate read reported from OS shouldn't cause a problem: | 280 // Duplicate read reported from OS shouldn't cause a problem: |
| 280 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 281 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 281 | 282 |
| 282 EXPECT_EQ(empty_vector, last_read_value_); | 283 EXPECT_EQ(empty_vector, last_read_value_); |
| 283 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); | 284 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); |
| 284 } | 285 } |
| 285 #endif // defined(OS_ANDROID) | 286 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 286 | 287 |
| 287 #if defined(OS_ANDROID) | 288 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 288 // Tests WriteRemoteCharacteristic with empty value buffer. | 289 // Tests WriteRemoteCharacteristic with empty value buffer. |
| 289 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { | 290 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { |
| 290 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 291 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 292 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 291 | 293 |
| 292 std::vector<uint8_t> empty_vector; | 294 std::vector<uint8_t> empty_vector; |
| 293 characteristic1_->WriteRemoteCharacteristic( | 295 characteristic1_->WriteRemoteCharacteristic( |
| 294 empty_vector, GetCallback(Call::EXPECTED), | 296 empty_vector, GetCallback(Call::EXPECTED), |
| 295 GetGattErrorCallback(Call::NOT_EXPECTED)); | 297 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 296 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | 298 EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| 297 SimulateGattCharacteristicWrite(characteristic1_); | 299 SimulateGattCharacteristicWrite(characteristic1_); |
| 298 | 300 |
| 299 EXPECT_EQ(empty_vector, last_write_value_); | 301 EXPECT_EQ(empty_vector, last_write_value_); |
| 300 } | 302 } |
| 301 #endif // defined(OS_ANDROID) | 303 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 302 | 304 |
| 303 #if defined(OS_ANDROID) | 305 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 304 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted. | 306 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted. |
| 305 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_AfterDeleted) { | 307 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_AfterDeleted) { |
| 306 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 308 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 309 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 307 | 310 |
| 308 characteristic1_->ReadRemoteCharacteristic( | 311 characteristic1_->ReadRemoteCharacteristic( |
| 309 GetReadValueCallback(Call::NOT_EXPECTED), | 312 GetReadValueCallback(Call::NOT_EXPECTED), |
| 310 GetGattErrorCallback(Call::NOT_EXPECTED)); | 313 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 311 | 314 |
| 312 RememberCharacteristicForSubsequentAction(characteristic1_); | 315 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 313 DeleteDevice(device_); | 316 DeleteDevice(device_); |
| 314 | 317 |
| 315 std::vector<uint8_t> empty_vector; | 318 std::vector<uint8_t> empty_vector; |
| 316 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, | 319 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, |
| 317 empty_vector); | 320 empty_vector); |
| 318 EXPECT_TRUE("Did not crash!"); | 321 EXPECT_TRUE("Did not crash!"); |
| 319 } | 322 } |
| 320 #endif // defined(OS_ANDROID) | 323 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 321 | 324 |
| 322 #if defined(OS_ANDROID) | 325 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 323 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. | 326 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. |
| 324 TEST_F(BluetoothGattCharacteristicTest, | 327 TEST_F(BluetoothGattCharacteristicTest, |
| 325 WriteRemoteCharacteristic_AfterDeleted) { | 328 WriteRemoteCharacteristic_AfterDeleted) { |
| 326 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 329 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 330 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 327 | 331 |
| 328 std::vector<uint8_t> empty_vector; | 332 std::vector<uint8_t> empty_vector; |
| 329 characteristic1_->WriteRemoteCharacteristic( | 333 characteristic1_->WriteRemoteCharacteristic( |
| 330 empty_vector, GetCallback(Call::NOT_EXPECTED), | 334 empty_vector, GetCallback(Call::NOT_EXPECTED), |
| 331 GetGattErrorCallback(Call::NOT_EXPECTED)); | 335 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 332 | 336 |
| 333 RememberCharacteristicForSubsequentAction(characteristic1_); | 337 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 334 DeleteDevice(device_); | 338 DeleteDevice(device_); |
| 335 | 339 |
| 336 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); | 340 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); |
| 337 EXPECT_TRUE("Did not crash!"); | 341 EXPECT_TRUE("Did not crash!"); |
| 338 } | 342 } |
| 339 #endif // defined(OS_ANDROID) | 343 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 340 | 344 |
| 341 #if defined(OS_ANDROID) | 345 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 342 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. | 346 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. |
| 343 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { | 347 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { |
| 344 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 348 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 349 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 345 | 350 |
| 346 characteristic1_->ReadRemoteCharacteristic( | 351 characteristic1_->ReadRemoteCharacteristic( |
| 347 GetReadValueCallback(Call::EXPECTED), | 352 GetReadValueCallback(Call::EXPECTED), |
| 348 GetGattErrorCallback(Call::NOT_EXPECTED)); | 353 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 349 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | 354 EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| 350 | 355 |
| 351 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; | 356 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| 352 std::vector<uint8_t> test_vector(values, values + arraysize(values)); | 357 std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| 353 SimulateGattCharacteristicRead(characteristic1_, test_vector); | 358 SimulateGattCharacteristicRead(characteristic1_, test_vector); |
| 354 | 359 |
| 355 // Duplicate read reported from OS shouldn't cause a problem: | 360 // Duplicate read reported from OS shouldn't cause a problem: |
| 356 std::vector<uint8_t> empty_vector; | 361 std::vector<uint8_t> empty_vector; |
| 357 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 362 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 358 | 363 |
| 359 EXPECT_EQ(test_vector, last_read_value_); | 364 EXPECT_EQ(test_vector, last_read_value_); |
| 360 EXPECT_EQ(test_vector, characteristic1_->GetValue()); | 365 EXPECT_EQ(test_vector, characteristic1_->GetValue()); |
| 361 } | 366 } |
| 362 #endif // defined(OS_ANDROID) | 367 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 363 | 368 |
| 364 #if defined(OS_ANDROID) | 369 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 365 // Tests WriteRemoteCharacteristic with non-empty value buffer. | 370 // Tests WriteRemoteCharacteristic with non-empty value buffer. |
| 366 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic) { | 371 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic) { |
| 367 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 372 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 373 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 368 | 374 |
| 369 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; | 375 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| 370 std::vector<uint8_t> test_vector(values, values + arraysize(values)); | 376 std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| 371 characteristic1_->WriteRemoteCharacteristic( | 377 characteristic1_->WriteRemoteCharacteristic( |
| 372 test_vector, GetCallback(Call::EXPECTED), | 378 test_vector, GetCallback(Call::EXPECTED), |
| 373 GetGattErrorCallback(Call::NOT_EXPECTED)); | 379 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 374 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | 380 EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| 375 | 381 |
| 376 SimulateGattCharacteristicWrite(characteristic1_); | 382 SimulateGattCharacteristicWrite(characteristic1_); |
| 377 | 383 |
| 378 EXPECT_EQ(test_vector, last_write_value_); | 384 EXPECT_EQ(test_vector, last_write_value_); |
| 379 } | 385 } |
| 380 #endif // defined(OS_ANDROID) | 386 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 381 | 387 |
| 382 #if defined(OS_ANDROID) | 388 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 383 // Tests ReadRemoteCharacteristic and GetValue multiple times. | 389 // Tests ReadRemoteCharacteristic and GetValue multiple times. |
| 384 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { | 390 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { |
| 385 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 391 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 392 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 386 | 393 |
| 387 characteristic1_->ReadRemoteCharacteristic( | 394 characteristic1_->ReadRemoteCharacteristic( |
| 388 GetReadValueCallback(Call::EXPECTED), | 395 GetReadValueCallback(Call::EXPECTED), |
| 389 GetGattErrorCallback(Call::NOT_EXPECTED)); | 396 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 390 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | 397 EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| 391 | 398 |
| 392 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; | 399 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| 393 std::vector<uint8_t> test_vector(values, values + arraysize(values)); | 400 std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| 394 SimulateGattCharacteristicRead(characteristic1_, test_vector); | 401 SimulateGattCharacteristicRead(characteristic1_, test_vector); |
| 395 EXPECT_EQ(1, callback_count_); | 402 EXPECT_EQ(1, callback_count_); |
| 396 EXPECT_EQ(0, error_callback_count_); | 403 EXPECT_EQ(0, error_callback_count_); |
| 397 EXPECT_EQ(test_vector, last_read_value_); | 404 EXPECT_EQ(test_vector, last_read_value_); |
| 398 EXPECT_EQ(test_vector, characteristic1_->GetValue()); | 405 EXPECT_EQ(test_vector, characteristic1_->GetValue()); |
| 399 | 406 |
| 400 // Read again, with different value: | 407 // Read again, with different value: |
| 401 ResetEventCounts(); | 408 ResetEventCounts(); |
| 402 characteristic1_->ReadRemoteCharacteristic( | 409 characteristic1_->ReadRemoteCharacteristic( |
| 403 GetReadValueCallback(Call::EXPECTED), | 410 GetReadValueCallback(Call::EXPECTED), |
| 404 GetGattErrorCallback(Call::NOT_EXPECTED)); | 411 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 405 EXPECT_EQ(1, gatt_read_characteristic_attempts_); | 412 EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
| 406 std::vector<uint8_t> empty_vector; | 413 std::vector<uint8_t> empty_vector; |
| 407 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 414 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 408 EXPECT_EQ(1, callback_count_); | 415 EXPECT_EQ(1, callback_count_); |
| 409 EXPECT_EQ(0, error_callback_count_); | 416 EXPECT_EQ(0, error_callback_count_); |
| 410 EXPECT_EQ(empty_vector, last_read_value_); | 417 EXPECT_EQ(empty_vector, last_read_value_); |
| 411 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); | 418 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); |
| 412 } | 419 } |
| 413 #endif // defined(OS_ANDROID) | 420 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 414 | 421 |
| 415 #if defined(OS_ANDROID) | 422 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 416 // Tests WriteRemoteCharacteristic multiple times. | 423 // Tests WriteRemoteCharacteristic multiple times. |
| 417 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { | 424 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { |
| 418 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 425 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 426 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 419 | 427 |
| 420 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; | 428 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; |
| 421 std::vector<uint8_t> test_vector(values, values + arraysize(values)); | 429 std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
| 422 characteristic1_->WriteRemoteCharacteristic( | 430 characteristic1_->WriteRemoteCharacteristic( |
| 423 test_vector, GetCallback(Call::EXPECTED), | 431 test_vector, GetCallback(Call::EXPECTED), |
| 424 GetGattErrorCallback(Call::NOT_EXPECTED)); | 432 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 425 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | 433 EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| 426 | 434 |
| 427 SimulateGattCharacteristicWrite(characteristic1_); | 435 SimulateGattCharacteristicWrite(characteristic1_); |
| 428 EXPECT_EQ(1, callback_count_); | 436 EXPECT_EQ(1, callback_count_); |
| 429 EXPECT_EQ(0, error_callback_count_); | 437 EXPECT_EQ(0, error_callback_count_); |
| 430 EXPECT_EQ(test_vector, last_write_value_); | 438 EXPECT_EQ(test_vector, last_write_value_); |
| 431 | 439 |
| 432 // Write again, with different value: | 440 // Write again, with different value: |
| 433 ResetEventCounts(); | 441 ResetEventCounts(); |
| 434 std::vector<uint8_t> empty_vector; | 442 std::vector<uint8_t> empty_vector; |
| 435 characteristic1_->WriteRemoteCharacteristic( | 443 characteristic1_->WriteRemoteCharacteristic( |
| 436 empty_vector, GetCallback(Call::EXPECTED), | 444 empty_vector, GetCallback(Call::EXPECTED), |
| 437 GetGattErrorCallback(Call::NOT_EXPECTED)); | 445 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 438 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | 446 EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| 439 SimulateGattCharacteristicWrite(characteristic1_); | 447 SimulateGattCharacteristicWrite(characteristic1_); |
| 440 EXPECT_EQ(1, callback_count_); | 448 EXPECT_EQ(1, callback_count_); |
| 441 EXPECT_EQ(0, error_callback_count_); | 449 EXPECT_EQ(0, error_callback_count_); |
| 442 EXPECT_EQ(empty_vector, last_write_value_); | 450 EXPECT_EQ(empty_vector, last_write_value_); |
| 443 } | 451 } |
| 444 #endif // defined(OS_ANDROID) | 452 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 445 | 453 |
| 446 #if defined(OS_ANDROID) | 454 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 447 // Tests ReadRemoteCharacteristic on two characteristics. | 455 // Tests ReadRemoteCharacteristic on two characteristics. |
| 448 TEST_F(BluetoothGattCharacteristicTest, | 456 TEST_F(BluetoothGattCharacteristicTest, |
| 449 ReadRemoteCharacteristic_MultipleCharacteristics) { | 457 ReadRemoteCharacteristic_MultipleCharacteristics) { |
| 450 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 458 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 459 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 451 | 460 |
| 452 characteristic1_->ReadRemoteCharacteristic( | 461 characteristic1_->ReadRemoteCharacteristic( |
| 453 GetReadValueCallback(Call::EXPECTED), | 462 GetReadValueCallback(Call::EXPECTED), |
| 454 GetGattErrorCallback(Call::NOT_EXPECTED)); | 463 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 455 characteristic2_->ReadRemoteCharacteristic( | 464 characteristic2_->ReadRemoteCharacteristic( |
| 456 GetReadValueCallback(Call::EXPECTED), | 465 GetReadValueCallback(Call::EXPECTED), |
| 457 GetGattErrorCallback(Call::NOT_EXPECTED)); | 466 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 458 EXPECT_EQ(2, gatt_read_characteristic_attempts_); | 467 EXPECT_EQ(2, gatt_read_characteristic_attempts_); |
| 459 EXPECT_EQ(0, callback_count_); | 468 EXPECT_EQ(0, callback_count_); |
| 460 EXPECT_EQ(0, error_callback_count_); | 469 EXPECT_EQ(0, error_callback_count_); |
| 461 | 470 |
| 462 std::vector<uint8_t> test_vector1; | 471 std::vector<uint8_t> test_vector1; |
| 463 test_vector1.push_back(111); | 472 test_vector1.push_back(111); |
| 464 SimulateGattCharacteristicRead(characteristic1_, test_vector1); | 473 SimulateGattCharacteristicRead(characteristic1_, test_vector1); |
| 465 EXPECT_EQ(test_vector1, last_read_value_); | 474 EXPECT_EQ(test_vector1, last_read_value_); |
| 466 | 475 |
| 467 std::vector<uint8_t> test_vector2; | 476 std::vector<uint8_t> test_vector2; |
| 468 test_vector2.push_back(222); | 477 test_vector2.push_back(222); |
| 469 SimulateGattCharacteristicRead(characteristic2_, test_vector2); | 478 SimulateGattCharacteristicRead(characteristic2_, test_vector2); |
| 470 EXPECT_EQ(test_vector2, last_read_value_); | 479 EXPECT_EQ(test_vector2, last_read_value_); |
| 471 | 480 |
| 472 EXPECT_EQ(2, callback_count_); | 481 EXPECT_EQ(2, callback_count_); |
| 473 EXPECT_EQ(0, error_callback_count_); | 482 EXPECT_EQ(0, error_callback_count_); |
| 474 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); | 483 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
| 475 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); | 484 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); |
| 476 } | 485 } |
| 477 #endif // defined(OS_ANDROID) | 486 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 478 | 487 |
| 479 #if defined(OS_ANDROID) | 488 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 480 // Tests WriteRemoteCharacteristic on two characteristics. | 489 // Tests WriteRemoteCharacteristic on two characteristics. |
| 481 TEST_F(BluetoothGattCharacteristicTest, | 490 TEST_F(BluetoothGattCharacteristicTest, |
| 482 WriteRemoteCharacteristic_MultipleCharacteristics) { | 491 WriteRemoteCharacteristic_MultipleCharacteristics) { |
| 483 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 492 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 493 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 484 | 494 |
| 485 std::vector<uint8_t> test_vector1; | 495 std::vector<uint8_t> test_vector1; |
| 486 test_vector1.push_back(111); | 496 test_vector1.push_back(111); |
| 487 characteristic1_->WriteRemoteCharacteristic( | 497 characteristic1_->WriteRemoteCharacteristic( |
| 488 test_vector1, GetCallback(Call::EXPECTED), | 498 test_vector1, GetCallback(Call::EXPECTED), |
| 489 GetGattErrorCallback(Call::NOT_EXPECTED)); | 499 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 500 #ifdef OS_ANDROID |
| 490 EXPECT_EQ(test_vector1, last_write_value_); | 501 EXPECT_EQ(test_vector1, last_write_value_); |
| 502 #endif |
| 491 | 503 |
| 492 std::vector<uint8_t> test_vector2; | 504 std::vector<uint8_t> test_vector2; |
| 493 test_vector2.push_back(222); | 505 test_vector2.push_back(222); |
| 494 characteristic2_->WriteRemoteCharacteristic( | 506 characteristic2_->WriteRemoteCharacteristic( |
| 495 test_vector2, GetCallback(Call::EXPECTED), | 507 test_vector2, GetCallback(Call::EXPECTED), |
| 496 GetGattErrorCallback(Call::NOT_EXPECTED)); | 508 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 509 #ifdef OS_ANDROID |
| 497 EXPECT_EQ(test_vector2, last_write_value_); | 510 EXPECT_EQ(test_vector2, last_write_value_); |
| 511 #endif |
| 498 | 512 |
| 499 EXPECT_EQ(2, gatt_write_characteristic_attempts_); | 513 EXPECT_EQ(2, gatt_write_characteristic_attempts_); |
| 500 EXPECT_EQ(0, callback_count_); | 514 EXPECT_EQ(0, callback_count_); |
| 501 EXPECT_EQ(0, error_callback_count_); | 515 EXPECT_EQ(0, error_callback_count_); |
| 502 | 516 |
| 503 SimulateGattCharacteristicWrite(characteristic1_); | 517 SimulateGattCharacteristicWrite(characteristic1_); |
| 518 #ifndef OS_ANDROID |
| 519 EXPECT_EQ(test_vector1, last_write_value_); |
| 520 #endif |
| 521 |
| 504 SimulateGattCharacteristicWrite(characteristic2_); | 522 SimulateGattCharacteristicWrite(characteristic2_); |
| 523 #ifndef OS_ANDROID |
| 524 EXPECT_EQ(test_vector2, last_write_value_); |
| 525 #endif |
| 505 | 526 |
| 506 EXPECT_EQ(2, callback_count_); | 527 EXPECT_EQ(2, callback_count_); |
| 507 EXPECT_EQ(0, error_callback_count_); | 528 EXPECT_EQ(0, error_callback_count_); |
| 529 |
| 530 // TODO(crbug.com/591740): Remove if define for OS_ANDROID in this test. |
| 508 } | 531 } |
| 509 #endif // defined(OS_ANDROID) | 532 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 510 | 533 |
| 511 #if defined(OS_ANDROID) | 534 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 512 // Tests ReadRemoteCharacteristic asynchronous error. | 535 // Tests ReadRemoteCharacteristic asynchronous error. |
| 513 TEST_F(BluetoothGattCharacteristicTest, ReadError) { | 536 TEST_F(BluetoothGattCharacteristicTest, ReadError) { |
| 514 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 537 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 538 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 515 | 539 |
| 516 characteristic1_->ReadRemoteCharacteristic( | 540 characteristic1_->ReadRemoteCharacteristic( |
| 517 GetReadValueCallback(Call::NOT_EXPECTED), | 541 GetReadValueCallback(Call::NOT_EXPECTED), |
| 518 GetGattErrorCallback(Call::EXPECTED)); | 542 GetGattErrorCallback(Call::EXPECTED)); |
| 519 SimulateGattCharacteristicReadError( | 543 SimulateGattCharacteristicReadError( |
| 520 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); | 544 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); |
| 521 SimulateGattCharacteristicReadError(characteristic1_, | 545 SimulateGattCharacteristicReadError(characteristic1_, |
| 522 BluetoothGattService::GATT_ERROR_FAILED); | 546 BluetoothGattService::GATT_ERROR_FAILED); |
| 523 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, | 547 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, |
| 524 last_gatt_error_code_); | 548 last_gatt_error_code_); |
| 525 } | 549 } |
| 526 #endif // defined(OS_ANDROID) | 550 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 527 | 551 |
| 528 #if defined(OS_ANDROID) | 552 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 529 // Tests WriteRemoteCharacteristic asynchronous error. | 553 // Tests WriteRemoteCharacteristic asynchronous error. |
| 530 TEST_F(BluetoothGattCharacteristicTest, WriteError) { | 554 TEST_F(BluetoothGattCharacteristicTest, WriteError) { |
| 531 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 555 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 556 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 532 | 557 |
| 533 std::vector<uint8_t> empty_vector; | 558 std::vector<uint8_t> empty_vector; |
| 534 characteristic1_->WriteRemoteCharacteristic( | 559 characteristic1_->WriteRemoteCharacteristic( |
| 535 empty_vector, GetCallback(Call::NOT_EXPECTED), | 560 empty_vector, GetCallback(Call::NOT_EXPECTED), |
| 536 GetGattErrorCallback(Call::EXPECTED)); | 561 GetGattErrorCallback(Call::EXPECTED)); |
| 537 SimulateGattCharacteristicWriteError( | 562 SimulateGattCharacteristicWriteError( |
| 538 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); | 563 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); |
| 539 SimulateGattCharacteristicWriteError(characteristic1_, | 564 SimulateGattCharacteristicWriteError(characteristic1_, |
| 540 BluetoothGattService::GATT_ERROR_FAILED); | 565 BluetoothGattService::GATT_ERROR_FAILED); |
| 541 | 566 |
| 542 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, | 567 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, |
| 543 last_gatt_error_code_); | 568 last_gatt_error_code_); |
| 544 } | 569 } |
| 545 #endif // defined(OS_ANDROID) | 570 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 546 | 571 |
| 547 #if defined(OS_ANDROID) | 572 #if defined(OS_ANDROID) |
| 548 // Tests ReadRemoteCharacteristic synchronous error. | 573 // Tests ReadRemoteCharacteristic synchronous error. |
| 549 TEST_F(BluetoothGattCharacteristicTest, ReadSynchronousError) { | 574 TEST_F(BluetoothGattCharacteristicTest, ReadSynchronousError) { |
| 550 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 575 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
| 551 | 576 |
| 552 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_); | 577 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_); |
| 553 characteristic1_->ReadRemoteCharacteristic( | 578 characteristic1_->ReadRemoteCharacteristic( |
| 554 GetReadValueCallback(Call::NOT_EXPECTED), | 579 GetReadValueCallback(Call::NOT_EXPECTED), |
| 555 GetGattErrorCallback(Call::EXPECTED)); | 580 GetGattErrorCallback(Call::EXPECTED)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 characteristic1_->WriteRemoteCharacteristic( | 618 characteristic1_->WriteRemoteCharacteristic( |
| 594 empty_vector, GetCallback(Call::EXPECTED), | 619 empty_vector, GetCallback(Call::EXPECTED), |
| 595 GetGattErrorCallback(Call::NOT_EXPECTED)); | 620 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 596 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | 621 EXPECT_EQ(1, gatt_write_characteristic_attempts_); |
| 597 SimulateGattCharacteristicWrite(characteristic1_); | 622 SimulateGattCharacteristicWrite(characteristic1_); |
| 598 EXPECT_EQ(1, callback_count_); | 623 EXPECT_EQ(1, callback_count_); |
| 599 EXPECT_EQ(0, error_callback_count_); | 624 EXPECT_EQ(0, error_callback_count_); |
| 600 } | 625 } |
| 601 #endif // defined(OS_ANDROID) | 626 #endif // defined(OS_ANDROID) |
| 602 | 627 |
| 603 #if defined(OS_ANDROID) | 628 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 604 // Tests ReadRemoteCharacteristic error with a pending read operation. | 629 // Tests ReadRemoteCharacteristic error with a pending read operation. |
| 605 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_ReadPending) { | 630 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_ReadPending) { |
| 606 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 631 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 632 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 607 | 633 |
| 608 characteristic1_->ReadRemoteCharacteristic( | 634 characteristic1_->ReadRemoteCharacteristic( |
| 609 GetReadValueCallback(Call::EXPECTED), | 635 GetReadValueCallback(Call::EXPECTED), |
| 610 GetGattErrorCallback(Call::NOT_EXPECTED)); | 636 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 611 characteristic1_->ReadRemoteCharacteristic( | 637 characteristic1_->ReadRemoteCharacteristic( |
| 612 GetReadValueCallback(Call::NOT_EXPECTED), | 638 GetReadValueCallback(Call::NOT_EXPECTED), |
| 613 GetGattErrorCallback(Call::EXPECTED)); | 639 GetGattErrorCallback(Call::EXPECTED)); |
| 614 | 640 |
| 615 base::RunLoop().RunUntilIdle(); | 641 base::RunLoop().RunUntilIdle(); |
| 616 | 642 |
| 617 EXPECT_EQ(0, callback_count_); | 643 EXPECT_EQ(0, callback_count_); |
| 618 EXPECT_EQ(1, error_callback_count_); | 644 EXPECT_EQ(1, error_callback_count_); |
| 619 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, | 645 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, |
| 620 last_gatt_error_code_); | 646 last_gatt_error_code_); |
| 621 | 647 |
| 622 // Initial read should still succeed: | 648 // Initial read should still succeed: |
| 623 ResetEventCounts(); | 649 ResetEventCounts(); |
| 624 std::vector<uint8_t> empty_vector; | 650 std::vector<uint8_t> empty_vector; |
| 625 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 651 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 626 EXPECT_EQ(1, callback_count_); | 652 EXPECT_EQ(1, callback_count_); |
| 627 EXPECT_EQ(0, error_callback_count_); | 653 EXPECT_EQ(0, error_callback_count_); |
| 628 } | 654 } |
| 629 #endif // defined(OS_ANDROID) | 655 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 630 | 656 |
| 631 #if defined(OS_ANDROID) | 657 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 632 // Tests WriteRemoteCharacteristic error with a pending write operation. | 658 // Tests WriteRemoteCharacteristic error with a pending write operation. |
| 633 TEST_F(BluetoothGattCharacteristicTest, | 659 TEST_F(BluetoothGattCharacteristicTest, |
| 634 WriteRemoteCharacteristic_WritePending) { | 660 WriteRemoteCharacteristic_WritePending) { |
| 635 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 661 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 662 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 636 | 663 |
| 637 std::vector<uint8_t> empty_vector; | 664 std::vector<uint8_t> empty_vector; |
| 638 characteristic1_->WriteRemoteCharacteristic( | 665 characteristic1_->WriteRemoteCharacteristic( |
| 639 empty_vector, GetCallback(Call::EXPECTED), | 666 empty_vector, GetCallback(Call::EXPECTED), |
| 640 GetGattErrorCallback(Call::NOT_EXPECTED)); | 667 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 641 characteristic1_->WriteRemoteCharacteristic( | 668 characteristic1_->WriteRemoteCharacteristic( |
| 642 empty_vector, GetCallback(Call::NOT_EXPECTED), | 669 empty_vector, GetCallback(Call::NOT_EXPECTED), |
| 643 GetGattErrorCallback(Call::EXPECTED)); | 670 GetGattErrorCallback(Call::EXPECTED)); |
| 644 | 671 |
| 645 base::RunLoop().RunUntilIdle(); | 672 base::RunLoop().RunUntilIdle(); |
| 646 | 673 |
| 647 EXPECT_EQ(0, callback_count_); | 674 EXPECT_EQ(0, callback_count_); |
| 648 EXPECT_EQ(1, error_callback_count_); | 675 EXPECT_EQ(1, error_callback_count_); |
| 649 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, | 676 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, |
| 650 last_gatt_error_code_); | 677 last_gatt_error_code_); |
| 651 | 678 |
| 652 // Initial write should still succeed: | 679 // Initial write should still succeed: |
| 653 ResetEventCounts(); | 680 ResetEventCounts(); |
| 654 SimulateGattCharacteristicWrite(characteristic1_); | 681 SimulateGattCharacteristicWrite(characteristic1_); |
| 655 EXPECT_EQ(1, callback_count_); | 682 EXPECT_EQ(1, callback_count_); |
| 656 EXPECT_EQ(0, error_callback_count_); | 683 EXPECT_EQ(0, error_callback_count_); |
| 657 } | 684 } |
| 658 #endif // defined(OS_ANDROID) | 685 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 659 | 686 |
| 660 #if defined(OS_ANDROID) | 687 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 661 // Tests ReadRemoteCharacteristic error with a pending write operation. | 688 // Tests ReadRemoteCharacteristic error with a pending write operation. |
| 662 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_WritePending) { | 689 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_WritePending) { |
| 663 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 690 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 691 BluetoothGattCharacteristic::PROPERTY_READ | |
| 692 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 664 | 693 |
| 665 std::vector<uint8_t> empty_vector; | 694 std::vector<uint8_t> empty_vector; |
| 666 characteristic1_->WriteRemoteCharacteristic( | 695 characteristic1_->WriteRemoteCharacteristic( |
| 667 empty_vector, GetCallback(Call::EXPECTED), | 696 empty_vector, GetCallback(Call::EXPECTED), |
| 668 GetGattErrorCallback(Call::NOT_EXPECTED)); | 697 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 669 characteristic1_->ReadRemoteCharacteristic( | 698 characteristic1_->ReadRemoteCharacteristic( |
| 670 GetReadValueCallback(Call::NOT_EXPECTED), | 699 GetReadValueCallback(Call::NOT_EXPECTED), |
| 671 GetGattErrorCallback(Call::EXPECTED)); | 700 GetGattErrorCallback(Call::EXPECTED)); |
| 672 | 701 |
| 673 base::RunLoop().RunUntilIdle(); | 702 base::RunLoop().RunUntilIdle(); |
| 674 | 703 |
| 675 EXPECT_EQ(0, callback_count_); | 704 EXPECT_EQ(0, callback_count_); |
| 676 EXPECT_EQ(1, error_callback_count_); | 705 EXPECT_EQ(1, error_callback_count_); |
| 677 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, | 706 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, |
| 678 last_gatt_error_code_); | 707 last_gatt_error_code_); |
| 679 | 708 |
| 680 // Initial write should still succeed: | 709 // Initial write should still succeed: |
| 681 ResetEventCounts(); | 710 ResetEventCounts(); |
| 682 SimulateGattCharacteristicWrite(characteristic1_); | 711 SimulateGattCharacteristicWrite(characteristic1_); |
| 683 EXPECT_EQ(1, callback_count_); | 712 EXPECT_EQ(1, callback_count_); |
| 684 EXPECT_EQ(0, error_callback_count_); | 713 EXPECT_EQ(0, error_callback_count_); |
| 685 } | 714 } |
| 686 #endif // defined(OS_ANDROID) | 715 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 687 | 716 |
| 688 #if defined(OS_ANDROID) | 717 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 689 // Tests WriteRemoteCharacteristic error with a pending Read operation. | 718 // Tests WriteRemoteCharacteristic error with a pending Read operation. |
| 690 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_ReadPending) { | 719 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_ReadPending) { |
| 691 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 720 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 721 BluetoothGattCharacteristic::PROPERTY_READ | |
| 722 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 692 | 723 |
| 693 std::vector<uint8_t> empty_vector; | 724 std::vector<uint8_t> empty_vector; |
| 694 characteristic1_->ReadRemoteCharacteristic( | 725 characteristic1_->ReadRemoteCharacteristic( |
| 695 GetReadValueCallback(Call::EXPECTED), | 726 GetReadValueCallback(Call::EXPECTED), |
| 696 GetGattErrorCallback(Call::NOT_EXPECTED)); | 727 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 697 characteristic1_->WriteRemoteCharacteristic( | 728 characteristic1_->WriteRemoteCharacteristic( |
| 698 empty_vector, GetCallback(Call::NOT_EXPECTED), | 729 empty_vector, GetCallback(Call::NOT_EXPECTED), |
| 699 GetGattErrorCallback(Call::EXPECTED)); | 730 GetGattErrorCallback(Call::EXPECTED)); |
| 700 base::RunLoop().RunUntilIdle(); | 731 base::RunLoop().RunUntilIdle(); |
| 701 | 732 |
| 702 EXPECT_EQ(0, callback_count_); | 733 EXPECT_EQ(0, callback_count_); |
| 703 EXPECT_EQ(1, error_callback_count_); | 734 EXPECT_EQ(1, error_callback_count_); |
| 704 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, | 735 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, |
| 705 last_gatt_error_code_); | 736 last_gatt_error_code_); |
| 706 | 737 |
| 707 // Initial read should still succeed: | 738 // Initial read should still succeed: |
| 708 ResetEventCounts(); | 739 ResetEventCounts(); |
| 709 SimulateGattCharacteristicRead(characteristic1_, empty_vector); | 740 SimulateGattCharacteristicRead(characteristic1_, empty_vector); |
| 710 EXPECT_EQ(1, callback_count_); | 741 EXPECT_EQ(1, callback_count_); |
| 711 EXPECT_EQ(0, error_callback_count_); | 742 EXPECT_EQ(0, error_callback_count_); |
| 712 } | 743 } |
| 713 #endif // defined(OS_ANDROID) | 744 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 714 | 745 |
| 715 #if defined(OS_ANDROID) | 746 #if defined(OS_ANDROID) |
| 716 // StartNotifySession fails if characteristic doesn't have Notify or Indicate | 747 // StartNotifySession fails if characteristic doesn't have Notify or Indicate |
| 717 // property. | 748 // property. |
| 718 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) { | 749 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) { |
| 719 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( | 750 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( |
| 720 /* properties: NOTIFY */ 0x10, | 751 /* properties: NOTIFY */ 0x10, |
| 721 /* expected_config_descriptor_value: NOTIFY */ 1, | 752 /* expected_config_descriptor_value: NOTIFY */ 1, |
| 722 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); | 753 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); |
| 723 | 754 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 | 978 |
| 948 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). | 979 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). |
| 949 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); | 980 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); |
| 950 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); | 981 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); |
| 951 // ... but not uuid 3 | 982 // ... but not uuid 3 |
| 952 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); | 983 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); |
| 953 } | 984 } |
| 954 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 985 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 955 | 986 |
| 956 } // namespace device | 987 } // namespace device |
| OLD | NEW |