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

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

Issue 935383003: Fix BluetoothAdapterProfileChromeOS lifecycle management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix for leak detected by LSAN Created 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chromeos/dbus/dbus_thread_manager.h" 9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 10 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 ++callback_count_; 317 ++callback_count_;
318 discovery_sessions_.push_back(discovery_session.release()); 318 discovery_sessions_.push_back(discovery_session.release());
319 QuitMessageLoop(); 319 QuitMessageLoop();
320 } 320 }
321 321
322 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) { 322 void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) {
323 ++callback_count_; 323 ++callback_count_;
324 QuitMessageLoop(); 324 QuitMessageLoop();
325 } 325 }
326 326
327 void ProfileRegisteredCallback(BluetoothAdapterProfileChromeOS*) { 327 void ProfileRegisteredCallback(BluetoothAdapterProfileChromeOS* profile) {
328 adapter_profile_ = profile;
328 ++callback_count_; 329 ++callback_count_;
329 QuitMessageLoop(); 330 QuitMessageLoop();
330 } 331 }
331 332
332 void ErrorCallback() { 333 void ErrorCallback() {
333 ++error_callback_count_; 334 ++error_callback_count_;
334 QuitMessageLoop(); 335 QuitMessageLoop();
335 } 336 }
336 337
337 base::Closure GetErrorCallback() { 338 base::Closure GetErrorCallback() {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 base::MessageLoop message_loop_; 420 base::MessageLoop message_loop_;
420 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; 421 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_;
421 FakeBluetoothDeviceClient* fake_bluetooth_device_client_; 422 FakeBluetoothDeviceClient* fake_bluetooth_device_client_;
422 scoped_refptr<BluetoothAdapter> adapter_; 423 scoped_refptr<BluetoothAdapter> adapter_;
423 424
424 int callback_count_; 425 int callback_count_;
425 int error_callback_count_; 426 int error_callback_count_;
426 enum BluetoothDevice::ConnectErrorCode last_connect_error_; 427 enum BluetoothDevice::ConnectErrorCode last_connect_error_;
427 std::string last_client_error_; 428 std::string last_client_error_;
428 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; 429 ScopedVector<BluetoothDiscoverySession> discovery_sessions_;
430 BluetoothAdapterProfileChromeOS *adapter_profile_;
429 431
430 private: 432 private:
431 // Some tests use a message loop since background processing is simulated; 433 // Some tests use a message loop since background processing is simulated;
432 // break out of those loops. 434 // break out of those loops.
433 void QuitMessageLoop() { 435 void QuitMessageLoop() {
434 if (base::MessageLoop::current() && 436 if (base::MessageLoop::current() &&
435 base::MessageLoop::current()->is_running()) 437 base::MessageLoop::current()->is_running())
436 base::MessageLoop::current()->Quit(); 438 base::MessageLoop::current()->Quit();
437 } 439 }
438 }; 440 };
(...skipping 2742 matching lines...) Expand 10 before | Expand all | Expand 10 after
3181 // NotifyGattDiscoveryComplete 3183 // NotifyGattDiscoveryComplete
3182 // NotifyGattCharacteristicAdded 3184 // NotifyGattCharacteristicAdded
3183 // NotifyGattCharacteristicRemoved 3185 // NotifyGattCharacteristicRemoved
3184 // NotifyGattDescriptorAdded 3186 // NotifyGattDescriptorAdded
3185 // NotifyGattDescriptorRemoved 3187 // NotifyGattDescriptorRemoved
3186 // NotifyGattCharacteristicValueChanged 3188 // NotifyGattCharacteristicValueChanged
3187 // NotifyGattDescriptorValueChanged 3189 // NotifyGattDescriptorValueChanged
3188 3190
3189 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path()); 3191 EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path());
3190 3192
3193 adapter_profile_ = NULL;
3194
3191 FakeBluetoothProfileServiceProviderDelegate profile_delegate; 3195 FakeBluetoothProfileServiceProviderDelegate profile_delegate;
3192 adapter_chrome_os->UseProfile( 3196 adapter_chrome_os->UseProfile(
3193 BluetoothUUID(), dbus::ObjectPath(""), 3197 BluetoothUUID(), dbus::ObjectPath(""),
3194 BluetoothProfileManagerClient::Options(), &profile_delegate, 3198 BluetoothProfileManagerClient::Options(), &profile_delegate,
3195 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 3199 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback,
3196 base::Unretained(this)), 3200 base::Unretained(this)),
3197 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, 3201 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
3198 base::Unretained(this))); 3202 base::Unretained(this)));
3199 base::MessageLoop::current()->Run();
3200 EXPECT_EQ(1, callback_count_--) << "UseProfile error";
3201 EXPECT_EQ(0, error_callback_count_) << "UseProfile error";
3202 3203
3203 adapter_chrome_os->ReleaseProfile(BluetoothUUID()); 3204 EXPECT_FALSE(adapter_profile_) << "UseProfile error";
3205 EXPECT_EQ(0, callback_count_) << "UseProfile error";
3206 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error";
3204 3207
3205 // Protected and private methods: 3208 // Protected and private methods:
3206 3209
3207 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate); 3210 adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate);
3208 3211
3209 // BluetoothAdapterClient::Observer methods omitted, dbus will be shutdown. 3212 // BluetoothAdapterClient::Observer methods omitted, dbus will be shutdown.
3210 // BluetoothDeviceClient::Observer methods omitted, dbus will be shutdown. 3213 // BluetoothDeviceClient::Observer methods omitted, dbus will be shutdown.
3211 // BluetoothInputClient::Observer methods omitted, dbus will be shutdown. 3214 // BluetoothInputClient::Observer methods omitted, dbus will be shutdown.
3212 // BluetoothAgentServiceProvider::Delegate omitted, dbus will be shutdown, 3215 // BluetoothAgentServiceProvider::Delegate omitted, dbus will be shutdown,
3213 // with the exception of Released. 3216 // with the exception of Released.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3251 3254
3252 adapter_chrome_os->RemoveDiscoverySession(GetCallback(), GetErrorCallback()); 3255 adapter_chrome_os->RemoveDiscoverySession(GetCallback(), GetErrorCallback());
3253 EXPECT_EQ(0, callback_count_) << "RemoveDiscoverySession error"; 3256 EXPECT_EQ(0, callback_count_) << "RemoveDiscoverySession error";
3254 EXPECT_EQ(1, error_callback_count_--) << "RemoveDiscoverySession error"; 3257 EXPECT_EQ(1, error_callback_count_--) << "RemoveDiscoverySession error";
3255 3258
3256 // OnStartDiscovery tested in Shutdown_OnStartDiscovery 3259 // OnStartDiscovery tested in Shutdown_OnStartDiscovery
3257 // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError 3260 // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError
3258 // OnStopDiscovery tested in Shutdown_OnStopDiscovery 3261 // OnStopDiscovery tested in Shutdown_OnStopDiscovery
3259 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError 3262 // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError
3260 3263
3264 adapter_profile_ = NULL;
3265
3261 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require 3266 // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require
3262 // UseProfile to be set first, do so again here just before calling them. 3267 // UseProfile to be set first, do so again here just before calling them.
3263 adapter_chrome_os->UseProfile( 3268 adapter_chrome_os->UseProfile(
3264 BluetoothUUID(), dbus::ObjectPath(""), 3269 BluetoothUUID(), dbus::ObjectPath(""),
3265 BluetoothProfileManagerClient::Options(), &profile_delegate, 3270 BluetoothProfileManagerClient::Options(), &profile_delegate,
3266 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 3271 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback,
3267 base::Unretained(this)), 3272 base::Unretained(this)),
3268 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, 3273 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
3269 base::Unretained(this))); 3274 base::Unretained(this)));
3270 3275
3271 adapter_chrome_os->OnRegisterProfile( 3276 EXPECT_FALSE(adapter_profile_) << "UseProfile error";
3272 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, 3277 EXPECT_EQ(0, callback_count_) << "UseProfile error";
3273 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 3278 EXPECT_EQ(1, error_callback_count_--) << "UseProfile error";
3274 base::Unretained(this)),
3275 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
3276 base::Unretained(this)));
3277 EXPECT_EQ(1, callback_count_--) << "OnRegisterProfile error";
3278 EXPECT_EQ(1, error_callback_count_--) << "OnRegisterProfile error";
3279 3279
3280 adapter_chrome_os->SetProfileDelegate( 3280 adapter_chrome_os->SetProfileDelegate(
3281 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate, 3281 BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate,
3282 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback, 3282 base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback,
3283 base::Unretained(this)), 3283 base::Unretained(this)),
3284 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback, 3284 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
3285 base::Unretained(this))); 3285 base::Unretained(this)));
3286 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error"; 3286 EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error";
3287 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error"; 3287 EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error";
3288 3288
3289 adapter_chrome_os->OnRegisterProfileError( 3289 adapter_chrome_os->OnRegisterProfileError(BluetoothUUID(), "", "");
3290 BluetoothUUID(),
3291 base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
3292 base::Unretained(this)),
3293 "", "");
3294 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error"; 3290 EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error";
3295 EXPECT_EQ(1, error_callback_count_--) << "OnRegisterProfileError error"; 3291 EXPECT_EQ(0, error_callback_count_) << "OnRegisterProfileError error";
3296 3292
3297 adapter_chrome_os->ProcessQueuedDiscoveryRequests(); 3293 adapter_chrome_os->ProcessQueuedDiscoveryRequests();
3298 3294
3299 // From BluetoothAdapater: 3295 // From BluetoothAdapater:
3300 3296
3301 adapter_->StartDiscoverySession( 3297 adapter_->StartDiscoverySession(
3302 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback, 3298 base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
3303 base::Unretained(this)), 3299 base::Unretained(this)),
3304 GetErrorCallback()); 3300 GetErrorCallback());
3305 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error"; 3301 EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error";
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3397 adapter_->Shutdown(); 3393 adapter_->Shutdown();
3398 adapter_chrome_os->OnStopDiscoveryError(GetErrorCallback(), "", ""); 3394 adapter_chrome_os->OnStopDiscoveryError(GetErrorCallback(), "", "");
3399 3395
3400 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 3396 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
3401 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 3397 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
3402 EXPECT_EQ(0, callback_count_); 3398 EXPECT_EQ(0, callback_count_);
3403 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 3399 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
3404 } 3400 }
3405 3401
3406 } // namespace chromeos 3402 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_profile_chromeos_unittest.cc ('k') | device/bluetooth/bluetooth_socket_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698