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 580cc0d7a8eb85494373a402451e6f03e49d2d73..79596c9c29137bd02d708fa86d78be8cf991b1f0 100644 |
--- a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp |
+++ b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp |
@@ -47,6 +47,18 @@ 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) {} |
+}; |
+ |
void EventHandlerTest::SetUp() { |
m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400)); |
} |
@@ -254,4 +266,79 @@ 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.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.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.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.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.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.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.selection().isHandleVisible()); |
+} |
+ |
} // namespace blink |