Commit 56d37103 authored by krstnmnlsn's avatar krstnmnlsn Committed by Commit bot

Adding class BluetoothTestMac so that the ConstructDefaultAdapter,

ConstructWithoutDefaultAdapter, and ConstructFakeAdapter tests
now pass on Mac as well as Android.

BUG=511008

Review URL: https://codereview.chromium.org/1232613004

Cr-Commit-Position: refs/heads/master@{#339730}
parent eb3e372e
...@@ -40,6 +40,8 @@ test("device_unittests") { ...@@ -40,6 +40,8 @@ test("device_unittests") {
"bluetooth/test/bluetooth_test.h", "bluetooth/test/bluetooth_test.h",
"bluetooth/test/bluetooth_test_android.cc", "bluetooth/test/bluetooth_test_android.cc",
"bluetooth/test/bluetooth_test_android.h", "bluetooth/test/bluetooth_test_android.h",
"bluetooth/test/bluetooth_test_mac.h",
"bluetooth/test/bluetooth_test_mac.mm",
"bluetooth/test/test_bluetooth_adapter_observer.cc", "bluetooth/test/test_bluetooth_adapter_observer.cc",
"bluetooth/test/test_bluetooth_adapter_observer.h", "bluetooth/test/test_bluetooth_adapter_observer.h",
"nfc/nfc_chromeos_unittest.cc", "nfc/nfc_chromeos_unittest.cc",
......
...@@ -41,7 +41,11 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac ...@@ -41,7 +41,11 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac
public BluetoothDiscoveryManagerMac::Observer, public BluetoothDiscoveryManagerMac::Observer,
public BluetoothLowEnergyDiscoveryManagerMac::Observer { public BluetoothLowEnergyDiscoveryManagerMac::Observer {
public: public:
static base::WeakPtr<BluetoothAdapter> CreateAdapter(); static base::WeakPtr<BluetoothAdapterMac> CreateAdapter();
static base::WeakPtr<BluetoothAdapterMac> CreateAdapterForTest(
std::string name,
std::string address,
scoped_refptr<base::SequencedTaskRunner> ui_task_runner);
// BluetoothAdapter overrides: // BluetoothAdapter overrides:
std::string GetAddress() const override; std::string GetAddress() const override;
...@@ -92,6 +96,11 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac ...@@ -92,6 +96,11 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac
// (crbug.com/506287). // (crbug.com/506287).
static bool IsLowEnergyAvailable(); static bool IsLowEnergyAvailable();
// Resets |low_energy_central_manager_| to |central_manager| and sets
// |low_energy_central_manager_delegate_| as the manager's delegate. Should
// be called only when |IsLowEnergyAvailable()|.
void SetCentralManagerForTesting(CBCentralManager* central_manager);
protected: protected:
// BluetoothAdapter override: // BluetoothAdapter override:
void RemovePairingDelegateInternal( void RemovePairingDelegateInternal(
...@@ -148,15 +157,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac ...@@ -148,15 +157,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac
// observers. // observers.
void AddPairedDevices(); void AddPairedDevices();
// Private method for testing. Resets |low_energy_central_manager_| to
// |central_manager| and sets |low_energy_central_manager_delegate_| as its
// delegate. Should be called only when CoreBluetooth is available.
void SetCentralManagerForTesting(CBCentralManager* central_manager);
std::string address_; std::string address_;
std::string name_; std::string name_;
bool powered_; bool classic_powered_;
int num_discovery_sessions_; int num_discovery_sessions_;
// Discovery manager for Bluetooth Classic. // Discovery manager for Bluetooth Classic.
......
...@@ -48,15 +48,27 @@ base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( ...@@ -48,15 +48,27 @@ base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
} }
// static // static
base::WeakPtr<BluetoothAdapter> BluetoothAdapterMac::CreateAdapter() { base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapter() {
BluetoothAdapterMac* adapter = new BluetoothAdapterMac(); BluetoothAdapterMac* adapter = new BluetoothAdapterMac();
adapter->Init(); adapter->Init();
return adapter->weak_ptr_factory_.GetWeakPtr(); return adapter->weak_ptr_factory_.GetWeakPtr();
} }
// static
base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapterForTest(
std::string name,
std::string address,
scoped_refptr<base::SequencedTaskRunner> ui_task_runner) {
BluetoothAdapterMac* adapter = new BluetoothAdapterMac();
adapter->InitForTest(ui_task_runner);
adapter->name_ = name;
adapter->address_ = address;
return adapter->weak_ptr_factory_.GetWeakPtr();
}
BluetoothAdapterMac::BluetoothAdapterMac() BluetoothAdapterMac::BluetoothAdapterMac()
: BluetoothAdapter(), : BluetoothAdapter(),
powered_(false), classic_powered_(false),
num_discovery_sessions_(0), num_discovery_sessions_(0),
classic_discovery_manager_( classic_discovery_manager_(
BluetoothDiscoveryManagerMac::CreateClassic(this)), BluetoothDiscoveryManagerMac::CreateClassic(this)),
...@@ -100,11 +112,21 @@ bool BluetoothAdapterMac::IsInitialized() const { ...@@ -100,11 +112,21 @@ bool BluetoothAdapterMac::IsInitialized() const {
} }
bool BluetoothAdapterMac::IsPresent() const { bool BluetoothAdapterMac::IsPresent() const {
return !address_.empty(); bool is_present = !address_.empty();
if (IsLowEnergyAvailable()) {
is_present = is_present || ([low_energy_central_manager_ state] ==
CBCentralManagerStatePoweredOn);
}
return is_present;
} }
bool BluetoothAdapterMac::IsPowered() const { bool BluetoothAdapterMac::IsPowered() const {
return powered_; bool is_powered = classic_powered_;
if (IsLowEnergyAvailable()) {
is_powered = is_powered || ([low_energy_central_manager_ state] ==
CBCentralManagerStatePoweredOn);
}
return is_powered;
} }
void BluetoothAdapterMac::SetPowered(bool powered, void BluetoothAdapterMac::SetPowered(bool powered,
...@@ -113,8 +135,9 @@ void BluetoothAdapterMac::SetPowered(bool powered, ...@@ -113,8 +135,9 @@ void BluetoothAdapterMac::SetPowered(bool powered,
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
// TODO(krstnmnlsn): If this information is retrievable form IOBluetooth we
// should return the discoverable status.
bool BluetoothAdapterMac::IsDiscoverable() const { bool BluetoothAdapterMac::IsDiscoverable() const {
NOTIMPLEMENTED();
return false; return false;
} }
...@@ -197,6 +220,16 @@ bool BluetoothAdapterMac::IsLowEnergyAvailable() { ...@@ -197,6 +220,16 @@ bool BluetoothAdapterMac::IsLowEnergyAvailable() {
return base::mac::IsOSYosemiteOrLater(); return base::mac::IsOSYosemiteOrLater();
} }
void BluetoothAdapterMac::SetCentralManagerForTesting(
CBCentralManager* central_manager) {
CHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
[central_manager performSelector:@selector(setDelegate:)
withObject:low_energy_central_manager_delegate_];
low_energy_central_manager_.reset(central_manager);
low_energy_discovery_manager_->SetCentralManager(
low_energy_central_manager_.get());
}
void BluetoothAdapterMac::RemovePairingDelegateInternal( void BluetoothAdapterMac::RemovePairingDelegateInternal(
BluetoothDevice::PairingDelegate* pairing_delegate) { BluetoothDevice::PairingDelegate* pairing_delegate) {
} }
...@@ -331,7 +364,7 @@ void BluetoothAdapterMac::PollAdapter() { ...@@ -331,7 +364,7 @@ void BluetoothAdapterMac::PollAdapter() {
"461181 BluetoothAdapterMac::PollAdapter::Start")); "461181 BluetoothAdapterMac::PollAdapter::Start"));
bool was_present = IsPresent(); bool was_present = IsPresent();
std::string address; std::string address;
bool powered = false; bool classic_powered = false;
IOBluetoothHostController* controller = IOBluetoothHostController* controller =
[IOBluetoothHostController defaultController]; [IOBluetoothHostController defaultController];
...@@ -343,7 +376,7 @@ void BluetoothAdapterMac::PollAdapter() { ...@@ -343,7 +376,7 @@ void BluetoothAdapterMac::PollAdapter() {
if (controller != nil) { if (controller != nil) {
address = BluetoothDevice::CanonicalizeAddress( address = BluetoothDevice::CanonicalizeAddress(
base::SysNSStringToUTF8([controller addressAsString])); base::SysNSStringToUTF8([controller addressAsString]));
powered = ([controller powerState] == kBluetoothHCIPowerStateON); classic_powered = ([controller powerState] == kBluetoothHCIPowerStateON);
// For performance reasons, cache the adapter's name. It's not uncommon for // For performance reasons, cache the adapter's name. It's not uncommon for
// a call to [controller nameAsString] to take tens of milliseconds. Note // a call to [controller nameAsString] to take tens of milliseconds. Note
...@@ -373,10 +406,10 @@ void BluetoothAdapterMac::PollAdapter() { ...@@ -373,10 +406,10 @@ void BluetoothAdapterMac::PollAdapter() {
tracked_objects::ScopedTracker tracking_profile4( tracked_objects::ScopedTracker tracking_profile4(
FROM_HERE_WITH_EXPLICIT_FUNCTION( FROM_HERE_WITH_EXPLICIT_FUNCTION(
"461181 BluetoothAdapterMac::PollAdapter::AdapterPowerChanged")); "461181 BluetoothAdapterMac::PollAdapter::AdapterPowerChanged"));
if (powered_ != powered) { if (classic_powered_ != classic_powered) {
powered_ = powered; classic_powered_ = classic_powered;
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
AdapterPoweredChanged(this, powered_)); AdapterPoweredChanged(this, classic_powered_));
} }
// TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/461181
...@@ -489,14 +522,4 @@ void BluetoothAdapterMac::AddPairedDevices() { ...@@ -489,14 +522,4 @@ void BluetoothAdapterMac::AddPairedDevices() {
} }
} }
void BluetoothAdapterMac::SetCentralManagerForTesting(
CBCentralManager* central_manager) {
CHECK(BluetoothAdapterMac::IsLowEnergyAvailable());
[central_manager performSelector:@selector(setDelegate:)
withObject:low_energy_central_manager_delegate_];
low_energy_central_manager_.reset(central_manager);
low_energy_discovery_manager_->SetCentralManager(
low_energy_central_manager_.get());
}
} // namespace device } // namespace device
...@@ -107,12 +107,13 @@ class BluetoothAdapterMacTest : public testing::Test { ...@@ -107,12 +107,13 @@ class BluetoothAdapterMacTest : public testing::Test {
void RemoveTimedOutDevices() { adapter_mac_->RemoveTimedOutDevices(); } void RemoveTimedOutDevices() { adapter_mac_->RemoveTimedOutDevices(); }
bool SetMockCentralManager() { bool SetMockCentralManager(CBCentralManagerState desired_state) {
if (!BluetoothAdapterMac::IsLowEnergyAvailable()) { if (!BluetoothAdapterMac::IsLowEnergyAvailable()) {
LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
return false; return false;
} }
mock_central_manager_ = [[MockCentralManager alloc] init]; mock_central_manager_ = [[MockCentralManager alloc] init];
[mock_central_manager_ setState:desired_state];
adapter_mac_->SetCentralManagerForTesting(mock_central_manager_); adapter_mac_->SetCentralManagerForTesting(mock_central_manager_);
return true; return true;
} }
...@@ -157,7 +158,7 @@ TEST_F(BluetoothAdapterMacTest, Poll) { ...@@ -157,7 +158,7 @@ TEST_F(BluetoothAdapterMacTest, Poll) {
} }
TEST_F(BluetoothAdapterMacTest, AddDiscoverySessionWithLowEnergyFilter) { TEST_F(BluetoothAdapterMacTest, AddDiscoverySessionWithLowEnergyFilter) {
if (!SetMockCentralManager()) if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return; return;
EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]);
EXPECT_EQ(0, NumDiscoverySessions()); EXPECT_EQ(0, NumDiscoverySessions());
...@@ -178,7 +179,7 @@ TEST_F(BluetoothAdapterMacTest, AddDiscoverySessionWithLowEnergyFilter) { ...@@ -178,7 +179,7 @@ TEST_F(BluetoothAdapterMacTest, AddDiscoverySessionWithLowEnergyFilter) {
// TODO(krstnmnlsn): Test changing the filter when adding the second discovery // TODO(krstnmnlsn): Test changing the filter when adding the second discovery
// session (once we have that ability). // session (once we have that ability).
TEST_F(BluetoothAdapterMacTest, AddSecondDiscoverySessionWithLowEnergyFilter) { TEST_F(BluetoothAdapterMacTest, AddSecondDiscoverySessionWithLowEnergyFilter) {
if (!SetMockCentralManager()) if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return; return;
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter( scoped_ptr<BluetoothDiscoveryFilter> discovery_filter(
new BluetoothDiscoveryFilter( new BluetoothDiscoveryFilter(
...@@ -200,7 +201,7 @@ TEST_F(BluetoothAdapterMacTest, AddSecondDiscoverySessionWithLowEnergyFilter) { ...@@ -200,7 +201,7 @@ TEST_F(BluetoothAdapterMacTest, AddSecondDiscoverySessionWithLowEnergyFilter) {
} }
TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilter) { TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilter) {
if (!SetMockCentralManager()) if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return; return;
EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]);
...@@ -224,7 +225,7 @@ TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilter) { ...@@ -224,7 +225,7 @@ TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilter) {
} }
TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilterFail) { TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilterFail) {
if (!SetMockCentralManager()) if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
return; return;
EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]);
EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]);
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "device/bluetooth/test/bluetooth_test_android.h" #include "device/bluetooth/test/bluetooth_test_android.h"
#elif defined(OS_MACOSX)
#include "device/bluetooth/test/bluetooth_test_mac.h"
#endif #endif
using device::BluetoothDevice; using device::BluetoothDevice;
...@@ -401,7 +403,7 @@ TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterAllFields) { ...@@ -401,7 +403,7 @@ TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterAllFields) {
} }
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms. // TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID) #if defined(OS_ANDROID) || defined(OS_MACOSX)
TEST_F(BluetoothTest, ConstructDefaultAdapter) { TEST_F(BluetoothTest, ConstructDefaultAdapter) {
InitWithDefaultAdapter(); InitWithDefaultAdapter();
if (!adapter_->IsPresent()) { if (!adapter_->IsPresent()) {
...@@ -417,10 +419,10 @@ TEST_F(BluetoothTest, ConstructDefaultAdapter) { ...@@ -417,10 +419,10 @@ TEST_F(BluetoothTest, ConstructDefaultAdapter) {
EXPECT_FALSE(adapter_->IsDiscoverable()); EXPECT_FALSE(adapter_->IsDiscoverable());
EXPECT_FALSE(adapter_->IsDiscovering()); EXPECT_FALSE(adapter_->IsDiscovering());
} }
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms. // TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID) #if defined(OS_ANDROID) || defined(OS_MACOSX)
TEST_F(BluetoothTest, ConstructWithoutDefaultAdapter) { TEST_F(BluetoothTest, ConstructWithoutDefaultAdapter) {
InitWithoutDefaultAdapter(); InitWithoutDefaultAdapter();
EXPECT_EQ(adapter_->GetAddress(), ""); EXPECT_EQ(adapter_->GetAddress(), "");
...@@ -430,20 +432,20 @@ TEST_F(BluetoothTest, ConstructWithoutDefaultAdapter) { ...@@ -430,20 +432,20 @@ TEST_F(BluetoothTest, ConstructWithoutDefaultAdapter) {
EXPECT_FALSE(adapter_->IsDiscoverable()); EXPECT_FALSE(adapter_->IsDiscoverable());
EXPECT_FALSE(adapter_->IsDiscovering()); EXPECT_FALSE(adapter_->IsDiscovering());
} }
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms. // TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID) #if defined(OS_ANDROID) || defined(OS_MACOSX)
TEST_F(BluetoothTest, ConstructFakeAdapter) { TEST_F(BluetoothTest, ConstructFakeAdapter) {
InitWithFakeAdapter(); InitWithFakeAdapter();
EXPECT_EQ(adapter_->GetAddress(), "A1:B2:C3:D4:E5:F6"); EXPECT_EQ(adapter_->GetAddress(), kTestAdapterAddress);
EXPECT_EQ(adapter_->GetName(), "FakeBluetoothAdapter"); EXPECT_EQ(adapter_->GetName(), kTestAdapterName);
EXPECT_TRUE(adapter_->IsPresent()); EXPECT_TRUE(adapter_->IsPresent());
EXPECT_TRUE(adapter_->IsPowered()); EXPECT_TRUE(adapter_->IsPowered());
EXPECT_FALSE(adapter_->IsDiscoverable()); EXPECT_FALSE(adapter_->IsDiscoverable());
EXPECT_FALSE(adapter_->IsDiscovering()); EXPECT_FALSE(adapter_->IsDiscovering());
} }
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms. // TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
namespace device { namespace device {
const std::string BluetoothTestBase::kTestAdapterName = "FakeBluetoothAdapter";
const std::string BluetoothTestBase::kTestAdapterAddress = "A1:B2:C3:D4:E5:F6";
BluetoothTestBase::BluetoothTestBase() { BluetoothTestBase::BluetoothTestBase() {
} }
......
...@@ -22,6 +22,9 @@ class BluetoothAdapter; ...@@ -22,6 +22,9 @@ class BluetoothAdapter;
// BluetoothTest. // BluetoothTest.
class BluetoothTestBase : public testing::Test { class BluetoothTestBase : public testing::Test {
public: public:
static const std::string kTestAdapterName;
static const std::string kTestAdapterAddress;
BluetoothTestBase(); BluetoothTestBase();
~BluetoothTestBase() override; ~BluetoothTestBase() override;
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_
#define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_
#include "base/test/test_simple_task_runner.h"
#include "device/bluetooth/test/bluetooth_test.h"
namespace device {
class BluetoothAdapterMac;
// Mac implementation of BluetoothTestBase.
class BluetoothTestMac : public BluetoothTestBase {
public:
BluetoothTestMac();
~BluetoothTestMac() override;
// Test overrides:
void SetUp() override;
// BluetoothTestBase overrides:
void InitWithDefaultAdapter() override;
void InitWithoutDefaultAdapter() override;
void InitWithFakeAdapter() override;
protected:
BluetoothAdapterMac* adapter_mac_ = NULL;
};
// Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName).
typedef BluetoothTestMac BluetoothTest;
} // namespace device
#endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_MAC_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/bluetooth/bluetooth_adapter_mac.h"
#include "device/bluetooth/test/bluetooth_test_mac.h"
#include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
namespace device {
BluetoothTestMac::BluetoothTestMac() {}
BluetoothTestMac::~BluetoothTestMac() {}
void BluetoothTestMac::SetUp() {}
void BluetoothTestMac::InitWithDefaultAdapter() {
adapter_mac_ = BluetoothAdapterMac::CreateAdapter().get();
adapter_ = adapter_mac_;
}
void BluetoothTestMac::InitWithoutDefaultAdapter() {
adapter_mac_ = BluetoothAdapterMac::CreateAdapterForTest(
"", "", message_loop_.task_runner())
.get();
adapter_ = adapter_mac_;
if (BluetoothAdapterMac::IsLowEnergyAvailable()) {
id low_energy_central_manager = [[MockCentralManager alloc] init];
[low_energy_central_manager setState:CBCentralManagerStateUnsupported];
adapter_mac_->SetCentralManagerForTesting(low_energy_central_manager);
}
}
void BluetoothTestMac::InitWithFakeAdapter() {
adapter_mac_ =
BluetoothAdapterMac::CreateAdapterForTest(
kTestAdapterName, kTestAdapterAddress, message_loop_.task_runner())
.get();
adapter_ = adapter_mac_;
if (BluetoothAdapterMac::IsLowEnergyAvailable()) {
id low_energy_central_manager = [[MockCentralManager alloc] init];
[low_energy_central_manager setState:CBCentralManagerStatePoweredOn];
adapter_mac_->SetCentralManagerForTesting(low_energy_central_manager);
}
}
} // namespace device
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
@property(nonatomic, assign) BOOL scanForPeripheralsCallCount; @property(nonatomic, assign) BOOL scanForPeripheralsCallCount;
@property(nonatomic, assign) BOOL stopScanCallCount; @property(nonatomic, assign) BOOL stopScanCallCount;
@property(nonatomic, assign) id<CBCentralManagerDelegate> delegate; @property(nonatomic, assign) id<CBCentralManagerDelegate> delegate;
@property(nonatomic, assign) CBCentralManagerState state;
// Designated initializer // Designated initializer
- (instancetype)init; - (instancetype)init;
...@@ -31,8 +32,6 @@ ...@@ -31,8 +32,6 @@
queue:(dispatch_queue_t)queue queue:(dispatch_queue_t)queue
options:(NSDictionary*)options; options:(NSDictionary*)options;
- (CBCentralManagerState)state;
- (void)scanForPeripheralsWithServices:(NSArray*)serviceUUIDs - (void)scanForPeripheralsWithServices:(NSArray*)serviceUUIDs
options:(NSDictionary*)options; options:(NSDictionary*)options;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
@synthesize scanForPeripheralsCallCount = _scanForPeripheralsCallCount; @synthesize scanForPeripheralsCallCount = _scanForPeripheralsCallCount;
@synthesize stopScanCallCount = _stopScanCallCount; @synthesize stopScanCallCount = _stopScanCallCount;
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
@synthesize state = _state;
- (instancetype)init { - (instancetype)init {
_scanForPeripheralsCallCount = 0; _scanForPeripheralsCallCount = 0;
...@@ -22,10 +23,6 @@ ...@@ -22,10 +23,6 @@
return [self init]; return [self init];
} }
- (CBCentralManagerState)state {
return CBCentralManagerStatePoweredOn;
}
- (void)scanForPeripheralsWithServices:(NSArray*)serviceUUIDs - (void)scanForPeripheralsWithServices:(NSArray*)serviceUUIDs
options:(NSDictionary*)options { options:(NSDictionary*)options {
_scanForPeripheralsCallCount++; _scanForPeripheralsCallCount++;
......
...@@ -55,6 +55,8 @@ ...@@ -55,6 +55,8 @@
'bluetooth/test/bluetooth_test.h', 'bluetooth/test/bluetooth_test.h',
'bluetooth/test/bluetooth_test_android.cc', 'bluetooth/test/bluetooth_test_android.cc',
'bluetooth/test/bluetooth_test_android.h', 'bluetooth/test/bluetooth_test_android.h',
'bluetooth/test/bluetooth_test_mac.h',
'bluetooth/test/bluetooth_test_mac.mm',
'bluetooth/test/test_bluetooth_adapter_observer.cc', 'bluetooth/test/test_bluetooth_adapter_observer.cc',
'bluetooth/test/test_bluetooth_adapter_observer.h', 'bluetooth/test/test_bluetooth_adapter_observer.h',
'devices_app/usb/device_impl_unittest.cc', 'devices_app/usb/device_impl_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment