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

Unified Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1132943002: bluetooth: Move mock creation out of BluetoothDispatcherHost to LayoutTestBluetoothAdapterProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-testing-layout-tests
Patch Set: Fix API tests failing Created 5 years, 7 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 | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | content/content_shell.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc
diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
index 6212690f5d9b467d8f8cefcdf93149977b4d1ea6..f6042833937de7839ffda678c25e17d266716c0a 100644
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
@@ -16,16 +16,14 @@ using device::BluetoothAdapterFactory;
namespace content {
-const uint32 kUnspecifiedDeviceClass =
- 0x1F00; // bluetooth.org/en-us/specification/assigned-numbers/baseband
const int kScanTime = 5; // 5 seconds of scan time
+const int kTestingScanTime = 0; // No need to scan for tests
BluetoothDispatcherHost::BluetoothDispatcherHost()
: BrowserMessageFilter(BluetoothMsgStart),
- bluetooth_mock_data_set_(MockData::NOT_MOCKING),
- bluetooth_request_device_reject_type_(BluetoothError::NOT_FOUND),
weak_ptr_factory_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ current_scan_time_ = kScanTime;
if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable())
BluetoothAdapterFactory::GetAdapter(
base::Bind(&BluetoothDispatcherHost::set_adapter,
@@ -56,20 +54,10 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) {
}
void BluetoothDispatcherHost::SetBluetoothAdapterForTesting(
- const std::string& name) {
+ scoped_refptr<device::BluetoothAdapter> mock_adapter) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- if (name == "RejectRequestDevice_NotFoundError") {
- bluetooth_mock_data_set_ = MockData::REJECT;
- bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND;
- } else if (name == "RejectRequestDevice_SecurityError") {
- bluetooth_mock_data_set_ = MockData::REJECT;
- bluetooth_request_device_reject_type_ = BluetoothError::SECURITY;
- } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove.
- name == "Single Empty Device") {
- bluetooth_mock_data_set_ = MockData::RESOLVE;
- } else {
- bluetooth_mock_data_set_ = MockData::NOT_MOCKING;
- }
+ current_scan_time_ = kTestingScanTime;
+ set_adapter(mock_adapter.Pass());
}
BluetoothDispatcherHost::~BluetoothDispatcherHost() {
@@ -90,53 +78,21 @@ void BluetoothDispatcherHost::set_adapter(
void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- // TODO(scheib) Extend this very simple mock implementation by using
- // device/bluetooth/test mock adapter and related classes.
- switch (bluetooth_mock_data_set_) {
- case MockData::NOT_MOCKING: {
- // TODO(scheib): Filter devices by services: crbug.com/440594
- // TODO(scheib): Device selection UI: crbug.com/436280
- // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed.
- BluetoothAdapter::DeviceList devices;
-
- if (adapter_.get()) {
- adapter_->StartDiscoverySession(
- base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted,
- weak_ptr_factory_.GetWeakPtr(), thread_id, request_id),
- base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError,
- weak_ptr_factory_.GetWeakPtr(), thread_id, request_id));
- } else {
- DLOG(WARNING) << "No BluetoothAdapter. Can't serve requestDevice.";
- Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
- BluetoothError::NOT_FOUND));
- }
- return;
- }
- case MockData::REJECT: {
- Send(new BluetoothMsg_RequestDeviceError(
- thread_id, request_id, bluetooth_request_device_reject_type_));
- return;
- }
- case MockData::RESOLVE: {
- std::vector<std::string> uuids;
- uuids.push_back("00001800-0000-1000-8000-00805f9b34fb");
- uuids.push_back("00001801-0000-1000-8000-00805f9b34fb");
- content::BluetoothDevice device_ipc(
- "Empty Mock Device instanceID", // instance_id
- base::UTF8ToUTF16("Empty Mock Device name"), // name
- kUnspecifiedDeviceClass, // device_class
- device::BluetoothDevice::VENDOR_ID_BLUETOOTH, // vendor_id_source
- 0xFFFF, // vendor_id
- 1, // product_id
- 2, // product_version
- true, // paired
- uuids); // uuids
- Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id,
- device_ipc));
- return;
- }
+ // TODO(scheib): Filter devices by services: crbug.com/440594
+ // TODO(scheib): Device selection UI: crbug.com/436280
+ // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed.
+ if (adapter_.get()) {
+ adapter_->StartDiscoverySession(
+ base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted,
+ weak_ptr_factory_.GetWeakPtr(), thread_id, request_id),
+ base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError,
+ weak_ptr_factory_.GetWeakPtr(), thread_id, request_id));
+ } else {
+ DLOG(WARNING) << "No BluetoothAdapter. Can't serve requestDevice.";
+ Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
+ BluetoothError::NOT_FOUND));
}
- NOTREACHED();
+ return;
}
void BluetoothDispatcherHost::OnConnectGATT(
@@ -160,7 +116,7 @@ void BluetoothDispatcherHost::OnDiscoverySessionStarted(
base::Bind(&BluetoothDispatcherHost::StopDiscoverySession,
weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
base::Passed(&discovery_session)),
- base::TimeDelta::FromSeconds(kScanTime));
+ base::TimeDelta::FromSeconds(current_scan_time_));
}
void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int thread_id,
« no previous file with comments | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | content/content_shell.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698