Commit a58d60c7 authored by ortuno's avatar ortuno Committed by Commit bot

bluetooth: Move testing IPC from BluetoothDispatcher to BlinkTestRunner

This patch removes the testing IPC from BluetoothDispatcher and
BluetoothDispatcherHost.

This patch also changes the way the mock BluetoothAdapter was set in
BluetoothDispatcherHost. Instead of receiving an IPC to set the adapter,
BluetoothDispatcherHost exposes a function to directly set the adapter.
This function is used by LayoutTestSupport to set the adapter.

Mock adapter flow before:
BlinkTestRunner -> LayoutTestSupport -> BluetoothDispatcher --IPC-->
BluetoothDispatcherHost (Mock constructed here)

After:
BlinkTestRunner --IPC--> LayoutTestMessages(Mock constructed here) ->
LayoutTestSupport -> BluetoothDispatcherHost

This is the first of two patches to remove testing from BluetoothDispatcher
and BluetoothDispatcherHost:

 [1] This patch.
 [2] http://crrev.com/1132943002

BUG=436284

Committed: https://crrev.com/3f7142d0acf5e930743cbe5d754084c464ac3c85
Cr-Commit-Position: refs/heads/master@{#330647}

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

Cr-Commit-Position: refs/heads/master@{#330696}
parent 64db4a23
...@@ -50,13 +50,28 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { ...@@ -50,13 +50,28 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message)
IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice)
IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT)
IPC_MESSAGE_HANDLER(BluetoothHostMsg_SetBluetoothMockDataSetForTesting,
OnSetBluetoothMockDataSetForTesting)
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
return handled; return handled;
} }
void BluetoothDispatcherHost::SetBluetoothAdapterForTesting(
const std::string& name) {
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;
}
}
BluetoothDispatcherHost::~BluetoothDispatcherHost() { BluetoothDispatcherHost::~BluetoothDispatcherHost() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Clear adapter, releasing observer references. // Clear adapter, releasing observer references.
...@@ -135,23 +150,6 @@ void BluetoothDispatcherHost::OnConnectGATT( ...@@ -135,23 +150,6 @@ void BluetoothDispatcherHost::OnConnectGATT(
device_instance_id)); device_instance_id));
} }
void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting(
const std::string& name) {
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;
}
}
void BluetoothDispatcherHost::OnDiscoverySessionStarted( void BluetoothDispatcherHost::OnDiscoverySessionStarted(
int thread_id, int thread_id,
int request_id, int request_id,
......
...@@ -23,7 +23,7 @@ namespace content { ...@@ -23,7 +23,7 @@ namespace content {
// UI Thread Note: // UI Thread Note:
// BluetoothDispatcherHost is constructed, operates, and destroyed on the UI // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI
// thread because BluetoothAdapter and related objects live there. // thread because BluetoothAdapter and related objects live there.
class BluetoothDispatcherHost final class CONTENT_EXPORT BluetoothDispatcherHost final
: public BrowserMessageFilter, : public BrowserMessageFilter,
public device::BluetoothAdapter::Observer { public device::BluetoothAdapter::Observer {
public: public:
...@@ -34,6 +34,8 @@ class BluetoothDispatcherHost final ...@@ -34,6 +34,8 @@ class BluetoothDispatcherHost final
BrowserThread::ID* thread) override; BrowserThread::ID* thread) override;
bool OnMessageReceived(const IPC::Message& message) override; bool OnMessageReceived(const IPC::Message& message) override;
void SetBluetoothAdapterForTesting(const std::string& name);
protected: protected:
~BluetoothDispatcherHost() override; ~BluetoothDispatcherHost() override;
...@@ -49,7 +51,6 @@ class BluetoothDispatcherHost final ...@@ -49,7 +51,6 @@ class BluetoothDispatcherHost final
void OnRequestDevice(int thread_id, int request_id); void OnRequestDevice(int thread_id, int request_id);
void OnConnectGATT(int thread_id, int request_id, void OnConnectGATT(int thread_id, int request_id,
const std::string& device_instance_id); const std::string& device_instance_id);
void OnSetBluetoothMockDataSetForTesting(const std::string& name);
// Callbacks for BluetoothAdapter::StartDiscoverySession. // Callbacks for BluetoothAdapter::StartDiscoverySession.
void OnDiscoverySessionStarted( void OnDiscoverySessionStarted(
......
...@@ -933,7 +933,8 @@ void RenderProcessHostImpl::CreateMessageFilters() { ...@@ -933,7 +933,8 @@ void RenderProcessHostImpl::CreateMessageFilters() {
message_port_message_filter_.get())); message_port_message_filter_.get()));
if (browser_command_line.HasSwitch( if (browser_command_line.HasSwitch(
switches::kEnableExperimentalWebPlatformFeatures)) { switches::kEnableExperimentalWebPlatformFeatures)) {
AddFilter(new BluetoothDispatcherHost()); bluetooth_dispatcher_host_ = new BluetoothDispatcherHost();
AddFilter(bluetooth_dispatcher_host_.get());
} }
} }
...@@ -2460,4 +2461,8 @@ void RenderProcessHostImpl::GetAudioOutputControllers( ...@@ -2460,4 +2461,8 @@ void RenderProcessHostImpl::GetAudioOutputControllers(
audio_renderer_host()->GetOutputControllers(callback); audio_renderer_host()->GetOutputControllers(callback);
} }
BluetoothDispatcherHost* RenderProcessHostImpl::GetBluetoothDispatcherHost() {
return bluetooth_dispatcher_host_.get();
}
} // namespace content } // namespace content
...@@ -43,6 +43,7 @@ class ChannelMojoHost; ...@@ -43,6 +43,7 @@ class ChannelMojoHost;
namespace content { namespace content {
class AudioRendererHost; class AudioRendererHost;
class BluetoothDispatcherHost;
class BrowserCdmManager; class BrowserCdmManager;
class BrowserDemuxerAndroid; class BrowserDemuxerAndroid;
class GpuMessageFilter; class GpuMessageFilter;
...@@ -270,6 +271,8 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -270,6 +271,8 @@ class CONTENT_EXPORT RenderProcessHostImpl
void GetAudioOutputControllers( void GetAudioOutputControllers(
const GetAudioOutputControllersCallback& callback) const override; const GetAudioOutputControllersCallback& callback) const override;
BluetoothDispatcherHost* GetBluetoothDispatcherHost();
protected: protected:
// A proxy for our IPC::Channel that lives on the IO thread (see // A proxy for our IPC::Channel that lives on the IO thread (see
// browser_process.h) // browser_process.h)
...@@ -451,6 +454,8 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -451,6 +454,8 @@ class CONTENT_EXPORT RenderProcessHostImpl
scoped_refptr<AudioRendererHost> audio_renderer_host_; scoped_refptr<AudioRendererHost> audio_renderer_host_;
scoped_refptr<BluetoothDispatcherHost> bluetooth_dispatcher_host_;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
scoped_refptr<BrowserDemuxerAndroid> browser_demuxer_android_; scoped_refptr<BrowserDemuxerAndroid> browser_demuxer_android_;
#endif #endif
......
...@@ -174,8 +174,6 @@ class CONTENT_EXPORT BlinkPlatformImpl ...@@ -174,8 +174,6 @@ class CONTENT_EXPORT BlinkPlatformImpl
void ResumeSharedTimer(); void ResumeSharedTimer();
virtual void OnStartSharedTimer(base::TimeDelta delay) {} virtual void OnStartSharedTimer(base::TimeDelta delay) {}
WebBluetoothImpl* BluetoothImplForTesting() { return bluetooth_.get(); }
virtual blink::WebString domCodeStringFromEnum(int dom_code); virtual blink::WebString domCodeStringFromEnum(int dom_code);
virtual int domEnumFromCodeString(const blink::WebString& codeString); virtual int domEnumFromCodeString(const blink::WebString& codeString);
......
...@@ -120,11 +120,6 @@ void BluetoothDispatcher::connectGATT( ...@@ -120,11 +120,6 @@ void BluetoothDispatcher::connectGATT(
device_instance_id.utf8())); device_instance_id.utf8()));
} }
void BluetoothDispatcher::SetBluetoothMockDataSetForTesting(
const std::string& name) {
Send(new BluetoothHostMsg_SetBluetoothMockDataSetForTesting(name));
}
void BluetoothDispatcher::OnWorkerRunLoopStopped() { void BluetoothDispatcher::OnWorkerRunLoopStopped() {
delete this; delete this;
} }
......
...@@ -50,7 +50,6 @@ class BluetoothDispatcher : public WorkerTaskRunner::Observer { ...@@ -50,7 +50,6 @@ class BluetoothDispatcher : public WorkerTaskRunner::Observer {
void requestDevice(blink::WebBluetoothRequestDeviceCallbacks* callbacks); void requestDevice(blink::WebBluetoothRequestDeviceCallbacks* callbacks);
void connectGATT(const blink::WebString& device_instance_id, void connectGATT(const blink::WebString& device_instance_id,
blink::WebBluetoothConnectGATTCallbacks* callbacks); blink::WebBluetoothConnectGATTCallbacks* callbacks);
void SetBluetoothMockDataSetForTesting(const std::string& name);
// WorkerTaskRunner::Observer implementation. // WorkerTaskRunner::Observer implementation.
void OnWorkerRunLoopStopped() override; void OnWorkerRunLoopStopped() override;
......
...@@ -26,11 +26,6 @@ void WebBluetoothImpl::connectGATT(const blink::WebString& device_instance_id, ...@@ -26,11 +26,6 @@ void WebBluetoothImpl::connectGATT(const blink::WebString& device_instance_id,
GetDispatcher()->connectGATT(device_instance_id, callbacks); GetDispatcher()->connectGATT(device_instance_id, callbacks);
} }
void WebBluetoothImpl::SetBluetoothMockDataSetForTesting(
const std::string& name) {
GetDispatcher()->SetBluetoothMockDataSetForTesting(name);
}
BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() {
return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( return BluetoothDispatcher::GetOrCreateThreadSpecificInstance(
thread_safe_sender_.get()); thread_safe_sender_.get());
......
...@@ -32,9 +32,6 @@ class CONTENT_EXPORT WebBluetoothImpl ...@@ -32,9 +32,6 @@ class CONTENT_EXPORT WebBluetoothImpl
void connectGATT(const blink::WebString& device_instance_id, void connectGATT(const blink::WebString& device_instance_id,
blink::WebBluetoothConnectGATTCallbacks* callbacks) override; blink::WebBluetoothConnectGATTCallbacks* callbacks) override;
// Testing interface:
void SetBluetoothMockDataSetForTesting(const std::string& name);
private: private:
BluetoothDispatcher* GetDispatcher(); BluetoothDispatcher* GetDispatcher();
......
...@@ -141,8 +141,3 @@ IPC_MESSAGE_CONTROL3(BluetoothHostMsg_ConnectGATT, ...@@ -141,8 +141,3 @@ IPC_MESSAGE_CONTROL3(BluetoothHostMsg_ConnectGATT,
int /* thread_id */, int /* thread_id */,
int /* request_id */, int /* request_id */,
std::string /* device_instance_id */) std::string /* device_instance_id */)
// Configures the mock data set in the browser used while under test.
// TODO(scheib): Disable testing in non-test executables. crbug.com/436284.
IPC_MESSAGE_CONTROL1(BluetoothHostMsg_SetBluetoothMockDataSetForTesting,
std::string /* name */)
...@@ -93,8 +93,8 @@ void SetDeviceScaleFactor(RenderView* render_view, float factor); ...@@ -93,8 +93,8 @@ void SetDeviceScaleFactor(RenderView* render_view, float factor);
// Set the device color profile associated with the profile |name|. // Set the device color profile associated with the profile |name|.
void SetDeviceColorProfile(RenderView* render_view, const std::string& name); void SetDeviceColorProfile(RenderView* render_view, const std::string& name);
// Change the bluetooth test data while running a layout test. // Change the bluetooth test adapter while running a layout test.
void SetBluetoothMockDataSetForTesting(const std::string& name); void SetBluetoothAdapter(int render_process_id, const std::string& name);
// Enables mock geofencing service while running a layout test. // Enables mock geofencing service while running a layout test.
// |service_available| indicates if the mock service should mock geofencing // |service_available| indicates if the mock service should mock geofencing
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/permission_type.h" #include "content/public/browser/permission_type.h"
#include "content/public/test/layouttest_support.h"
#include "content/shell/browser/layout_test/layout_test_browser_context.h" #include "content/shell/browser/layout_test/layout_test_browser_context.h"
#include "content/shell/browser/layout_test/layout_test_content_browser_client.h" #include "content/shell/browser/layout_test/layout_test_content_browser_client.h"
#include "content/shell/browser/layout_test/layout_test_notification_manager.h" #include "content/shell/browser/layout_test/layout_test_notification_manager.h"
...@@ -47,7 +48,8 @@ void LayoutTestMessageFilter::OverrideThreadForMessage( ...@@ -47,7 +48,8 @@ void LayoutTestMessageFilter::OverrideThreadForMessage(
*thread = BrowserThread::FILE; *thread = BrowserThread::FILE;
if (message.type() == LayoutTestHostMsg_SimulateWebNotificationClick::ID || if (message.type() == LayoutTestHostMsg_SimulateWebNotificationClick::ID ||
message.type() == LayoutTestHostMsg_SetPermission::ID || message.type() == LayoutTestHostMsg_SetPermission::ID ||
message.type() == LayoutTestHostMsg_ResetPermissions::ID) message.type() == LayoutTestHostMsg_ResetPermissions::ID ||
message.type() == LayoutTestHostMsg_SetBluetoothAdapter::ID)
*thread = BrowserThread::UI; *thread = BrowserThread::UI;
} }
...@@ -66,6 +68,8 @@ bool LayoutTestMessageFilter::OnMessageReceived(const IPC::Message& message) { ...@@ -66,6 +68,8 @@ bool LayoutTestMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(LayoutTestHostMsg_DeleteAllCookies, OnDeleteAllCookies) IPC_MESSAGE_HANDLER(LayoutTestHostMsg_DeleteAllCookies, OnDeleteAllCookies)
IPC_MESSAGE_HANDLER(LayoutTestHostMsg_SetPermission, OnSetPermission) IPC_MESSAGE_HANDLER(LayoutTestHostMsg_SetPermission, OnSetPermission)
IPC_MESSAGE_HANDLER(LayoutTestHostMsg_ResetPermissions, OnResetPermissions) IPC_MESSAGE_HANDLER(LayoutTestHostMsg_ResetPermissions, OnResetPermissions)
IPC_MESSAGE_HANDLER(LayoutTestHostMsg_SetBluetoothAdapter,
OnSetBluetoothAdapter)
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
...@@ -161,4 +165,10 @@ void LayoutTestMessageFilter::OnResetPermissions() { ...@@ -161,4 +165,10 @@ void LayoutTestMessageFilter::OnResetPermissions() {
->ResetPermissions(); ->ResetPermissions();
} }
void LayoutTestMessageFilter::OnSetBluetoothAdapter(const std::string& name) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// TODO(ortuno): Create mock adapter here. See http://crrev.com/1132943002
SetBluetoothAdapter(render_process_id_, name);
}
} // namespace content } // namespace content
...@@ -64,6 +64,7 @@ class LayoutTestMessageFilter : public BrowserMessageFilter { ...@@ -64,6 +64,7 @@ class LayoutTestMessageFilter : public BrowserMessageFilter {
const GURL& origin, const GURL& origin,
const GURL& embedding_origin); const GURL& embedding_origin);
void OnResetPermissions(); void OnResetPermissions();
void OnSetBluetoothAdapter(const std::string& name);
int render_process_id_; int render_process_id_;
......
...@@ -38,3 +38,5 @@ IPC_MESSAGE_ROUTED4(LayoutTestHostMsg_SetPermission, ...@@ -38,3 +38,5 @@ IPC_MESSAGE_ROUTED4(LayoutTestHostMsg_SetPermission,
GURL /* origin */, GURL /* origin */,
GURL /* embedding_origin */ ) GURL /* embedding_origin */ )
IPC_MESSAGE_ROUTED0(LayoutTestHostMsg_ResetPermissions) IPC_MESSAGE_ROUTED0(LayoutTestHostMsg_ResetPermissions)
IPC_MESSAGE_CONTROL1(LayoutTestHostMsg_SetBluetoothAdapter,
std::string /* name */)
...@@ -464,7 +464,7 @@ void BlinkTestRunner::SetDeviceColorProfile(const std::string& name) { ...@@ -464,7 +464,7 @@ void BlinkTestRunner::SetDeviceColorProfile(const std::string& name) {
} }
void BlinkTestRunner::SetBluetoothMockDataSet(const std::string& name) { void BlinkTestRunner::SetBluetoothMockDataSet(const std::string& name) {
content::SetBluetoothMockDataSetForTesting(name); Send(new LayoutTestHostMsg_SetBluetoothAdapter(name));
} }
void BlinkTestRunner::SetGeofencingMockProvider(bool service_available) { void BlinkTestRunner::SetGeofencingMockProvider(bool service_available) {
......
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "cc/blink/web_layer_impl.h" #include "cc/blink/web_layer_impl.h"
#include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/child/bluetooth/web_bluetooth_impl.h"
#include "content/child/geofencing/web_geofencing_provider_impl.h" #include "content/child/geofencing/web_geofencing_provider_impl.h"
#include "content/common/gpu/image_transport_surface.h" #include "content/common/gpu/image_transport_surface.h"
#include "content/public/common/page_state.h" #include "content/public/common/page_state.h"
...@@ -312,11 +313,16 @@ void SetDeviceColorProfile(RenderView* render_view, const std::string& name) { ...@@ -312,11 +313,16 @@ void SetDeviceColorProfile(RenderView* render_view, const std::string& name) {
SetDeviceColorProfileForTesting(color_profile); SetDeviceColorProfileForTesting(color_profile);
} }
void SetBluetoothMockDataSetForTesting(const std::string& name) { void SetBluetoothAdapter(int render_process_id, const std::string& name) {
RenderThreadImpl::current() RenderProcessHostImpl* render_process_host_impl =
->blink_platform_impl() static_cast<RenderProcessHostImpl*>(
->BluetoothImplForTesting() RenderProcessHost::FromID(render_process_id));
->SetBluetoothMockDataSetForTesting(name);
BluetoothDispatcherHost* dispatcher_host = render_process_host_impl
->GetBluetoothDispatcherHost();
if (dispatcher_host != NULL)
dispatcher_host->SetBluetoothAdapterForTesting(name);
} }
void SetGeofencingMockProvider(bool service_available) { void SetGeofencingMockProvider(bool service_available) {
......
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