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

Unified Diff: third_party/WebKit/Source/core/editing/iterators/TextIteratorTest.cpp

Issue 2883163002: Un-insanify first-letter handling in TextIterator (to some degree) (Closed)
Patch Set: Tue May 16 16:31:00 PDT 2017 Created 3 years, 7 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/iterators/TextIteratorTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/iterators/TextIteratorTest.cpp b/third_party/WebKit/Source/core/editing/iterators/TextIteratorTest.cpp
index 06fb00eace6155c7c367d0c63ab47652b175c63a..182fd399c9619398867e86015bf78d83a52851ad 100644
--- a/third_party/WebKit/Source/core/editing/iterators/TextIteratorTest.cpp
+++ b/third_party/WebKit/Source/core/editing/iterators/TextIteratorTest.cpp
@@ -777,6 +777,30 @@ TEST_F(TextIteratorTest, StartInMultiCharFirstLetterWithCollapsedSpace) {
EXPECT_EQ("A) xyz", String(buffer.Data()));
}
+TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterWithCollapsedSpace) {
+ SetBodyContent(
+ "<style>div:first-letter {color:red;}</style><div> (A) xyz</div>");
+
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+ Position start(text, 3);
+ Position end(text, 4);
+ TextIterator iter(start, end);
+ ForwardsTextBuffer buffer;
+
+ EXPECT_FALSE(iter.AtEnd());
+ EXPECT_EQ(1, iter.length());
+ EXPECT_EQ(1, iter.CopyTextTo(&buffer, 0)) << "Should emit 'A'.";
+ EXPECT_EQ(text, iter.CurrentContainer());
+ EXPECT_EQ(Position(text, 3), iter.StartPositionInCurrentContainer());
+ EXPECT_EQ(Position(text, 4), iter.EndPositionInCurrentContainer());
+
+ iter.Advance();
+ EXPECT_TRUE(iter.AtEnd());
+
+ EXPECT_EQ("A", String(buffer.Data()));
+}
+
TEST_F(TextIteratorTest, StartAtRemainingText) {
SetBodyContent("<style>div:first-letter {color:red;}</style><div>Axyz</div>");
@@ -800,4 +824,114 @@ TEST_F(TextIteratorTest, StartAtRemainingText) {
EXPECT_EQ("xyz", String(buffer.Data()));
}
+TEST_F(TextIteratorTest, StartAtFirstLetterInPre) {
+ SetBodyContent("<style>pre:first-letter {color:red;}</style><pre>Axyz</pre>");
+
+ Element* pre = GetDocument().QuerySelector("pre");
+ Node* text = pre->firstChild();
+ Position start(text, 0);
+ Position end(text, 4);
+ TextIterator iter(start, end);
+ ForwardsTextBuffer buffer;
+
+ EXPECT_FALSE(iter.AtEnd());
+ EXPECT_EQ(1, iter.length());
+ EXPECT_EQ(1, iter.CopyTextTo(&buffer, 0)) << "Should emit 'A'.";
+ EXPECT_EQ(text, iter.CurrentContainer());
+ EXPECT_EQ(Position(text, 0), iter.StartPositionInCurrentContainer());
+ EXPECT_EQ(Position(text, 1), iter.EndPositionInCurrentContainer());
+
+ iter.Advance();
+ EXPECT_FALSE(iter.AtEnd());
+ EXPECT_EQ(3, iter.length());
+ EXPECT_EQ(3, iter.CopyTextTo(&buffer, 0)) << "Should emit 'xyz'.";
+ EXPECT_EQ(text, iter.CurrentContainer());
+ EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer());
+ EXPECT_EQ(Position(text, 4), iter.EndPositionInCurrentContainer());
+
+ iter.Advance();
+ EXPECT_TRUE(iter.AtEnd());
+
+ EXPECT_EQ("Axyz", String(buffer.Data()));
+}
+
+TEST_F(TextIteratorTest, StartInMultiCharFirstLetterInPre) {
+ SetBodyContent(
+ "<style>pre:first-letter {color:red;}</style><pre>(A)xyz</pre>");
+
+ Element* pre = GetDocument().QuerySelector("pre");
+ Node* text = pre->firstChild();
+ Position start(text, 1);
+ Position end(text, 6);
+ TextIterator iter(start, end);
+ ForwardsTextBuffer buffer;
+
+ EXPECT_FALSE(iter.AtEnd());
+ EXPECT_EQ(2, iter.length());
+ EXPECT_EQ(2, iter.CopyTextTo(&buffer, 0)) << "Should emit 'A)'.";
+ EXPECT_EQ(text, iter.CurrentContainer());
+ EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer());
+ EXPECT_EQ(Position(text, 3), iter.EndPositionInCurrentContainer());
+
+ iter.Advance();
+ EXPECT_FALSE(iter.AtEnd());
+ EXPECT_EQ(3, iter.length());
+ EXPECT_EQ(3, iter.CopyTextTo(&buffer, 0)) << "Should emit 'xyz'.";
+ EXPECT_EQ(text, iter.CurrentContainer());
+ EXPECT_EQ(Position(text, 3), iter.StartPositionInCurrentContainer());
+ EXPECT_EQ(Position(text, 6), iter.EndPositionInCurrentContainer());
+
+ iter.Advance();
+ EXPECT_TRUE(iter.AtEnd());
+
+ EXPECT_EQ("A)xyz", String(buffer.Data()));
+}
+
+TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterInPre) {
+ SetBodyContent(
+ "<style>pre:first-letter {color:red;}</style><pre>(A)xyz</pre>");
+
+ Element* pre = GetDocument().QuerySelector("pre");
+ Node* text = pre->firstChild();
+ Position start(text, 1);
+ Position end(text, 2);
+ TextIterator iter(start, end);
+ ForwardsTextBuffer buffer;
+
+ EXPECT_FALSE(iter.AtEnd());
+ EXPECT_EQ(1, iter.length());
+ EXPECT_EQ(1, iter.CopyTextTo(&buffer, 0)) << "Should emit 'A'.";
+ EXPECT_EQ(text, iter.CurrentContainer());
+ EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer());
+ EXPECT_EQ(Position(text, 2), iter.EndPositionInCurrentContainer());
+
+ iter.Advance();
+ EXPECT_TRUE(iter.AtEnd());
+
+ EXPECT_EQ("A", String(buffer.Data()));
+}
+
+TEST_F(TextIteratorTest, StartAtRemainingTextInPre) {
+ SetBodyContent("<style>pre:first-letter {color:red;}</style><pre>Axyz</pre>");
+
+ Element* pre = GetDocument().QuerySelector("pre");
+ Node* text = pre->firstChild();
+ Position start(text, 1);
+ Position end(text, 4);
+ TextIterator iter(start, end);
+ ForwardsTextBuffer buffer;
+
+ EXPECT_FALSE(iter.AtEnd());
+ EXPECT_EQ(3, iter.length());
+ EXPECT_EQ(3, iter.CopyTextTo(&buffer, 0)) << "Should emit 'xyz'.";
+ EXPECT_EQ(text, iter.CurrentContainer());
+ EXPECT_EQ(Position(text, 1), iter.StartPositionInCurrentContainer());
+ EXPECT_EQ(Position(text, 4), iter.EndPositionInCurrentContainer());
+
+ iter.Advance();
+ EXPECT_TRUE(iter.AtEnd());
+
+ EXPECT_EQ("xyz", String(buffer.Data()));
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698