Commit 0eb00ed9 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Add test cases for TextIterator::RangeLength()

This patch introduces test cases for |TextIterator::RangeLength()| to record
current behavior as a preparation of fixing ::first-letter bug[1].


[1] http://crbug.com/810623 TextIterator::RangeLength() returns wrong value for
::first-letter

Bug: 810623
Change-Id: I59b80f4f0a2b260bbcb7a02915ead354f796d3fb
Reviewed-on: https://chromium-review.googlesource.com/908271Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536683}
parent 24c4e649
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/editing/EphemeralRange.h" #include "core/editing/EphemeralRange.h"
#include "core/editing/SelectionTemplate.h"
#include "core/editing/testing/EditingTestBase.h" #include "core/editing/testing/EditingTestBase.h"
#include "core/frame/LocalFrameView.h" #include "core/frame/LocalFrameView.h"
#include "core/html/forms/TextControlElement.h" #include "core/html/forms/TextControlElement.h"
...@@ -141,6 +142,14 @@ class ParameterizedTextIteratorTest ...@@ -141,6 +142,14 @@ class ParameterizedTextIteratorTest
public TextIteratorTest { public TextIteratorTest {
public: public:
ParameterizedTextIteratorTest() : ScopedLayoutNGForTest(GetParam()) {} ParameterizedTextIteratorTest() : ScopedLayoutNGForTest(GetParam()) {}
protected:
bool LayoutNGEnabled() const { return GetParam(); }
int TestRangeLength(const std::string& selection_text) {
return TextIterator::RangeLength(
SetSelectionTextToBody(selection_text).ComputeRange());
}
}; };
INSTANTIATE_TEST_CASE_P(All, ParameterizedTextIteratorTest, ::testing::Bool()); INSTANTIATE_TEST_CASE_P(All, ParameterizedTextIteratorTest, ::testing::Bool());
...@@ -485,6 +494,43 @@ TEST_F(TextIteratorTest, RangeLengthInMultilineSpan) { ...@@ -485,6 +494,43 @@ TEST_F(TextIteratorTest, RangeLengthInMultilineSpan) {
TextIteratorBehavior::NoTrailingSpaceRangeLengthBehavior())); TextIteratorBehavior::NoTrailingSpaceRangeLengthBehavior()));
} }
TEST_P(ParameterizedTextIteratorTest, RangeLengthBasic) {
EXPECT_EQ(0, TestRangeLength("<p>^| (1) abc def</p>"));
EXPECT_EQ(0, TestRangeLength("<p>^ |(1) abc def</p>"));
EXPECT_EQ(1, TestRangeLength("<p>^ (|1) abc def</p>"));
EXPECT_EQ(2, TestRangeLength("<p>^ (1|) abc def</p>"));
EXPECT_EQ(3, TestRangeLength("<p>^ (1)| abc def</p>"));
EXPECT_EQ(4, TestRangeLength("<p>^ (1) |abc def</p>"));
EXPECT_EQ(5, TestRangeLength("<p>^ (1) a|bc def</p>"));
EXPECT_EQ(6, TestRangeLength("<p>^ (1) ab|c def</p>"));
EXPECT_EQ(7, TestRangeLength("<p>^ (1) abc| def</p>"));
EXPECT_EQ(8, TestRangeLength("<p>^ (1) abc |def</p>"));
EXPECT_EQ(9, TestRangeLength("<p>^ (1) abc d|ef</p>"));
EXPECT_EQ(10, TestRangeLength("<p>^ (1) abc de|f</p>"));
EXPECT_EQ(11, TestRangeLength("<p>^ (1) abc def|</p>"));
}
TEST_P(ParameterizedTextIteratorTest, RangeLengthWithFirstLetter) {
InsertStyleElement("p::first-letter {font-size:200%;}");
// Expectation should be as same as |RangeLengthBasic|
EXPECT_EQ(0, TestRangeLength("<p>^| (1) abc def</p>"));
// TODO(editing-dev): We should fix legacy layout tree version.
// See http://crbug.com/810623
EXPECT_EQ(LayoutNGEnabled() ? 0 : 8,
TestRangeLength("<p>^ |(1) abc def</p>"));
EXPECT_EQ(1, TestRangeLength("<p>^ (|1) abc def</p>"));
EXPECT_EQ(2, TestRangeLength("<p>^ (1|) abc def</p>"));
EXPECT_EQ(3, TestRangeLength("<p>^ (1)| abc def</p>"));
EXPECT_EQ(4, TestRangeLength("<p>^ (1) |abc def</p>"));
EXPECT_EQ(5, TestRangeLength("<p>^ (1) a|bc def</p>"));
EXPECT_EQ(6, TestRangeLength("<p>^ (1) ab|c def</p>"));
EXPECT_EQ(7, TestRangeLength("<p>^ (1) abc| def</p>"));
EXPECT_EQ(8, TestRangeLength("<p>^ (1) abc |def</p>"));
EXPECT_EQ(9, TestRangeLength("<p>^ (1) abc d|ef</p>"));
EXPECT_EQ(10, TestRangeLength("<p>^ (1) abc de|f</p>"));
EXPECT_EQ(11, TestRangeLength("<p>^ (1) abc def|</p>"));
}
TEST_F(TextIteratorTest, WhitespaceCollapseForReplacedElements) { TEST_F(TextIteratorTest, WhitespaceCollapseForReplacedElements) {
static const char* body_content = static const char* body_content =
"<span>Some text </span> <input type='button' value='Button " "<span>Some text </span> <input type='button' value='Button "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment