diff options
author | leviw <leviw@chromium.org> | 2015-05-19 17:26:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-20 00:26:32 +0000 |
commit | 5e096ae82760009e5435785ca7fb2f96b0f0f473 (patch) | |
tree | 91354109bee9f5375cd5da5beb51daa357c1c682 | |
parent | 0b0b636093a7dbb56cc8712e2263b1c9a1ad8079 (diff) | |
download | chromium_src-5e096ae82760009e5435785ca7fb2f96b0f0f473.zip chromium_src-5e096ae82760009e5435785ca7fb2f96b0f0f473.tar.gz chromium_src-5e096ae82760009e5435785ca7fb2f96b0f0f473.tar.bz2 |
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}
16 files changed, 53 insertions, 58 deletions
diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc index 6212690..b440cdb 100644 --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc @@ -50,28 +50,13 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) + IPC_MESSAGE_HANDLER(BluetoothHostMsg_SetBluetoothMockDataSetForTesting, + OnSetBluetoothMockDataSetForTesting) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() 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() { DCHECK_CURRENTLY_ON(BrowserThread::UI); // Clear adapter, releasing observer references. @@ -150,6 +135,23 @@ void BluetoothDispatcherHost::OnConnectGATT( 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( int thread_id, int request_id, diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.h b/content/browser/bluetooth/bluetooth_dispatcher_host.h index 86aca14..1cc27c5 100644 --- a/content/browser/bluetooth/bluetooth_dispatcher_host.h +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.h @@ -23,7 +23,7 @@ namespace content { // UI Thread Note: // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI // thread because BluetoothAdapter and related objects live there. -class CONTENT_EXPORT BluetoothDispatcherHost final +class BluetoothDispatcherHost final : public BrowserMessageFilter, public device::BluetoothAdapter::Observer { public: @@ -34,8 +34,6 @@ class CONTENT_EXPORT BluetoothDispatcherHost final BrowserThread::ID* thread) override; bool OnMessageReceived(const IPC::Message& message) override; - void SetBluetoothAdapterForTesting(const std::string& name); - protected: ~BluetoothDispatcherHost() override; @@ -51,6 +49,7 @@ class CONTENT_EXPORT BluetoothDispatcherHost final void OnRequestDevice(int thread_id, int request_id); void OnConnectGATT(int thread_id, int request_id, const std::string& device_instance_id); + void OnSetBluetoothMockDataSetForTesting(const std::string& name); // Callbacks for BluetoothAdapter::StartDiscoverySession. void OnDiscoverySessionStarted( diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 66dfa9c..b364c29 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -933,8 +933,7 @@ void RenderProcessHostImpl::CreateMessageFilters() { message_port_message_filter_.get())); if (browser_command_line.HasSwitch( switches::kEnableExperimentalWebPlatformFeatures)) { - bluetooth_dispatcher_host_ = new BluetoothDispatcherHost(); - AddFilter(bluetooth_dispatcher_host_.get()); + AddFilter(new BluetoothDispatcherHost()); } } @@ -2461,8 +2460,4 @@ void RenderProcessHostImpl::GetAudioOutputControllers( audio_renderer_host()->GetOutputControllers(callback); } -BluetoothDispatcherHost* RenderProcessHostImpl::GetBluetoothDispatcherHost() { - return bluetooth_dispatcher_host_.get(); -} - } // namespace content diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h index cce983d..d89ed48 100644 --- a/content/browser/renderer_host/render_process_host_impl.h +++ b/content/browser/renderer_host/render_process_host_impl.h @@ -43,7 +43,6 @@ class ChannelMojoHost; namespace content { class AudioRendererHost; -class BluetoothDispatcherHost; class BrowserCdmManager; class BrowserDemuxerAndroid; class GpuMessageFilter; @@ -271,8 +270,6 @@ class CONTENT_EXPORT RenderProcessHostImpl void GetAudioOutputControllers( const GetAudioOutputControllersCallback& callback) const override; - BluetoothDispatcherHost* GetBluetoothDispatcherHost(); - protected: // A proxy for our IPC::Channel that lives on the IO thread (see // browser_process.h) @@ -454,8 +451,6 @@ class CONTENT_EXPORT RenderProcessHostImpl scoped_refptr<AudioRendererHost> audio_renderer_host_; - scoped_refptr<BluetoothDispatcherHost> bluetooth_dispatcher_host_; - #if defined(OS_ANDROID) scoped_refptr<BrowserDemuxerAndroid> browser_demuxer_android_; #endif diff --git a/content/child/blink_platform_impl.h b/content/child/blink_platform_impl.h index 9502663..8ca60ea 100644 --- a/content/child/blink_platform_impl.h +++ b/content/child/blink_platform_impl.h @@ -174,6 +174,8 @@ class CONTENT_EXPORT BlinkPlatformImpl void ResumeSharedTimer(); virtual void OnStartSharedTimer(base::TimeDelta delay) {} + WebBluetoothImpl* BluetoothImplForTesting() { return bluetooth_.get(); } + virtual blink::WebString domCodeStringFromEnum(int dom_code); virtual int domEnumFromCodeString(const blink::WebString& codeString); diff --git a/content/child/bluetooth/bluetooth_dispatcher.cc b/content/child/bluetooth/bluetooth_dispatcher.cc index c76c5ef..47d2531 100644 --- a/content/child/bluetooth/bluetooth_dispatcher.cc +++ b/content/child/bluetooth/bluetooth_dispatcher.cc @@ -120,6 +120,11 @@ void BluetoothDispatcher::connectGATT( device_instance_id.utf8())); } +void BluetoothDispatcher::SetBluetoothMockDataSetForTesting( + const std::string& name) { + Send(new BluetoothHostMsg_SetBluetoothMockDataSetForTesting(name)); +} + void BluetoothDispatcher::OnWorkerRunLoopStopped() { delete this; } diff --git a/content/child/bluetooth/bluetooth_dispatcher.h b/content/child/bluetooth/bluetooth_dispatcher.h index 0492a1a..86057d8 100644 --- a/content/child/bluetooth/bluetooth_dispatcher.h +++ b/content/child/bluetooth/bluetooth_dispatcher.h @@ -50,6 +50,7 @@ class BluetoothDispatcher : public WorkerTaskRunner::Observer { void requestDevice(blink::WebBluetoothRequestDeviceCallbacks* callbacks); void connectGATT(const blink::WebString& device_instance_id, blink::WebBluetoothConnectGATTCallbacks* callbacks); + void SetBluetoothMockDataSetForTesting(const std::string& name); // WorkerTaskRunner::Observer implementation. void OnWorkerRunLoopStopped() override; diff --git a/content/child/bluetooth/web_bluetooth_impl.cc b/content/child/bluetooth/web_bluetooth_impl.cc index 46a08e2..d8b5813 100644 --- a/content/child/bluetooth/web_bluetooth_impl.cc +++ b/content/child/bluetooth/web_bluetooth_impl.cc @@ -26,6 +26,11 @@ void WebBluetoothImpl::connectGATT(const blink::WebString& device_instance_id, GetDispatcher()->connectGATT(device_instance_id, callbacks); } +void WebBluetoothImpl::SetBluetoothMockDataSetForTesting( + const std::string& name) { + GetDispatcher()->SetBluetoothMockDataSetForTesting(name); +} + BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( thread_safe_sender_.get()); diff --git a/content/child/bluetooth/web_bluetooth_impl.h b/content/child/bluetooth/web_bluetooth_impl.h index f324e08..11403c0 100644 --- a/content/child/bluetooth/web_bluetooth_impl.h +++ b/content/child/bluetooth/web_bluetooth_impl.h @@ -32,6 +32,9 @@ class CONTENT_EXPORT WebBluetoothImpl void connectGATT(const blink::WebString& device_instance_id, blink::WebBluetoothConnectGATTCallbacks* callbacks) override; + // Testing interface: + void SetBluetoothMockDataSetForTesting(const std::string& name); + private: BluetoothDispatcher* GetDispatcher(); diff --git a/content/common/bluetooth/bluetooth_messages.h b/content/common/bluetooth/bluetooth_messages.h index 12da031..dda97d4 100644 --- a/content/common/bluetooth/bluetooth_messages.h +++ b/content/common/bluetooth/bluetooth_messages.h @@ -141,3 +141,8 @@ IPC_MESSAGE_CONTROL3(BluetoothHostMsg_ConnectGATT, int /* thread_id */, int /* request_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 */) diff --git a/content/public/test/layouttest_support.h b/content/public/test/layouttest_support.h index c8ec1e5..8e75dfe 100644 --- a/content/public/test/layouttest_support.h +++ b/content/public/test/layouttest_support.h @@ -93,8 +93,8 @@ void SetDeviceScaleFactor(RenderView* render_view, float factor); // Set the device color profile associated with the profile |name|. void SetDeviceColorProfile(RenderView* render_view, const std::string& name); -// Change the bluetooth test adapter while running a layout test. -void SetBluetoothAdapter(int render_process_id, const std::string& name); +// Change the bluetooth test data while running a layout test. +void SetBluetoothMockDataSetForTesting(const std::string& name); // Enables mock geofencing service while running a layout test. // |service_available| indicates if the mock service should mock geofencing diff --git a/content/shell/browser/layout_test/layout_test_message_filter.cc b/content/shell/browser/layout_test/layout_test_message_filter.cc index ed8360b..dd09baa 100644 --- a/content/shell/browser/layout_test/layout_test_message_filter.cc +++ b/content/shell/browser/layout_test/layout_test_message_filter.cc @@ -8,7 +8,6 @@ #include "base/threading/thread_restrictions.h" #include "content/public/browser/child_process_security_policy.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_content_browser_client.h" #include "content/shell/browser/layout_test/layout_test_notification_manager.h" @@ -48,8 +47,7 @@ void LayoutTestMessageFilter::OverrideThreadForMessage( *thread = BrowserThread::FILE; if (message.type() == LayoutTestHostMsg_SimulateWebNotificationClick::ID || message.type() == LayoutTestHostMsg_SetPermission::ID || - message.type() == LayoutTestHostMsg_ResetPermissions::ID || - message.type() == LayoutTestHostMsg_SetBluetoothAdapter::ID) + message.type() == LayoutTestHostMsg_ResetPermissions::ID) *thread = BrowserThread::UI; } @@ -68,8 +66,6 @@ bool LayoutTestMessageFilter::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(LayoutTestHostMsg_DeleteAllCookies, OnDeleteAllCookies) IPC_MESSAGE_HANDLER(LayoutTestHostMsg_SetPermission, OnSetPermission) IPC_MESSAGE_HANDLER(LayoutTestHostMsg_ResetPermissions, OnResetPermissions) - IPC_MESSAGE_HANDLER(LayoutTestHostMsg_SetBluetoothAdapter, - OnSetBluetoothAdapter) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -165,10 +161,4 @@ void LayoutTestMessageFilter::OnResetPermissions() { ->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 diff --git a/content/shell/browser/layout_test/layout_test_message_filter.h b/content/shell/browser/layout_test/layout_test_message_filter.h index bf437d0..a41f72a 100644 --- a/content/shell/browser/layout_test/layout_test_message_filter.h +++ b/content/shell/browser/layout_test/layout_test_message_filter.h @@ -64,7 +64,6 @@ class LayoutTestMessageFilter : public BrowserMessageFilter { const GURL& origin, const GURL& embedding_origin); void OnResetPermissions(); - void OnSetBluetoothAdapter(const std::string& name); int render_process_id_; diff --git a/content/shell/common/layout_test/layout_test_messages.h b/content/shell/common/layout_test/layout_test_messages.h index cef6cb5..7ab85bf1 100644 --- a/content/shell/common/layout_test/layout_test_messages.h +++ b/content/shell/common/layout_test/layout_test_messages.h @@ -38,5 +38,3 @@ IPC_MESSAGE_ROUTED4(LayoutTestHostMsg_SetPermission, GURL /* origin */, GURL /* embedding_origin */ ) IPC_MESSAGE_ROUTED0(LayoutTestHostMsg_ResetPermissions) -IPC_MESSAGE_CONTROL1(LayoutTestHostMsg_SetBluetoothAdapter, - std::string /* name */) diff --git a/content/shell/renderer/layout_test/blink_test_runner.cc b/content/shell/renderer/layout_test/blink_test_runner.cc index 71f00ac..905eb5f 100644 --- a/content/shell/renderer/layout_test/blink_test_runner.cc +++ b/content/shell/renderer/layout_test/blink_test_runner.cc @@ -464,7 +464,7 @@ void BlinkTestRunner::SetDeviceColorProfile(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) { diff --git a/content/test/layouttest_support.cc b/content/test/layouttest_support.cc index 0ae2b51..731f991 100644 --- a/content/test/layouttest_support.cc +++ b/content/test/layouttest_support.cc @@ -7,9 +7,8 @@ #include "base/callback.h" #include "base/lazy_instance.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/child/bluetooth/web_bluetooth_impl.h" #include "content/child/geofencing/web_geofencing_provider_impl.h" #include "content/common/gpu/image_transport_surface.h" #include "content/public/common/page_state.h" @@ -313,14 +312,11 @@ void SetDeviceColorProfile(RenderView* render_view, const std::string& name) { SetDeviceColorProfileForTesting(color_profile); } -void SetBluetoothAdapter(int render_process_id, const std::string& name) { - RenderProcessHostImpl* render_process_host_impl = - static_cast<RenderProcessHostImpl*>( - RenderProcessHost::FromID(render_process_id)); - - render_process_host_impl - ->GetBluetoothDispatcherHost() - ->SetBluetoothAdapterForTesting(name); +void SetBluetoothMockDataSetForTesting(const std::string& name) { + RenderThreadImpl::current() + ->blink_platform_impl() + ->BluetoothImplForTesting() + ->SetBluetoothMockDataSetForTesting(name); } void SetGeofencingMockProvider(bool service_available) { |