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

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

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