Commit 5e096ae8 authored by leviw's avatar leviw Committed by Commit bot

Revert of bluetooth: Move testing IPC from BluetoothDispatcher to...

Revert of bluetooth: Move testing IPC from BluetoothDispatcher to BlinkTestRunner (patchset #2 id:250001 of https://codereview.chromium.org/1125133005/)

Reason for revert:
Broke a bunch of Layout Tests. Here's an example: http://test-results.appspot.com/dashboards/flakiness_dashboard.html#showExpectations=true&tests=virtual%2Fstable%2Fanimations-unprefixed%2Fanimation-events-prefixed-04.html

STDERR: ==28151==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000050 (pc 0x000006a00bd0 bp 0x7fff171be890 sp 0x7fff171be880 T0)
STDERR:     #0 0x6a00bcf in content::BluetoothDispatcherHost::SetBluetoothAdapterForTesting(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) content/browser/bluetooth/bluetooth_dispatcher_host.cc:63:43
STDERR:     #1 0x4e5d9d in OnSetBluetoothAdapter content/shell/browser/layout_test/layout_test_message_filter.cc:171:3
STDERR:     #2 0x4e5d9d in DispatchToMethodImpl<content::LayoutTestMessageFilter, void (content::LayoutTestMessageFilter::*)(const std::__1::basic_string<char> &), std::__1::basic_string<char> , 0> base/tuple.h:252:0

Original issue's description:
> 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}

TBR=jam@chromium.org,scheib@chromium.org,tsepez@chromium.org,ortuno@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=436284

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

Cr-Commit-Position: refs/heads/master@{#330653}
parent 0b0b6360
...@@ -50,28 +50,13 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { ...@@ -50,28 +50,13 @@ 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.
...@@ -150,6 +135,23 @@ void BluetoothDispatcherHost::OnConnectGATT( ...@@ -150,6 +135,23 @@ 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 CONTENT_EXPORT BluetoothDispatcherHost final class BluetoothDispatcherHost final
: public BrowserMessageFilter, : public BrowserMessageFilter,
public device::BluetoothAdapter::Observer { public device::BluetoothAdapter::Observer {
public: public:
...@@ -34,8 +34,6 @@ class CONTENT_EXPORT BluetoothDispatcherHost final ...@@ -34,8 +34,6 @@ class CONTENT_EXPORT 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;
...@@ -51,6 +49,7 @@ class CONTENT_EXPORT BluetoothDispatcherHost final ...@@ -51,6 +49,7 @@ class CONTENT_EXPORT 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,8 +933,7 @@ void RenderProcessHostImpl::CreateMessageFilters() { ...@@ -933,8 +933,7 @@ 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)) {
bluetooth_dispatcher_host_ = new BluetoothDispatcherHost(); AddFilter(new BluetoothDispatcherHost());
AddFilter(bluetooth_dispatcher_host_.get());
} }
} }
...@@ -2461,8 +2460,4 @@ void RenderProcessHostImpl::GetAudioOutputControllers( ...@@ -2461,8 +2460,4 @@ 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,7 +43,6 @@ class ChannelMojoHost; ...@@ -43,7 +43,6 @@ class ChannelMojoHost;
namespace content { namespace content {
class AudioRendererHost; class AudioRendererHost;
class BluetoothDispatcherHost;
class BrowserCdmManager; class BrowserCdmManager;
class BrowserDemuxerAndroid; class BrowserDemuxerAndroid;
class GpuMessageFilter; class GpuMessageFilter;
...@@ -271,8 +270,6 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -271,8 +270,6 @@ 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)
...@@ -454,8 +451,6 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -454,8 +451,6 @@ 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,6 +174,8 @@ class CONTENT_EXPORT BlinkPlatformImpl ...@@ -174,6 +174,8 @@ 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,6 +120,11 @@ void BluetoothDispatcher::connectGATT( ...@@ -120,6 +120,11 @@ 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,6 +50,7 @@ class BluetoothDispatcher : public WorkerTaskRunner::Observer { ...@@ -50,6 +50,7 @@ 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,6 +26,11 @@ void WebBluetoothImpl::connectGATT(const blink::WebString& device_instance_id, ...@@ -26,6 +26,11 @@ 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,6 +32,9 @@ class CONTENT_EXPORT WebBluetoothImpl ...@@ -32,6 +32,9 @@ 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,3 +141,8 @@ IPC_MESSAGE_CONTROL3(BluetoothHostMsg_ConnectGATT, ...@@ -141,3 +141,8 @@ 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 adapter while running a layout test. // Change the bluetooth test data while running a layout test.
void SetBluetoothAdapter(int render_process_id, const std::string& name); void SetBluetoothMockDataSetForTesting(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,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#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"
...@@ -48,8 +47,7 @@ void LayoutTestMessageFilter::OverrideThreadForMessage( ...@@ -48,8 +47,7 @@ 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;
} }
...@@ -68,8 +66,6 @@ bool LayoutTestMessageFilter::OnMessageReceived(const IPC::Message& message) { ...@@ -68,8 +66,6 @@ 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()
...@@ -165,10 +161,4 @@ void LayoutTestMessageFilter::OnResetPermissions() { ...@@ -165,10 +161,4 @@ 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,7 +64,6 @@ class LayoutTestMessageFilter : public BrowserMessageFilter { ...@@ -64,7 +64,6 @@ 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,5 +38,3 @@ IPC_MESSAGE_ROUTED4(LayoutTestHostMsg_SetPermission, ...@@ -38,5 +38,3 @@ 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) {
Send(new LayoutTestHostMsg_SetBluetoothAdapter(name)); content::SetBluetoothMockDataSetForTesting(name);
} }
void BlinkTestRunner::SetGeofencingMockProvider(bool service_available) { void BlinkTestRunner::SetGeofencingMockProvider(bool service_available) {
......
...@@ -7,9 +7,8 @@ ...@@ -7,9 +7,8 @@
#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"
...@@ -313,14 +312,11 @@ void SetDeviceColorProfile(RenderView* render_view, const std::string& name) { ...@@ -313,14 +312,11 @@ void SetDeviceColorProfile(RenderView* render_view, const std::string& name) {
SetDeviceColorProfileForTesting(color_profile); SetDeviceColorProfileForTesting(color_profile);
} }
void SetBluetoothAdapter(int render_process_id, const std::string& name) { void SetBluetoothMockDataSetForTesting(const std::string& name) {
RenderProcessHostImpl* render_process_host_impl = RenderThreadImpl::current()
static_cast<RenderProcessHostImpl*>( ->blink_platform_impl()
RenderProcessHost::FromID(render_process_id)); ->BluetoothImplForTesting()
->SetBluetoothMockDataSetForTesting(name);
render_process_host_impl
->GetBluetoothDispatcherHost()
->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