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

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: Fix test Created 3 years, 9 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 2225 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id1).size()); 2236 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id1).size());
2237 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 2237 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
2238 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 2238 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
2239 2239
2240 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 2240 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
2241 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 2241 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
2242 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 2242 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
2243 } 2243 }
2244 #endif // defined(OS_ANDROID) || defined(OS_WIN) 2244 #endif // defined(OS_ANDROID) || defined(OS_WIN)
2245 2245
2246 #if defined(OS_ANDROID)
2247 // Tests that read requests after a device disconnects but before the disconnect
2248 // task has a chance to run result in an error.
2249 // macOS: Does not apply. All events arrive on the UI Thread.
2250 // TODO(crbug.com/694102): Enable this test on Windows.
2251 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadDuringDisconnect) {
2252 if (!PlatformSupportsLowEnergy()) {
2253 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2254 return;
2255 }
2256 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
2257 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
2258
2259 SimulateGattDisconnection(device_);
2260 // Do not yet call RunUntilIdle() to process the disconnect task.
2261 characteristic1_->ReadRemoteCharacteristic(
2262 GetReadValueCallback(Call::NOT_EXPECTED),
2263 GetGattErrorCallback(Call::EXPECTED));
2264
2265 base::RunLoop().RunUntilIdle();
2266 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
2267 last_gatt_error_code_);
2268 }
2269 #endif
2270
2271 #if defined(OS_ANDROID)
2272 // Tests that write requests after a device disconnects but before the
2273 // disconnect task runs result in an error.
2274 // macOS: Does not apply. All events arrive on the UI Thread.
2275 // TODO(crbug.com/694102): Enable this test on Windows.
2276 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteDuringDisconnect) {
2277 if (!PlatformSupportsLowEnergy()) {
2278 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2279 return;
2280 }
2281 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
2282 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
2283
2284 SimulateGattDisconnection(device_);
2285 // Do not yet call RunUntilIdle() to process the disconnect task.
2286 characteristic1_->WriteRemoteCharacteristic(
2287 std::vector<uint8_t>(), GetCallback(Call::NOT_EXPECTED),
2288 GetGattErrorCallback(Call::EXPECTED));
2289
2290 base::RunLoop().RunUntilIdle();
2291 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
2292 last_gatt_error_code_);
2293 }
2294 #endif
2295
2296 #if defined(OS_ANDROID)
2297 // Tests that start notifications requests after a device disconnects but before
2298 // the disconnect task runs result in an error.
2299 // macOS: Does not apply. All events arrive on the UI Thread.
2300 // TODO(crbug.com/694102): Enable this test on Windows.
2301 TEST_F(BluetoothRemoteGattCharacteristicTest,
2302 StartNotifySessionDuringDisconnect) {
2303 if (!PlatformSupportsLowEnergy()) {
2304 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2305 return;
2306 }
2307 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
2308 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY));
2309 SimulateGattDescriptor(
2310 characteristic1_,
2311 BluetoothRemoteGattDescriptor::ClientCharacteristicConfigurationUuid()
2312 .canonical_value());
2313
2314 SimulateGattDisconnection(device_);
2315 // Don't run the disconnect task.
2316 characteristic1_->StartNotifySession(GetNotifyCallback(Call::NOT_EXPECTED),
2317 GetGattErrorCallback(Call::EXPECTED));
2318
2319 base::RunLoop().RunUntilIdle();
2320 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_FAILED,
2321 last_gatt_error_code_);
2322 }
2323 #endif
2324
2325 #if defined(OS_ANDROID)
2326 // Tests that stop notifications requests after a device disconnects but before
2327 // the disconnect task runs do not result in a crash.
2328 // macOS: Does not apply. All events arrive on the UI Thread.
2329 // TODO(crbug.com/694102): Enable this test on Windows.
2330 TEST_F(BluetoothRemoteGattCharacteristicTest,
2331 StopNotifySessionDuringDisconnect) {
2332 if (!PlatformSupportsLowEnergy()) {
2333 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2334 return;
2335 }
2336 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
2337 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY));
2338
2339 SimulateGattDisconnection(device_);
2340 // Don't run the disconnect task.
2341 notify_sessions_[0]->Stop(GetStopNotifyCallback(Call::EXPECTED));
2342 base::RunLoop().RunUntilIdle();
2343 }
2344 #endif
2345
2346 #if defined(OS_ANDROID)
2347 // Tests that deleting notify sessions after a device disconnects but before the
2348 // disconnect task runs do not result in a crash.
2349 // macOS: Does not apply. All events arrive on the UI Thread.
2350 // TODO(crbug.com/694102): Enable this test on Windows.
2351 TEST_F(BluetoothRemoteGattCharacteristicTest,
2352 DeleteNotifySessionDuringDisconnect) {
2353 if (!PlatformSupportsLowEnergy()) {
2354 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
2355 return;
2356 }
2357 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
2358 /* properties: NOTIFY */ 0x10, NotifyValueState::NOTIFY));
2359
2360 SimulateGattDisconnection(device_);
2361 // Don't run the disconnect task.
2362 notify_sessions_.clear();
2363 base::RunLoop().RunUntilIdle();
2364 }
2365 #endif
2246 } // namespace device 2366 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698