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

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

Issue 2702163002: bluetooth: Close and null out BluetoothGatt on the UI Thread (Closed)
Patch Set: Created 3 years, 10 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
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 2353 matching lines...) Expand 10 before | Expand all | Expand 10 after
2364 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id1).size()); 2364 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id1).size());
2365 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 2365 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
2366 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 2366 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
2367 2367
2368 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 2368 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
2369 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 2369 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
2370 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 2370 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
2371 } 2371 }
2372 #endif // defined(OS_ANDROID) || defined(OS_WIN) 2372 #endif // defined(OS_ANDROID) || defined(OS_WIN)
2373 2373
2374 #if defined(OS_ANDROID)
2375 // Tests that read requests after a device disconnects but before the disconnect
2376 // task has a chance to run result in an error.
2377 // macOS: Does not apply. All events arrive on the UI Thread.
2378 // TODO(crbug.com/694102): Enable this test on Windows.
2379 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadDuringDisconnect) {
2380 if (!PlatformSupportsLowEnergy()) {
2381 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2382 return;
2383 }
2384 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
2385 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
2386
2387 SimulateGattDisconnection(device_);
2388 // Don't run the disconnect task.
scheib 2017/03/04 18:52:24 // Do not yet call RunUntilIdle() to process the d
ortuno 2017/03/07 05:06:47 Makes sense. Done.
2389 characteristic1_->ReadRemoteCharacteristic(
2390 GetReadValueCallback(Call::NOT_EXPECTED),
2391 GetGattErrorCallback(Call::EXPECTED));
2392
2393 base::RunLoop().RunUntilIdle();
2394 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
2395 last_gatt_error_code_);
2396 }
2397 #endif
2398
2399 #if defined(OS_ANDROID)
2400 // Tests that write requests after a device disconnects but before the
2401 // disconnect task runs result in an error.
2402 // macOS: Does not apply. All events arrive on the UI Thread.
2403 // TODO(crbug.com/694102): Enable this test on Windows.
2404 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteDuringDisconnect) {
2405 if (!PlatformSupportsLowEnergy()) {
2406 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2407 return;
2408 }
2409 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
2410 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
2411
2412 SimulateGattDisconnection(device_);
2413 // Don't run the disconnect task.
2414 characteristic1_->WriteRemoteCharacteristic(
2415 std::vector<uint8_t>(), GetCallback(Call::NOT_EXPECTED),
2416 GetGattErrorCallback(Call::EXPECTED));
2417
2418 base::RunLoop().RunUntilIdle();
2419 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
2420 last_gatt_error_code_);
2421 }
2422 #endif
2423
2424 #if defined(OS_ANDROID)
2425 // Tests that start notifications requests after a device disconnects but before
2426 // the disconnect task runs result in an error.
2427 // macOS: Does not apply. All events arrive on the UI Thread.
2428 // TODO(crbug.com/694102): Enable this test on Windows.
2429 TEST_F(BluetoothRemoteGattCharacteristicTest,
2430 StartNotifySessionDuringDisconnect) {
2431 if (!PlatformSupportsLowEnergy()) {
2432 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2433 return;
2434 }
2435 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
2436 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY));
2437 SimulateGattDescriptor(
2438 characteristic1_,
2439 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
2440 .canonical_value());
2441
2442 SimulateGattDisconnection(device_);
2443 // Don't run the disconnect task.
2444 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
2445 GetGattErrorCallback(Call::EXPECTED));
2446
2447 base::RunLoop().RunUntilIdle();
2448 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
2449 last_gatt_error_code_);
2450 }
2451 #endif
2452
2453 #if defined(OS_ANDROID)
2454 // Tests that stop notifications requests after a device disconnects but before
2455 // the disconnect task runs do not result in a crash.
2456 // macOS: Does not apply. All events arrive on the UI Thread.
2457 // TODO(crbug.com/694102): Enable this test on Windows.
2458 TEST_F(BluetoothRemoteGattCharacteristicTest,
2459 StopNotifySessionDuringDisconnect) {
2460 if (!PlatformSupportsLowEnergy()) {
2461 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2462 return;
2463 }
2464 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
2465 /* properties: NOTIFY */ 0x10,
2466 /* expected_config_descriptor_value: NOTIFY */ 1));
2467
2468 SimulateGattDisconnection(device_);
2469 // Don't run the disconnect task.
2470 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
2471 base::RunLoop().RunUntilIdle();
2472 }
2473 #endif
2474
2475 #if defined(OS_ANDROID)
2476 // Tests that deleting notify sessions after a device disconnects but before the
2477 // disconnect task runs do not result in a crash.
2478 // macOS: Does not apply. All events arrive on the UI Thread.
2479 // TODO(crbug.com/694102): Enable this test on Windows.
2480 TEST_F(BluetoothRemoteGattCharacteristicTest,
2481 DeleteNotifySessionDuringDisconnect) {
2482 if (!PlatformSupportsLowEnergy()) {
2483 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2484 return;
2485 }
2486 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
2487 /* properties: NOTIFY */ 0x10,
2488 /* expected_config_descriptor_value: NOTIFY */ 1));
2489
2490 SimulateGattDisconnection(device_);
2491 // Don't run the disconnect task.
2492 notify_sessions_.clear();
2493 base::RunLoop().RunUntilIdle();
2494 }
2495 #endif
2374 } // namespace device 2496 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698