| Index: third_party/WebKit/Source/core/input/EventHandlerTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
|
| index d1ec45a7f6382c6a7bfd52d9896a6379d6c7fed6..f243e9e248f911c6607266c422c4bd5da6c15e04 100644
|
| --- a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
|
| +++ b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
|
| @@ -47,6 +47,32 @@ class TapEventBuilder : public PlatformGestureEvent {
|
| }
|
| };
|
|
|
| +class LongPressEventBuilder : public PlatformGestureEvent {
|
| + public:
|
| + LongPressEventBuilder(IntPoint position)
|
| + : PlatformGestureEvent(PlatformEvent::GestureLongPress,
|
| + position,
|
| + position,
|
| + IntSize(5, 5),
|
| + WTF::monotonicallyIncreasingTime(),
|
| + static_cast<PlatformEvent::Modifiers>(0),
|
| + PlatformGestureSourceTouchscreen) {}
|
| +};
|
| +
|
| +class MousePressEventBuilder : public PlatformMouseEvent {
|
| + public:
|
| + MousePressEventBuilder(IntPoint position,
|
| + int clickCount,
|
| + WebMouseEvent::Button button)
|
| + : PlatformMouseEvent(position,
|
| + position,
|
| + button,
|
| + PlatformEvent::MousePressed,
|
| + clickCount,
|
| + static_cast<PlatformEvent::Modifiers>(0),
|
| + WTF::monotonicallyIncreasingTime()) {}
|
| +};
|
| +
|
| void EventHandlerTest::SetUp() {
|
| m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400));
|
| }
|
| @@ -255,4 +281,116 @@ TEST_F(EventHandlerTest, sendContextMenuEventWithHover) {
|
| document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent));
|
| }
|
|
|
| +TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnTap) {
|
| + setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>");
|
| +
|
| + FrameSelection& selection = document().frame()->selection();
|
| +
|
| + TapEventBuilder singleTapEvent(IntPoint(200, 200), 1);
|
| + document().frame()->eventHandler().handleGestureEvent(singleTapEvent);
|
| +
|
| + ASSERT_TRUE(selection.isCaret());
|
| + ASSERT_FALSE(selection.isHandleVisible());
|
| +}
|
| +
|
| +TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnTap) {
|
| + setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>");
|
| +
|
| + FrameSelection& selection = document().frame()->selection();
|
| +
|
| + TapEventBuilder singleTapEvent(IntPoint(200, 200), 1);
|
| + document().frame()->eventHandler().handleGestureEvent(singleTapEvent);
|
| +
|
| + ASSERT_TRUE(selection.isCaret());
|
| + ASSERT_TRUE(selection.isHandleVisible());
|
| +}
|
| +
|
| +TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnLongPress) {
|
| + setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>");
|
| +
|
| + FrameSelection& selection = document().frame()->selection();
|
| +
|
| + LongPressEventBuilder longPressEvent(IntPoint(200, 200));
|
| + document().frame()->eventHandler().handleGestureEvent(longPressEvent);
|
| +
|
| + ASSERT_TRUE(selection.isCaret());
|
| + ASSERT_TRUE(selection.isHandleVisible());
|
| +
|
| + // Single Tap on an empty edit field should clear insertion handle
|
| + TapEventBuilder singleTapEvent(IntPoint(200, 200), 1);
|
| + document().frame()->eventHandler().handleGestureEvent(singleTapEvent);
|
| +
|
| + ASSERT_TRUE(selection.isCaret());
|
| + ASSERT_FALSE(selection.isHandleVisible());
|
| +}
|
| +
|
| +TEST_F(EventHandlerTest, NonEmptyTextfieldInsertionOnLongPress) {
|
| + setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>");
|
| +
|
| + FrameSelection& selection = document().frame()->selection();
|
| +
|
| + LongPressEventBuilder longPressEvent(IntPoint(200, 200));
|
| + document().frame()->eventHandler().handleGestureEvent(longPressEvent);
|
| +
|
| + ASSERT_TRUE(selection.selection().isCaret());
|
| + ASSERT_TRUE(selection.isHandleVisible());
|
| +}
|
| +
|
| +TEST_F(EventHandlerTest, ClearHandleAfterTap) {
|
| + setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>");
|
| +
|
| + FrameSelection& selection = document().frame()->selection();
|
| +
|
| + // Show handle
|
| + LongPressEventBuilder longPressEvent(IntPoint(200, 200));
|
| + document().frame()->eventHandler().handleGestureEvent(longPressEvent);
|
| +
|
| + ASSERT_TRUE(selection.selection().isCaret());
|
| + ASSERT_TRUE(selection.isHandleVisible());
|
| +
|
| + // Tap away from text area should clear handle
|
| + TapEventBuilder singleTapEvent(IntPoint(700, 700), 1);
|
| + document().frame()->eventHandler().handleGestureEvent(singleTapEvent);
|
| +
|
| + ASSERT_TRUE(selection.isNone());
|
| + ASSERT_FALSE(selection.isHandleVisible());
|
| +}
|
| +
|
| +TEST_F(EventHandlerTest, HandleNotShownOnMouseEvents) {
|
| + setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>");
|
| +
|
| + FrameSelection& selection = document().frame()->selection();
|
| +
|
| + MousePressEventBuilder leftMousePressEvent(
|
| + IntPoint(200, 200), 1, WebPointerProperties::Button::Left);
|
| + document().frame()->eventHandler().handleMousePressEvent(leftMousePressEvent);
|
| +
|
| + ASSERT_TRUE(selection.isCaret());
|
| + ASSERT_FALSE(selection.isHandleVisible());
|
| +
|
| + MousePressEventBuilder rightMousePressEvent(
|
| + IntPoint(200, 200), 1, WebPointerProperties::Button::Right);
|
| + document().frame()->eventHandler().handleMousePressEvent(
|
| + rightMousePressEvent);
|
| +
|
| + ASSERT_TRUE(selection.isCaret());
|
| + ASSERT_FALSE(selection.isHandleVisible());
|
| +
|
| + MousePressEventBuilder doubleClickMousePressEvent(
|
| + IntPoint(200, 200), 2, WebPointerProperties::Button::Left);
|
| + document().frame()->eventHandler().handleMousePressEvent(
|
| + doubleClickMousePressEvent);
|
| +
|
| + ASSERT_TRUE(selection.isRange());
|
| + ASSERT_FALSE(selection.isHandleVisible());
|
| +
|
| + MousePressEventBuilder tripleClickMousePressEvent(
|
| + IntPoint(200, 200), 3, WebPointerProperties::Button::Left);
|
| + document().frame()->eventHandler().handleMousePressEvent(
|
| + tripleClickMousePressEvent);
|
| +
|
| + ASSERT_TRUE(selection.isRange());
|
| + ASSERT_FALSE(selection.isHandleVisible());
|
| +}
|
| +
|
| } // namespace blink
|
|
|