This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "content/browser/renderer_host/input/touch_action_filter.h"
#include "content/common/input/synthetic_web_input_event_builders.h"
#include "content/port/browser/event_with_latency_info.h"
#include "content/port/common/input_event_ack_state.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
using blink::WebGestureEvent;
using blink::WebInputEvent;
namespace content {
TEST(TouchActionFilterTest, SimpleFilter) {
TouchActionFilter filter;
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(2, 3);
const float kDeltaX = 5;
const float kDeltaY = 10;
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDeltaX, kDeltaY, 0);
WebGestureEvent scroll_end = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureScrollEnd, WebGestureEvent::Touchscreen);
WebGestureEvent tap = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTap, WebGestureEvent::Touchscreen);
filter.ResetTouchAction();
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDeltaX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDeltaY, scroll_update.data.scrollUpdate.deltaY);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
EXPECT_FALSE(filter.FilterGestureEvent(&tap));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDeltaX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDeltaY, scroll_update.data.scrollUpdate.deltaY);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_FALSE(filter.FilterGestureEvent(&tap));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDeltaX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDeltaY, scroll_update.data.scrollUpdate.deltaY);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDeltaX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDeltaY, scroll_update.data.scrollUpdate.deltaY);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, Fling) {
TouchActionFilter filter;
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(2, 3);
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(5, 10, 0);
const float kFlingX = 7;
const float kFlingY = -4;
WebGestureEvent fling_start = SyntheticWebGestureEventBuilder::BuildFling(
kFlingX, kFlingY, WebGestureEvent::Touchscreen);
WebGestureEvent pad_fling = SyntheticWebGestureEventBuilder::BuildFling(
kFlingX, kFlingY, WebGestureEvent::Touchpad);
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_TRUE(filter.FilterGestureEvent(&fling_start));
EXPECT_EQ(kFlingX, fling_start.data.flingStart.velocityX);
EXPECT_EQ(kFlingY, fling_start.data.flingStart.velocityY);
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_FALSE(filter.FilterGestureEvent(&pad_fling));
EXPECT_TRUE(filter.FilterGestureEvent(&fling_start));
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, PanX) {
TouchActionFilter filter;
const float kDX = 5;
const float kDY = 10;
const float kFlingX = 7;
const float kFlingY = -4;
WebGestureEvent scroll_end = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureScrollEnd, WebGestureEvent::Touchscreen);
{
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_X);
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(0, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDX, kDY, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(0, scroll_update.data.scrollUpdate.deltaY);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
}
{
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_X);
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(-7, 6);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDX, kDY, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(0, scroll_update.data.scrollUpdate.deltaY);
WebGestureEvent scroll_update2 =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(-4, -2, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update2));
EXPECT_EQ(-4, scroll_update2.data.scrollUpdate.deltaX);
EXPECT_EQ(0, scroll_update2.data.scrollUpdate.deltaY);
WebGestureEvent fling_start = SyntheticWebGestureEventBuilder::BuildFling(
kFlingX, kFlingY, WebGestureEvent::Touchscreen);
EXPECT_FALSE(filter.FilterGestureEvent(&fling_start));
EXPECT_EQ(kFlingX, fling_start.data.flingStart.velocityX);
EXPECT_EQ(0, fling_start.data.flingStart.velocityY);
}
{
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_X);
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(-7, 8);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDX, kDY, 0);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDY, scroll_update.data.scrollUpdate.deltaY);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_end));
}
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, PanY) {
TouchActionFilter filter;
const float kDX = 5;
const float kDY = 10;
const float kFlingX = 7;
const float kFlingY = -4;
WebGestureEvent scroll_end = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureScrollEnd, WebGestureEvent::Touchscreen);
{
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_Y);
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(0, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDX, kDY, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(0, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDY, scroll_update.data.scrollUpdate.deltaY);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
}
{
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_Y);
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(-6, 7);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDX, kDY, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(0, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDY, scroll_update.data.scrollUpdate.deltaY);
WebGestureEvent scroll_update2 =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(-4, -2, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update2));
EXPECT_EQ(0, scroll_update2.data.scrollUpdate.deltaX);
EXPECT_EQ(-2, scroll_update2.data.scrollUpdate.deltaY);
WebGestureEvent fling_start = SyntheticWebGestureEventBuilder::BuildFling(
kFlingX, kFlingY, WebGestureEvent::Touchscreen);
EXPECT_FALSE(filter.FilterGestureEvent(&fling_start));
EXPECT_EQ(0, fling_start.data.flingStart.velocityX);
EXPECT_EQ(kFlingY, fling_start.data.flingStart.velocityY);
}
{
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_Y);
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(-8, 7);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDX, kDY, 0);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDY, scroll_update.data.scrollUpdate.deltaY);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_end));
}
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, PanXY) {
TouchActionFilter filter;
const float kDX = 5;
const float kDY = 10;
const float kFlingX = 7;
const float kFlingY = -4;
{
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_X_Y);
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(-7, 6);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDX, kDY, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDY, scroll_update.data.scrollUpdate.deltaY);
WebGestureEvent fling_start = SyntheticWebGestureEventBuilder::BuildFling(
kFlingX, kFlingY, WebGestureEvent::Touchscreen);
EXPECT_FALSE(filter.FilterGestureEvent(&fling_start));
EXPECT_EQ(kFlingX, fling_start.data.flingStart.velocityX);
EXPECT_EQ(kFlingY, fling_start.data.flingStart.velocityY);
}
{
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_X_Y);
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(-6, 7);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDX, kDY, 0);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDY, scroll_update.data.scrollUpdate.deltaY);
WebGestureEvent fling_start = SyntheticWebGestureEventBuilder::BuildFling(
kFlingX, kFlingY, WebGestureEvent::Touchscreen);
EXPECT_FALSE(filter.FilterGestureEvent(&fling_start));
EXPECT_EQ(kFlingX, fling_start.data.flingStart.velocityX);
EXPECT_EQ(kFlingY, fling_start.data.flingStart.velocityY);
}
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, Intersect) {
EXPECT_EQ(TOUCH_ACTION_NONE,
TouchActionFilter::Intersect(TOUCH_ACTION_NONE, TOUCH_ACTION_AUTO));
EXPECT_EQ(TOUCH_ACTION_NONE,
TouchActionFilter::Intersect(TOUCH_ACTION_AUTO, TOUCH_ACTION_NONE));
EXPECT_EQ(TOUCH_ACTION_PAN_X,
TouchActionFilter::Intersect(TOUCH_ACTION_AUTO, TOUCH_ACTION_PAN_X));
EXPECT_EQ(TOUCH_ACTION_PAN_Y,
TouchActionFilter::Intersect(TOUCH_ACTION_PAN_Y, TOUCH_ACTION_AUTO));
EXPECT_EQ(TOUCH_ACTION_AUTO,
TouchActionFilter::Intersect(TOUCH_ACTION_AUTO, TOUCH_ACTION_AUTO));
EXPECT_EQ(TOUCH_ACTION_PAN_X,
TouchActionFilter::Intersect(TOUCH_ACTION_PAN_X_Y, TOUCH_ACTION_PAN_X));
EXPECT_EQ(TOUCH_ACTION_PAN_Y,
TouchActionFilter::Intersect(TOUCH_ACTION_PAN_Y, TOUCH_ACTION_PAN_X_Y));
EXPECT_EQ(TOUCH_ACTION_PAN_X_Y,
TouchActionFilter::Intersect(TOUCH_ACTION_PAN_X_Y, TOUCH_ACTION_AUTO));
EXPECT_EQ(TOUCH_ACTION_NONE,
TouchActionFilter::Intersect(TOUCH_ACTION_PAN_X, TOUCH_ACTION_PAN_Y));
}
TEST(TouchActionFilterTest, MultiTouch) {
TouchActionFilter filter;
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(2, 3);
const float kDeltaX = 5;
const float kDeltaY = 10;
WebGestureEvent scroll_update =
SyntheticWebGestureEventBuilder::BuildScrollUpdate(kDeltaX, kDeltaY, 0);
WebGestureEvent scroll_end = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureScrollEnd, WebGestureEvent::Touchscreen);
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_EQ(kDeltaX, scroll_update.data.scrollUpdate.deltaX);
EXPECT_EQ(kDeltaY, scroll_update.data.scrollUpdate.deltaY);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_X);
filter.OnSetTouchAction(TOUCH_ACTION_PAN_Y);
filter.OnSetTouchAction(TOUCH_ACTION_PAN_X_Y);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_update));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, Pinch) {
TouchActionFilter filter;
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(2, 3);
WebGestureEvent pinch_begin = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GesturePinchBegin, WebGestureEvent::Touchscreen);
WebGestureEvent pinch_update =
SyntheticWebGestureEventBuilder::BuildPinchUpdate(1.2f, 5, 5, 0);
WebGestureEvent pinch_end = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GesturePinchEnd, WebGestureEvent::Touchscreen);
WebGestureEvent scroll_end = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureScrollEnd, WebGestureEvent::Touchscreen);
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_update));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_end));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_PAN_X_Y);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_update));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_end));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_MANIPULATION);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_update));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_end));
filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_update));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_end));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_begin));
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_update));
EXPECT_FALSE(filter.FilterGestureEvent(&pinch_end));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_update));
EXPECT_TRUE(filter.FilterGestureEvent(&pinch_end));
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, DoubleTapWithTouchActionAuto) {
TouchActionFilter filter;
WebGestureEvent tap_down = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapDown, WebGestureEvent::Touchscreen);
WebGestureEvent unconfirmed_tap = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapUnconfirmed, WebGestureEvent::Touchscreen);
WebGestureEvent tap_cancel = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapCancel, WebGestureEvent::Touchscreen);
WebGestureEvent double_tap = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureDoubleTap, WebGestureEvent::Touchscreen);
filter.ResetTouchAction();
EXPECT_FALSE(filter.FilterGestureEvent(&tap_down));
EXPECT_FALSE(filter.FilterGestureEvent(&unconfirmed_tap));
EXPECT_EQ(unconfirmed_tap.type, WebInputEvent::GestureTapUnconfirmed);
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_FALSE(filter.FilterGestureEvent(&tap_cancel));
EXPECT_FALSE(filter.FilterGestureEvent(&tap_down));
EXPECT_FALSE(filter.FilterGestureEvent(&double_tap));
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, DoubleTap) {
TouchActionFilter filter;
WebGestureEvent tap_down = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapDown, WebGestureEvent::Touchscreen);
WebGestureEvent unconfirmed_tap = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapUnconfirmed, WebGestureEvent::Touchscreen);
WebGestureEvent tap_cancel = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapCancel, WebGestureEvent::Touchscreen);
WebGestureEvent double_tap = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureDoubleTap, WebGestureEvent::Touchscreen);
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_MANIPULATION);
EXPECT_FALSE(filter.FilterGestureEvent(&tap_down));
EXPECT_FALSE(filter.FilterGestureEvent(&unconfirmed_tap));
EXPECT_EQ(WebInputEvent::GestureTap, unconfirmed_tap.type);
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_AUTO);
EXPECT_TRUE(filter.FilterGestureEvent(&tap_cancel));
EXPECT_FALSE(filter.FilterGestureEvent(&tap_down));
EXPECT_FALSE(filter.FilterGestureEvent(&double_tap));
EXPECT_EQ(WebInputEvent::GestureTap, double_tap.type);
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, SingleTapWithTouchActionAuto) {
TouchActionFilter filter;
WebGestureEvent tap_down = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapDown, WebGestureEvent::Touchscreen);
WebGestureEvent unconfirmed_tap1 = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapUnconfirmed, WebGestureEvent::Touchscreen);
WebGestureEvent tap = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTap, WebGestureEvent::Touchscreen);
filter.ResetTouchAction();
EXPECT_FALSE(filter.FilterGestureEvent(&tap_down));
EXPECT_FALSE(filter.FilterGestureEvent(&unconfirmed_tap1));
EXPECT_EQ(WebInputEvent::GestureTapUnconfirmed, unconfirmed_tap1.type);
EXPECT_FALSE(filter.FilterGestureEvent(&tap));
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, SingleTap) {
TouchActionFilter filter;
WebGestureEvent tap_down = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapDown, WebGestureEvent::Touchscreen);
WebGestureEvent unconfirmed_tap1 = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTapUnconfirmed, WebGestureEvent::Touchscreen);
WebGestureEvent tap = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTap, WebGestureEvent::Touchscreen);
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_FALSE(filter.FilterGestureEvent(&tap_down));
EXPECT_FALSE(filter.FilterGestureEvent(&unconfirmed_tap1));
EXPECT_EQ(WebInputEvent::GestureTap, unconfirmed_tap1.type);
EXPECT_TRUE(filter.FilterGestureEvent(&tap));
filter.ResetTouchAction();
}
TEST(TouchActionFilterTest, TouchActionResetsOnResetTouchAction) {
TouchActionFilter filter;
WebGestureEvent tap = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureTap, WebGestureEvent::Touchscreen);
WebGestureEvent scroll_begin =
SyntheticWebGestureEventBuilder::BuildScrollBegin(2, 3);
WebGestureEvent scroll_end = SyntheticWebGestureEventBuilder::Build(
WebInputEvent::GestureScrollEnd, WebGestureEvent::Touchscreen);
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_begin));
EXPECT_TRUE(filter.FilterGestureEvent(&scroll_end));
filter.ResetTouchAction();
filter.OnSetTouchAction(TOUCH_ACTION_NONE);
EXPECT_FALSE(filter.FilterGestureEvent(&tap));
filter.ResetTouchAction();
EXPECT_FALSE(filter.FilterGestureEvent(&scroll_begin));
}
}