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

Unified Diff: third_party/WebKit/Source/core/input/EventHandlerTest.cpp

Issue 2201853002: Blink handle selection handle visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed ESTABLISHED/DISSOLVED Created 4 years, 1 month 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
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 4aaba62ea4ae67acc294a34ae8992e20a34fc12a..55efd23023e3573a17327d0c4fec50cade1b3d0e 100644
--- a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
+++ b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
@@ -26,6 +26,7 @@ class EventHandlerTest : public ::testing::Test {
Page& page() const { return m_dummyPageHolder->page(); }
Document& document() const { return m_dummyPageHolder->document(); }
+ FrameSelection& selection() const { return document().frame()->selection(); }
void setHtmlInnerHTML(const char* htmlContent);
@@ -47,6 +48,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));
}
@@ -98,10 +125,9 @@ TEST_F(EventHandlerTest, dragSelectionAfterScroll) {
WTF::monotonicallyIncreasingTime());
document().frame()->eventHandler().handleMouseReleaseEvent(mouseUpEvent);
- FrameSelection& selection = document().frame()->selection();
- ASSERT_TRUE(selection.isRange());
+ ASSERT_TRUE(selection().isRange());
Range* range =
- createRange(selection.selection().toNormalizedEphemeralRange());
+ createRange(selection().selection().toNormalizedEphemeralRange());
ASSERT_TRUE(range);
EXPECT_EQ("Line 1\nLine 2", range->text());
}
@@ -113,34 +139,33 @@ TEST_F(EventHandlerTest, multiClickSelectionFromTap) {
"<body contenteditable='true'><span class='line' id='line'>One Two "
"Three</span></body>");
- FrameSelection& selection = document().frame()->selection();
Node* line = document().getElementById("line")->firstChild();
TapEventBuilder singleTapEvent(IntPoint(0, 0), 1);
document().frame()->eventHandler().handleGestureEvent(singleTapEvent);
- ASSERT_TRUE(selection.isCaret());
- EXPECT_EQ(Position(line, 0), selection.start());
+ ASSERT_TRUE(selection().isCaret());
+ EXPECT_EQ(Position(line, 0), selection().start());
// Multi-tap events on editable elements should trigger selection, just
// like multi-click events.
TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2);
document().frame()->eventHandler().handleGestureEvent(doubleTapEvent);
- ASSERT_TRUE(selection.isRange());
- EXPECT_EQ(Position(line, 0), selection.start());
+ ASSERT_TRUE(selection().isRange());
+ EXPECT_EQ(Position(line, 0), selection().start());
if (document().frame()->editor().isSelectTrailingWhitespaceEnabled()) {
- EXPECT_EQ(Position(line, 4), selection.end());
- EXPECT_EQ("One ", WebString(selection.selectedText()).utf8());
+ EXPECT_EQ(Position(line, 4), selection().end());
+ EXPECT_EQ("One ", WebString(selection().selectedText()).utf8());
} else {
- EXPECT_EQ(Position(line, 3), selection.end());
- EXPECT_EQ("One", WebString(selection.selectedText()).utf8());
+ EXPECT_EQ(Position(line, 3), selection().end());
+ EXPECT_EQ("One", WebString(selection().selectedText()).utf8());
}
TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3);
document().frame()->eventHandler().handleGestureEvent(tripleTapEvent);
- ASSERT_TRUE(selection.isRange());
- EXPECT_EQ(Position(line, 0), selection.start());
- EXPECT_EQ(Position(line, 13), selection.end());
- EXPECT_EQ("One Two Three", WebString(selection.selectedText()).utf8());
+ ASSERT_TRUE(selection().isRange());
+ EXPECT_EQ(Position(line, 0), selection().start());
+ EXPECT_EQ(Position(line, 13), selection().end());
+ EXPECT_EQ("One Two Three", WebString(selection().selectedText()).utf8());
}
TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) {
@@ -149,24 +174,23 @@ TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) {
"height: 30px; } </style>"
"<span class='line' id='line'>One Two Three</span>");
- FrameSelection& selection = document().frame()->selection();
Node* line = document().getElementById("line")->firstChild();
TapEventBuilder singleTapEvent(IntPoint(0, 0), 1);
document().frame()->eventHandler().handleGestureEvent(singleTapEvent);
- ASSERT_TRUE(selection.isCaret());
- EXPECT_EQ(Position(line, 0), selection.start());
+ ASSERT_TRUE(selection().isCaret());
+ EXPECT_EQ(Position(line, 0), selection().start());
// As the text is readonly, multi-tap events should not trigger selection.
TapEventBuilder doubleTapEvent(IntPoint(0, 0), 2);
document().frame()->eventHandler().handleGestureEvent(doubleTapEvent);
- ASSERT_TRUE(selection.isCaret());
- EXPECT_EQ(Position(line, 0), selection.start());
+ ASSERT_TRUE(selection().isCaret());
+ EXPECT_EQ(Position(line, 0), selection().start());
TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3);
document().frame()->eventHandler().handleGestureEvent(tripleTapEvent);
- ASSERT_TRUE(selection.isCaret());
- EXPECT_EQ(Position(line, 0), selection.start());
+ ASSERT_TRUE(selection().isCaret());
+ EXPECT_EQ(Position(line, 0), selection().start());
}
TEST_F(EventHandlerTest, draggedInlinePositionTest) {
@@ -257,4 +281,104 @@ TEST_F(EventHandlerTest, sendContextMenuEventWithHover) {
document().frame()->eventHandler().sendContextMenuEvent(mouseDownEvent));
}
+TEST_F(EventHandlerTest, EmptyTextfieldInsertionOnTap) {
+ setHtmlInnerHTML("<textarea cols=50 rows=50></textarea>");
+
+ 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>");
+
+ 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>");
+
+ 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>");
+
+ LongPressEventBuilder longPressEvent(IntPoint(200, 200));
+ document().frame()->eventHandler().handleGestureEvent(longPressEvent);
+
+ ASSERT_TRUE(selection().isCaret());
+ ASSERT_TRUE(selection().isHandleVisible());
+}
+
+TEST_F(EventHandlerTest, ClearHandleAfterTap) {
+ setHtmlInnerHTML("<textarea cols=50 rows=50>Enter text</textarea>");
+
+ // Show handle
+ LongPressEventBuilder longPressEvent(IntPoint(200, 200));
+ document().frame()->eventHandler().handleGestureEvent(longPressEvent);
+
+ ASSERT_TRUE(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>");
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698