Commit d9b9bab1 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make TextIteratorTest to run on both legacy and ng layout tree

This patch makes |TextIteratorTest| to run on both legacy and ng layout tree
to catch ng failure earlier for helping layout ng release.

Change-Id: I10e98c10d29082fc7de4afd040cb9d93b370e854
Reviewed-on: https://chromium-review.googlesource.com/c/1343872Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609889}
parent 2a5578c2
...@@ -85,8 +85,14 @@ struct FlatTree : FlatTreeTraversal { ...@@ -85,8 +85,14 @@ struct FlatTree : FlatTreeTraversal {
using TextIteratorType = TextIteratorInFlatTree; using TextIteratorType = TextIteratorInFlatTree;
}; };
class TextIteratorTest : public EditingTestBase { class TextIteratorTest : public testing::WithParamInterface<bool>,
private ScopedLayoutNGForTest,
public EditingTestBase {
protected: protected:
TextIteratorTest() : ScopedLayoutNGForTest(GetParam()) {}
bool LayoutNGEnabled() const { return GetParam(); }
template <typename Tree> template <typename Tree>
std::string Iterate(const TextIteratorBehavior& = TextIteratorBehavior()); std::string Iterate(const TextIteratorBehavior& = TextIteratorBehavior());
...@@ -98,6 +104,11 @@ class TextIteratorTest : public EditingTestBase { ...@@ -98,6 +104,11 @@ class TextIteratorTest : public EditingTestBase {
Range* GetBodyRange() const; Range* GetBodyRange() const;
int TestRangeLength(const std::string& selection_text) {
return TextIterator::RangeLength(
SetSelectionTextToBody(selection_text).ComputeRange());
}
private: private:
template <typename Tree> template <typename Tree>
std::string IterateWithIterator(typename Tree::TextIteratorType&); std::string IterateWithIterator(typename Tree::TextIteratorType&);
...@@ -141,24 +152,9 @@ Range* TextIteratorTest::GetBodyRange() const { ...@@ -141,24 +152,9 @@ Range* TextIteratorTest::GetBodyRange() const {
return range; return range;
} }
class ParameterizedTextIteratorTest : public testing::WithParamInterface<bool>, INSTANTIATE_TEST_CASE_P(All, TextIteratorTest, testing::Bool());
private ScopedLayoutNGForTest,
public TextIteratorTest {
public:
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());
TEST_F(TextIteratorTest, BitStackOverflow) { TEST_P(TextIteratorTest, BitStackOverflow) {
const unsigned kBitsInWord = sizeof(unsigned) * 8; const unsigned kBitsInWord = sizeof(unsigned) * 8;
BitStack bs; BitStack bs;
...@@ -170,14 +166,14 @@ TEST_F(TextIteratorTest, BitStackOverflow) { ...@@ -170,14 +166,14 @@ TEST_F(TextIteratorTest, BitStackOverflow) {
EXPECT_TRUE(bs.Top()); EXPECT_TRUE(bs.Top());
} }
TEST_F(TextIteratorTest, BasicIteration) { TEST_P(TextIteratorTest, BasicIteration) {
static const char* input = "<p>Hello, \ntext</p><p>iterator.</p>"; static const char* input = "<p>Hello, \ntext</p><p>iterator.</p>";
SetBodyContent(input); SetBodyContent(input);
EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", Iterate<DOMTree>()); EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", Iterate<DOMTree>());
EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", Iterate<FlatTree>()); EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", Iterate<FlatTree>());
} }
TEST_F(TextIteratorTest, EmitsSmallXForTextSecurity) { TEST_P(TextIteratorTest, EmitsSmallXForTextSecurity) {
InsertStyleElement("s {-webkit-text-security:disc;}"); InsertStyleElement("s {-webkit-text-security:disc;}");
SetBodyContent("abc<s>foo</s>baz"); SetBodyContent("abc<s>foo</s>baz");
// E2 80 A2 is U+2022 BULLET // E2 80 A2 is U+2022 BULLET
...@@ -191,28 +187,28 @@ TEST_F(TextIteratorTest, EmitsSmallXForTextSecurity) { ...@@ -191,28 +187,28 @@ TEST_F(TextIteratorTest, EmitsSmallXForTextSecurity) {
Iterate<FlatTree>(TextIteratorBehavior())); Iterate<FlatTree>(TextIteratorBehavior()));
} }
TEST_F(TextIteratorTest, IgnoreAltTextInTextControls) { TEST_P(TextIteratorTest, IgnoreAltTextInTextControls) {
static const char* input = "<p>Hello <input type='text' value='value'>!</p>"; static const char* input = "<p>Hello <input type='text' value='value'>!</p>";
SetBodyContent(input); SetBodyContent(input);
EXPECT_EQ("[Hello ][][!]", Iterate<DOMTree>(EmitsImageAltTextBehavior())); EXPECT_EQ("[Hello ][][!]", Iterate<DOMTree>(EmitsImageAltTextBehavior()));
EXPECT_EQ("[Hello ][][!]", Iterate<FlatTree>(EmitsImageAltTextBehavior())); EXPECT_EQ("[Hello ][][!]", Iterate<FlatTree>(EmitsImageAltTextBehavior()));
} }
TEST_F(TextIteratorTest, DisplayAltTextInImageControls) { TEST_P(TextIteratorTest, DisplayAltTextInImageControls) {
static const char* input = "<p>Hello <input type='image' alt='alt'>!</p>"; static const char* input = "<p>Hello <input type='image' alt='alt'>!</p>";
SetBodyContent(input); SetBodyContent(input);
EXPECT_EQ("[Hello ][alt][!]", Iterate<DOMTree>(EmitsImageAltTextBehavior())); EXPECT_EQ("[Hello ][alt][!]", Iterate<DOMTree>(EmitsImageAltTextBehavior()));
EXPECT_EQ("[Hello ][alt][!]", Iterate<FlatTree>(EmitsImageAltTextBehavior())); EXPECT_EQ("[Hello ][alt][!]", Iterate<FlatTree>(EmitsImageAltTextBehavior()));
} }
TEST_F(TextIteratorTest, NotEnteringTextControls) { TEST_P(TextIteratorTest, NotEnteringTextControls) {
static const char* input = "<p>Hello <input type='text' value='input'>!</p>"; static const char* input = "<p>Hello <input type='text' value='input'>!</p>";
SetBodyContent(input); SetBodyContent(input);
EXPECT_EQ("[Hello ][][!]", Iterate<DOMTree>()); EXPECT_EQ("[Hello ][][!]", Iterate<DOMTree>());
EXPECT_EQ("[Hello ][][!]", Iterate<FlatTree>()); EXPECT_EQ("[Hello ][][!]", Iterate<FlatTree>());
} }
TEST_F(TextIteratorTest, EnteringTextControlsWithOption) { TEST_P(TextIteratorTest, EnteringTextControlsWithOption) {
static const char* input = "<p>Hello <input type='text' value='input'>!</p>"; static const char* input = "<p>Hello <input type='text' value='input'>!</p>";
SetBodyContent(input); SetBodyContent(input);
EXPECT_EQ("[Hello ][\n][input][!]", EXPECT_EQ("[Hello ][\n][input][!]",
...@@ -221,7 +217,7 @@ TEST_F(TextIteratorTest, EnteringTextControlsWithOption) { ...@@ -221,7 +217,7 @@ TEST_F(TextIteratorTest, EnteringTextControlsWithOption) {
Iterate<FlatTree>(EntersTextControlsBehavior())); Iterate<FlatTree>(EntersTextControlsBehavior()));
} }
TEST_F(TextIteratorTest, EnteringTextControlsWithOptionComplex) { TEST_P(TextIteratorTest, EnteringTextControlsWithOptionComplex) {
static const char* input = static const char* input =
"<input type='text' value='Beginning of range'><div><div><input " "<input type='text' value='Beginning of range'><div><div><input "
"type='text' value='Under DOM nodes'></div></div><input type='text' " "type='text' value='Under DOM nodes'></div></div><input type='text' "
...@@ -233,7 +229,7 @@ TEST_F(TextIteratorTest, EnteringTextControlsWithOptionComplex) { ...@@ -233,7 +229,7 @@ TEST_F(TextIteratorTest, EnteringTextControlsWithOptionComplex) {
Iterate<FlatTree>(EntersTextControlsBehavior())); Iterate<FlatTree>(EntersTextControlsBehavior()));
} }
TEST_F(TextIteratorTest, NotEnteringShadowTree) { TEST_P(TextIteratorTest, NotEnteringShadowTree) {
static const char* body_content = static const char* body_content =
"<div>Hello, <span id='host'>text</span> iterator.</div>"; "<div>Hello, <span id='host'>text</span> iterator.</div>";
static const char* shadow_content = "<span>shadow</span>"; static const char* shadow_content = "<span>shadow</span>";
...@@ -246,7 +242,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTree) { ...@@ -246,7 +242,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTree) {
EXPECT_EQ("[Hello, ][shadow][ iterator.]", Iterate<FlatTree>()); EXPECT_EQ("[Hello, ][shadow][ iterator.]", Iterate<FlatTree>());
} }
TEST_F(TextIteratorTest, NotEnteringShadowTreeWithNestedShadowTrees) { TEST_P(TextIteratorTest, NotEnteringShadowTreeWithNestedShadowTrees) {
static const char* body_content = static const char* body_content =
"<div>Hello, <span id='host-in-document'>text</span> iterator.</div>"; "<div>Hello, <span id='host-in-document'>text</span> iterator.</div>";
static const char* shadow_content1 = static const char* shadow_content1 =
...@@ -262,7 +258,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTreeWithNestedShadowTrees) { ...@@ -262,7 +258,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTreeWithNestedShadowTrees) {
Iterate<FlatTree>()); Iterate<FlatTree>());
} }
TEST_F(TextIteratorTest, NotEnteringShadowTreeWithContentInsertionPoint) { TEST_P(TextIteratorTest, NotEnteringShadowTreeWithContentInsertionPoint) {
static const char* body_content = static const char* body_content =
"<div>Hello, <span id='host'>text</span> iterator.</div>"; "<div>Hello, <span id='host'>text</span> iterator.</div>";
static const char* shadow_content = static const char* shadow_content =
...@@ -275,7 +271,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTreeWithContentInsertionPoint) { ...@@ -275,7 +271,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTreeWithContentInsertionPoint) {
EXPECT_EQ("[Hello, ][shadow ][text][ iterator.]", Iterate<FlatTree>()); EXPECT_EQ("[Hello, ][shadow ][text][ iterator.]", Iterate<FlatTree>());
} }
TEST_F(TextIteratorTest, EnteringShadowTreeWithOption) { TEST_P(TextIteratorTest, EnteringShadowTreeWithOption) {
static const char* body_content = static const char* body_content =
"<div>Hello, <span id='host'>text</span> iterator.</div>"; "<div>Hello, <span id='host'>text</span> iterator.</div>";
static const char* shadow_content = "<span>shadow</span>"; static const char* shadow_content = "<span>shadow</span>";
...@@ -290,7 +286,7 @@ TEST_F(TextIteratorTest, EnteringShadowTreeWithOption) { ...@@ -290,7 +286,7 @@ TEST_F(TextIteratorTest, EnteringShadowTreeWithOption) {
Iterate<FlatTree>(EntersOpenShadowRootsBehavior())); Iterate<FlatTree>(EntersOpenShadowRootsBehavior()));
} }
TEST_F(TextIteratorTest, EnteringShadowTreeWithNestedShadowTreesWithOption) { TEST_P(TextIteratorTest, EnteringShadowTreeWithNestedShadowTreesWithOption) {
static const char* body_content = static const char* body_content =
"<div>Hello, <span id='host-in-document'>text</span> iterator.</div>"; "<div>Hello, <span id='host-in-document'>text</span> iterator.</div>";
static const char* shadow_content1 = static const char* shadow_content1 =
...@@ -307,7 +303,7 @@ TEST_F(TextIteratorTest, EnteringShadowTreeWithNestedShadowTreesWithOption) { ...@@ -307,7 +303,7 @@ TEST_F(TextIteratorTest, EnteringShadowTreeWithNestedShadowTreesWithOption) {
Iterate<FlatTree>(EntersOpenShadowRootsBehavior())); Iterate<FlatTree>(EntersOpenShadowRootsBehavior()));
} }
TEST_F(TextIteratorTest, TEST_P(TextIteratorTest,
EnteringShadowTreeWithContentInsertionPointWithOption) { EnteringShadowTreeWithContentInsertionPointWithOption) {
static const char* body_content = static const char* body_content =
"<div>Hello, <span id='host'>text</span> iterator.</div>"; "<div>Hello, <span id='host'>text</span> iterator.</div>";
...@@ -327,7 +323,7 @@ TEST_F(TextIteratorTest, ...@@ -327,7 +323,7 @@ TEST_F(TextIteratorTest,
Iterate<FlatTree>(EntersOpenShadowRootsBehavior())); Iterate<FlatTree>(EntersOpenShadowRootsBehavior()));
} }
TEST_F(TextIteratorTest, StartingAtNodeInShadowRoot) { TEST_P(TextIteratorTest, StartingAtNodeInShadowRoot) {
static const char* body_content = static const char* body_content =
"<div id='outer'>Hello, <span id='host'>text</span> iterator.</div>"; "<div id='outer'>Hello, <span id='host'>text</span> iterator.</div>";
static const char* shadow_content = static const char* shadow_content =
...@@ -352,7 +348,7 @@ TEST_F(TextIteratorTest, StartingAtNodeInShadowRoot) { ...@@ -352,7 +348,7 @@ TEST_F(TextIteratorTest, StartingAtNodeInShadowRoot) {
EntersOpenShadowRootsBehavior())); EntersOpenShadowRootsBehavior()));
} }
TEST_F(TextIteratorTest, FinishingAtNodeInShadowRoot) { TEST_P(TextIteratorTest, FinishingAtNodeInShadowRoot) {
static const char* body_content = static const char* body_content =
"<div id='outer'>Hello, <span id='host'>text</span> iterator.</div>"; "<div id='outer'>Hello, <span id='host'>text</span> iterator.</div>";
static const char* shadow_content = static const char* shadow_content =
...@@ -377,7 +373,7 @@ TEST_F(TextIteratorTest, FinishingAtNodeInShadowRoot) { ...@@ -377,7 +373,7 @@ TEST_F(TextIteratorTest, FinishingAtNodeInShadowRoot) {
EntersOpenShadowRootsBehavior())); EntersOpenShadowRootsBehavior()));
} }
TEST_F(TextIteratorTest, FullyClipsContents) { TEST_P(TextIteratorTest, FullyClipsContents) {
static const char* body_content = static const char* body_content =
"<div style='overflow: hidden; width: 200px; height: 0;'>" "<div style='overflow: hidden; width: 200px; height: 0;'>"
"I'm invisible" "I'm invisible"
...@@ -387,7 +383,7 @@ TEST_F(TextIteratorTest, FullyClipsContents) { ...@@ -387,7 +383,7 @@ TEST_F(TextIteratorTest, FullyClipsContents) {
EXPECT_EQ("", Iterate<FlatTree>()); EXPECT_EQ("", Iterate<FlatTree>());
} }
TEST_F(TextIteratorTest, IgnoresContainerClip) { TEST_P(TextIteratorTest, IgnoresContainerClip) {
static const char* body_content = static const char* body_content =
"<div style='overflow: hidden; width: 200px; height: 0;'>" "<div style='overflow: hidden; width: 200px; height: 0;'>"
"<div>I'm not visible</div>" "<div>I'm not visible</div>"
...@@ -401,7 +397,7 @@ TEST_F(TextIteratorTest, IgnoresContainerClip) { ...@@ -401,7 +397,7 @@ TEST_F(TextIteratorTest, IgnoresContainerClip) {
EXPECT_EQ("[but I am!]", Iterate<FlatTree>()); EXPECT_EQ("[but I am!]", Iterate<FlatTree>());
} }
TEST_F(TextIteratorTest, FullyClippedContentsDistributed) { TEST_P(TextIteratorTest, FullyClippedContentsDistributed) {
static const char* body_content = static const char* body_content =
"<div id='host'>" "<div id='host'>"
"<div>Am I visible?</div>" "<div>Am I visible?</div>"
...@@ -420,7 +416,7 @@ TEST_F(TextIteratorTest, FullyClippedContentsDistributed) { ...@@ -420,7 +416,7 @@ TEST_F(TextIteratorTest, FullyClippedContentsDistributed) {
EXPECT_EQ("", Iterate<FlatTree>(EntersOpenShadowRootsBehavior())); EXPECT_EQ("", Iterate<FlatTree>(EntersOpenShadowRootsBehavior()));
} }
TEST_F(TextIteratorTest, IgnoresContainersClipDistributed) { TEST_P(TextIteratorTest, IgnoresContainersClipDistributed) {
static const char* body_content = static const char* body_content =
"<div id='host' style='overflow: hidden; width: 200px; height: 0;'>" "<div id='host' style='overflow: hidden; width: 200px; height: 0;'>"
"<div>Nobody can find me!</div>" "<div>Nobody can find me!</div>"
...@@ -441,7 +437,7 @@ TEST_F(TextIteratorTest, IgnoresContainersClipDistributed) { ...@@ -441,7 +437,7 @@ TEST_F(TextIteratorTest, IgnoresContainersClipDistributed) {
Iterate<FlatTree>(EntersOpenShadowRootsBehavior())); Iterate<FlatTree>(EntersOpenShadowRootsBehavior()));
} }
TEST_F(TextIteratorTest, EmitsReplacementCharForInput) { TEST_P(TextIteratorTest, EmitsReplacementCharForInput) {
static const char* body_content = static const char* body_content =
"<div contenteditable='true'>" "<div contenteditable='true'>"
"Before" "Before"
...@@ -455,7 +451,7 @@ TEST_F(TextIteratorTest, EmitsReplacementCharForInput) { ...@@ -455,7 +451,7 @@ TEST_F(TextIteratorTest, EmitsReplacementCharForInput) {
Iterate<FlatTree>(EmitsObjectReplacementCharacterBehavior())); Iterate<FlatTree>(EmitsObjectReplacementCharacterBehavior()));
} }
TEST_F(TextIteratorTest, RangeLengthWithReplacedElements) { TEST_P(TextIteratorTest, RangeLengthWithReplacedElements) {
static const char* body_content = static const char* body_content =
"<div id='div' contenteditable='true'>1<img src='foo.png'>3</div>"; "<div id='div' contenteditable='true'>1<img src='foo.png'>3</div>";
SetBodyContent(body_content); SetBodyContent(body_content);
...@@ -467,7 +463,7 @@ TEST_F(TextIteratorTest, RangeLengthWithReplacedElements) { ...@@ -467,7 +463,7 @@ TEST_F(TextIteratorTest, RangeLengthWithReplacedElements) {
EXPECT_EQ(3, TextIterator::RangeLength(range)); EXPECT_EQ(3, TextIterator::RangeLength(range));
} }
TEST_F(TextIteratorTest, RangeLengthInMultilineSpan) { TEST_P(TextIteratorTest, RangeLengthInMultilineSpan) {
static const char* body_content = static const char* body_content =
"<table style='width:5em'>" "<table style='width:5em'>"
"<tbody>" "<tbody>"
...@@ -489,13 +485,13 @@ TEST_F(TextIteratorTest, RangeLengthInMultilineSpan) { ...@@ -489,13 +485,13 @@ TEST_F(TextIteratorTest, RangeLengthInMultilineSpan) {
const EphemeralRange range(Position(text_node, 4), Position(text_node, 7)); const EphemeralRange range(Position(text_node, 4), Position(text_node, 7));
EXPECT_EQ(4, TextIterator::RangeLength(range)); EXPECT_EQ(LayoutNGEnabled() ? 3 : 4, TextIterator::RangeLength(range));
EXPECT_EQ(3, TextIterator::RangeLength( EXPECT_EQ(3, TextIterator::RangeLength(
range, range,
TextIteratorBehavior::NoTrailingSpaceRangeLengthBehavior())); TextIteratorBehavior::NoTrailingSpaceRangeLengthBehavior()));
} }
TEST_P(ParameterizedTextIteratorTest, RangeLengthBasic) { TEST_P(TextIteratorTest, RangeLengthBasic) {
EXPECT_EQ(0, TestRangeLength("<p>^| (1) abc def</p>")); EXPECT_EQ(0, TestRangeLength("<p>^| (1) abc def</p>"));
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(1, TestRangeLength("<p>^ (|1) abc def</p>"));
...@@ -511,7 +507,7 @@ TEST_P(ParameterizedTextIteratorTest, RangeLengthBasic) { ...@@ -511,7 +507,7 @@ TEST_P(ParameterizedTextIteratorTest, RangeLengthBasic) {
EXPECT_EQ(11, TestRangeLength("<p>^ (1) abc def|</p>")); EXPECT_EQ(11, TestRangeLength("<p>^ (1) abc def|</p>"));
} }
TEST_P(ParameterizedTextIteratorTest, RangeLengthWithFirstLetter) { TEST_P(TextIteratorTest, RangeLengthWithFirstLetter) {
InsertStyleElement("p::first-letter {font-size:200%;}"); InsertStyleElement("p::first-letter {font-size:200%;}");
// Expectation should be as same as |RangeLengthBasic| // Expectation should be as same as |RangeLengthBasic|
EXPECT_EQ(0, TestRangeLength("<p>^| (1) abc def</p>")); EXPECT_EQ(0, TestRangeLength("<p>^| (1) abc def</p>"));
...@@ -529,8 +525,7 @@ TEST_P(ParameterizedTextIteratorTest, RangeLengthWithFirstLetter) { ...@@ -529,8 +525,7 @@ TEST_P(ParameterizedTextIteratorTest, RangeLengthWithFirstLetter) {
EXPECT_EQ(11, TestRangeLength("<p>^ (1) abc def|</p>")); EXPECT_EQ(11, TestRangeLength("<p>^ (1) abc def|</p>"));
} }
TEST_P(ParameterizedTextIteratorTest, TEST_P(TextIteratorTest, RangeLengthWithFirstLetterMultipleLeadingSpaces) {
RangeLengthWithFirstLetterMultipleLeadingSpaces) {
InsertStyleElement("p::first-letter {font-size:200%;}"); InsertStyleElement("p::first-letter {font-size:200%;}");
EXPECT_EQ(0, TestRangeLength("<p>^| foo</p>")); EXPECT_EQ(0, TestRangeLength("<p>^| foo</p>"));
EXPECT_EQ(0, TestRangeLength("<p>^ | foo</p>")); EXPECT_EQ(0, TestRangeLength("<p>^ | foo</p>"));
...@@ -541,7 +536,7 @@ TEST_P(ParameterizedTextIteratorTest, ...@@ -541,7 +536,7 @@ TEST_P(ParameterizedTextIteratorTest,
EXPECT_EQ(3, TestRangeLength("<p>^ foo|</p>")); EXPECT_EQ(3, TestRangeLength("<p>^ foo|</p>"));
} }
TEST_F(TextIteratorTest, WhitespaceCollapseForReplacedElements) { TEST_P(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 "
"text'/><span>Some more text</span>"; "text'/><span>Some more text</span>";
...@@ -553,7 +548,7 @@ TEST_F(TextIteratorTest, WhitespaceCollapseForReplacedElements) { ...@@ -553,7 +548,7 @@ TEST_F(TextIteratorTest, WhitespaceCollapseForReplacedElements) {
Iterate<FlatTree>(CollapseTrailingSpaceBehavior())); Iterate<FlatTree>(CollapseTrailingSpaceBehavior()));
} }
TEST_F(TextIteratorTest, copyTextTo) { TEST_P(TextIteratorTest, copyTextTo) {
const char* body_content = const char* body_content =
"<a id=host><b id=one>one</b> not appeared <b id=two>two</b></a>"; "<a id=host><b id=one>one</b> not appeared <b id=two>two</b></a>";
const char* shadow_content = const char* shadow_content =
...@@ -623,7 +618,7 @@ TEST_F(TextIteratorTest, copyTextTo) { ...@@ -623,7 +618,7 @@ TEST_F(TextIteratorTest, copyTextTo) {
<< String::Format(message, 2, "three two one zero").Utf8().data(); << String::Format(message, 2, "three two one zero").Utf8().data();
} }
TEST_F(TextIteratorTest, characterAt) { TEST_P(TextIteratorTest, characterAt) {
const char* body_content = const char* body_content =
"<a id=host><b id=one>one</b> not appeared <b id=two>two</b></a>"; "<a id=host><b id=one>one</b> not appeared <b id=two>two</b></a>";
const char* shadow_content = const char* shadow_content =
...@@ -678,7 +673,7 @@ TEST_F(TextIteratorTest, characterAt) { ...@@ -678,7 +673,7 @@ TEST_F(TextIteratorTest, characterAt) {
EXPECT_EQ('o', iter2.CharacterAt(4)) << message2; EXPECT_EQ('o', iter2.CharacterAt(4)) << message2;
} }
TEST_F(TextIteratorTest, CopyWholeCodePoints) { TEST_P(TextIteratorTest, CopyWholeCodePoints) {
const char* body_content = "&#x13000;&#x13001;&#x13002; &#x13140;&#x13141;."; const char* body_content = "&#x13000;&#x13001;&#x13002; &#x13140;&#x13141;.";
SetBodyContent(body_content); SetBodyContent(body_content);
...@@ -703,7 +698,7 @@ TEST_F(TextIteratorTest, CopyWholeCodePoints) { ...@@ -703,7 +698,7 @@ TEST_F(TextIteratorTest, CopyWholeCodePoints) {
} }
// Regression test for crbug.com/630921 // Regression test for crbug.com/630921
TEST_F(TextIteratorTest, EndingConditionWithDisplayNone) { TEST_P(TextIteratorTest, EndingConditionWithDisplayNone) {
SetBodyContent( SetBodyContent(
"<div style='display: none'><span>hello</span>world</div>Lorem ipsum " "<div style='display: none'><span>hello</span>world</div>Lorem ipsum "
"dolor sit amet."); "dolor sit amet.");
...@@ -714,7 +709,7 @@ TEST_F(TextIteratorTest, EndingConditionWithDisplayNone) { ...@@ -714,7 +709,7 @@ TEST_F(TextIteratorTest, EndingConditionWithDisplayNone) {
} }
// Trickier regression test for crbug.com/630921 // Trickier regression test for crbug.com/630921
TEST_F(TextIteratorTest, EndingConditionWithDisplayNoneInShadowTree) { TEST_P(TextIteratorTest, EndingConditionWithDisplayNoneInShadowTree) {
const char* body_content = const char* body_content =
"<div style='display: none'><span id=host><a></a></span>world</div>Lorem " "<div style='display: none'><span id=host><a></a></span>world</div>Lorem "
"ipsum dolor sit amet."; "ipsum dolor sit amet.";
...@@ -732,7 +727,7 @@ TEST_F(TextIteratorTest, EndingConditionWithDisplayNoneInShadowTree) { ...@@ -732,7 +727,7 @@ TEST_F(TextIteratorTest, EndingConditionWithDisplayNoneInShadowTree) {
EXPECT_TRUE(iter.AtEnd()); EXPECT_TRUE(iter.AtEnd());
} }
TEST_F(TextIteratorTest, PreserveLeadingSpace) { TEST_P(TextIteratorTest, PreserveLeadingSpace) {
SetBodyContent("<div style='width: 2em;'><b><i>foo</i></b> bar</div>"); SetBodyContent("<div style='width: 2em;'><b><i>foo</i></b> bar</div>");
Element* div = GetDocument().QuerySelector("div"); Element* div = GetDocument().QuerySelector("div");
Position start(div->firstChild()->firstChild()->firstChild(), 0); Position start(div->firstChild()->firstChild()->firstChild(), 0);
...@@ -743,7 +738,7 @@ TEST_F(TextIteratorTest, PreserveLeadingSpace) { ...@@ -743,7 +738,7 @@ TEST_F(TextIteratorTest, PreserveLeadingSpace) {
// We used to have a bug where the leading space was duplicated if we didn't // We used to have a bug where the leading space was duplicated if we didn't
// emit alt text, this tests for that bug // emit alt text, this tests for that bug
TEST_F(TextIteratorTest, PreserveLeadingSpaceWithoutEmittingAltText) { TEST_P(TextIteratorTest, PreserveLeadingSpaceWithoutEmittingAltText) {
SetBodyContent("<div style='width: 2em;'><b><i>foo</i></b> bar</div>"); SetBodyContent("<div style='width: 2em;'><b><i>foo</i></b> bar</div>");
Element* div = GetDocument().QuerySelector("div"); Element* div = GetDocument().QuerySelector("div");
Position start(div->firstChild()->firstChild()->firstChild(), 0); Position start(div->firstChild()->firstChild()->firstChild(), 0);
...@@ -751,7 +746,7 @@ TEST_F(TextIteratorTest, PreserveLeadingSpaceWithoutEmittingAltText) { ...@@ -751,7 +746,7 @@ TEST_F(TextIteratorTest, PreserveLeadingSpaceWithoutEmittingAltText) {
EXPECT_EQ("foo bar", PlainText(EphemeralRange(start, end))); EXPECT_EQ("foo bar", PlainText(EphemeralRange(start, end)));
} }
TEST_F(TextIteratorTest, PreserveOnlyLeadingSpace) { TEST_P(TextIteratorTest, PreserveOnlyLeadingSpace) {
SetBodyContent( SetBodyContent(
"<div style='width: 2em;'><b><i id='foo'>foo </i></b> bar</div>"); "<div style='width: 2em;'><b><i id='foo'>foo </i></b> bar</div>");
Element* div = GetDocument().QuerySelector("div"); Element* div = GetDocument().QuerySelector("div");
...@@ -761,7 +756,7 @@ TEST_F(TextIteratorTest, PreserveOnlyLeadingSpace) { ...@@ -761,7 +756,7 @@ TEST_F(TextIteratorTest, PreserveOnlyLeadingSpace) {
PlainText(EphemeralRange(start, end), EmitsImageAltTextBehavior())); PlainText(EphemeralRange(start, end), EmitsImageAltTextBehavior()));
} }
TEST_F(TextIteratorTest, StartAtFirstLetter) { TEST_P(TextIteratorTest, StartAtFirstLetter) {
SetBodyContent("<style>div:first-letter {color:red;}</style><div>Axyz</div>"); SetBodyContent("<style>div:first-letter {color:red;}</style><div>Axyz</div>");
Element* div = GetDocument().QuerySelector("div"); Element* div = GetDocument().QuerySelector("div");
...@@ -792,7 +787,7 @@ TEST_F(TextIteratorTest, StartAtFirstLetter) { ...@@ -792,7 +787,7 @@ TEST_F(TextIteratorTest, StartAtFirstLetter) {
EXPECT_EQ("Axyz", String(buffer.Data())); EXPECT_EQ("Axyz", String(buffer.Data()));
} }
TEST_F(TextIteratorTest, StartInMultiCharFirstLetterWithCollapsedSpace) { TEST_P(TextIteratorTest, StartInMultiCharFirstLetterWithCollapsedSpace) {
SetBodyContent( SetBodyContent(
"<style>div:first-letter {color:red;}</style><div> (A) xyz</div>"); "<style>div:first-letter {color:red;}</style><div> (A) xyz</div>");
...@@ -832,7 +827,7 @@ TEST_F(TextIteratorTest, StartInMultiCharFirstLetterWithCollapsedSpace) { ...@@ -832,7 +827,7 @@ TEST_F(TextIteratorTest, StartInMultiCharFirstLetterWithCollapsedSpace) {
EXPECT_EQ("A) xyz", String(buffer.Data())); EXPECT_EQ("A) xyz", String(buffer.Data()));
} }
TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterWithCollapsedSpace) { TEST_P(TextIteratorTest, StartAndEndInMultiCharFirstLetterWithCollapsedSpace) {
SetBodyContent( SetBodyContent(
"<style>div:first-letter {color:red;}</style><div> (A) xyz</div>"); "<style>div:first-letter {color:red;}</style><div> (A) xyz</div>");
...@@ -856,7 +851,7 @@ TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterWithCollapsedSpace) { ...@@ -856,7 +851,7 @@ TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterWithCollapsedSpace) {
EXPECT_EQ("A", String(buffer.Data())); EXPECT_EQ("A", String(buffer.Data()));
} }
TEST_F(TextIteratorTest, StartAtRemainingText) { TEST_P(TextIteratorTest, StartAtRemainingText) {
SetBodyContent("<style>div:first-letter {color:red;}</style><div>Axyz</div>"); SetBodyContent("<style>div:first-letter {color:red;}</style><div>Axyz</div>");
Element* div = GetDocument().QuerySelector("div"); Element* div = GetDocument().QuerySelector("div");
...@@ -879,7 +874,7 @@ TEST_F(TextIteratorTest, StartAtRemainingText) { ...@@ -879,7 +874,7 @@ TEST_F(TextIteratorTest, StartAtRemainingText) {
EXPECT_EQ("xyz", String(buffer.Data())); EXPECT_EQ("xyz", String(buffer.Data()));
} }
TEST_F(TextIteratorTest, StartAtFirstLetterInPre) { TEST_P(TextIteratorTest, StartAtFirstLetterInPre) {
SetBodyContent("<style>pre:first-letter {color:red;}</style><pre>Axyz</pre>"); SetBodyContent("<style>pre:first-letter {color:red;}</style><pre>Axyz</pre>");
Element* pre = GetDocument().QuerySelector("pre"); Element* pre = GetDocument().QuerySelector("pre");
...@@ -910,7 +905,7 @@ TEST_F(TextIteratorTest, StartAtFirstLetterInPre) { ...@@ -910,7 +905,7 @@ TEST_F(TextIteratorTest, StartAtFirstLetterInPre) {
EXPECT_EQ("Axyz", String(buffer.Data())); EXPECT_EQ("Axyz", String(buffer.Data()));
} }
TEST_F(TextIteratorTest, StartInMultiCharFirstLetterInPre) { TEST_P(TextIteratorTest, StartInMultiCharFirstLetterInPre) {
SetBodyContent( SetBodyContent(
"<style>pre:first-letter {color:red;}</style><pre>(A)xyz</pre>"); "<style>pre:first-letter {color:red;}</style><pre>(A)xyz</pre>");
...@@ -942,7 +937,7 @@ TEST_F(TextIteratorTest, StartInMultiCharFirstLetterInPre) { ...@@ -942,7 +937,7 @@ TEST_F(TextIteratorTest, StartInMultiCharFirstLetterInPre) {
EXPECT_EQ("A)xyz", String(buffer.Data())); EXPECT_EQ("A)xyz", String(buffer.Data()));
} }
TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterInPre) { TEST_P(TextIteratorTest, StartAndEndInMultiCharFirstLetterInPre) {
SetBodyContent( SetBodyContent(
"<style>pre:first-letter {color:red;}</style><pre>(A)xyz</pre>"); "<style>pre:first-letter {color:red;}</style><pre>(A)xyz</pre>");
...@@ -966,7 +961,7 @@ TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterInPre) { ...@@ -966,7 +961,7 @@ TEST_F(TextIteratorTest, StartAndEndInMultiCharFirstLetterInPre) {
EXPECT_EQ("A", String(buffer.Data())); EXPECT_EQ("A", String(buffer.Data()));
} }
TEST_F(TextIteratorTest, StartAtRemainingTextInPre) { TEST_P(TextIteratorTest, StartAtRemainingTextInPre) {
SetBodyContent("<style>pre:first-letter {color:red;}</style><pre>Axyz</pre>"); SetBodyContent("<style>pre:first-letter {color:red;}</style><pre>Axyz</pre>");
Element* pre = GetDocument().QuerySelector("pre"); Element* pre = GetDocument().QuerySelector("pre");
...@@ -989,7 +984,7 @@ TEST_F(TextIteratorTest, StartAtRemainingTextInPre) { ...@@ -989,7 +984,7 @@ TEST_F(TextIteratorTest, StartAtRemainingTextInPre) {
EXPECT_EQ("xyz", String(buffer.Data())); EXPECT_EQ("xyz", String(buffer.Data()));
} }
TEST_F(TextIteratorTest, VisitsDisplayContentsChildren) { TEST_P(TextIteratorTest, VisitsDisplayContentsChildren) {
SetBodyContent( SetBodyContent(
"<p>Hello, \ntext</p><p style='display: contents'>iterator.</p>"); "<p>Hello, \ntext</p><p style='display: contents'>iterator.</p>");
...@@ -997,27 +992,27 @@ TEST_F(TextIteratorTest, VisitsDisplayContentsChildren) { ...@@ -997,27 +992,27 @@ TEST_F(TextIteratorTest, VisitsDisplayContentsChildren) {
EXPECT_EQ("[Hello, ][text][iterator.]", Iterate<FlatTree>()); EXPECT_EQ("[Hello, ][text][iterator.]", Iterate<FlatTree>());
} }
TEST_F(TextIteratorTest, BasicIterationEmptyContent) { TEST_P(TextIteratorTest, BasicIterationEmptyContent) {
SetBodyContent(""); SetBodyContent("");
EXPECT_EQ("", Iterate<DOMTree>()); EXPECT_EQ("", Iterate<DOMTree>());
} }
TEST_F(TextIteratorTest, BasicIterationSingleCharacter) { TEST_P(TextIteratorTest, BasicIterationSingleCharacter) {
SetBodyContent("a"); SetBodyContent("a");
EXPECT_EQ("[a]", Iterate<DOMTree>()); EXPECT_EQ("[a]", Iterate<DOMTree>());
} }
TEST_F(TextIteratorTest, BasicIterationSingleDiv) { TEST_P(TextIteratorTest, BasicIterationSingleDiv) {
SetBodyContent("<div>a</div>"); SetBodyContent("<div>a</div>");
EXPECT_EQ("[a]", Iterate<DOMTree>()); EXPECT_EQ("[a]", Iterate<DOMTree>());
} }
TEST_F(TextIteratorTest, BasicIterationMultipleDivs) { TEST_P(TextIteratorTest, BasicIterationMultipleDivs) {
SetBodyContent("<div>a</div><div>b</div>"); SetBodyContent("<div>a</div><div>b</div>");
EXPECT_EQ("[a][\n][b]", Iterate<DOMTree>()); EXPECT_EQ("[a][\n][b]", Iterate<DOMTree>());
} }
TEST_F(TextIteratorTest, BasicIterationMultipleDivsWithStyle) { TEST_P(TextIteratorTest, BasicIterationMultipleDivsWithStyle) {
SetBodyContent( SetBodyContent(
"<div style='line-height: 18px; min-height: 436px; '>" "<div style='line-height: 18px; min-height: 436px; '>"
"debugging this note" "debugging this note"
...@@ -1025,12 +1020,12 @@ TEST_F(TextIteratorTest, BasicIterationMultipleDivsWithStyle) { ...@@ -1025,12 +1020,12 @@ TEST_F(TextIteratorTest, BasicIterationMultipleDivsWithStyle) {
EXPECT_EQ("[debugging this note]", Iterate<DOMTree>()); EXPECT_EQ("[debugging this note]", Iterate<DOMTree>());
} }
TEST_F(TextIteratorTest, BasicIterationMultipleDivsWithChildren) { TEST_P(TextIteratorTest, BasicIterationMultipleDivsWithChildren) {
SetBodyContent("<div>Hello<div><br><span></span></div></div>"); SetBodyContent("<div>Hello<div><br><span></span></div></div>");
EXPECT_EQ("[Hello][\n][\n]", Iterate<DOMTree>()); EXPECT_EQ("[Hello][\n][\n]", Iterate<DOMTree>());
} }
TEST_F(TextIteratorTest, BasicIterationOnChildrenWithStyle) { TEST_P(TextIteratorTest, BasicIterationOnChildrenWithStyle) {
SetBodyContent( SetBodyContent(
"<div style='left:22px'>" "<div style='left:22px'>"
"</div>" "</div>"
...@@ -1057,7 +1052,7 @@ TEST_F(TextIteratorTest, BasicIterationOnChildrenWithStyle) { ...@@ -1057,7 +1052,7 @@ TEST_F(TextIteratorTest, BasicIterationOnChildrenWithStyle) {
EXPECT_EQ("[hey]", Iterate<DOMTree>()); EXPECT_EQ("[hey]", Iterate<DOMTree>());
} }
TEST_F(TextIteratorTest, BasicIterationInput) { TEST_P(TextIteratorTest, BasicIterationInput) {
SetBodyContent("<input id='a' value='b'>"); SetBodyContent("<input id='a' value='b'>");
auto* input_element = ToTextControl(GetDocument().getElementById("a")); auto* input_element = ToTextControl(GetDocument().getElementById("a"));
const ShadowRoot* shadow_root = input_element->UserAgentShadowRoot(); const ShadowRoot* shadow_root = input_element->UserAgentShadowRoot();
...@@ -1066,7 +1061,7 @@ TEST_F(TextIteratorTest, BasicIterationInput) { ...@@ -1066,7 +1061,7 @@ TEST_F(TextIteratorTest, BasicIterationInput) {
EXPECT_EQ("[b]", IteratePartial<DOMTree>(start, end)); EXPECT_EQ("[b]", IteratePartial<DOMTree>(start, end));
} }
TEST_F(TextIteratorTest, BasicIterationInputiWithBr) { TEST_P(TextIteratorTest, BasicIterationInputiWithBr) {
SetBodyContent("<input id='a' value='b'>"); SetBodyContent("<input id='a' value='b'>");
auto* input_element = ToTextControl(GetDocument().getElementById("a")); auto* input_element = ToTextControl(GetDocument().getElementById("a"));
Element* inner_editor = input_element->InnerEditorElement(); Element* inner_editor = input_element->InnerEditorElement();
...@@ -1079,30 +1074,30 @@ TEST_F(TextIteratorTest, BasicIterationInputiWithBr) { ...@@ -1079,30 +1074,30 @@ TEST_F(TextIteratorTest, BasicIterationInputiWithBr) {
EXPECT_EQ("[b]", IteratePartial<DOMTree>(start, end)); EXPECT_EQ("[b]", IteratePartial<DOMTree>(start, end));
} }
TEST_P(ParameterizedTextIteratorTest, FloatLeft) { TEST_P(TextIteratorTest, FloatLeft) {
SetBodyContent("abc<span style='float:left'>DEF</span>ghi"); SetBodyContent("abc<span style='float:left'>DEF</span>ghi");
EXPECT_EQ("[abc][DEF][ghi]", Iterate<DOMTree>()) EXPECT_EQ("[abc][DEF][ghi]", Iterate<DOMTree>())
<< "float doesn't affect text iteration"; << "float doesn't affect text iteration";
} }
TEST_P(ParameterizedTextIteratorTest, FloatRight) { TEST_P(TextIteratorTest, FloatRight) {
SetBodyContent("abc<span style='float:right'>DEF</span>ghi"); SetBodyContent("abc<span style='float:right'>DEF</span>ghi");
EXPECT_EQ("[abc][DEF][ghi]", Iterate<DOMTree>()) EXPECT_EQ("[abc][DEF][ghi]", Iterate<DOMTree>())
<< "float doesn't affect text iteration"; << "float doesn't affect text iteration";
} }
TEST_P(ParameterizedTextIteratorTest, InlineBlock) { TEST_P(TextIteratorTest, InlineBlock) {
SetBodyContent("abc<span style='display:inline-block'>DEF<br>GHI</span>jkl"); SetBodyContent("abc<span style='display:inline-block'>DEF<br>GHI</span>jkl");
EXPECT_EQ("[abc][DEF][\n][GHI][jkl]", Iterate<DOMTree>()) EXPECT_EQ("[abc][DEF][\n][GHI][jkl]", Iterate<DOMTree>())
<< "inline-block doesn't insert newline around itself."; << "inline-block doesn't insert newline around itself.";
} }
TEST_P(ParameterizedTextIteratorTest, NoZWSForSpaceAfterNoWrapSpace) { TEST_P(TextIteratorTest, NoZWSForSpaceAfterNoWrapSpace) {
SetBodyContent("<span style='white-space: nowrap'>foo </span> bar"); SetBodyContent("<span style='white-space: nowrap'>foo </span> bar");
EXPECT_EQ("[foo ][bar]", Iterate<DOMTree>()); EXPECT_EQ("[foo ][bar]", Iterate<DOMTree>());
} }
TEST_P(ParameterizedTextIteratorTest, PositionInShadowTree) { TEST_P(TextIteratorTest, PositionInShadowTree) {
// Flat Tree: <div id=host>A<slot name=c><img slot=c alt=C></slot></div> // Flat Tree: <div id=host>A<slot name=c><img slot=c alt=C></slot></div>
SetBodyContent("<div id=host><a></a><b></b><img slot=c alt=C></div>"); SetBodyContent("<div id=host><a></a><b></b><img slot=c alt=C></div>");
Element& host = *GetDocument().getElementById("host"); Element& host = *GetDocument().getElementById("host");
...@@ -1134,20 +1129,20 @@ TEST_P(ParameterizedTextIteratorTest, PositionInShadowTree) { ...@@ -1134,20 +1129,20 @@ TEST_P(ParameterizedTextIteratorTest, PositionInShadowTree) {
ASSERT_TRUE(it.AtEnd()); ASSERT_TRUE(it.AtEnd());
} }
TEST_P(ParameterizedTextIteratorTest, HiddenFirstLetter) { TEST_P(TextIteratorTest, HiddenFirstLetter) {
InsertStyleElement("body::first-letter{visibility:hidden}"); InsertStyleElement("body::first-letter{visibility:hidden}");
SetBodyContent("foo"); SetBodyContent("foo");
EXPECT_EQ("[oo]", Iterate<DOMTree>()); EXPECT_EQ("[oo]", Iterate<DOMTree>());
} }
TEST_P(ParameterizedTextIteratorTest, HiddenFirstLetterInPre) { TEST_P(TextIteratorTest, HiddenFirstLetterInPre) {
InsertStyleElement( InsertStyleElement(
"body::first-letter{visibility:hidden} body{white-space:pre}"); "body::first-letter{visibility:hidden} body{white-space:pre}");
SetBodyContent("foo"); SetBodyContent("foo");
EXPECT_EQ("[oo]", Iterate<DOMTree>()); EXPECT_EQ("[oo]", Iterate<DOMTree>());
} }
TEST_P(ParameterizedTextIteratorTest, TextOffsetMappingAndFlatTree) { TEST_P(TextIteratorTest, TextOffsetMappingAndFlatTree) {
// Tests that TextOffsetMapping should skip text control even though it runs // Tests that TextOffsetMapping should skip text control even though it runs
// on flat tree. // on flat tree.
SetBodyContent("foo <input value='bla bla. bla bla.'> bar"); SetBodyContent("foo <input value='bla bla. bla bla.'> bar");
......
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