Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp b/third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp |
| index 639f888434cb57c6257d7c74c33b1d97adaaab07..9d46a31abd1d5aca647228f9699df8db815be791 100644 |
| --- a/third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp |
| +++ b/third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp |
| @@ -14,6 +14,7 @@ |
| #include "core/html/HTMLDocument.h" |
| #include "core/layout/LayoutView.h" |
| #include "core/paint/PaintInfo.h" |
| +#include "core/paint/PaintLayer.h" |
| #include "core/testing/DummyPageHolder.h" |
| #include "platform/graphics/paint/DrawingRecorder.h" |
| #include "platform/graphics/paint/PaintController.h" |
| @@ -35,6 +36,9 @@ protected: |
| PassRefPtrWillBeRawPtr<Text> appendTextNode(const String& data); |
| int layoutCount() const { return dummyPageHolder().frameView().layoutCount(); } |
| + bool ShouldPaintCaretForTesting() const { return selection().ShouldPaintCaretForTesting(); } |
|
jbroman
2016/02/25 18:29:22
same here
|
| + bool isPreviousCaretDirtyForTesting() const { return selection().isPreviousCaretDirtyForTesting(); } |
| + |
| private: |
| RefPtrWillBePersistent<Text> m_textNode; |
| }; |
| @@ -117,7 +121,7 @@ TEST_F(FrameSelectionTest, PaintCaretShouldNotLayout) |
| selection().setCaretVisible(true); |
| setSelection(validSelection); |
| EXPECT_TRUE(selection().isCaret()); |
| - EXPECT_TRUE(selection().ShouldPaintCaretForTesting()); |
| + EXPECT_TRUE(ShouldPaintCaretForTesting()); |
| int startCount = layoutCount(); |
| { |
| @@ -135,6 +139,54 @@ TEST_F(FrameSelectionTest, PaintCaretShouldNotLayout) |
| EXPECT_EQ(startCount, layoutCount()); |
| } |
| +TEST_F(FrameSelectionTest, InvalidatePreviousCaretAfterRemovingLastCharacter) |
| +{ |
| + RefPtrWillBeRawPtr<Text> text = appendTextNode("Hello, World!"); |
| + document().view()->updateAllLifecyclePhases(); |
| + |
| + document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); |
| + document().body()->focus(); |
| + EXPECT_TRUE(document().body()->focused()); |
| + |
| + selection().setCaretVisible(true); |
| + EXPECT_TRUE(selection().isCaret()); |
| + EXPECT_TRUE(ShouldPaintCaretForTesting()); |
| + |
| + // Simulate to type "Hello, World!". |
| + DisableCompositingQueryAsserts disabler; |
| + selection().moveTo(createVisiblePosition(selection().end(), selection().affinity()), NotUserTriggered); |
| + selection().setCaretRectNeedsUpdate(); |
| + EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| + EXPECT_FALSE(isPreviousCaretDirtyForTesting()); |
| + selection().invalidateCaretRect(); |
| + EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| + EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| + |
| + // Simulate to remove all except for "H". |
| + text->replaceWholeText("H"); |
| + selection().moveTo(createVisiblePosition(selection().end(), selection().affinity()), NotUserTriggered); |
| + selection().setCaretRectNeedsUpdate(); |
| + EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| + // "H" remains so early previousCaret invalidation isn't needed. |
| + EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| + selection().invalidateCaretRect(); |
| + EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| + EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| + |
| + // Simulate to remove the last character. |
| + document().body()->removeChild(text); |
| + // This line is the objective of this test. |
| + // As removing the last character, early previousCaret invalidation is executed. |
| + EXPECT_FALSE(isPreviousCaretDirtyForTesting()); |
| + document().updateLayoutIgnorePendingStylesheets(); |
| + selection().setCaretRectNeedsUpdate(); |
| + EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| + EXPECT_FALSE(isPreviousCaretDirtyForTesting()); |
| + selection().invalidateCaretRect(); |
| + EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| + EXPECT_TRUE(isPreviousCaretDirtyForTesting()); |
| +} |
| + |
| #define EXPECT_EQ_SELECTED_TEXT(text) \ |
| EXPECT_EQ(text, WebString(selection().selectedText()).utf8()) |