| Index: Source/core/editing/SurroundingTextTest.cpp
|
| diff --git a/Source/core/editing/SurroundingTextTest.cpp b/Source/core/editing/SurroundingTextTest.cpp
|
| index cee97200f93ffaadec8cc8df4e04eb5323ecf8da..0c1ac4854a7e8732b3526b71053d0e58e02a56f5 100644
|
| --- a/Source/core/editing/SurroundingTextTest.cpp
|
| +++ b/Source/core/editing/SurroundingTextTest.cpp
|
| @@ -58,7 +58,8 @@ TEST_F(SurroundingTextTest, BasicCaretSelection)
|
| SurroundingText surroundingText(selection.start(), 1);
|
|
|
| EXPECT_EQ("f", surroundingText.content());
|
| - EXPECT_EQ(0u, surroundingText.positionOffsetInContent());
|
| + EXPECT_EQ(0u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(0u, surroundingText.endOffsetInContent());
|
| }
|
|
|
| {
|
| @@ -67,7 +68,8 @@ TEST_F(SurroundingTextTest, BasicCaretSelection)
|
|
|
| // maxlength/2 is used on the left and right.
|
| EXPECT_EQ("foo", surroundingText.content().simplifyWhiteSpace());
|
| - EXPECT_EQ(1u, surroundingText.positionOffsetInContent());
|
| + EXPECT_EQ(1u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(1u, surroundingText.endOffsetInContent());
|
| }
|
|
|
| {
|
| @@ -75,8 +77,8 @@ TEST_F(SurroundingTextTest, BasicCaretSelection)
|
| SurroundingText surroundingText(selection.start(), 42);
|
|
|
| EXPECT_EQ("foo bar", surroundingText.content().simplifyWhiteSpace());
|
| - EXPECT_EQ(1u, surroundingText.positionOffsetInContent());
|
| - }
|
| + EXPECT_EQ(1u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(1u, surroundingText.endOffsetInContent()); }
|
|
|
| {
|
| // FIXME: if the selection is at the end of the text, SurroundingText
|
| @@ -84,24 +86,75 @@ TEST_F(SurroundingTextTest, BasicCaretSelection)
|
| VisibleSelection selection = select(7);
|
| SurroundingText surroundingText(selection.start(), 42);
|
|
|
| - EXPECT_EQ(0u, surroundingText.content().length());
|
| - EXPECT_EQ(0u, surroundingText.positionOffsetInContent());
|
| - }
|
| + EXPECT_TRUE(surroundingText.content().isEmpty());
|
| + EXPECT_EQ(0u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(0u, surroundingText.endOffsetInContent()); }
|
|
|
| {
|
| VisibleSelection selection = select(6);
|
| SurroundingText surroundingText(selection.start(), 2);
|
|
|
| EXPECT_EQ("ar", surroundingText.content());
|
| - EXPECT_EQ(1u, surroundingText.positionOffsetInContent());
|
| - }
|
| + EXPECT_EQ(1u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(1u, surroundingText.endOffsetInContent()); }
|
|
|
| {
|
| VisibleSelection selection = select(6);
|
| SurroundingText surroundingText(selection.start(), 42);
|
|
|
| EXPECT_EQ("foo bar", surroundingText.content().simplifyWhiteSpace());
|
| - EXPECT_EQ(7u, surroundingText.positionOffsetInContent());
|
| + EXPECT_EQ(7u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(7u, surroundingText.endOffsetInContent());
|
| + }
|
| +}
|
| +
|
| +TEST_F(SurroundingTextTest, BasicRangeSelection)
|
| +{
|
| + setHTML(String("<p id='selection'>Lorem ipsum dolor sit amet</p>"));
|
| +
|
| + {
|
| + VisibleSelection selection = select(0, 5);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 1);
|
| +
|
| + EXPECT_EQ("Lorem ", surroundingText.content());
|
| + EXPECT_EQ(0u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(5u, surroundingText.endOffsetInContent());
|
| + }
|
| +
|
| + {
|
| + VisibleSelection selection = select(0, 5);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 5);
|
| +
|
| + EXPECT_EQ("Lorem ip", surroundingText.content().simplifyWhiteSpace());
|
| + EXPECT_EQ(1u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(6u, surroundingText.endOffsetInContent());
|
| + }
|
| +
|
| + {
|
| + VisibleSelection selection = select(0, 5);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 42);
|
| +
|
| + EXPECT_EQ("Lorem ipsum dolor sit amet", surroundingText.content().simplifyWhiteSpace());
|
| + EXPECT_EQ(1u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(6u, surroundingText.endOffsetInContent());
|
| + }
|
| +
|
| + {
|
| + VisibleSelection selection = select(6, 11);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 2);
|
| +
|
| + EXPECT_EQ(" ipsum ", surroundingText.content());
|
| + EXPECT_EQ(1u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(6u, surroundingText.endOffsetInContent());
|
| + }
|
| +
|
| + {
|
| + VisibleSelection selection = select(6, 11);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 42);
|
| +
|
| + EXPECT_EQ("Lorem ipsum dolor sit amet", surroundingText.content().simplifyWhiteSpace());
|
| + EXPECT_EQ(7u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(12u, surroundingText.endOffsetInContent());
|
| }
|
| }
|
|
|
| @@ -114,7 +167,8 @@ TEST_F(SurroundingTextTest, TreeCaretSelection)
|
| SurroundingText surroundingText(selection.start(), 1);
|
|
|
| EXPECT_EQ("f", surroundingText.content());
|
| - EXPECT_EQ(0u, surroundingText.positionOffsetInContent());
|
| + EXPECT_EQ(0u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(0u, surroundingText.endOffsetInContent());
|
| }
|
|
|
| {
|
| @@ -122,7 +176,8 @@ TEST_F(SurroundingTextTest, TreeCaretSelection)
|
| SurroundingText surroundingText(selection.start(), 5);
|
|
|
| EXPECT_EQ("foo", surroundingText.content().simplifyWhiteSpace());
|
| - EXPECT_EQ(1u, surroundingText.positionOffsetInContent());
|
| + EXPECT_EQ(1u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(1u, surroundingText.endOffsetInContent());
|
| }
|
|
|
| {
|
| @@ -130,7 +185,8 @@ TEST_F(SurroundingTextTest, TreeCaretSelection)
|
| SurroundingText surroundingText(selection.start(), 1337);
|
|
|
| EXPECT_EQ("This is outside of foo bar the selected node", surroundingText.content().simplifyWhiteSpace());
|
| - EXPECT_EQ(20u, surroundingText.positionOffsetInContent());
|
| + EXPECT_EQ(20u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(20u, surroundingText.endOffsetInContent());
|
| }
|
|
|
| {
|
| @@ -138,7 +194,8 @@ TEST_F(SurroundingTextTest, TreeCaretSelection)
|
| SurroundingText surroundingText(selection.start(), 2);
|
|
|
| EXPECT_EQ("ar", surroundingText.content());
|
| - EXPECT_EQ(1u, surroundingText.positionOffsetInContent());
|
| + EXPECT_EQ(1u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(1u, surroundingText.endOffsetInContent());
|
| }
|
|
|
| {
|
| @@ -146,7 +203,58 @@ TEST_F(SurroundingTextTest, TreeCaretSelection)
|
| SurroundingText surroundingText(selection.start(), 1337);
|
|
|
| EXPECT_EQ("This is outside of foo bar the selected node", surroundingText.content().simplifyWhiteSpace());
|
| - EXPECT_EQ(26u, surroundingText.positionOffsetInContent());
|
| + EXPECT_EQ(26u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(26u, surroundingText.endOffsetInContent());
|
| + }
|
| +}
|
| +
|
| +TEST_F(SurroundingTextTest, TreeRangeSelection)
|
| +{
|
| + setHTML(String("<div>This is outside of <p id='selection'>foo bar</p> the selected node</div>"));
|
| +
|
| + {
|
| + VisibleSelection selection = select(0, 1);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 1);
|
| +
|
| + EXPECT_EQ("fo", surroundingText.content().simplifyWhiteSpace());
|
| + EXPECT_EQ(0u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(1u, surroundingText.endOffsetInContent());
|
| + }
|
| +
|
| + {
|
| + VisibleSelection selection = select(0, 3);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 12);
|
| +
|
| + EXPECT_EQ("e of foo bar", surroundingText.content().simplifyWhiteSpace());
|
| + EXPECT_EQ(5u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(8u, surroundingText.endOffsetInContent());
|
| + }
|
| +
|
| + {
|
| + VisibleSelection selection = select(0, 3);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 1337);
|
| +
|
| + EXPECT_EQ("This is outside of foo bar the selected node", surroundingText.content().simplifyWhiteSpace());
|
| + EXPECT_EQ(20u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(23u, surroundingText.endOffsetInContent());
|
| + }
|
| +
|
| + {
|
| + VisibleSelection selection = select(4, 7);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 12);
|
| +
|
| + EXPECT_EQ("foo bar the se", surroundingText.content().simplifyWhiteSpace());
|
| + EXPECT_EQ(5u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(8u, surroundingText.endOffsetInContent());
|
| + }
|
| +
|
| + {
|
| + VisibleSelection selection = select(0, 7);
|
| + SurroundingText surroundingText(selection.start(), selection.end(), 1337);
|
| +
|
| + EXPECT_EQ("This is outside of foo bar the selected node", surroundingText.content().simplifyWhiteSpace());
|
| + EXPECT_EQ(20u, surroundingText.startOffsetInContent());
|
| + EXPECT_EQ(27u, surroundingText.endOffsetInContent());
|
| }
|
| }
|
|
|
|
|