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

Unified Diff: device/bluetooth/bluetooth_chromeos_unittest.cc

Issue 933823003: bluetooth: Modify DCHECK to conditionals in several BluetoothAdapterChromeOS methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_adapter_chromeos.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_chromeos_unittest.cc
diff --git a/device/bluetooth/bluetooth_chromeos_unittest.cc b/device/bluetooth/bluetooth_chromeos_unittest.cc
index 6ce931b4974ddf19fd3bf7cc4c023a946bafe1ee..7da63b789c4de98ae3c903bcf58f45763f4fbe95 100644
--- a/device/bluetooth/bluetooth_chromeos_unittest.cc
+++ b/device/bluetooth/bluetooth_chromeos_unittest.cc
@@ -4,6 +4,7 @@
#include "base/memory/scoped_vector.h"
#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_bluetooth_adapter_client.h"
@@ -24,6 +25,7 @@
using device::BluetoothAdapter;
using device::BluetoothAdapterFactory;
+using device::BluetoothAudioSink;
using device::BluetoothDevice;
using device::BluetoothDiscoverySession;
using device::BluetoothUUID;
@@ -146,6 +148,25 @@ void SaveConnectionInfo(BluetoothDevice::ConnectionInfo* out,
*out = conn_info;
};
+class FakeBluetoothProfileServiceProviderDelegate
+ : public chromeos::BluetoothProfileServiceProvider::Delegate {
+ public:
+ FakeBluetoothProfileServiceProviderDelegate() {}
+
+ // BluetoothProfileServiceProvider::Delegate:
+ void Released() override {}
+
+ void NewConnection(const dbus::ObjectPath&,
+ scoped_ptr<dbus::FileDescriptor>,
+ const BluetoothProfileServiceProvider::Delegate::Options&,
+ const ConfirmationCallback&) override {}
+
+ void RequestDisconnection(const dbus::ObjectPath&,
+ const ConfirmationCallback&) override {}
+
+ void Cancel() override {}
+};
+
} // namespace
class TestPairingDelegate : public BluetoothDevice::PairingDelegate {
@@ -272,11 +293,7 @@ class BluetoothChromeOSTest : public testing::Test {
if (!session->IsActive())
continue;
callback_count_ = 0;
- session->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ session->Stop(GetCallback(), GetErrorCallback());
message_loop_.Run();
ASSERT_EQ(1, callback_count_);
}
@@ -291,6 +308,10 @@ class BluetoothChromeOSTest : public testing::Test {
QuitMessageLoop();
}
+ base::Closure GetCallback() {
+ return base::Bind(&BluetoothChromeOSTest::Callback, base::Unretained(this));
+ }
+
void DiscoverySessionCallback(
scoped_ptr<BluetoothDiscoverySession> discovery_session) {
++callback_count_;
@@ -298,11 +319,26 @@ class BluetoothChromeOSTest : public testing::Test {
QuitMessageLoop();
}
+ void AudioSinkAcquiredCallback(scoped_refptr<BluetoothAudioSink>) {
+ ++callback_count_;
+ QuitMessageLoop();
+ }
+
+ void ProfileRegisteredCallback(BluetoothAdapterProfileChromeOS*) {
+ ++callback_count_;
+ QuitMessageLoop();
+ }
+
void ErrorCallback() {
++error_callback_count_;
QuitMessageLoop();
}
+ base::Closure GetErrorCallback() {
+ return base::Bind(&BluetoothChromeOSTest::ErrorCallback,
+ base::Unretained(this));
+ }
+
void DBusErrorCallback(const std::string& error_name,
const std::string& error_message) {
++error_callback_count_;
@@ -315,6 +351,16 @@ class BluetoothChromeOSTest : public testing::Test {
last_connect_error_ = error;
}
+ void AudioSinkErrorCallback(BluetoothAudioSink::ErrorCode) {
+ ++error_callback_count_;
+ QuitMessageLoop();
+ }
+
+ void ErrorCompletionCallback(const std::string& error_message) {
+ ++error_callback_count_;
+ QuitMessageLoop();
+ }
+
// Call to fill the adapter_ member with a BluetoothAdapter instance.
void GetAdapter() {
adapter_ = new BluetoothAdapterChromeOS();
@@ -334,17 +380,11 @@ class BluetoothChromeOSTest : public testing::Test {
TestObserver observer(adapter_);
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
adapter_->StartDiscoverySession(
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ GetErrorCallback());
base::MessageLoop::current()->Run();
ASSERT_EQ(2, callback_count_);
ASSERT_EQ(0, error_callback_count_);
@@ -359,11 +399,7 @@ class BluetoothChromeOSTest : public testing::Test {
observer.last_device_address_ != address)
base::MessageLoop::current()->Run();
- discovery_sessions_[0]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
base::MessageLoop::current()->Run();
ASSERT_EQ(1, callback_count_);
ASSERT_EQ(0, error_callback_count_);
@@ -530,12 +566,7 @@ TEST_F(BluetoothChromeOSTest, BecomePowered) {
// with true, and IsPowered() to return true.
TestObserver observer(adapter_);
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -547,12 +578,7 @@ TEST_F(BluetoothChromeOSTest, BecomePowered) {
TEST_F(BluetoothChromeOSTest, BecomeNotPowered) {
GetAdapter();
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
callback_count_ = 0;
@@ -563,12 +589,7 @@ TEST_F(BluetoothChromeOSTest, BecomeNotPowered) {
// with false, and IsPowered() to return false.
TestObserver observer(adapter_);
- adapter_->SetPowered(
- false,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(false, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -594,12 +615,7 @@ TEST_F(BluetoothChromeOSTest, SetPoweredWhenNotPresent) {
EXPECT_FALSE(adapter_->IsPresent());
EXPECT_FALSE(adapter_->IsPowered());
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(0, callback_count_);
EXPECT_EQ(1, error_callback_count_);
@@ -614,12 +630,7 @@ TEST_F(BluetoothChromeOSTest, ChangeAdapterName) {
static const std::string new_name(".__.");
- adapter_->SetName(
- new_name,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetName(new_name, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -642,12 +653,7 @@ TEST_F(BluetoothChromeOSTest, ChangeAdapterNameWhenNotPresent) {
EXPECT_FALSE(adapter_->IsPresent());
EXPECT_FALSE(adapter_->IsPowered());
- adapter_->SetName(
- "^o^",
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetName("^o^", GetCallback(), GetErrorCallback());
EXPECT_EQ(0, callback_count_);
EXPECT_EQ(1, error_callback_count_);
@@ -662,12 +668,7 @@ TEST_F(BluetoothChromeOSTest, BecomeDiscoverable) {
// with true, and IsDiscoverable() to return true.
TestObserver observer(adapter_);
- adapter_->SetDiscoverable(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -678,12 +679,7 @@ TEST_F(BluetoothChromeOSTest, BecomeDiscoverable) {
TEST_F(BluetoothChromeOSTest, BecomeNotDiscoverable) {
GetAdapter();
- adapter_->SetDiscoverable(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
callback_count_ = 0;
@@ -694,12 +690,7 @@ TEST_F(BluetoothChromeOSTest, BecomeNotDiscoverable) {
// with false, and IsDiscoverable() to return false.
TestObserver observer(adapter_);
- adapter_->SetDiscoverable(
- false,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetDiscoverable(false, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -725,12 +716,7 @@ TEST_F(BluetoothChromeOSTest, SetDiscoverableWhenNotPresent) {
EXPECT_FALSE(adapter_->IsPresent());
EXPECT_FALSE(adapter_->IsDiscoverable());
- adapter_->SetDiscoverable(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(0, callback_count_);
EXPECT_EQ(1, error_callback_count_);
@@ -742,17 +728,11 @@ TEST_F(BluetoothChromeOSTest, SetDiscoverableWhenNotPresent) {
TEST_F(BluetoothChromeOSTest, StopDiscovery) {
GetAdapter();
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
adapter_->StartDiscoverySession(
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ GetErrorCallback());
message_loop_.Run();
EXPECT_EQ(2, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -768,11 +748,7 @@ TEST_F(BluetoothChromeOSTest, StopDiscovery) {
// discovering,
TestObserver observer(adapter_);
- discovery_sessions_[0]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
message_loop_.Run();
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -790,17 +766,11 @@ TEST_F(BluetoothChromeOSTest, Discovery) {
TestObserver observer(adapter_);
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
adapter_->StartDiscoverySession(
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ GetErrorCallback());
message_loop_.Run();
EXPECT_EQ(2, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -833,17 +803,11 @@ TEST_F(BluetoothChromeOSTest, Discovery) {
TEST_F(BluetoothChromeOSTest, PoweredAndDiscovering) {
GetAdapter();
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
adapter_->StartDiscoverySession(
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ GetErrorCallback());
message_loop_.Run();
EXPECT_EQ(2, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -907,12 +871,7 @@ TEST_F(BluetoothChromeOSTest, PoweredAndDiscovering) {
// correctly for discovery requests done via the BluetoothAdapter.
TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) {
GetAdapter();
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
EXPECT_TRUE(adapter_->IsPowered());
@@ -927,10 +886,9 @@ TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) {
// Request device discovery 3 times.
for (int i = 0; i < 3; i++) {
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
}
// Run only once, as there should have been one D-Bus call.
message_loop_.Run();
@@ -947,11 +905,7 @@ TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) {
// Request to stop discovery twice.
for (int i = 0; i < 2; i++) {
- discovery_sessions_[i]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[i]->Stop(GetCallback(), GetErrorCallback());
}
// The observer should have received no additional discovering changed events,
@@ -970,10 +924,9 @@ TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) {
// Request device discovery 3 times.
for (int i = 0; i < 3; i++) {
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
}
// The observer should have received no additional discovering changed events,
@@ -988,11 +941,7 @@ TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) {
// Request to stop discovery 4 times.
for (int i = 2; i < 6; i++) {
- discovery_sessions_[i]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[i]->Stop(GetCallback(), GetErrorCallback());
}
// Run only once, as there should have been one D-Bus call.
message_loop_.Run();
@@ -1011,11 +960,7 @@ TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) {
EXPECT_FALSE(discovery_sessions_[i]->IsActive());
// Request to stop discovery on of the inactive sessions.
- discovery_sessions_[0]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
// The call should have failed.
EXPECT_EQ(2, observer.discovering_changed_count_);
@@ -1031,12 +976,7 @@ TEST_F(BluetoothChromeOSTest, MultipleDiscoverySessions) {
TEST_F(BluetoothChromeOSTest,
UnexpectedChangesDuringMultipleDiscoverySessions) {
GetAdapter();
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
EXPECT_TRUE(adapter_->IsPowered());
@@ -1051,10 +991,9 @@ TEST_F(BluetoothChromeOSTest,
// Request device discovery 3 times.
for (int i = 0; i < 3; i++) {
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
}
// Run only once, as there should have been one D-Bus call.
message_loop_.Run();
@@ -1086,9 +1025,7 @@ TEST_F(BluetoothChromeOSTest,
// FakeBluetoothAdapterClient's count should be only 1 and a single call to
// FakeBluetoothAdapterClient::StopDiscovery should work.
fake_bluetooth_adapter_client_->StopDiscovery(
- dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
+ dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), GetCallback(),
base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
base::Unretained(this)));
message_loop_.Run();
@@ -1106,10 +1043,9 @@ TEST_F(BluetoothChromeOSTest,
// It should be possible to successfully start discovery.
for (int i = 0; i < 2; i++) {
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
}
// Run only once, as there should have been one D-Bus call.
message_loop_.Run();
@@ -1154,10 +1090,9 @@ TEST_F(BluetoothChromeOSTest,
// application other than us. Starting and stopping discovery will succeed
// but it won't cause the discovery state to change.
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
message_loop_.Run(); // Run the loop, as there should have been a D-Bus call.
EXPECT_EQ(5, observer.discovering_changed_count_);
EXPECT_EQ(7, callback_count_);
@@ -1167,11 +1102,7 @@ TEST_F(BluetoothChromeOSTest,
ASSERT_EQ((size_t)1, discovery_sessions_.size());
EXPECT_TRUE(discovery_sessions_[0]->IsActive());
- discovery_sessions_[0]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
message_loop_.Run(); // Run the loop, as there should have been a D-Bus call.
EXPECT_EQ(5, observer.discovering_changed_count_);
EXPECT_EQ(8, callback_count_);
@@ -1183,10 +1114,9 @@ TEST_F(BluetoothChromeOSTest,
// Start discovery again.
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
message_loop_.Run(); // Run the loop, as there should have been a D-Bus call.
EXPECT_EQ(5, observer.discovering_changed_count_);
EXPECT_EQ(9, callback_count_);
@@ -1200,9 +1130,7 @@ TEST_F(BluetoothChromeOSTest,
// the discovery state won't change since our BluetoothAdapter also just
// requested it via D-Bus.
fake_bluetooth_adapter_client_->StopDiscovery(
- dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
+ dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), GetCallback(),
base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
base::Unretained(this)));
message_loop_.Run();
@@ -1214,11 +1142,7 @@ TEST_F(BluetoothChromeOSTest,
// Now end the discovery session. This should change the adapter's discovery
// state.
- discovery_sessions_[0]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
message_loop_.Run();
EXPECT_EQ(6, observer.discovering_changed_count_);
EXPECT_EQ(11, callback_count_);
@@ -1230,12 +1154,7 @@ TEST_F(BluetoothChromeOSTest,
TEST_F(BluetoothChromeOSTest, InvalidatedDiscoverySessions) {
GetAdapter();
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
EXPECT_TRUE(adapter_->IsPowered());
@@ -1250,10 +1169,9 @@ TEST_F(BluetoothChromeOSTest, InvalidatedDiscoverySessions) {
// Request device discovery 3 times.
for (int i = 0; i < 3; i++) {
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
}
// Run only once, as there should have been one D-Bus call.
message_loop_.Run();
@@ -1290,9 +1208,7 @@ TEST_F(BluetoothChromeOSTest, InvalidatedDiscoverySessions) {
// memory errors as the sessions that we explicitly deleted should get
// cleaned up.
fake_bluetooth_adapter_client_->StopDiscovery(
- dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
+ dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), GetCallback(),
base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
base::Unretained(this)));
message_loop_.Run();
@@ -1307,12 +1223,7 @@ TEST_F(BluetoothChromeOSTest, InvalidatedDiscoverySessions) {
TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) {
GetAdapter();
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
EXPECT_TRUE(adapter_->IsPowered());
@@ -1326,10 +1237,9 @@ TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) {
// Request to start discovery. The call should be pending.
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
EXPECT_EQ(0, callback_count_);
fake_bluetooth_device_client_->EndDiscoverySimulation(
@@ -1346,10 +1256,9 @@ TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) {
// be no change in state.
for (int i = 0; i < 2; i++) {
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
}
EXPECT_EQ(0, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -1371,11 +1280,7 @@ TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) {
// Verify the reference count by removing sessions 3 times. The last request
// should remain pending.
for (int i = 0; i < 3; i++) {
- discovery_sessions_[i]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[i]->Stop(GetCallback(), GetErrorCallback());
}
EXPECT_EQ(5, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -1387,11 +1292,7 @@ TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) {
EXPECT_TRUE(discovery_sessions_[2]->IsActive());
// Request to stop the session whose call is pending should fail.
- discovery_sessions_[2]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[2]->Stop(GetCallback(), GetErrorCallback());
EXPECT_EQ(5, callback_count_);
EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(2, observer.discovering_changed_count_);
@@ -1401,10 +1302,9 @@ TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) {
// Request to start should get queued.
adapter_->StartDiscoverySession(
- base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
+ base::Unretained(this)),
+ GetErrorCallback());
EXPECT_EQ(5, callback_count_);
EXPECT_EQ(1, error_callback_count_);
EXPECT_EQ(2, observer.discovering_changed_count_);
@@ -1437,12 +1337,7 @@ TEST_F(BluetoothChromeOSTest, QueuedDiscoveryRequests) {
TEST_F(BluetoothChromeOSTest, StartDiscoverySession) {
GetAdapter();
- adapter_->SetPowered(
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
EXPECT_TRUE(adapter_->IsPowered());
@@ -1459,8 +1354,7 @@ TEST_F(BluetoothChromeOSTest, StartDiscoverySession) {
adapter_->StartDiscoverySession(
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ GetErrorCallback());
message_loop_.Run();
EXPECT_EQ(1, observer.discovering_changed_count_);
EXPECT_EQ(1, callback_count_);
@@ -1476,8 +1370,7 @@ TEST_F(BluetoothChromeOSTest, StartDiscoverySession) {
adapter_->StartDiscoverySession(
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ GetErrorCallback());
message_loop_.Run();
EXPECT_EQ(1, observer.discovering_changed_count_);
EXPECT_EQ(2, callback_count_);
@@ -1491,8 +1384,7 @@ TEST_F(BluetoothChromeOSTest, StartDiscoverySession) {
adapter_->StartDiscoverySession(
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ GetErrorCallback());
message_loop_.Run();
EXPECT_EQ(1, observer.discovering_changed_count_);
EXPECT_EQ(3, callback_count_);
@@ -1505,11 +1397,7 @@ TEST_F(BluetoothChromeOSTest, StartDiscoverySession) {
// Stop the previous discovery session. The session should end but discovery
// should continue.
- discovery_sessions_[0]->Stop(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
message_loop_.Run();
EXPECT_EQ(1, observer.discovering_changed_count_);
EXPECT_EQ(4, callback_count_);
@@ -1675,9 +1563,7 @@ TEST_F(BluetoothChromeOSTest, ForgetDevice) {
// with the device we remove.
TestObserver observer(adapter_);
- devices[0]->Forget(
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ devices[0]->Forget(GetErrorCallback());
EXPECT_EQ(0, error_callback_count_);
EXPECT_EQ(1, observer.device_removed_count_);
@@ -1698,12 +1584,9 @@ TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) {
ASSERT_FALSE(device->IsPaired());
// Connect the device so it becomes trusted and remembered.
- device->Connect(
- NULL,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(NULL, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
ASSERT_EQ(1, callback_count_);
ASSERT_EQ(0, error_callback_count_);
@@ -1722,9 +1605,7 @@ TEST_F(BluetoothChromeOSTest, ForgetUnpairedDevice) {
// with the device we remove.
TestObserver observer(adapter_);
- device->Forget(
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ device->Forget(GetErrorCallback());
EXPECT_EQ(0, error_callback_count_);
EXPECT_EQ(1, observer.device_removed_count_);
@@ -1749,12 +1630,9 @@ TEST_F(BluetoothChromeOSTest, ConnectPairedDevice) {
// Connect without a pairing delegate; since the device is already Paired
// this should succeed and the device should become connected.
- device->Connect(
- NULL,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(NULL, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -1781,12 +1659,9 @@ TEST_F(BluetoothChromeOSTest, ConnectUnpairableDevice) {
// Connect without a pairing delegate; since the device does not require
// pairing, this should succeed and the device should become connected.
- device->Connect(
- NULL,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(NULL, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -1820,12 +1695,9 @@ TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) {
ASSERT_TRUE(device != NULL);
ASSERT_TRUE(device->IsPaired());
- device->Connect(
- NULL,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(NULL, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
ASSERT_EQ(1, callback_count_);
ASSERT_EQ(0, error_callback_count_);
@@ -1837,12 +1709,9 @@ TEST_F(BluetoothChromeOSTest, ConnectConnectedDevice) {
// anything to initiate the connection.
TestObserver observer(adapter_);
- device->Connect(
- NULL,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(NULL, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -1868,12 +1737,9 @@ TEST_F(BluetoothChromeOSTest, ConnectDeviceFails) {
// Connect without a pairing delegate; since the device requires pairing,
// this should fail with an error.
- device->Connect(
- NULL,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(NULL, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(0, callback_count_);
EXPECT_EQ(1, error_callback_count_);
@@ -1893,12 +1759,9 @@ TEST_F(BluetoothChromeOSTest, DisconnectDevice) {
ASSERT_TRUE(device != NULL);
ASSERT_TRUE(device->IsPaired());
- device->Connect(
- NULL,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(NULL, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
ASSERT_EQ(1, callback_count_);
ASSERT_EQ(0, error_callback_count_);
@@ -1911,11 +1774,7 @@ TEST_F(BluetoothChromeOSTest, DisconnectDevice) {
// device get dropped.
TestObserver observer(adapter_);
- device->Disconnect(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ device->Disconnect(GetCallback(), GetErrorCallback());
EXPECT_EQ(1, callback_count_);
EXPECT_EQ(0, error_callback_count_);
@@ -1939,11 +1798,7 @@ TEST_F(BluetoothChromeOSTest, DisconnectUnconnectedDevice) {
// device get dropped.
TestObserver observer(adapter_);
- device->Disconnect(
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ device->Disconnect(GetCallback(), GetErrorCallback());
EXPECT_EQ(0, callback_count_);
EXPECT_EQ(1, error_callback_count_);
@@ -1969,12 +1824,9 @@ TEST_F(BluetoothChromeOSTest, PairLegacyAutopair) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(0, pairing_delegate.call_count_);
EXPECT_TRUE(device->IsConnecting());
@@ -2023,12 +1875,9 @@ TEST_F(BluetoothChromeOSTest, PairDisplayPinCode) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.display_pincode_count_);
@@ -2080,12 +1929,9 @@ TEST_F(BluetoothChromeOSTest, PairDisplayPasskey) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
// One call for DisplayPasskey() and one for KeysEntered().
EXPECT_EQ(2, pairing_delegate.call_count_);
@@ -2157,12 +2003,9 @@ TEST_F(BluetoothChromeOSTest, PairRequestPinCode) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
@@ -2214,12 +2057,9 @@ TEST_F(BluetoothChromeOSTest, PairConfirmPasskey) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
@@ -2269,12 +2109,9 @@ TEST_F(BluetoothChromeOSTest, PairRequestPasskey) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
@@ -2323,12 +2160,9 @@ TEST_F(BluetoothChromeOSTest, PairJustWorks) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(0, pairing_delegate.call_count_);
@@ -2371,12 +2205,9 @@ TEST_F(BluetoothChromeOSTest, PairUnpairableDeviceFails) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(0, pairing_delegate.call_count_);
EXPECT_TRUE(device->IsConnecting());
@@ -2409,12 +2240,9 @@ TEST_F(BluetoothChromeOSTest, PairingFails) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(0, pairing_delegate.call_count_);
EXPECT_TRUE(device->IsConnecting());
@@ -2448,12 +2276,9 @@ TEST_F(BluetoothChromeOSTest, PairingFailsAtConnection) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(0, pairing_delegate.call_count_);
EXPECT_TRUE(device->IsConnecting());
@@ -2498,12 +2323,9 @@ TEST_F(BluetoothChromeOSTest, PairingRejectedAtPinCode) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
@@ -2539,12 +2361,9 @@ TEST_F(BluetoothChromeOSTest, PairingCancelledAtPinCode) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
@@ -2580,12 +2399,9 @@ TEST_F(BluetoothChromeOSTest, PairingRejectedAtPasskey) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
@@ -2621,12 +2437,9 @@ TEST_F(BluetoothChromeOSTest, PairingCancelledAtPasskey) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
@@ -2662,12 +2475,9 @@ TEST_F(BluetoothChromeOSTest, PairingRejectedAtConfirmation) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
@@ -2703,12 +2513,9 @@ TEST_F(BluetoothChromeOSTest, PairingCancelledAtConfirmation) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
@@ -2744,12 +2551,9 @@ TEST_F(BluetoothChromeOSTest, PairingCancelledInFlight) {
TestObserver observer(adapter_);
TestPairingDelegate pairing_delegate;
- device->Connect(
- &pairing_delegate,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(&pairing_delegate, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(0, pairing_delegate.call_count_);
EXPECT_TRUE(device->IsConnecting());
@@ -2791,12 +2595,9 @@ TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCode) {
TestObserver observer(adapter_);
fake_bluetooth_device_client_->SimulatePairing(
- dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath),
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
- base::Unretained(this)));
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), true,
+ GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.request_pincode_count_);
@@ -2848,12 +2649,9 @@ TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskey) {
TestObserver observer(adapter_);
fake_bluetooth_device_client_->SimulatePairing(
- dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath),
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
- base::Unretained(this)));
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), true,
+ GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.confirm_passkey_count_);
@@ -2906,12 +2704,9 @@ TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskey) {
TestObserver observer(adapter_);
fake_bluetooth_device_client_->SimulatePairing(
- dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath),
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
- base::Unretained(this)));
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true,
+ GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
@@ -2964,12 +2759,9 @@ TEST_F(BluetoothChromeOSTest, IncomingPairJustWorks) {
TestObserver observer(adapter_);
fake_bluetooth_device_client_->SimulatePairing(
- dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath),
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
- base::Unretained(this)));
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), true,
+ GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.authorize_pairing_count_);
@@ -3017,12 +2809,9 @@ TEST_F(BluetoothChromeOSTest, IncomingPairRequestPinCodeWithoutDelegate) {
TestObserver observer(adapter_);
fake_bluetooth_device_client_->SimulatePairing(
- dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath),
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
- base::Unretained(this)));
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath), true,
+ GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
+ base::Unretained(this)));
message_loop_.Run();
@@ -3059,12 +2848,9 @@ TEST_F(BluetoothChromeOSTest, IncomingPairConfirmPasskeyWithoutDelegate) {
TestObserver observer(adapter_);
fake_bluetooth_device_client_->SimulatePairing(
- dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath),
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
- base::Unretained(this)));
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath), true,
+ GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
+ base::Unretained(this)));
message_loop_.Run();
@@ -3101,12 +2887,9 @@ TEST_F(BluetoothChromeOSTest, IncomingPairRequestPasskeyWithoutDelegate) {
TestObserver observer(adapter_);
fake_bluetooth_device_client_->SimulatePairing(
- dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath),
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
- base::Unretained(this)));
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true,
+ GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
+ base::Unretained(this)));
message_loop_.Run();
@@ -3143,12 +2926,9 @@ TEST_F(BluetoothChromeOSTest, IncomingPairJustWorksWithoutDelegate) {
TestObserver observer(adapter_);
fake_bluetooth_device_client_->SimulatePairing(
- dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath),
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
- base::Unretained(this)));
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kJustWorksPath), true,
+ GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
+ base::Unretained(this)));
message_loop_.Run();
@@ -3189,12 +2969,9 @@ TEST_F(BluetoothChromeOSTest, RemovePairingDelegateDuringPairing) {
TestObserver observer(adapter_);
fake_bluetooth_device_client_->SimulatePairing(
- dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath),
- true,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
- base::Unretained(this)));
+ dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPasskeyPath), true,
+ GetCallback(), base::Bind(&BluetoothChromeOSTest::DBusErrorCallback,
+ base::Unretained(this)));
EXPECT_EQ(1, pairing_delegate.call_count_);
EXPECT_EQ(1, pairing_delegate.request_passkey_count_);
@@ -3296,12 +3073,9 @@ TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) {
BluetoothDevice* device =
adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress);
- device->Connect(
- NULL,
- base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
- base::Unretained(this)));
+ device->Connect(NULL, GetCallback(),
+ base::Bind(&BluetoothChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
EXPECT_TRUE(device->IsConnected());
// Calling GetConnectionInfo for a connected device should return valid
@@ -3316,26 +3090,23 @@ TEST_F(BluetoothChromeOSTest, GetConnectionInfoForConnectedDevice) {
// Verifies Shutdown shuts down the adapter as expected.
TEST_F(BluetoothChromeOSTest, Shutdown) {
- // Set up and adapter, power, discoverable, start discovery.
- GetAdapter();
- adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
- adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ // Set up adapter. Set powered & discoverable, start discovery.
+ GetAdapter();
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
+ adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
adapter_->StartDiscoverySession(
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
+ GetErrorCallback());
base::MessageLoop::current()->Run();
ASSERT_EQ(3, callback_count_);
ASSERT_EQ(0, error_callback_count_);
callback_count_ = 0;
+ TestPairingDelegate pairing_delegate;
+ adapter_->AddPairingDelegate(
+ &pairing_delegate, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
+
// Validate running adapter state.
EXPECT_NE("", adapter_->GetAddress());
EXPECT_NE("", adapter_->GetName());
@@ -3351,37 +3122,285 @@ TEST_F(BluetoothChromeOSTest, Shutdown) {
adapter_.get())->object_path());
// Shutdown
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get())->Shutdown();
+ adapter_->Shutdown();
- // Validate post shutdown state.
+ // Validate post shutdown state by calling all BluetoothAdapterChromeOS
+ // members, in declaration order:
+
+ adapter_->Shutdown();
+ // DeleteOnCorrectThread omitted as we don't want to delete in this test.
+ {
+ TestObserver observer(adapter_); // Calls AddObserver
+ } // TestObserver::~TestObserver calls RemoveObserver.
EXPECT_EQ("", adapter_->GetAddress());
EXPECT_EQ("", adapter_->GetName());
+
+ adapter_->SetName("", GetCallback(), GetErrorCallback());
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(1, error_callback_count_--) << "SetName error";
+
EXPECT_TRUE(adapter_->IsInitialized());
EXPECT_FALSE(adapter_->IsPresent());
EXPECT_FALSE(adapter_->IsPowered());
+
+ adapter_->SetPowered(true, GetCallback(), GetErrorCallback());
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(1, error_callback_count_--) << "SetPowered error";
+
EXPECT_FALSE(adapter_->IsDiscoverable());
+
+ adapter_->SetDiscoverable(true, GetCallback(), GetErrorCallback());
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(1, error_callback_count_--) << "SetDiscoverable error";
+
EXPECT_FALSE(adapter_->IsDiscovering());
- EXPECT_EQ(0U, adapter_->GetDevices().size());
- EXPECT_EQ(nullptr, adapter_->GetDevice(
- FakeBluetoothDeviceClient::kPairedDeviceAddress));
- EXPECT_EQ(dbus::ObjectPath(""), static_cast<BluetoothAdapterChromeOS*>(
- adapter_.get())->object_path());
+ // CreateRfcommService will DCHECK after Shutdown().
+ // CreateL2capService will DCHECK after Shutdown().
+
+ BluetoothAudioSink::Options audio_sink_options;
+ adapter_->RegisterAudioSink(
+ audio_sink_options,
+ base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback,
+ base::Unretained(this)));
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error";
+
+ BluetoothAdapterChromeOS* adapter_chrome_os =
+ static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
+ EXPECT_EQ(NULL, adapter_chrome_os->GetDeviceWithPath(dbus::ObjectPath("")));
+
+ // Notify methods presume objects exist that are owned by the adapter and
+ // destroyed in Shutdown(). Mocks are not attempted here that won't exist,
+ // as verified below by EXPECT_EQ(0U, adapter_->GetDevices().size());
+ // NotifyDeviceChanged
+ // NotifyGattServiceAdded
+ // NotifyGattServiceRemoved
+ // NotifyGattServiceChanged
+ // NotifyGattDiscoveryComplete
+ // NotifyGattCharacteristicAdded
+ // NotifyGattCharacteristicRemoved
+ // NotifyGattDescriptorAdded
+ // NotifyGattDescriptorRemoved
+ // NotifyGattCharacteristicValueChanged
+ // NotifyGattDescriptorValueChanged
+
+ EXPECT_EQ(dbus::ObjectPath(""), adapter_chrome_os->object_path());
+
+ FakeBluetoothProfileServiceProviderDelegate profile_delegate;
+ adapter_chrome_os->UseProfile(
+ BluetoothUUID(), dbus::ObjectPath(""),
+ BluetoothProfileManagerClient::Options(), &profile_delegate,
+ base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
+ base::Unretained(this)));
+ base::MessageLoop::current()->Run();
+ EXPECT_EQ(1, callback_count_--) << "UseProfile error";
+ EXPECT_EQ(0, error_callback_count_) << "UseProfile error";
+
+ adapter_chrome_os->ReleaseProfile(BluetoothUUID());
+
+ // Protected and private methods:
+
+ adapter_chrome_os->RemovePairingDelegateInternal(&pairing_delegate);
+
+ // BluetoothAdapterClient::Observer methods omitted, dbus will be shutdown.
+ // BluetoothDeviceClient::Observer methods omitted, dbus will be shutdown.
+ // BluetoothInputClient::Observer methods omitted, dbus will be shutdown.
+ // BluetoothAgentServiceProvider::Delegate omitted, dbus will be shutdown,
+ // with the exception of Released.
+ adapter_chrome_os->Released();
+
+ adapter_chrome_os->OnRegisterAgent();
+ adapter_chrome_os->OnRegisterAgentError("", "");
+ adapter_chrome_os->OnRequestDefaultAgent();
+ adapter_chrome_os->OnRequestDefaultAgentError("", "");
+
+ adapter_chrome_os->OnRegisterAudioSink(
+ base::Bind(&BluetoothChromeOSTest::AudioSinkAcquiredCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothChromeOSTest::AudioSinkErrorCallback,
+ base::Unretained(this)),
+ scoped_refptr<device::BluetoothAudioSink>());
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(1, error_callback_count_--) << "RegisterAudioSink error";
+
+ // GetPairing will DCHECK after Shutdown().
+ // SetAdapter will DCHECK after Shutdown().
+ // SetDefaultAdapterName will DCHECK after Shutdown().
+ // RemoveAdapter will DCHECK after Shutdown().
+ adapter_chrome_os->PoweredChanged(false);
+ adapter_chrome_os->DiscoverableChanged(false);
+ adapter_chrome_os->DiscoveringChanged(false);
+ adapter_chrome_os->PresentChanged(false);
+
+ adapter_chrome_os->OnSetDiscoverable(GetCallback(), GetErrorCallback(), true);
+ EXPECT_EQ(0, callback_count_) << "OnSetDiscoverable error";
+ EXPECT_EQ(1, error_callback_count_--) << "OnSetDiscoverable error";
+
+ adapter_chrome_os->OnPropertyChangeCompleted(GetCallback(),
+ GetErrorCallback(), true);
+ EXPECT_EQ(0, callback_count_) << "OnPropertyChangeCompleted error";
+ EXPECT_EQ(1, error_callback_count_--) << "OnPropertyChangeCompleted error";
+
+ adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback());
+ EXPECT_EQ(0, callback_count_) << "AddDiscoverySession error";
+ EXPECT_EQ(1, error_callback_count_--) << "AddDiscoverySession error";
+
+ adapter_chrome_os->RemoveDiscoverySession(GetCallback(), GetErrorCallback());
+ EXPECT_EQ(0, callback_count_) << "RemoveDiscoverySession error";
+ EXPECT_EQ(1, error_callback_count_--) << "RemoveDiscoverySession error";
+
+ // OnStartDiscovery tested in Shutdown_OnStartDiscovery
+ // OnStartDiscoveryError tested in Shutdown_OnStartDiscoveryError
+ // OnStopDiscovery tested in Shutdown_OnStopDiscovery
+ // OnStopDiscoveryError tested in Shutdown_OnStopDiscoveryError
+
+ // OnRegisterProfile SetProfileDelegate, OnRegisterProfileError, require
+ // UseProfile to be set first, do so again here just before calling them.
+ adapter_chrome_os->UseProfile(
+ BluetoothUUID(), dbus::ObjectPath(""),
+ BluetoothProfileManagerClient::Options(), &profile_delegate,
+ base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
+ base::Unretained(this)));
+
+ adapter_chrome_os->OnRegisterProfile(
+ BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate,
+ base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
+ base::Unretained(this)));
+ EXPECT_EQ(1, callback_count_--) << "OnRegisterProfile error";
+ EXPECT_EQ(1, error_callback_count_--) << "OnRegisterProfile error";
+
+ adapter_chrome_os->SetProfileDelegate(
+ BluetoothUUID(), dbus::ObjectPath(""), &profile_delegate,
+ base::Bind(&BluetoothChromeOSTest::ProfileRegisteredCallback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
+ base::Unretained(this)));
+ EXPECT_EQ(0, callback_count_) << "SetProfileDelegate error";
+ EXPECT_EQ(1, error_callback_count_--) << "SetProfileDelegate error";
+
+ adapter_chrome_os->OnRegisterProfileError(
+ BluetoothUUID(),
+ base::Bind(&BluetoothChromeOSTest::ErrorCompletionCallback,
+ base::Unretained(this)),
+ "", "");
+ EXPECT_EQ(0, callback_count_) << "OnRegisterProfileError error";
+ EXPECT_EQ(1, error_callback_count_--) << "OnRegisterProfileError error";
+
+ adapter_chrome_os->ProcessQueuedDiscoveryRequests();
+
+ // From BluetoothAdapater:
- adapter_->SetPowered(true, base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
- adapter_->SetDiscoverable(true, base::Bind(&BluetoothChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
adapter_->StartDiscoverySession(
base::Bind(&BluetoothChromeOSTest::DiscoverySessionCallback,
base::Unretained(this)),
- base::Bind(&BluetoothChromeOSTest::ErrorCallback,
- base::Unretained(this)));
- ASSERT_EQ(0, callback_count_);
- ASSERT_EQ(3, error_callback_count_);
+ GetErrorCallback());
+ EXPECT_EQ(0, callback_count_) << "StartDiscoverySession error";
+ EXPECT_EQ(1, error_callback_count_--) << "StartDiscoverySession error";
+
+ EXPECT_EQ(0U, adapter_->GetDevices().size());
+ EXPECT_EQ(nullptr, adapter_->GetDevice(
+ FakeBluetoothDeviceClient::kPairedDeviceAddress));
+ TestPairingDelegate pairing_delegate2;
+ adapter_->AddPairingDelegate(
+ &pairing_delegate2, BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
+ adapter_->RemovePairingDelegate(&pairing_delegate2);
+}
+
+// Verifies post-Shutdown of discovery sessions and OnStartDiscovery.
+TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscovery) {
+ const int kNumberOfDiscoverySessions = 10;
+ GetAdapter();
+ BluetoothAdapterChromeOS* adapter_chrome_os =
+ static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
+
+ for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
+ adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback());
+ }
+ adapter_->Shutdown();
+ adapter_chrome_os->OnStartDiscovery(GetCallback(), GetErrorCallback());
+
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_);
+}
+
+// Verifies post-Shutdown of discovery sessions and OnStartDiscoveryError.
+TEST_F(BluetoothChromeOSTest, Shutdown_OnStartDiscoveryError) {
+ const int kNumberOfDiscoverySessions = 10;
+ GetAdapter();
+ BluetoothAdapterChromeOS* adapter_chrome_os =
+ static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
+
+ for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
+ adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback());
+ }
+ adapter_->Shutdown();
+ adapter_chrome_os->OnStartDiscoveryError(GetCallback(), GetErrorCallback(),
+ "", "");
+
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_);
+}
+
+// Verifies post-Shutdown of discovery sessions and OnStartDiscovery.
+TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscovery) {
+ const int kNumberOfDiscoverySessions = 10;
+ GetAdapter();
+ BluetoothAdapterChromeOS* adapter_chrome_os =
+ static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
+
+ // In order to queue up discovery sessions before an OnStopDiscovery call
+ // RemoveDiscoverySession must be called, so Add, Start, and Remove:
+ adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback());
+ adapter_chrome_os->OnStartDiscovery(GetCallback(), GetErrorCallback());
+ adapter_chrome_os->RemoveDiscoverySession(GetCallback(), GetErrorCallback());
+ callback_count_ = 0;
+ error_callback_count_ = 0;
+ // Can now queue discovery sessions while waiting for OnStopDiscovery.
+ for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
+ adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback());
+ }
+ adapter_->Shutdown();
+ adapter_chrome_os->OnStopDiscovery(GetCallback());
+
+ // 1 successful stopped discovery from RemoveDiscoverySession, and
+ // kNumberOfDiscoverySessions errors from AddDiscoverySession/OnStopDiscovery.
+ EXPECT_EQ(1, callback_count_);
+ EXPECT_EQ(kNumberOfDiscoverySessions, error_callback_count_);
+}
+
+// Verifies post-Shutdown of discovery sessions and OnStopDiscoveryError.
+TEST_F(BluetoothChromeOSTest, Shutdown_OnStopDiscoveryError) {
+ const int kNumberOfDiscoverySessions = 10;
+ GetAdapter();
+ BluetoothAdapterChromeOS* adapter_chrome_os =
+ static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
+
+ // In order to queue up discovery sessions before an OnStopDiscoveryError call
+ // RemoveDiscoverySession must be called, so Add, Start, and Remove:
+ adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback());
+ adapter_chrome_os->OnStartDiscovery(GetCallback(), GetErrorCallback());
+ adapter_chrome_os->RemoveDiscoverySession(GetCallback(), GetErrorCallback());
+ callback_count_ = 0;
+ error_callback_count_ = 0;
+ // Can now queue discovery sessions while waiting for OnStopDiscoveryError.
+ for (int i = 0; i < kNumberOfDiscoverySessions; i++) {
+ adapter_chrome_os->AddDiscoverySession(GetCallback(), GetErrorCallback());
+ }
+ adapter_->Shutdown();
+ adapter_chrome_os->OnStopDiscoveryError(GetErrorCallback(), "", "");
+
+ // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
+ // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
}
} // namespace chromeos
« no previous file with comments | « device/bluetooth/bluetooth_adapter_chromeos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698