Commit 078780b9 authored by b.kelemen@samsung.com's avatar b.kelemen@samsung.com

Gamepad: make page visibility behavior layout testable

This CL refactors testing infrastructure for gamepad so that we can
actually write a layout test that would fail if Blink doesn't honor
visibility state. Now Platform::setGamepadListener is now hooked to
GamepadController.

BUG=344556

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278723 0039d316-1c4b-4281-b951-d872f2087c98
parent 332d17d2
// Copyright 2014 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 CONTENT_GAMEPAD_RENDERER_PROVIDER_H_
#define CONTENT_GAMEPAD_RENDERER_PROVIDER_H_
namespace blink {
class WebGamepadListener;
class WebGamepads;
}
namespace content {
// Provides gamepad data and events for blink.
class RendererGamepadProvider {
public:
// Provides latest snapshot of gamepads.
virtual void SampleGamepads(blink::WebGamepads& gamepads) = 0;
// Registers listener for be notified of events.
virtual void SetGamepadListener(blink::WebGamepadListener* listener) = 0;
protected:
virtual ~RendererGamepadProvider() {}
};
} // namespace content
#endif
...@@ -26,6 +26,7 @@ namespace content { ...@@ -26,6 +26,7 @@ namespace content {
class PageState; class PageState;
class RenderFrame; class RenderFrame;
class RendererGamepadProvider;
class RenderView; class RenderView;
class WebTestProxyBase; class WebTestProxyBase;
...@@ -44,15 +45,8 @@ void EnableRendererLayoutTestMode(); ...@@ -44,15 +45,8 @@ void EnableRendererLayoutTestMode();
void EnableWebTestProxyCreation( void EnableWebTestProxyCreation(
const base::Callback<void(RenderView*, WebTestProxyBase*)>& callback); const base::Callback<void(RenderView*, WebTestProxyBase*)>& callback);
// Sets the WebGamepads that should be returned by // Sets gamepad provider to be used for layout tests.
// WebKitPlatformSupport::sampleGamepads(). void SetMockGamepadProvider(RendererGamepadProvider* provider);
void SetMockGamepads(const blink::WebGamepads& pads);
// Notifies blink about a new gamepad.
void MockGamepadConnected(int index, const blink::WebGamepad& pad);
// Notifies blink that a gamepad has been disconnected.
void MockGamepadDisconnected(int index, const blink::WebGamepad& pad);
// Sets WebDeviceMotionData that should be used when registering // Sets WebDeviceMotionData that should be used when registering
// a listener through WebKitPlatformSupport::setDeviceMotionListener(). // a listener through WebKitPlatformSupport::setDeviceMotionListener().
......
...@@ -6,19 +6,22 @@ ...@@ -6,19 +6,22 @@
#include "base/debug/trace_event.h" #include "base/debug/trace_event.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "content/common/gamepad_hardware_buffer.h"
#include "content/common/gamepad_user_gesture.h" #include "content/common/gamepad_user_gesture.h"
#include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_thread.h"
#include "content/common/gamepad_hardware_buffer.h" #include "content/renderer/renderer_webkitplatformsupport_impl.h"
#include "ipc/ipc_sync_message_filter.h" #include "ipc/ipc_sync_message_filter.h"
#include "third_party/WebKit/public/platform/WebGamepadListener.h" #include "third_party/WebKit/public/platform/WebGamepadListener.h"
namespace content { namespace content {
GamepadSharedMemoryReader::GamepadSharedMemoryReader() GamepadSharedMemoryReader::GamepadSharedMemoryReader(
RendererWebKitPlatformSupportImpl* webkit_platform_support)
: gamepad_hardware_buffer_(NULL), : gamepad_hardware_buffer_(NULL),
gamepad_listener_(NULL), gamepad_listener_(NULL),
is_polling_(false), is_polling_(false),
ever_interacted_with_(false) { ever_interacted_with_(false) {
webkit_platform_support->set_gamepad_provider(this);
} }
void GamepadSharedMemoryReader::StartPollingIfNecessary() { void GamepadSharedMemoryReader::StartPollingIfNecessary() {
......
...@@ -9,21 +9,27 @@ ...@@ -9,21 +9,27 @@
#include "base/memory/shared_memory.h" #include "base/memory/shared_memory.h"
#include "content/common/gamepad_messages.h" #include "content/common/gamepad_messages.h"
#include "content/public/renderer/render_process_observer.h" #include "content/public/renderer/render_process_observer.h"
#include "content/public/renderer/renderer_gamepad_provider.h"
#include "third_party/WebKit/public/platform/WebGamepads.h" #include "third_party/WebKit/public/platform/WebGamepads.h"
namespace blink { class WebGamepadListener; }
namespace content { namespace content {
struct GamepadHardwareBuffer; struct GamepadHardwareBuffer;
class RendererWebKitPlatformSupportImpl;
class GamepadSharedMemoryReader : public RenderProcessObserver { class GamepadSharedMemoryReader
: public RenderProcessObserver,
public RendererGamepadProvider {
public: public:
GamepadSharedMemoryReader(); GamepadSharedMemoryReader(
RendererWebKitPlatformSupportImpl* webkit_platform_support);
virtual ~GamepadSharedMemoryReader(); virtual ~GamepadSharedMemoryReader();
void SampleGamepads(blink::WebGamepads& gamepads); // RendererGamepadProvider implementation.
void SetGamepadListener(blink::WebGamepadListener* listener); virtual void SampleGamepads(
blink::WebGamepads& gamepads) OVERRIDE;
virtual void SetGamepadListener(
blink::WebGamepadListener* listener) OVERRIDE;
// RenderProcessObserver implementation. // RenderProcessObserver implementation.
virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
......
...@@ -405,9 +405,6 @@ void RenderThreadImpl::Init() { ...@@ -405,9 +405,6 @@ void RenderThreadImpl::Init() {
AddFilter((new EmbeddedWorkerContextMessageFilter())->GetFilter()); AddFilter((new EmbeddedWorkerContextMessageFilter())->GetFilter());
gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader());
AddObserver(gamepad_shared_memory_reader_.get());
GetContentClient()->renderer()->RenderThreadStarted(); GetContentClient()->renderer()->RenderThreadStarted();
InitSkiaEventTracer(); InitSkiaEventTracer();
...@@ -792,6 +789,10 @@ void RenderThreadImpl::EnsureWebKitInitialized() { ...@@ -792,6 +789,10 @@ void RenderThreadImpl::EnsureWebKitInitialized() {
CompositorOutputSurface::CreateFilter(output_surface_loop.get()); CompositorOutputSurface::CreateFilter(output_surface_loop.get());
AddFilter(compositor_output_surface_filter_.get()); AddFilter(compositor_output_surface_filter_.get());
gamepad_shared_memory_reader_.reset(
new GamepadSharedMemoryReader(webkit_platform_support_.get()));
AddObserver(gamepad_shared_memory_reader_.get());
RenderThreadImpl::RegisterSchemes(); RenderThreadImpl::RegisterSchemes();
EnableBlinkPlatformLogChannels( EnableBlinkPlatformLogChannels(
......
...@@ -192,6 +192,11 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread, ...@@ -192,6 +192,11 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread,
layout_test_mode_ = layout_test_mode; layout_test_mode_ = layout_test_mode;
} }
RendererWebKitPlatformSupportImpl* webkit_platform_support() const {
DCHECK(webkit_platform_support_);
return webkit_platform_support_.get();
}
IPC::ForwardingMessageFilter* compositor_output_surface_filter() const { IPC::ForwardingMessageFilter* compositor_output_surface_filter() const {
return compositor_output_surface_filter_.get(); return compositor_output_surface_filter_.get();
} }
......
...@@ -141,9 +141,6 @@ namespace content { ...@@ -141,9 +141,6 @@ namespace content {
namespace { namespace {
static bool g_sandbox_enabled = true; static bool g_sandbox_enabled = true;
static blink::WebGamepadListener* web_gamepad_listener = NULL;
base::LazyInstance<WebGamepads>::Leaky g_test_gamepads =
LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<blink::WebDeviceMotionData>::Leaky base::LazyInstance<blink::WebDeviceMotionData>::Leaky
g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER; g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<blink::WebDeviceOrientationData>::Leaky base::LazyInstance<blink::WebDeviceOrientationData>::Leaky
...@@ -231,7 +228,8 @@ RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() ...@@ -231,7 +228,8 @@ RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl()
sudden_termination_disables_(0), sudden_termination_disables_(0),
plugin_refresh_allowed_(true), plugin_refresh_allowed_(true),
child_thread_loop_(base::MessageLoopProxy::current()), child_thread_loop_(base::MessageLoopProxy::current()),
web_scrollbar_behavior_(new WebScrollbarBehaviorImpl) { web_scrollbar_behavior_(new WebScrollbarBehaviorImpl),
gamepad_provider_(NULL) {
if (g_sandbox_enabled && sandboxEnabled()) { if (g_sandbox_enabled && sandboxEnabled()) {
sandbox_support_.reset( sandbox_support_.reset(
new RendererWebKitPlatformSupportImpl::SandboxSupport); new RendererWebKitPlatformSupportImpl::SandboxSupport);
...@@ -885,19 +883,14 @@ WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { ...@@ -885,19 +883,14 @@ WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) {
if (g_test_gamepads == 0) { DCHECK(gamepad_provider_);
RenderThreadImpl::current()->gamepad_shared_memory_reader()-> gamepad_provider_->SampleGamepads(gamepads);
SampleGamepads(gamepads);
} else {
gamepads = g_test_gamepads.Get();
}
} }
void RendererWebKitPlatformSupportImpl::setGamepadListener( void RendererWebKitPlatformSupportImpl::setGamepadListener(
blink::WebGamepadListener* listener) { blink::WebGamepadListener* listener) {
web_gamepad_listener = listener; DCHECK(gamepad_provider_);
RenderThreadImpl::current()->gamepad_shared_memory_reader()-> gamepad_provider_->SetGamepadListener(listener);
SetGamepadListener(listener);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -945,28 +938,6 @@ bool RendererWebKitPlatformSupportImpl::SetSandboxEnabledForTesting( ...@@ -945,28 +938,6 @@ bool RendererWebKitPlatformSupportImpl::SetSandboxEnabledForTesting(
return was_enabled; return was_enabled;
} }
// static
void RendererWebKitPlatformSupportImpl::SetMockGamepadsForTesting(
const WebGamepads& pads) {
g_test_gamepads.Get() = pads;
}
// static
void RendererWebKitPlatformSupportImpl::MockGamepadConnected(
int index,
const WebGamepad& pad) {
if (web_gamepad_listener)
web_gamepad_listener->didConnectGamepad(index, pad);
}
// static
void RendererWebKitPlatformSupportImpl::MockGamepadDisconnected(
int index,
const WebGamepad& pad) {
if (web_gamepad_listener)
web_gamepad_listener->didDisconnectGamepad(index, pad);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
blink::WebSpeechSynthesizer* blink::WebSpeechSynthesizer*
......
...@@ -41,6 +41,7 @@ class DeviceOrientationEventPump; ...@@ -41,6 +41,7 @@ class DeviceOrientationEventPump;
class QuotaMessageFilter; class QuotaMessageFilter;
class RendererClipboardClient; class RendererClipboardClient;
class RenderView; class RenderView;
class RendererGamepadProvider;
class ThreadSafeSender; class ThreadSafeSender;
class WebClipboardImpl; class WebClipboardImpl;
class WebDatabaseObserverImpl; class WebDatabaseObserverImpl;
...@@ -148,6 +149,10 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl ...@@ -148,6 +149,10 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
virtual void setBatteryStatusListener( virtual void setBatteryStatusListener(
blink::WebBatteryStatusListener* listener); blink::WebBatteryStatusListener* listener);
void set_gamepad_provider(RendererGamepadProvider* provider) {
gamepad_provider_ = provider;
}
// Disables the WebSandboxSupport implementation for testing. // Disables the WebSandboxSupport implementation for testing.
// Tests that do not set up a full sandbox environment should call // Tests that do not set up a full sandbox environment should call
// SetSandboxEnabledForTesting(false) _before_ creating any instances // SetSandboxEnabledForTesting(false) _before_ creating any instances
...@@ -157,17 +162,6 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl ...@@ -157,17 +162,6 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
// Returns the previous |enable| value. // Returns the previous |enable| value.
static bool SetSandboxEnabledForTesting(bool enable); static bool SetSandboxEnabledForTesting(bool enable);
// Set WebGamepads to return when sampleGamepads() is invoked.
static void SetMockGamepadsForTesting(const blink::WebGamepads& pads);
// Notifies blink::WebGamepadListener about a new gamepad if a listener
// has been set via setGamepadListener.
static void MockGamepadConnected(int index, const blink::WebGamepad& pad);
// Notifies blink::WebGamepadListener that a gamepad has been disconnected if
// a listener has been set via setGamepadListener.
static void MockGamepadDisconnected(int index, const blink::WebGamepad& pad);
// Set WebDeviceMotionData to return when setDeviceMotionListener is invoked. // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked.
static void SetMockDeviceMotionDataForTesting( static void SetMockDeviceMotionDataForTesting(
const blink::WebDeviceMotionData& data); const blink::WebDeviceMotionData& data);
...@@ -236,6 +230,8 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl ...@@ -236,6 +230,8 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
scoped_ptr<BatteryStatusDispatcher> battery_status_dispatcher_; scoped_ptr<BatteryStatusDispatcher> battery_status_dispatcher_;
RendererGamepadProvider* gamepad_provider_;
DISALLOW_COPY_AND_ASSIGN(RendererWebKitPlatformSupportImpl); DISALLOW_COPY_AND_ASSIGN(RendererWebKitPlatformSupportImpl);
}; };
......
...@@ -29,6 +29,7 @@ struct WebURLError; ...@@ -29,6 +29,7 @@ struct WebURLError;
namespace content { namespace content {
class RendererGamepadProvider;
class WebTask; class WebTask;
class WebTestProxyBase; class WebTestProxyBase;
struct TestPreferences; struct TestPreferences;
...@@ -40,14 +41,8 @@ public: ...@@ -40,14 +41,8 @@ public:
virtual void clearEditCommand() = 0; virtual void clearEditCommand() = 0;
virtual void setEditCommand(const std::string& name, const std::string& value) = 0; virtual void setEditCommand(const std::string& name, const std::string& value) = 0;
// Set the gamepads to return from Platform::sampleGamepads(). // Sets gamepad provider to be used for tests.
virtual void setGamepadData(const blink::WebGamepads&) = 0; virtual void setGamepadProvider(RendererGamepadProvider*) = 0;
// Notifies blink about a new gamepad.
virtual void didConnectGamepad(int index, const blink::WebGamepad&) = 0;
// Notifies blink that a gamepad has been disconnected.
virtual void didDisconnectGamepad(int index, const blink::WebGamepad&) = 0;
// Set data to return when registering via Platform::setDeviceMotionListener(). // Set data to return when registering via Platform::setDeviceMotionListener().
virtual void setDeviceMotionData(const blink::WebDeviceMotionData&) = 0; virtual void setDeviceMotionData(const blink::WebDeviceMotionData&) = 0;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "gin/handle.h" #include "gin/handle.h"
#include "gin/object_template_builder.h" #include "gin/object_template_builder.h"
#include "gin/wrappable.h" #include "gin/wrappable.h"
#include "third_party/WebKit/public/platform/WebGamepadListener.h"
#include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebKit.h" #include "third_party/WebKit/public/web/WebKit.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
...@@ -136,7 +137,9 @@ void GamepadControllerBindings::SetAxisData(int index, int axis, double data) { ...@@ -136,7 +137,9 @@ void GamepadControllerBindings::SetAxisData(int index, int axis, double data) {
controller_->SetAxisData(index, axis, data); controller_->SetAxisData(index, axis, data);
} }
GamepadController::GamepadController() : delegate_(NULL), weak_factory_(this) { GamepadController::GamepadController()
: listener_(NULL),
weak_factory_(this) {
Reset(); Reset();
} }
...@@ -151,7 +154,16 @@ void GamepadController::Install(WebFrame* frame) { ...@@ -151,7 +154,16 @@ void GamepadController::Install(WebFrame* frame) {
} }
void GamepadController::SetDelegate(WebTestDelegate* delegate) { void GamepadController::SetDelegate(WebTestDelegate* delegate) {
delegate_ = delegate; delegate->setGamepadProvider(this);
}
void GamepadController::SampleGamepads(blink::WebGamepads& gamepads) {
memcpy(&gamepads, &gamepads_, sizeof(blink::WebGamepads));
}
void GamepadController::SetGamepadListener(
blink::WebGamepadListener* listener) {
listener_ = listener;
} }
void GamepadController::Connect(int index) { void GamepadController::Connect(int index) {
...@@ -163,16 +175,15 @@ void GamepadController::Connect(int index) { ...@@ -163,16 +175,15 @@ void GamepadController::Connect(int index) {
if (gamepads_.items[i].connected) if (gamepads_.items[i].connected)
gamepads_.length = i + 1; gamepads_.length = i + 1;
} }
if (delegate_)
delegate_->setGamepadData(gamepads_);
} }
void GamepadController::DispatchConnected(int index) { void GamepadController::DispatchConnected(int index) {
if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)) if (index < 0 || index >= static_cast<int>(WebGamepads::itemsLengthCap)
|| !gamepads_.items[index].connected)
return; return;
const WebGamepad& pad = gamepads_.items[index]; const WebGamepad& pad = gamepads_.items[index];
if (pad.connected && delegate_) if (listener_)
delegate_->didConnectGamepad(index, pad); listener_->didConnectGamepad(index, pad);
} }
void GamepadController::Disconnect(int index) { void GamepadController::Disconnect(int index) {
...@@ -185,10 +196,8 @@ void GamepadController::Disconnect(int index) { ...@@ -185,10 +196,8 @@ void GamepadController::Disconnect(int index) {
if (gamepads_.items[i].connected) if (gamepads_.items[i].connected)
gamepads_.length = i + 1; gamepads_.length = i + 1;
} }
if (delegate_) { if (listener_)
delegate_->setGamepadData(gamepads_); listener_->didDisconnectGamepad(index, pad);
delegate_->didDisconnectGamepad(index, pad);
}
} }
void GamepadController::SetId(int index, const std::string& src) { void GamepadController::SetId(int index, const std::string& src) {
...@@ -198,8 +207,6 @@ void GamepadController::SetId(int index, const std::string& src) { ...@@ -198,8 +207,6 @@ void GamepadController::SetId(int index, const std::string& src) {
memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id)); memset(gamepads_.items[index].id, 0, sizeof(gamepads_.items[index].id));
for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i) for (unsigned i = 0; *p && i < WebGamepad::idLengthCap - 1; ++i)
gamepads_.items[index].id[i] = *p++; gamepads_.items[index].id[i] = *p++;
if (delegate_)
delegate_->setGamepadData(gamepads_);
} }
void GamepadController::SetButtonCount(int index, int buttons) { void GamepadController::SetButtonCount(int index, int buttons) {
...@@ -208,8 +215,6 @@ void GamepadController::SetButtonCount(int index, int buttons) { ...@@ -208,8 +215,6 @@ void GamepadController::SetButtonCount(int index, int buttons) {
if (buttons < 0 || buttons >= static_cast<int>(WebGamepad::buttonsLengthCap)) if (buttons < 0 || buttons >= static_cast<int>(WebGamepad::buttonsLengthCap))
return; return;
gamepads_.items[index].buttonsLength = buttons; gamepads_.items[index].buttonsLength = buttons;
if (delegate_)
delegate_->setGamepadData(gamepads_);
} }
void GamepadController::SetButtonData(int index, int button, double data) { void GamepadController::SetButtonData(int index, int button, double data) {
...@@ -219,8 +224,6 @@ void GamepadController::SetButtonData(int index, int button, double data) { ...@@ -219,8 +224,6 @@ void GamepadController::SetButtonData(int index, int button, double data) {
return; return;
gamepads_.items[index].buttons[button].value = data; gamepads_.items[index].buttons[button].value = data;
gamepads_.items[index].buttons[button].pressed = data > 0.1f; gamepads_.items[index].buttons[button].pressed = data > 0.1f;
if (delegate_)
delegate_->setGamepadData(gamepads_);
} }
void GamepadController::SetAxisCount(int index, int axes) { void GamepadController::SetAxisCount(int index, int axes) {
...@@ -229,8 +232,6 @@ void GamepadController::SetAxisCount(int index, int axes) { ...@@ -229,8 +232,6 @@ void GamepadController::SetAxisCount(int index, int axes) {
if (axes < 0 || axes >= static_cast<int>(WebGamepad::axesLengthCap)) if (axes < 0 || axes >= static_cast<int>(WebGamepad::axesLengthCap))
return; return;
gamepads_.items[index].axesLength = axes; gamepads_.items[index].axesLength = axes;
if (delegate_)
delegate_->setGamepadData(gamepads_);
} }
void GamepadController::SetAxisData(int index, int axis, double data) { void GamepadController::SetAxisData(int index, int axis, double data) {
...@@ -239,8 +240,6 @@ void GamepadController::SetAxisData(int index, int axis, double data) { ...@@ -239,8 +240,6 @@ void GamepadController::SetAxisData(int index, int axis, double data) {
if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap)) if (axis < 0 || axis >= static_cast<int>(WebGamepad::axesLengthCap))
return; return;
gamepads_.items[index].axes[axis] = data; gamepads_.items[index].axes[axis] = data;
if (delegate_)
delegate_->setGamepadData(gamepads_);
} }
} // namespace content } // namespace content
...@@ -5,26 +5,38 @@ ...@@ -5,26 +5,38 @@
#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_
#define CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ #define CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_
#include <map>
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "content/public/renderer/renderer_gamepad_provider.h"
#include "third_party/WebKit/public/platform/WebGamepads.h" #include "third_party/WebKit/public/platform/WebGamepads.h"
namespace blink { namespace blink {
class WebFrame; class WebFrame;
class WebGamepadListener;
} }
namespace content { namespace content {
class WebTestDelegate; class WebTestDelegate;
class GamepadController : public base::SupportsWeakPtr<GamepadController> { class GamepadController
: public base::SupportsWeakPtr<GamepadController>,
public RendererGamepadProvider {
public: public:
GamepadController(); GamepadController();
~GamepadController(); virtual ~GamepadController();
void Reset(); void Reset();
void Install(blink::WebFrame* frame); void Install(blink::WebFrame* frame);
void SetDelegate(WebTestDelegate* delegate); void SetDelegate(WebTestDelegate* delegate);
// RendererGamepadProvider implementation.
virtual void SampleGamepads(
blink::WebGamepads& gamepads) OVERRIDE;
virtual void SetGamepadListener(
blink::WebGamepadListener* listener) OVERRIDE;
private: private:
friend class GamepadControllerBindings; friend class GamepadControllerBindings;
...@@ -46,7 +58,10 @@ class GamepadController : public base::SupportsWeakPtr<GamepadController> { ...@@ -46,7 +58,10 @@ class GamepadController : public base::SupportsWeakPtr<GamepadController> {
blink::WebGamepads gamepads_; blink::WebGamepads gamepads_;
WebTestDelegate* delegate_; blink::WebGamepadListener* listener_;
// Mapping from gamepad index to connection state.
std::map<int, bool> pending_changes_;
base::WeakPtrFactory<GamepadController> weak_factory_; base::WeakPtrFactory<GamepadController> weak_factory_;
......
...@@ -201,20 +201,9 @@ void WebKitTestRunner::setEditCommand(const std::string& name, ...@@ -201,20 +201,9 @@ void WebKitTestRunner::setEditCommand(const std::string& name,
render_view()->SetEditCommandForNextKeyEvent(name, value); render_view()->SetEditCommandForNextKeyEvent(name, value);
} }
void WebKitTestRunner::setGamepadData(const WebGamepads& gamepads) { void WebKitTestRunner::setGamepadProvider(
SetMockGamepads(gamepads); RendererGamepadProvider* provider) {
} SetMockGamepadProvider(provider);
void WebKitTestRunner::didConnectGamepad(
int index,
const blink::WebGamepad& gamepad) {
MockGamepadConnected(index, gamepad);
}
void WebKitTestRunner::didDisconnectGamepad(
int index,
const blink::WebGamepad& gamepad) {
MockGamepadDisconnected(index, gamepad);
} }
void WebKitTestRunner::setDeviceMotionData(const WebDeviceMotionData& data) { void WebKitTestRunner::setDeviceMotionData(const WebDeviceMotionData& data) {
......
...@@ -55,11 +55,7 @@ class WebKitTestRunner : public RenderViewObserver, ...@@ -55,11 +55,7 @@ class WebKitTestRunner : public RenderViewObserver,
virtual void clearEditCommand() OVERRIDE; virtual void clearEditCommand() OVERRIDE;
virtual void setEditCommand(const std::string& name, virtual void setEditCommand(const std::string& name,
const std::string& value) OVERRIDE; const std::string& value) OVERRIDE;
virtual void setGamepadData(const blink::WebGamepads& gamepads) OVERRIDE; virtual void setGamepadProvider(RendererGamepadProvider*) OVERRIDE;
virtual void didConnectGamepad(int index,
const blink::WebGamepad& gamepad) OVERRIDE;
virtual void didDisconnectGamepad(int index,
const blink::WebGamepad& gamepad) OVERRIDE;
virtual void setDeviceMotionData( virtual void setDeviceMotionData(
const blink::WebDeviceMotionData& data) OVERRIDE; const blink::WebDeviceMotionData& data) OVERRIDE;
virtual void setDeviceOrientationData( virtual void setDeviceOrientationData(
......
...@@ -81,16 +81,9 @@ void EnableWebTestProxyCreation( ...@@ -81,16 +81,9 @@ void EnableWebTestProxyCreation(
RenderFrameImpl::InstallCreateHook(CreateWebFrameTestProxy); RenderFrameImpl::InstallCreateHook(CreateWebFrameTestProxy);
} }
void SetMockGamepads(const WebGamepads& pads) { void SetMockGamepadProvider(RendererGamepadProvider* provider) {
RendererWebKitPlatformSupportImpl::SetMockGamepadsForTesting(pads); RenderThreadImpl::current()->webkit_platform_support()->
} set_gamepad_provider(provider);
void MockGamepadConnected(int index, const WebGamepad& pad) {
RendererWebKitPlatformSupportImpl::MockGamepadConnected(index, pad);
}
void MockGamepadDisconnected(int index, const WebGamepad& pad) {
RendererWebKitPlatformSupportImpl::MockGamepadDisconnected(index, pad);
} }
void SetMockDeviceMotionData(const WebDeviceMotionData& data) { void SetMockDeviceMotionData(const WebDeviceMotionData& data) {
......
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