| Index: Source/core/editing/FrameSelectionTest.cpp
|
| diff --git a/Source/core/editing/FrameSelectionTest.cpp b/Source/core/editing/FrameSelectionTest.cpp
|
| index 54bd4d02d634b461740cfc14f3c24cd45c981891..8f6115459531f1fcb38712ebd88d25e1a7303098 100644
|
| --- a/Source/core/editing/FrameSelectionTest.cpp
|
| +++ b/Source/core/editing/FrameSelectionTest.cpp
|
| @@ -71,6 +71,35 @@ PassRefPtrWillBeRawPtr<Text> FrameSelectionTest::appendTextNode(const String& da
|
| return text.release();
|
| }
|
|
|
| +IntPoint visiblePositionToContentsPoint(const VisiblePosition& pos)
|
| +{
|
| + return pos.absoluteCaretBounds().minXMinYCorner();
|
| +}
|
| +
|
| +// Parses a text node populating the supplied vectors with positions of letters
|
| +// and words middles in the text. Whitespaces are not considered as separate words.
|
| +void parseString(Text* text, std::vector<IntPoint>& letterPos, std::vector<IntPoint>& wordMiddles)
|
| +{
|
| + WTF::String str = text->wholeText();
|
| + int wordStartIndex = -1;
|
| + for (size_t i = 0; i < str.length(); i++) {
|
| + letterPos.push_back(visiblePositionToContentsPoint(VisiblePosition(Position(text, i))));
|
| + char c = str.characterAt(i);
|
| + if (isASCIIAlphanumeric(c) && wordStartIndex < 0) {
|
| + wordStartIndex = i;
|
| + } else if (!isASCIIAlphanumeric(c) && wordStartIndex >= 0) {
|
| + IntPoint wordMiddle((letterPos[wordStartIndex].x() + letterPos[i].x()) / 2, letterPos[wordStartIndex].y());
|
| + wordMiddles.push_back(wordMiddle);
|
| + wordStartIndex = -1;
|
| + }
|
| + }
|
| + if (wordStartIndex >=0) {
|
| + int xEnd = visiblePositionToContentsPoint(VisiblePosition(Position(text, str.length()))).x();
|
| + IntPoint wordMiddle((letterPos[wordStartIndex].x() + xEnd) / 2, letterPos[wordStartIndex].y());
|
| + wordMiddles.push_back(wordMiddle);
|
| + }
|
| +}
|
| +
|
| TEST_F(FrameSelectionTest, SetValidSelection)
|
| {
|
| RefPtrWillBeRawPtr<Text> text = appendTextNode("Hello, World!");
|
| @@ -170,136 +199,257 @@ TEST_F(FrameSelectionTest, SelectWordAroundPosition)
|
| // Test for MoveRangeSelectionExtent with the default CharacterGranularityStrategy
|
| TEST_F(FrameSelectionTest, MoveRangeSelectionExtentCharacter)
|
| {
|
| + dummyPageHolder().frame().settings()->setDefaultFontSize(12);
|
| // "Foo Bar Baz,"
|
| RefPtrWillBeRawPtr<Text> text = appendTextNode("Foo Bar Baz,");
|
| - // "Foo B|a>r Baz," (| means start and > means end).
|
| + // "Foo B^a|r Baz," (^ means base and | means extent).
|
| selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6)));
|
| EXPECT_EQ_SELECTED_TEXT("a");
|
| - // "Foo B|ar B>az," with the Character granularity.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 1)));
|
| + // "Foo B^ar B|az,"
|
| + selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(VisiblePosition(Position(text, 9))));
|
| + EXPECT_EQ_SELECTED_TEXT("ar B");
|
| + // "F|oo B^ar Baz,"
|
| + selection().moveRangeSelectionExtent(visiblePositionToContentsPoint(VisiblePosition(Position(text, 1))));
|
| EXPECT_EQ_SELECTED_TEXT("oo B");
|
| }
|
|
|
| // Test for MoveRangeSelectionExtent with DirectionGranularityStrategy
|
| -TEST_F(FrameSelectionTest, MoveRangeSelectionExtentDirection)
|
| +TEST_F(FrameSelectionTest, MoveRangeSelectionExtentDirectionExpand)
|
| {
|
| - RefPtrWillBeRawPtr<Text> text = document().createTextNode("abcdef ghij kl mnopqr stuvwx yzab,");
|
| + dummyPageHolder().frame().settings()->setDefaultFontSize(12);
|
| + WTF::String str = "abcdef ghij kl mnopqr stuvwi inm,";
|
| + RefPtrWillBeRawPtr<Text> text = document().createTextNode(str);
|
| document().body()->appendChild(text);
|
| dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy::Direction);
|
|
|
| - // "abcdef ghij kl mno|p>qr stuvwx yzab," (| means start and > means end).
|
| + std::vector<IntPoint> letterPos;
|
| + std::vector<IntPoint> wordMiddlePos;
|
| + parseString(text.get(), letterPos, wordMiddlePos);
|
| +
|
| + // "abcdef ghij kl mno^p|>qr stuvwi inm," (^ means base, | means extent, < means start, and > means end).
|
| selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 19)));
|
| EXPECT_EQ_SELECTED_TEXT("p");
|
| - // "abcdef ghij kl mno|pq>r stuvwx yzab," - expand selection using character granularity
|
| - // until the end of the word is reached.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 20)));
|
| + // Expand selection using character granularity until the end of the word
|
| + // is reached.
|
| + // "abcdef ghij kl mno^pq|>r stuvwi inm,"
|
| + selection().moveRangeSelectionExtent(letterPos[20]);
|
| + EXPECT_EQ_SELECTED_TEXT("pq");
|
| + // Move to the same postion shouldn't change anything.
|
| + selection().moveRangeSelectionExtent(letterPos[20]);
|
| EXPECT_EQ_SELECTED_TEXT("pq");
|
| - // "abcdef ghij kl mno|pqr> stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 21)));
|
| + // "abcdef ghij kl mno^pqr|> stuvwi inm,"
|
| + selection().moveRangeSelectionExtent(letterPos[21]);
|
| EXPECT_EQ_SELECTED_TEXT("pqr");
|
| - // "abcdef ghij kl mno|pqr >stuvwx yzab," - confirm selection doesn't
|
| - // jump over the beginning of the word.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 22)));
|
| + // Selection should stay the same until the middle of the word is passed.
|
| + // "abcdef ghij kl mno^pqr |>stuvwi inm," -
|
| + selection().moveRangeSelectionExtent(letterPos[22]);
|
| EXPECT_EQ_SELECTED_TEXT("pqr ");
|
| - // "abcdef ghij kl mno|pqr s>tuvwx yzab," - confirm selection switches to word granularity.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 23)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvwx");
|
| - // "abcdef ghij kl mno|pqr stu>vwx yzab," - selection stays the same.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 25)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvwx");
|
| - // "abcdef ghij kl mno|pqr stuvwx yz>ab," - next word.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 31)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvwx yzab");
|
| - // "abcdef ghij kl mno|pqr stuvwx y>zab," - move back one character -
|
| - // confirm switch to character granularity.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 30)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvwx y");
|
| - // "abcdef ghij kl mno|pqr stuvwx yz>ab," - stay in character granularity
|
| - // if the user moves the position within the word.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 31)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvwx yz");
|
| - // "abcdef ghij kl mno|pqr stuvwx >yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 29)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvwx ");
|
| - // "abcdef ghij kl mno|pqr stuvwx >yzab," - it's possible to get a move when
|
| - // position doesn't change. It shouldn't affect anything.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 29)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvwx ");
|
| - // "abcdef ghij kl mno|pqr stuvwx y>zab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 30)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvwx y");
|
| - // "abcdef ghij kl mno|pqr stuv>wx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 26)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuv");
|
| - // "abcdef ghij kl mno|pqr stuvw>x yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 27)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvw");
|
| - // "abcdef ghij kl mno|pqr stuvwx y>zab," - switch to word granularity
|
| - // after expanding beyond the word boundary
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 30)));
|
| - EXPECT_EQ_SELECTED_TEXT("pqr stuvwx yzab");
|
| - // "abcdef ghij kl mn<o|pqr stuvwx yzab," - over to the other side of the base
|
| - // - stay in character granularity until the beginning of the word is passed.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 17)));
|
| - EXPECT_EQ_SELECTED_TEXT("o");
|
| - // "abcdef ghij kl m<no|pqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 16)));
|
| - EXPECT_EQ_SELECTED_TEXT("no");
|
| - // "abcdef ghij kl <mno|pqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 15)));
|
| - EXPECT_EQ_SELECTED_TEXT("mno");
|
| - // "abcdef ghij kl mn<o|pqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 17)));
|
| - EXPECT_EQ_SELECTED_TEXT("o");
|
| - // "abcdef ghij k<l mno|pqr stuvwx yzab," - switch to word granularity
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 13)));
|
| - EXPECT_EQ_SELECTED_TEXT("kl mno");
|
| - // "abcd<ef ghij kl mno|pqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 4)));
|
| - EXPECT_EQ_SELECTED_TEXT("abcdef ghij kl mno");
|
| - // "abcde<f ghij kl mno|pqr stuvwx yzab," - decrease selection -
|
| - // switch back to character granularity.
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 5)));
|
| - EXPECT_EQ_SELECTED_TEXT("f ghij kl mno");
|
| - // "abcdef ghij kl mn<o|pqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 17)));
|
| + // "abcdef ghij kl mno^pqr >st|uvwi inm,"
|
| + selection().moveRangeSelectionExtent(letterPos[24]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr ");
|
| + IntPoint p = wordMiddlePos[4];
|
| + p.move(-1, 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr ");
|
| + p.move(1, 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr stuvwi");
|
| + // Selection should stay the same until the end of the word is reached.
|
| + // "abcdef ghij kl mno^pqr stuvw|i> inm,"
|
| + selection().moveRangeSelectionExtent(letterPos[27]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr stuvwi");
|
| + // "abcdef ghij kl mno^pqr stuvwi|> inm,"
|
| + selection().moveRangeSelectionExtent(letterPos[28]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr stuvwi");
|
| + // "abcdef ghij kl mno^pqr stuvwi |>inm,"
|
| + selection().moveRangeSelectionExtent(letterPos[29]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr stuvwi ");
|
| +}
|
| +
|
| +TEST_F(FrameSelectionTest, MoveRangeSelectionExtentDirectionShrink)
|
| +{
|
| + dummyPageHolder().frame().settings()->setDefaultFontSize(12);
|
| + WTF::String str = "abcdef ghij kl mnopqr iiinmni, abc";
|
| + RefPtrWillBeRawPtr<Text> text = document().createTextNode(str);
|
| + document().body()->appendChild(text);
|
| + dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy::Direction);
|
| +
|
| + std::vector<IntPoint> letterPos;
|
| + std::vector<IntPoint> wordMiddlePos;
|
| + parseString(text.get(), letterPos, wordMiddlePos);
|
| +
|
| + // "abcdef ghij kl mno^pqr|> iiinmni, abc" (^ means base, | means extent, < means start, and > means end).
|
| + selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21)));
|
| + EXPECT_EQ_SELECTED_TEXT("pqr");
|
| + // Move to the middle of word #4 to it and then move back, confirming
|
| + // that the selection end is moving with the extent. The offset between the
|
| + // extent and the selection end will be equal to half the width of "iiinmni".
|
| + selection().moveRangeSelectionExtent(wordMiddlePos[4]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr iiinmni");
|
| + IntPoint p = wordMiddlePos[4];
|
| + p.move(letterPos[28].x() - letterPos[29].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr iiinmn");
|
| + p.move(letterPos[27].x() - letterPos[28].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr iiinm");
|
| + p.move(letterPos[26].x() - letterPos[27].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr iiin");
|
| + // Move right by the width of char 30 ('m'). Selection shouldn't change,
|
| + // but offset should be reduced.
|
| + p.move(letterPos[27].x() - letterPos[26].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr iiin");
|
| + // Move back a couple of character widths and confirm the selection still
|
| + // updates accordingly.
|
| + p.move(letterPos[25].x() - letterPos[26].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr iii");
|
| + p.move(letterPos[24].x() - letterPos[25].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr ii");
|
| + // "Catch up" with the handle - move the extent to where the handle is.
|
| + // "abcdef ghij kl mno^pqr ii|>inmni, abc"
|
| + selection().moveRangeSelectionExtent(letterPos[24]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr ii");
|
| + // Move ahead and confirm the selection expands accordingly
|
| + // "abcdef ghij kl mno^pqr iii|>nmni, abc"
|
| + selection().moveRangeSelectionExtent(letterPos[25]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr iii");
|
| +
|
| + // Confirm we stay in character granularity if the user moves within a word.
|
| + // "abcdef ghij kl mno^pqr |>iiinmni, abc"
|
| + selection().moveRangeSelectionExtent(letterPos[22]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr ");
|
| + // It's possible to get a move when position doesn't change.
|
| + // It shouldn't affect anything.
|
| + p = letterPos[22];
|
| + p.move(1, 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr ");
|
| + // "abcdef ghij kl mno^pqr i|>iinmni, abc"
|
| + selection().moveRangeSelectionExtent(letterPos[23]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr i");
|
| +}
|
| +
|
| +TEST_F(FrameSelectionTest, MoveRangeSelectionExtentDirectionSwitchSide)
|
| +{
|
| + dummyPageHolder().frame().settings()->setDefaultFontSize(12);
|
| + WTF::String str = "abcd efgh ijkl mnopqr iiinmni, abc";
|
| + RefPtrWillBeRawPtr<Text> text = document().createTextNode(str);
|
| + document().body()->appendChild(text);
|
| + dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy::Direction);
|
| +
|
| + std::vector<IntPoint> letterPos;
|
| + std::vector<IntPoint> wordMiddlePos;
|
| + parseString(text.get(), letterPos, wordMiddlePos);
|
| +
|
| + // "abcd efgh ijkl mno^pqr|> iiinmni, abc" (^ means base, | means extent, < means start, and > means end).
|
| + selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21)));
|
| + EXPECT_EQ_SELECTED_TEXT("pqr");
|
| + // Move to the middle of word #4, selecting it - this will set the offset to
|
| + // be half the width of "iiinmni.
|
| + selection().moveRangeSelectionExtent(wordMiddlePos[4]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr iiinmni");
|
| + // Move back leaving only one letter selected.
|
| + IntPoint p = wordMiddlePos[4];
|
| + p.move(letterPos[19].x() - letterPos[29].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("p");
|
| + // Confirm selection doesn't change if extent is positioned at base.
|
| + p.move(letterPos[18].x() - letterPos[19].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("p");
|
| + // Move over to the other side of the base. Confirm the offset is preserved.
|
| + // (i.e. the selection start stays on the right of the extent)
|
| + // Confirm we stay in character granularity until the beginning of the word
|
| + // is passed.
|
| + p.move(letterPos[17].x() - letterPos[18].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| EXPECT_EQ_SELECTED_TEXT("o");
|
| - // "abcdef ghij kl m<no|pqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 16)));
|
| + p.move(letterPos[16].x() - letterPos[17].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| EXPECT_EQ_SELECTED_TEXT("no");
|
| - // "abcdef ghij k<l mno|pqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 13)));
|
| - EXPECT_EQ_SELECTED_TEXT("kl mno");
|
| + p.move(letterPos[14].x() - letterPos[16].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT(" mno");
|
| + // Move to just one pixel on the right before the middle of the word #2.
|
| + // We should switch to word granularity, so the selection shouldn't change.
|
| + p.move(wordMiddlePos[2].x() - letterPos[14].x() + 1, 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT(" mno");
|
| + // Move over the middle of the word. The word should get selected.
|
| + // This should reduce the offset, but it should still stay greated than 0,
|
| + // since the width of "iiinmni" is greater than the width of "ijkl".
|
| + p.move(-2, 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("ijkl mno");
|
| + // Move to just one pixel on the right of the middle of word #1.
|
| + // The selection should now include the space between the words.
|
| + p.move(wordMiddlePos[1].x() - letterPos[10].x() + 1, 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT(" ijkl mno");
|
| + // Move over the middle of the word. The word should get selected.
|
| + p.move(-2, 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("efgh ijkl mno");
|
| +}
|
| +
|
| +// Tests moving extent over to the other side of the vase and immediately
|
| +// passing the word boundary and going into word granularity.
|
| +TEST_F(FrameSelectionTest, MoveRangeSelectionExtentDirectionSwitchSideWordGranularityThenShrink)
|
| +{
|
| + dummyPageHolder().frame().settings()->setDefaultFontSize(12);
|
| + WTF::String str = "ab cd efghijkl mnopqr iiin, abc";
|
| + RefPtrWillBeRawPtr<Text> text = document().createTextNode(str);
|
| + document().body()->appendChild(text);
|
| + dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy::Direction);
|
| +
|
| + std::vector<IntPoint> letterPos;
|
| + std::vector<IntPoint> wordMiddlePos;
|
| + parseString(text.get(), letterPos, wordMiddlePos);
|
| +
|
| + // "abcd efgh ijkl mno^pqr|> iiin, abc" (^ means base, | means extent, < means start, and > means end).
|
| + selection().setSelection(VisibleSelection(Position(text, 18), Position(text, 21)));
|
| + EXPECT_EQ_SELECTED_TEXT("pqr");
|
| + // Move to the middle of word #4 selecting it - this will set the offset to
|
| + // be half the width of "iiin".
|
| + selection().moveRangeSelectionExtent(wordMiddlePos[4]);
|
| + EXPECT_EQ_SELECTED_TEXT("pqr iiin");
|
| + // Move to the middle of word #2 - extent will switch over to the other
|
| + // side of the base, and we should enter word granularity since we pass
|
| + // the word boundary. The offset should become negative since the width
|
| + // of "efghjkkl" is greater than that of "iiin".
|
| + int offset = letterPos[26].x() - wordMiddlePos[4].x();
|
| + IntPoint p = IntPoint(wordMiddlePos[2].x() - offset - 1, wordMiddlePos[2].y());
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("efghijkl mno");
|
| + p.move(letterPos[7].x() - letterPos[6].x(), 0);
|
| + selection().moveRangeSelectionExtent(p);
|
| + EXPECT_EQ_SELECTED_TEXT("fghijkl mno");
|
| +}
|
| +
|
| +// Make sure we switch to word granularity right away when starting on a
|
| +// word boundary and extending.
|
| +TEST_F(FrameSelectionTest, MoveRangeSelectionExtentDirectionSwitchStartOnBoundary)
|
| +{
|
| + dummyPageHolder().frame().settings()->setDefaultFontSize(12);
|
| + WTF::String str = "ab cd efghijkl mnopqr iiin, abc";
|
| + RefPtrWillBeRawPtr<Text> text = document().createTextNode(str);
|
| + document().body()->appendChild(text);
|
| + dummyPageHolder().frame().settings()->setSelectionStrategy(SelectionStrategy::Direction);
|
| +
|
| + std::vector<IntPoint> letterPos;
|
| + std::vector<IntPoint> wordMiddlePos;
|
| + parseString(text.get(), letterPos, wordMiddlePos);
|
|
|
| - // Make sure we switch to word granularity right away when starting on a
|
| - // word boundary and extending.
|
| - // "abcdef ghij kl |mnopqr >stuvwx yzab," (| means start and > means end).
|
| + // "ab cd efghijkl ^mnopqr |>stuvwi inm," (^ means base and | means extent,
|
| + // > means end).
|
| selection().setSelection(VisibleSelection(Position(text, 15), Position(text, 22)));
|
| EXPECT_EQ_SELECTED_TEXT("mnopqr ");
|
| - // "abcdef ghij kl |mnopqr s>tuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 23)));
|
| - EXPECT_EQ_SELECTED_TEXT("mnopqr stuvwx");
|
| -
|
| - // Make sure we start in character granularity when moving extent over to the other
|
| - // side of the base.
|
| - // "abcdef| ghij> kl mnopqr stuvwx yzab," (| means start and > means end).
|
| - selection().setSelection(VisibleSelection(Position(text, 6), Position(text, 11)));
|
| - EXPECT_EQ_SELECTED_TEXT(" ghij");
|
| - // "abcde<f| ghij kl mnopqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 5)));
|
| - EXPECT_EQ_SELECTED_TEXT("f");
|
| -
|
| - // Make sure we switch to word granularity when moving over to the other
|
| - // side of the base and then passing over the word boundary.
|
| - // "abcdef |ghij> kl mnopqr stuvwx yzab,"
|
| - selection().setSelection(VisibleSelection(Position(text, 7), Position(text, 11)));
|
| - EXPECT_EQ_SELECTED_TEXT("ghij");
|
| - // "abcdef< |ghij kl mnopqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 6)));
|
| - EXPECT_EQ_SELECTED_TEXT(" ");
|
| - // "abcde<f |ghij kl mnopqr stuvwx yzab,"
|
| - selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 5)));
|
| - EXPECT_EQ_SELECTED_TEXT("abcdef ");
|
| + selection().moveRangeSelectionExtent(wordMiddlePos[4]);
|
| + EXPECT_EQ_SELECTED_TEXT("mnopqr iiin");
|
| }
|
|
|
| TEST_F(FrameSelectionTest, MoveRangeSelectionTest)
|
|
|