This source file includes following definitions.
- AddObserver
- RemoveObserver
- GetAddress
- GetName
- SetName
- IsInitialized
- IsPresent
- IsPowered
- SetPowered
- IsDiscoverable
- SetDiscoverable
- IsDiscovering
- StartDiscoverySession
- ReadLocalOutOfBandPairingData
- AddDiscoverySession
- RemoveDiscoverySession
- RemovePairingDelegateInternal
- RequestPinCode
- RequestPasskey
- DisplayPinCode
- DisplayPasskey
- KeysEntered
- ConfirmPasskey
- AuthorizePairing
- TEST
- TEST
- TEST
- TEST
- TEST
#include "base/memory/ref_counted.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_device.h"
#include "testing/gtest/include/gtest/gtest.h"
using device::BluetoothAdapter;
using device::BluetoothDevice;
namespace device {
class TestBluetoothAdapter : public BluetoothAdapter {
public:
TestBluetoothAdapter() {
}
virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE {
}
virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE {
}
virtual std::string GetAddress() const OVERRIDE {
return "";
}
virtual std::string GetName() const OVERRIDE {
return "";
}
virtual void SetName(const std::string& name,
const base::Closure& callback,
const ErrorCallback& error_callback) OVERRIDE {
}
virtual bool IsInitialized() const OVERRIDE {
return false;
}
virtual bool IsPresent() const OVERRIDE {
return false;
}
virtual bool IsPowered() const OVERRIDE {
return false;
}
virtual void SetPowered(
bool powered,
const base::Closure& callback,
const ErrorCallback& error_callback) OVERRIDE {
}
virtual bool IsDiscoverable() const OVERRIDE {
return false;
}
virtual void SetDiscoverable(
bool discoverable,
const base::Closure& callback,
const ErrorCallback& error_callback) OVERRIDE {
}
virtual bool IsDiscovering() const OVERRIDE {
return false;
}
virtual void StartDiscoverySession(
const DiscoverySessionCallback& callback,
const ErrorCallback& error_callback) OVERRIDE {
}
virtual void ReadLocalOutOfBandPairingData(
const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback,
const ErrorCallback& error_callback) OVERRIDE {
}
protected:
virtual ~TestBluetoothAdapter() {}
virtual void AddDiscoverySession(
const base::Closure& callback,
const ErrorCallback& error_callback) OVERRIDE {
}
virtual void RemoveDiscoverySession(
const base::Closure& callback,
const ErrorCallback& error_callback) OVERRIDE {
}
virtual void RemovePairingDelegateInternal(
BluetoothDevice::PairingDelegate* pairing_delegate) OVERRIDE {
}
};
class TestPairingDelegate : public BluetoothDevice::PairingDelegate {
public:
virtual void RequestPinCode(BluetoothDevice* device) OVERRIDE {}
virtual void RequestPasskey(BluetoothDevice* device) OVERRIDE {}
virtual void DisplayPinCode(BluetoothDevice* device,
const std::string& pincode) OVERRIDE {}
virtual void DisplayPasskey(BluetoothDevice* device,
uint32 passkey) OVERRIDE {}
virtual void KeysEntered(BluetoothDevice* device,
uint32 entered) OVERRIDE {}
virtual void ConfirmPasskey(BluetoothDevice* device,
uint32 passkey) OVERRIDE {}
virtual void AuthorizePairing(BluetoothDevice* device) OVERRIDE {}
};
TEST(BluetoothAdapterTest, NoDefaultPairingDelegate) {
scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter();
EXPECT_TRUE(adapter->DefaultPairingDelegate() == NULL);
}
TEST(BluetoothAdapterTest, OneDefaultPairingDelegate) {
scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter();
TestPairingDelegate delegate;
adapter->AddPairingDelegate(&delegate,
BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_LOW);
EXPECT_EQ(&delegate, adapter->DefaultPairingDelegate());
}
TEST(BluetoothAdapterTest, SamePriorityDelegates) {
scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter();
TestPairingDelegate delegate1, delegate2;
adapter->AddPairingDelegate(&delegate1,
BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_LOW);
adapter->AddPairingDelegate(&delegate2,
BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_LOW);
EXPECT_EQ(&delegate1, adapter->DefaultPairingDelegate());
adapter->RemovePairingDelegate(&delegate1);
EXPECT_EQ(&delegate2, adapter->DefaultPairingDelegate());
}
TEST(BluetoothAdapterTest, HighestPriorityDelegate) {
scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter();
TestPairingDelegate delegate1, delegate2;
adapter->AddPairingDelegate(&delegate1,
BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_LOW);
adapter->AddPairingDelegate(&delegate2,
BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH);
EXPECT_EQ(&delegate2, adapter->DefaultPairingDelegate());
}
TEST(BluetoothAdapterTest, UnregisterDelegate) {
scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter();
TestPairingDelegate delegate;
adapter->AddPairingDelegate(&delegate,
BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_LOW);
adapter->RemovePairingDelegate(&delegate);
EXPECT_TRUE(adapter->DefaultPairingDelegate() == NULL);
}
}