| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 RememberCharacteristicForSubsequentAction(characteristic1_); | 371 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 372 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 372 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 373 | 373 |
| 374 std::vector<uint8_t> empty_vector; | 374 std::vector<uint8_t> empty_vector; |
| 375 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, | 375 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, |
| 376 empty_vector); | 376 empty_vector); |
| 377 EXPECT_TRUE("Did not crash!"); | 377 EXPECT_TRUE("Did not crash!"); |
| 378 } | 378 } |
| 379 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 379 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 380 | 380 |
| 381 // TODO(crbug.com/621901): Enable test on all platforms. |
| 382 #if defined(OS_MACOSX) |
| 383 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 384 ReadRemoteCharacteristic_Disconnected) { |
| 385 if (!PlatformSupportsLowEnergy()) { |
| 386 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 387 return; |
| 388 } |
| 389 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 390 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
| 391 |
| 392 characteristic1_->ReadRemoteCharacteristic( |
| 393 GetReadValueCallback(Call::NOT_EXPECTED), |
| 394 GetGattErrorCallback(Call::EXPECTED)); |
| 395 |
| 396 // Set up for receiving a read response after disconnection. |
| 397 // On macOS no events arrive after disconnection so there is no point |
| 398 // in building the infrastructure to test this behavior. FYI |
| 399 // the code CHECKs that responses arrive only when the device is connected. |
| 400 #if !defined(OS_MACOSX) |
| 401 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 402 #endif |
| 403 |
| 404 ASSERT_EQ(1u, adapter_->GetDevices().size()); |
| 405 SimulateGattDisconnection(adapter_->GetDevices()[0]); |
| 406 |
| 407 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, |
| 408 last_gatt_error_code_); |
| 409 |
| 410 // Dispatch read response after disconnection. See above explanation for why |
| 411 // we don't do this in macOS. |
| 412 #if !defined(OS_MACOSX) |
| 413 std::vector<uint8_t> empty_vector; |
| 414 SimulateGattCharacteristicRead(nullptr /* use remembered characteristic */, |
| 415 empty_vector); |
| 416 #endif |
| 417 } |
| 418 #endif // defined(OS_MACOSX) |
| 419 |
| 381 #if defined(OS_ANDROID) || defined(OS_WIN) | 420 #if defined(OS_ANDROID) || defined(OS_WIN) |
| 382 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. | 421 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. |
| 383 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set | 422 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set |
| 384 // to nil. | 423 // to nil. |
| 385 TEST_F(BluetoothRemoteGattCharacteristicTest, | 424 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 386 WriteRemoteCharacteristic_AfterDeleted) { | 425 WriteRemoteCharacteristic_AfterDeleted) { |
| 387 if (!PlatformSupportsLowEnergy()) { | 426 if (!PlatformSupportsLowEnergy()) { |
| 388 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 427 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 389 return; | 428 return; |
| 390 } | 429 } |
| 391 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 430 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 392 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); | 431 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); |
| 393 | 432 |
| 394 std::vector<uint8_t> empty_vector; | 433 std::vector<uint8_t> empty_vector; |
| 395 characteristic1_->WriteRemoteCharacteristic( | 434 characteristic1_->WriteRemoteCharacteristic( |
| 396 empty_vector, GetCallback(Call::NOT_EXPECTED), | 435 empty_vector, GetCallback(Call::NOT_EXPECTED), |
| 397 GetGattErrorCallback(Call::NOT_EXPECTED)); | 436 GetGattErrorCallback(Call::NOT_EXPECTED)); |
| 398 | 437 |
| 399 RememberCharacteristicForSubsequentAction(characteristic1_); | 438 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 400 DeleteDevice(device_); // TODO(576906) delete only the characteristic. | 439 DeleteDevice(device_); // TODO(576906) delete only the characteristic. |
| 401 | 440 |
| 402 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); | 441 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); |
| 403 EXPECT_TRUE("Did not crash!"); | 442 EXPECT_TRUE("Did not crash!"); |
| 404 } | 443 } |
| 405 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 444 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 406 | 445 |
| 446 // TODO(crbug.com/621901): Enable test on all platforms. |
| 447 #if defined(OS_MACOSX) |
| 448 TEST_F(BluetoothRemoteGattCharacteristicTest, |
| 449 WriteRemoteCharacteristic_Disconnected) { |
| 450 if (!PlatformSupportsLowEnergy()) { |
| 451 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 452 return; |
| 453 } |
| 454 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 455 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); |
| 456 |
| 457 std::vector<uint8_t> empty_vector; |
| 458 characteristic1_->WriteRemoteCharacteristic( |
| 459 empty_vector, GetCallback(Call::NOT_EXPECTED), |
| 460 GetGattErrorCallback(Call::EXPECTED)); |
| 461 |
| 462 // Set up for receiving a write response after disconnection. |
| 463 // On macOS no events arrive after disconnection so there is no point |
| 464 // in building the infrastructure to test this behavior. FYI |
| 465 // the code CHECKs that responses arrive only when the device is connected. |
| 466 #if !defined(OS_MACOSX) |
| 467 RememberCharacteristicForSubsequentAction(characteristic1_); |
| 468 #endif // !defined(OS_MACOSX) |
| 469 |
| 470 ASSERT_EQ(1u, adapter_->GetDevices().size()); |
| 471 SimulateGattDisconnection(adapter_->GetDevices()[0]); |
| 472 |
| 473 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED, |
| 474 last_gatt_error_code_); |
| 475 |
| 476 // Dispatch write response after disconnection. See above explanation for why |
| 477 // we don't do this in macOS. |
| 478 #if !defined(OS_MACOSX) |
| 479 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); |
| 480 #endif // !defined(OS_MACOSX) |
| 481 } |
| 482 #endif // defined(OS_MACOSX) |
| 483 |
| 407 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 484 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
| 408 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. | 485 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. |
| 409 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) { | 486 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) { |
| 410 if (!PlatformSupportsLowEnergy()) { | 487 if (!PlatformSupportsLowEnergy()) { |
| 411 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 488 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 412 return; | 489 return; |
| 413 } | 490 } |
| 414 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( | 491 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
| 415 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); | 492 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
| 416 | 493 |
| (...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2054 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); | 2131 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); |
| 2055 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); | 2132 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); |
| 2056 | 2133 |
| 2057 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); | 2134 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); |
| 2058 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); | 2135 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); |
| 2059 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); | 2136 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); |
| 2060 } | 2137 } |
| 2061 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 2138 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
| 2062 | 2139 |
| 2063 } // namespace device | 2140 } // namespace device |
| OLD | NEW |