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

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

Issue 2664253002: Revert "Blink handle selection handle visibility" (Closed)
Patch Set: Created 3 years, 11 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
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 8ff61f1149f03e95299c9ce6c4fa3678b2eb5ee1..c6235cbfaae7c94080beb1f6e280891b744526e1 100644
--- a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
+++ b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
@@ -26,7 +26,6 @@ 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);
@@ -50,33 +49,6 @@ class TapEventBuilder : public WebGestureEvent {
}
};
-class LongPressEventBuilder : public WebGestureEvent {
- public:
- LongPressEventBuilder(IntPoint position) : WebGestureEvent() {
- m_type = WebInputEvent::GestureLongPress;
- x = globalX = position.x();
- y = globalY = position.y();
- sourceDevice = WebGestureDeviceTouchscreen;
- data.longPress.width = 5;
- data.longPress.height = 5;
- m_frameScale = 1;
- }
-};
-
-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),
- TimeTicks::Now()) {}
-};
-
void EventHandlerTest::SetUp() {
m_dummyPageHolder = DummyPageHolder::create(IntSize(300, 400));
}
@@ -128,9 +100,10 @@ TEST_F(EventHandlerTest, dragSelectionAfterScroll) {
TimeTicks::Now());
document().frame()->eventHandler().handleMouseReleaseEvent(mouseUpEvent);
- ASSERT_TRUE(selection().isRange());
+ FrameSelection& selection = document().frame()->selection();
+ 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());
}
@@ -142,33 +115,34 @@ 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) {
@@ -177,23 +151,24 @@ 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) {
@@ -282,138 +257,4 @@ 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());
-}
-
-TEST_F(EventHandlerTest, dragEndInNewDrag) {
- setHtmlInnerHTML(
- "<style>.box { width: 100px; height: 100px; display: block; }</style>"
- "<a class='box' href=''>Drag me</a>");
-
- PlatformMouseEvent mouseDownEvent(
- IntPoint(50, 50), IntPoint(50, 50), WebPointerProperties::Button::Left,
- PlatformEvent::MousePressed, 1, PlatformEvent::Modifiers::LeftButtonDown,
- TimeTicks::Now());
- document().frame()->eventHandler().handleMousePressEvent(mouseDownEvent);
-
- PlatformMouseEvent mouseMoveEvent(
- IntPoint(51, 50), IntPoint(51, 50), WebPointerProperties::Button::Left,
- PlatformEvent::MouseMoved, 1, PlatformEvent::Modifiers::LeftButtonDown,
- TimeTicks::Now());
- document().frame()->eventHandler().handleMouseMoveEvent(
- mouseMoveEvent, Vector<PlatformMouseEvent>());
-
- // This reproduces what might be the conditions of http://crbug.com/677916
- //
- // TODO(crbug.com/682047): The call sequence below should not occur outside
- // this contrived test. Given the current code, it is unclear how the
- // dragSourceEndedAt() call could occur before a drag operation is started.
-
- PlatformMouseEvent mouseUpEvent(
- IntPoint(100, 50), IntPoint(200, 250), WebPointerProperties::Button::Left,
- PlatformEvent::MouseReleased, 1, static_cast<PlatformEvent::Modifiers>(0),
- TimeTicks::Now());
- document().frame()->eventHandler().dragSourceEndedAt(mouseUpEvent,
- DragOperationNone);
-
- // This test passes if it doesn't crash.
-}
-
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.cpp ('k') | third_party/WebKit/Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698