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

Unified Diff: third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp

Issue 1654123002: Invalidate the previous caret even if the parent text node is removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add FrameSelectionTest.InvalidatePreviousCaretAfterRemovingLastCharacter Created 4 years, 10 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/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(); }
+ 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())

Powered by Google App Engine
This is Rietveld 408576698