Commit 512935cc authored by gogerald's avatar gogerald Committed by Commit bot

Add cross platform Bluetooth testing fixture for Windows.

This CL is the first step to implement GATT service in Chrome for Windows by using cross platform testing fixture.

BUG=579202

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

Cr-Commit-Position: refs/heads/master@{#371668}
parent 0004ce15
......@@ -49,6 +49,8 @@ test("device_unittests") {
"bluetooth/test/bluetooth_test_android.h",
"bluetooth/test/bluetooth_test_mac.h",
"bluetooth/test/bluetooth_test_mac.mm",
"bluetooth/test/bluetooth_test_win.cc",
"bluetooth/test/bluetooth_test_win.h",
"bluetooth/test/test_bluetooth_adapter_observer.cc",
"bluetooth/test/test_bluetooth_adapter_observer.h",
"nfc/nfc_chromeos_unittest.cc",
......
......@@ -22,6 +22,8 @@
#include "device/bluetooth/test/bluetooth_test_android.h"
#elif defined(OS_MACOSX)
#include "device/bluetooth/test/bluetooth_test_mac.h"
#elif defined(OS_WIN)
#include "device/bluetooth/test/bluetooth_test_win.h"
#endif
using device::BluetoothDevice;
......@@ -411,7 +413,7 @@ TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterAllFields) {
}
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID) || defined(OS_MACOSX)
#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
TEST_F(BluetoothTest, ConstructDefaultAdapter) {
InitWithDefaultAdapter();
if (!adapter_->IsPresent()) {
......@@ -427,10 +429,10 @@ TEST_F(BluetoothTest, ConstructDefaultAdapter) {
EXPECT_FALSE(adapter_->IsDiscoverable());
EXPECT_FALSE(adapter_->IsDiscovering());
}
#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
#endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID) || defined(OS_MACOSX)
#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
TEST_F(BluetoothTest, ConstructWithoutDefaultAdapter) {
InitWithoutDefaultAdapter();
EXPECT_EQ(adapter_->GetAddress(), "");
......@@ -440,10 +442,10 @@ TEST_F(BluetoothTest, ConstructWithoutDefaultAdapter) {
EXPECT_FALSE(adapter_->IsDiscoverable());
EXPECT_FALSE(adapter_->IsDiscovering());
}
#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
#endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID) || defined(OS_MACOSX)
#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
TEST_F(BluetoothTest, ConstructFakeAdapter) {
InitWithFakeAdapter();
EXPECT_EQ(adapter_->GetAddress(), kTestAdapterAddress);
......@@ -453,7 +455,7 @@ TEST_F(BluetoothTest, ConstructFakeAdapter) {
EXPECT_FALSE(adapter_->IsDiscoverable());
EXPECT_FALSE(adapter_->IsDiscovering());
}
#endif // defined(OS_ANDROID) || defined(OS_MACOSX)
#endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
// TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
#if defined(OS_ANDROID)
......
......@@ -100,6 +100,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterWin
private:
friend class BluetoothAdapterWinTest;
friend class BluetoothTestWin;
enum DiscoveryStatus {
NOT_DISCOVERING,
......
......@@ -76,7 +76,7 @@ class DEVICE_BLUETOOTH_EXPORT DevicePropertyValue {
};
// Returns true only on Windows platforms supporting Bluetooth Low Energy.
bool IsBluetoothLowEnergySupported();
bool DEVICE_BLUETOOTH_EXPORT IsBluetoothLowEnergySupported();
struct BluetoothLowEnergyServiceInfo {
BluetoothLowEnergyServiceInfo();
......
// Copyright 2016 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/test/bluetooth_test_win.h"
#include "base/bind.h"
#include "device/bluetooth/bluetooth_adapter_win.h"
#include "device/bluetooth/bluetooth_low_energy_win.h"
namespace device {
BluetoothTestWin::BluetoothTestWin()
: ui_task_runner_(new base::TestSimpleTaskRunner()),
bluetooth_task_runner_(new base::TestSimpleTaskRunner()) {}
BluetoothTestWin::~BluetoothTestWin() {}
bool BluetoothTestWin::PlatformSupportsLowEnergy() {
return win::IsBluetoothLowEnergySupported();
}
void BluetoothTestWin::AdapterInitCallback() {}
void BluetoothTestWin::InitWithDefaultAdapter() {
adapter_ = new BluetoothAdapterWin(base::Bind(
&BluetoothTestWin::AdapterInitCallback, base::Unretained(this)));
adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
adapter_win_->Init();
}
void BluetoothTestWin::InitWithoutDefaultAdapter() {
adapter_ = new BluetoothAdapterWin(base::Bind(
&BluetoothTestWin::AdapterInitCallback, base::Unretained(this)));
adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
adapter_win_->InitForTest(ui_task_runner_, bluetooth_task_runner_);
}
void BluetoothTestWin::InitWithFakeAdapter() {
adapter_ = new BluetoothAdapterWin(base::Bind(
&BluetoothTestWin::AdapterInitCallback, base::Unretained(this)));
adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
adapter_win_->InitForTest(ui_task_runner_, bluetooth_task_runner_);
BluetoothTaskManagerWin::AdapterState* adapter_state =
new BluetoothTaskManagerWin::AdapterState();
adapter_state->name = kTestAdapterName;
adapter_state->address = kTestAdapterAddress;
adapter_state->powered = true;
adapter_win_->AdapterStateChanged(*adapter_state);
}
bool BluetoothTestWin::DenyPermission() {
return false;
}
}
// Copyright 2016 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_WIN_H_
#define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_WIN_H_
#include "device/bluetooth/test/bluetooth_test.h"
#include "base/memory/ref_counted.h"
#include "base/test/test_pending_task.h"
#include "base/test/test_simple_task_runner.h"
namespace device {
class BluetoothAdapterWin;
// Windows implementation of BluetoothTestBase.
class BluetoothTestWin : public BluetoothTestBase {
public:
BluetoothTestWin();
~BluetoothTestWin() override;
// BluetoothTestBase overrides
bool PlatformSupportsLowEnergy() override;
void InitWithDefaultAdapter() override;
void InitWithoutDefaultAdapter() override;
void InitWithFakeAdapter() override;
bool DenyPermission() override;
private:
scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_;
scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_;
BluetoothAdapterWin* adapter_win_;
void AdapterInitCallback();
};
// Defines common test fixture name. Use TEST_F(BluetoothTest, YourTestName).
typedef BluetoothTestWin BluetoothTest;
} // namespace device
#endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_WIN_H_
......@@ -57,6 +57,8 @@
'bluetooth/test/bluetooth_test_android.h',
'bluetooth/test/bluetooth_test_mac.h',
'bluetooth/test/bluetooth_test_mac.mm',
'bluetooth/test/bluetooth_test_win.h',
'bluetooth/test/bluetooth_test_win.cc',
'bluetooth/test/test_bluetooth_adapter_observer.cc',
'bluetooth/test/test_bluetooth_adapter_observer.h',
'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