Commit dad74f04 authored by dtapuska's avatar dtapuska Committed by Commit bot

Add a unit test expection for calling the render scheduler on coalesced events.

Change the API around a little so that we can mock out the callback to
ensure that we are calling in the correct scenarios.

BUG=637640

Review-Url: https://codereview.chromium.org/2259823007
Cr-Commit-Position: refs/heads/master@{#413442}
parent f6c4d75a
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "content/common/input_messages.h" #include "content/common/input_messages.h"
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/renderer/render_thread_impl.h"
#include "ipc/ipc_listener.h" #include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h" #include "ipc/ipc_sender.h"
#include "ui/events/blink/did_overscroll_params.h" #include "ui/events/blink/did_overscroll_params.h"
...@@ -52,8 +53,13 @@ InputEventFilter::InputEventFilter( ...@@ -52,8 +53,13 @@ InputEventFilter::InputEventFilter(
main_listener_(main_listener), main_listener_(main_listener),
sender_(NULL), sender_(NULL),
target_task_runner_(target_task_runner), target_task_runner_(target_task_runner),
current_overscroll_params_(NULL) { current_overscroll_params_(NULL),
renderer_scheduler_(NULL) {
DCHECK(target_task_runner_.get()); DCHECK(target_task_runner_.get());
DCHECK(main_task_runner_->BelongsToCurrentThread());
RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
renderer_scheduler_ =
render_thread_impl ? render_thread_impl->GetRendererScheduler() : nullptr;
} }
void InputEventFilter::SetBoundHandler(const Handler& handler) { void InputEventFilter::SetBoundHandler(const Handler& handler) {
...@@ -73,8 +79,8 @@ void InputEventFilter::SetIsFlingingInMainThreadEventQueue(int routing_id, ...@@ -73,8 +79,8 @@ void InputEventFilter::SetIsFlingingInMainThreadEventQueue(int routing_id,
void InputEventFilter::RegisterRoutingID(int routing_id) { void InputEventFilter::RegisterRoutingID(int routing_id) {
base::AutoLock locked(routes_lock_); base::AutoLock locked(routes_lock_);
routes_.insert(routing_id); routes_.insert(routing_id);
route_queues_[routing_id] = route_queues_[routing_id] = new MainThreadEventQueue(
new MainThreadEventQueue(routing_id, this, main_task_runner_); routing_id, this, main_task_runner_, renderer_scheduler_);
} }
void InputEventFilter::UnregisterRoutingID(int routing_id) { void InputEventFilter::UnregisterRoutingID(int routing_id) {
......
...@@ -125,6 +125,7 @@ class CONTENT_EXPORT InputEventFilter : public InputHandlerManagerClient, ...@@ -125,6 +125,7 @@ class CONTENT_EXPORT InputEventFilter : public InputHandlerManagerClient,
// bundled in the event ack, saving an IPC. Note that we must continue // bundled in the event ack, saving an IPC. Note that we must continue
// supporting overscroll IPC notifications due to fling animation updates. // supporting overscroll IPC notifications due to fling animation updates.
std::unique_ptr<ui::DidOverscrollParams>* current_overscroll_params_; std::unique_ptr<ui::DidOverscrollParams>* current_overscroll_params_;
blink::scheduler::RendererScheduler* renderer_scheduler_;
}; };
} // namespace content } // namespace content
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "content/common/input/event_with_latency_info.h" #include "content/common/input/event_with_latency_info.h"
#include "content/common/input_messages.h" #include "content/common/input_messages.h"
#include "content/renderer/render_thread_impl.h"
namespace content { namespace content {
...@@ -39,14 +38,16 @@ void EventWithDispatchType::CoalesceWith(const EventWithDispatchType& other) { ...@@ -39,14 +38,16 @@ void EventWithDispatchType::CoalesceWith(const EventWithDispatchType& other) {
MainThreadEventQueue::MainThreadEventQueue( MainThreadEventQueue::MainThreadEventQueue(
int routing_id, int routing_id,
MainThreadEventQueueClient* client, MainThreadEventQueueClient* client,
const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner,
blink::scheduler::RendererScheduler* renderer_scheduler)
: routing_id_(routing_id), : routing_id_(routing_id),
client_(client), client_(client),
is_flinging_(false), is_flinging_(false),
last_touch_start_forced_nonblocking_due_to_fling_(false), last_touch_start_forced_nonblocking_due_to_fling_(false),
enable_fling_passive_listener_flag_(base::FeatureList::IsEnabled( enable_fling_passive_listener_flag_(base::FeatureList::IsEnabled(
features::kPassiveEventListenersDueToFling)), features::kPassiveEventListenersDueToFling)),
main_task_runner_(main_task_runner) {} main_task_runner_(main_task_runner),
renderer_scheduler_(renderer_scheduler) {}
MainThreadEventQueue::~MainThreadEventQueue() {} MainThreadEventQueue::~MainThreadEventQueue() {}
...@@ -134,13 +135,12 @@ void MainThreadEventQueue::PopEventOnMainThread() { ...@@ -134,13 +135,12 @@ void MainThreadEventQueue::PopEventOnMainThread() {
void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type, void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type,
InputEventAckState ack_result) { InputEventAckState ack_result) {
if (in_flight_event_) { if (in_flight_event_) {
RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
// Send acks for blocking touch events. // Send acks for blocking touch events.
for (const auto id : in_flight_event_->eventsToAck()) { for (const auto id : in_flight_event_->eventsToAck()) {
client_->SendInputEventAck(routing_id_, type, ack_result, id); client_->SendInputEventAck(routing_id_, type, ack_result, id);
if (render_thread_impl) { if (renderer_scheduler_) {
render_thread_impl->GetRendererScheduler() renderer_scheduler_->DidHandleInputEventOnMainThread(
->DidHandleInputEventOnMainThread(in_flight_event_->event()); in_flight_event_->event());
} }
} }
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "content/common/input/input_event_dispatch_type.h" #include "content/common/input/input_event_dispatch_type.h"
#include "content/common/input/web_input_event_queue.h" #include "content/common/input/web_input_event_queue.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
#include "third_party/WebKit/public/web/WebInputEvent.h" #include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/events/blink/web_input_event_traits.h" #include "ui/events/blink/web_input_event_traits.h"
#include "ui/events/latency_info.h" #include "ui/events/latency_info.h"
...@@ -101,7 +102,8 @@ class CONTENT_EXPORT MainThreadEventQueue ...@@ -101,7 +102,8 @@ class CONTENT_EXPORT MainThreadEventQueue
MainThreadEventQueue( MainThreadEventQueue(
int routing_id, int routing_id,
MainThreadEventQueueClient* client, MainThreadEventQueueClient* client,
const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner,
blink::scheduler::RendererScheduler* renderer_scheduler);
// Called once the compositor has handled |event| and indicated that it is // Called once the compositor has handled |event| and indicated that it is
// a non-blocking event to be queued to the main thread. // a non-blocking event to be queued to the main thread.
...@@ -138,6 +140,7 @@ class CONTENT_EXPORT MainThreadEventQueue ...@@ -138,6 +140,7 @@ class CONTENT_EXPORT MainThreadEventQueue
base::Lock event_queue_lock_; base::Lock event_queue_lock_;
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
blink::scheduler::RendererScheduler* renderer_scheduler_;
DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue);
}; };
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "content/common/input/synthetic_web_input_event_builders.h" #include "content/common/input/synthetic_web_input_event_builders.h"
#include "content/renderer/input/main_thread_event_queue.h" #include "content/renderer/input/main_thread_event_queue.h"
#include "content/renderer/render_thread_impl.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/scheduler/test/mock_renderer_scheduler.h"
using blink::WebInputEvent; using blink::WebInputEvent;
using blink::WebMouseEvent; using blink::WebMouseEvent;
...@@ -41,9 +43,10 @@ class MainThreadEventQueueTest : public testing::Test, ...@@ -41,9 +43,10 @@ class MainThreadEventQueueTest : public testing::Test,
public: public:
MainThreadEventQueueTest() MainThreadEventQueueTest()
: main_task_runner_(new base::TestSimpleTaskRunner()), : main_task_runner_(new base::TestSimpleTaskRunner()),
queue_( queue_(new MainThreadEventQueue(kTestRoutingID,
new MainThreadEventQueue(kTestRoutingID, this, main_task_runner_)) { this,
} main_task_runner_,
&renderer_scheduler_)) {}
void HandleEventOnMainThread(int routing_id, void HandleEventOnMainThread(int routing_id,
const blink::WebInputEvent* event, const blink::WebInputEvent* event,
...@@ -84,6 +87,7 @@ class MainThreadEventQueueTest : public testing::Test, ...@@ -84,6 +87,7 @@ class MainThreadEventQueueTest : public testing::Test,
protected: protected:
scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_; scoped_refptr<base::TestSimpleTaskRunner> main_task_runner_;
blink::scheduler::MockRendererScheduler renderer_scheduler_;
scoped_refptr<MainThreadEventQueue> queue_; scoped_refptr<MainThreadEventQueue> queue_;
std::vector<ui::ScopedWebInputEvent> handled_events_; std::vector<ui::ScopedWebInputEvent> handled_events_;
std::vector<uint32_t> additional_acked_events_; std::vector<uint32_t> additional_acked_events_;
...@@ -192,6 +196,9 @@ TEST_F(MainThreadEventQueueTest, BlockingTouch) { ...@@ -192,6 +196,9 @@ TEST_F(MainThreadEventQueueTest, BlockingTouch) {
kEvents[2].MovePoint(0, 30, 30); kEvents[2].MovePoint(0, 30, 30);
kEvents[3].PressPoint(10, 10); kEvents[3].PressPoint(10, 10);
kEvents[3].MovePoint(0, 35, 35); kEvents[3].MovePoint(0, 35, 35);
EXPECT_CALL(renderer_scheduler_, DidHandleInputEventOnMainThread(testing::_))
.Times(2);
// Ensure that coalescing takes place. // Ensure that coalescing takes place.
HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING); HandleEvent(kEvents[0], INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING);
HandleEvent(kEvents[1], INPUT_EVENT_ACK_STATE_NOT_CONSUMED); HandleEvent(kEvents[1], INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
......
...@@ -323,6 +323,7 @@ ...@@ -323,6 +323,7 @@
"platform/scheduler/renderer/render_widget_scheduling_state.h", "platform/scheduler/renderer/render_widget_scheduling_state.h",
"platform/scheduler/renderer/renderer_scheduler.h", "platform/scheduler/renderer/renderer_scheduler.h",
"platform/scheduler/test/fake_renderer_scheduler.h", "platform/scheduler/test/fake_renderer_scheduler.h",
"platform/scheduler/test/mock_renderer_scheduler.h",
"platform/scheduler/test/renderer_scheduler_test_support.h", "platform/scheduler/test/renderer_scheduler_test_support.h",
"platform/scheduler/utility/webthread_impl_for_utility_thread.h", "platform/scheduler/utility/webthread_impl_for_utility_thread.h",
"web/WebAXEnums.h", "web/WebAXEnums.h",
......
include_rules = [
"+testing/gmock/include/gmock/gmock.h",
]
// Copyright 2016 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 THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_TEST_MOCK_RENDERER_SCHEDULER_H_
#define THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_TEST_MOCK_RENDERER_SCHEDULER_H_
#include "base/macros.h"
#include "public/platform/scheduler/renderer/renderer_scheduler.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace blink {
namespace scheduler {
class MockRendererScheduler : public RendererScheduler {
public:
MockRendererScheduler() = default;
~MockRendererScheduler() override = default;
MOCK_METHOD0(CreateMainThread, std::unique_ptr<blink::WebThread>());
MOCK_METHOD0(DefaultTaskRunner, scoped_refptr<TaskQueue>());
MOCK_METHOD0(CompositorTaskRunner, scoped_refptr<TaskQueue>());
MOCK_METHOD0(LoadingTaskRunner, scoped_refptr<TaskQueue>());
MOCK_METHOD0(IdleTaskRunner,
scoped_refptr<blink::scheduler::SingleThreadIdleTaskRunner>());
MOCK_METHOD0(TimerTaskRunner, scoped_refptr<TaskQueue>());
MOCK_METHOD1(NewLoadingTaskRunner, scoped_refptr<TaskQueue>(const char*));
MOCK_METHOD1(NewTimerTaskRunner, scoped_refptr<TaskQueue>(const char*));
MOCK_METHOD1(NewUnthrottledTaskRunner, scoped_refptr<TaskQueue>(const char*));
MOCK_METHOD0(NewRenderWidgetSchedulingState,
std::unique_ptr<RenderWidgetSchedulingState>());
MOCK_METHOD1(WillBeginFrame, void(const cc::BeginFrameArgs&));
MOCK_METHOD0(BeginFrameNotExpectedSoon, void());
MOCK_METHOD0(DidCommitFrameToCompositor, void());
MOCK_METHOD2(DidHandleInputEventOnCompositorThread,
void(const WebInputEvent&, InputEventState));
MOCK_METHOD1(DidHandleInputEventOnMainThread, void(const WebInputEvent&));
MOCK_METHOD0(DidAnimateForInputOnCompositorThread, void());
MOCK_METHOD0(OnRendererBackgrounded, void());
MOCK_METHOD0(OnRendererForegrounded, void());
MOCK_METHOD0(SuspendRenderer, void());
MOCK_METHOD1(AddPendingNavigation, void(WebScheduler::NavigatingFrameType));
MOCK_METHOD1(RemovePendingNavigation,
void(WebScheduler::NavigatingFrameType));
MOCK_METHOD0(OnNavigationStarted, void());
MOCK_METHOD0(IsHighPriorityWorkAnticipated, bool());
MOCK_CONST_METHOD0(CanExceedIdleDeadlineIfRequired, bool());
MOCK_METHOD0(ShouldYieldForHighPriorityWork, bool());
MOCK_METHOD1(AddTaskObserver, void(base::MessageLoop::TaskObserver*));
MOCK_METHOD1(RemoveTaskObserver, void(base::MessageLoop::TaskObserver*));
MOCK_METHOD0(Shutdown, void());
MOCK_METHOD0(SuspendTimerQueue, void());
MOCK_METHOD0(ResumeTimerQueue, void());
MOCK_METHOD1(SetTimerQueueSuspensionWhenBackgroundedEnabled, void(bool));
MOCK_METHOD1(SetTopLevelBlameContext, void(base::trace_event::BlameContext*));
MOCK_METHOD1(SetRAILModeObserver, void(RAILModeObserver*));
private:
DISALLOW_COPY_AND_ASSIGN(MockRendererScheduler);
};
} // namespace scheduler
} // namespace blink
#endif // THIRD_PARTY_WEBKIT_PUBLIC_PLATFORM_SCHEDULER_TEST_MOCK_RENDERER_SCHEDULER_H_
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