TEST_F(EventHandlerTest, multiClickSelectionFromTap) { setHtmlInnerHTML("<style> body { margin: 0px; } .line { display: block; width: 300px; height: 30px; } </style>" "<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()); // 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()); if (document().frame()->editor().isSelectTrailingWhitespaceEnabled()) { 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()); } 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()); }
TEST_F(EventHandlerTest, multiClickSelectionFromTapDisabledIfNotEditable) { setHtmlInnerHTML( "<style> body { margin: 0px; } .line { display: block; width: 300px; " "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()); // 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()); TapEventBuilder tripleTapEvent(IntPoint(0, 0), 3); document().frame()->eventHandler().handleGestureEvent(tripleTapEvent); ASSERT_TRUE(selection.isCaret()); EXPECT_EQ(Position(line, 0), selection.start()); }