Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(914)

Unified Diff: content/browser/renderer_host/input/input_router_impl_unittest.cc

Issue 2727683002: Fix unit tests to enable them testing with the rAF aligned touch input. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/renderer_host/render_widget_host_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/input/input_router_impl_unittest.cc
diff --git a/content/browser/renderer_host/input/input_router_impl_unittest.cc b/content/browser/renderer_host/input/input_router_impl_unittest.cc
index 4bd65caa7dc13c5af0a967228bbf9257cf1db63b..f54ba2ed725c502622f085384d2e1231e257e325 100644
--- a/content/browser/renderer_host/input/input_router_impl_unittest.cc
+++ b/content/browser/renderer_host/input/input_router_impl_unittest.cc
@@ -17,6 +17,7 @@
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "content/browser/renderer_host/input/gesture_event_queue.h"
@@ -29,6 +30,7 @@
#include "content/common/input/touch_action.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
+#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
@@ -142,7 +144,8 @@ bool EventListIsSubset(const ScopedVector<ui::TouchEvent>& subset,
class InputRouterImplTest : public testing::Test {
public:
- InputRouterImplTest() {}
+ InputRouterImplTest() { EnableRafAlignedTouchInput(); }
+
~InputRouterImplTest() override {}
protected:
@@ -345,6 +348,16 @@ class InputRouterImplTest : public testing::Test {
base::RunLoop().Run();
}
+ void EnableRafAlignedTouchInput() {
+ feature_list_.InitFromCommandLine(
+ features::kRafAlignedTouchInputEvents.name, "");
+ }
+
+ void DisableRafAlignedTouchInput() {
+ feature_list_.InitFromCommandLine(
+ "", features::kRafAlignedTouchInputEvents.name);
+ }
+
InputRouterImpl::Config config_;
std::unique_ptr<MockRenderProcessHost> process_;
std::unique_ptr<MockInputRouterClient> client_;
@@ -355,9 +368,18 @@ class InputRouterImplTest : public testing::Test {
base::MessageLoopForUI message_loop_;
SyntheticWebTouchEvent touch_event_;
+ base::test::ScopedFeatureList feature_list_;
std::unique_ptr<TestBrowserContext> browser_context_;
};
+class InputRouterImplRafAlignedTouchDisabledTest : public InputRouterImplTest {
+ public:
+ void SetUp() override {
+ DisableRafAlignedTouchInput();
+ InputRouterImplTest::SetUp();
+ }
+};
+
TEST_F(InputRouterImplTest, CoalescesRangeSelection) {
input_router_->SendInput(std::unique_ptr<IPC::Message>(
new InputMsg_SelectRange(0, gfx::Point(1, 2), gfx::Point(3, 4))));
@@ -783,7 +805,7 @@ TEST_F(InputRouterImplTest, CoalescesWheelEvents) {
}
// Tests that touch-events are queued properly.
-TEST_F(InputRouterImplTest, TouchEventQueue) {
+TEST_F(InputRouterImplRafAlignedTouchDisabledTest, TouchEventQueue) {
OnHasTouchEventHandlers(true);
PressTouchPoint(1, 1);
@@ -817,6 +839,41 @@ TEST_F(InputRouterImplTest, TouchEventQueue) {
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
}
+// Tests that touch-events are sent properly.
+TEST_F(InputRouterImplTest, TouchEventQueue) {
+ OnHasTouchEventHandlers(true);
+
+ PressTouchPoint(1, 1);
+ uint32_t touch_press_event_id = SendTouchEvent();
+ EXPECT_TRUE(client_->GetAndResetFilterEventCalled());
+ EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
+ EXPECT_FALSE(TouchEventQueueEmpty());
+
+ // The second touch should be sent right away.
+ MoveTouchPoint(0, 5, 5);
+ uint32_t touch_move_event_id = SendTouchEvent();
+ EXPECT_TRUE(client_->GetAndResetFilterEventCalled());
+ EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
+ EXPECT_FALSE(TouchEventQueueEmpty());
+
+ // Receive an ACK for the first touch-event.
+ SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED,
+ touch_press_event_id);
+ EXPECT_FALSE(TouchEventQueueEmpty());
+ EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
+ EXPECT_EQ(WebInputEvent::TouchStart,
+ ack_handler_->acked_touch_event().event.type());
+ EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
+
+ SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED,
+ touch_move_event_id);
+ EXPECT_TRUE(TouchEventQueueEmpty());
+ EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
+ EXPECT_EQ(WebInputEvent::TouchMove,
+ ack_handler_->acked_touch_event().event.type());
+ EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
+}
+
// Tests that the touch-queue is emptied after a page stops listening for touch
// events and the outstanding ack is received.
TEST_F(InputRouterImplTest, TouchEventQueueFlush) {
@@ -1038,7 +1095,10 @@ TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) {
WebInputEvent::Type type = eventTypes[i];
if (WebInputEventTraits::ShouldBlockEventStream(GetEventWithType(type))) {
SimulateGestureEvent(type, blink::WebGestureDeviceTouchscreen);
- EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
+ if (type == WebInputEvent::GestureScrollUpdate)
+ EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
+ else
+ EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1, client_->in_flight_event_count());
EXPECT_TRUE(HasPendingEvents());
@@ -1124,7 +1184,7 @@ TEST_F(InputRouterImplTest, GestureTypesIgnoringAckInterleaved) {
SimulateGestureEvent(WebInputEvent::GestureScrollUpdate,
blink::WebGestureDeviceTouchscreen);
- ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
+ ASSERT_EQ(2U, GetSentMessageCountAndResetSink());
EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
EXPECT_EQ(1, client_->in_flight_event_count());
@@ -1376,7 +1436,7 @@ TEST_F(InputRouterImplTest, TouchActionResetBeforeEventReachesRenderer) {
// Ensure touch action is still none, as the next touch start hasn't been
// acked yet. ScrollBegin and ScrollEnd don't require acks.
- EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
+ EXPECT_EQ(6U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
@@ -1394,7 +1454,7 @@ TEST_F(InputRouterImplTest, TouchActionResetBeforeEventReachesRenderer) {
touch_press_event_id2);
SendTouchEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED,
touch_move_event_id2);
- EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
+ EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
@@ -1434,7 +1494,7 @@ TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHasNoConsumer) {
// Ensure we have touch-action:none. ScrollBegin and ScrollEnd don't require
// acks.
- EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
+ EXPECT_EQ(6U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
@@ -1449,7 +1509,7 @@ TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHasNoConsumer) {
touch_press_event_id2);
// Ensure touch action has been set to auto, as the touch had no consumer.
- EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
+ EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
@@ -1470,15 +1530,15 @@ TEST_F(InputRouterImplTest, TouchActionResetWhenTouchHandlerRemoved) {
OnSetTouchAction(TOUCH_ACTION_NONE);
ReleaseTouchPoint(0);
uint32_t touch_release_event_id = SendTouchEvent();
- EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
+ EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
// Ensure we have touch-action:none, suppressing scroll events.
SendTouchEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED,
touch_press_event_id);
- EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
+ EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SendTouchEventACK(WebInputEvent::TouchMove,
INPUT_EVENT_ACK_STATE_NOT_CONSUMED, touch_move_event_id);
- EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
+ EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
@@ -1523,7 +1583,7 @@ TEST_F(InputRouterImplTest, DoubleTapGestureDependsOnFirstTap) {
uint32_t touch_press_event_id2 = SendTouchEvent();
// First tap.
- EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
+ EXPECT_EQ(3U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureTapDown,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
@@ -1536,10 +1596,10 @@ TEST_F(InputRouterImplTest, DoubleTapGestureDependsOnFirstTap) {
// This test will become invalid if GestureTap stops requiring an ack.
ASSERT_TRUE(WebInputEventTraits::ShouldBlockEventStream(
GetEventWithType(WebInputEvent::GestureTap)));
- EXPECT_EQ(2, client_->in_flight_event_count());
+ EXPECT_EQ(3, client_->in_flight_event_count());
SendInputEventACK(WebInputEvent::GestureTap,
INPUT_EVENT_ACK_STATE_CONSUMED);
- EXPECT_EQ(1, client_->in_flight_event_count());
+ EXPECT_EQ(2, client_->in_flight_event_count());
// This tap gesture is dropped, since the GestureTapUnconfirmed was turned
// into a tap.
@@ -1554,7 +1614,7 @@ TEST_F(InputRouterImplTest, DoubleTapGestureDependsOnFirstTap) {
touch_press_event_id2);
// Second Tap.
- EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
+ EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
SimulateGestureEvent(WebInputEvent::GestureTapDown,
blink::WebGestureDeviceTouchscreen);
EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
« no previous file with comments | « no previous file | content/browser/renderer_host/render_widget_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698