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

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

Issue 2347133002: bluetooth: Call error callback when characteristics get destroyed during a GATT Event (mac) (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/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
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 #if !defined(OS_MACOSX)
397 // On macOS we don't get any events after disconnection so no need to
scheib 2016/09/16 19:50:12 If there's just 'no need to remember' then we migh
ortuno 2016/09/20 02:41:43 Through experimentation and the bug report for thi
scheib 2016/09/20 03:53:16 Thanks for explanation, please include in code the
ortuno 2016/09/22 03:06:32 Done.
398 // remember the characteristic for the read response.
399 RememberCharacteristicForSubsequentAction(characteristic1_);
400 #endif
401
402 ASSERT_EQ(1u, adapter_->GetDevices().size());
403 SimulateGattDisconnection(adapter_->GetDevices()[0]);
404
405 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
406 last_gatt_error_code_);
407
408 #if !defined(OS_MACOSX)
409 // On macOS we don't get any events after disconnection so no need to
410 // dispatch a read response.
411 std::vector<uint8_t> empty_vector;
412 SimulateGattCharacteristicRead(nullptr /* use remembered characteristic */,
413 empty_vector);
414 #endif
415 }
416 #endif // defined(OS_MACOSX)
417
381 #if defined(OS_ANDROID) || defined(OS_WIN) 418 #if defined(OS_ANDROID) || defined(OS_WIN)
382 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. 419 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted.
383 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set 420 // macOS: Not applicable: This can never happen if CBPeripheral delegate is set
384 // to nil. 421 // to nil.
385 TEST_F(BluetoothRemoteGattCharacteristicTest, 422 TEST_F(BluetoothRemoteGattCharacteristicTest,
386 WriteRemoteCharacteristic_AfterDeleted) { 423 WriteRemoteCharacteristic_AfterDeleted) {
387 if (!PlatformSupportsLowEnergy()) { 424 if (!PlatformSupportsLowEnergy()) {
388 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 425 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
389 return; 426 return;
390 } 427 }
391 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 428 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
392 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 429 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
393 430
394 std::vector<uint8_t> empty_vector; 431 std::vector<uint8_t> empty_vector;
395 characteristic1_->WriteRemoteCharacteristic( 432 characteristic1_->WriteRemoteCharacteristic(
396 empty_vector, GetCallback(Call::NOT_EXPECTED), 433 empty_vector, GetCallback(Call::NOT_EXPECTED),
397 GetGattErrorCallback(Call::NOT_EXPECTED)); 434 GetGattErrorCallback(Call::NOT_EXPECTED));
398 435
399 RememberCharacteristicForSubsequentAction(characteristic1_); 436 RememberCharacteristicForSubsequentAction(characteristic1_);
400 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 437 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
401 438
402 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); 439 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr);
403 EXPECT_TRUE("Did not crash!"); 440 EXPECT_TRUE("Did not crash!");
404 } 441 }
405 #endif // defined(OS_ANDROID) || defined(OS_WIN) 442 #endif // defined(OS_ANDROID) || defined(OS_WIN)
406 443
444 // TODO(crbug.com/621901): Enable test on all platforms.
445 #if defined(OS_MACOSX)
446 TEST_F(BluetoothRemoteGattCharacteristicTest,
447 WriteRemoteCharacteristic_Disconnected) {
448 if (!PlatformSupportsLowEnergy()) {
449 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
450 return;
451 }
452 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
453 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
454
455 std::vector<uint8_t> empty_vector;
456 characteristic1_->WriteRemoteCharacteristic(
457 empty_vector, GetCallback(Call::NOT_EXPECTED),
458 GetGattErrorCallback(Call::EXPECTED));
459
460 #if !defined(OS_MACOSX)
461 // On macOS we don't get any events after disconnection so no need to
462 // remember the characteristic for the write response.
463 RememberCharacteristicForSubsequentAction(characteristic1_);
464 #endif // !defined(OS_MACOSX)
465
466 ASSERT_EQ(1u, adapter_->GetDevices().size());
467 SimulateGattDisconnection(adapter_->GetDevices()[0]);
468
469 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
470 last_gatt_error_code_);
471
472 #if !defined(OS_MACOSX)
473 // On macOS we don't get any events after disconnection so no need
474 // to dispatch a write response.
475 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr);
476 #endif // !defined(OS_MACOSX)
477 }
478 #endif // defined(OS_MACOSX)
479
407 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 480 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
408 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. 481 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer.
409 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) { 482 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) {
410 if (!PlatformSupportsLowEnergy()) { 483 if (!PlatformSupportsLowEnergy()) {
411 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 484 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
412 return; 485 return;
413 } 486 }
414 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 487 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
415 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 488 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
416 489
(...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 2127 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
2055 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 2128 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
2056 2129
2057 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 2130 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
2058 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 2131 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
2059 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 2132 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
2060 } 2133 }
2061 #endif // defined(OS_ANDROID) || defined(OS_WIN) 2134 #endif // defined(OS_ANDROID) || defined(OS_WIN)
2062 2135
2063 } // namespace device 2136 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698