Index: Source/core/editing/FrameSelectionTest.cpp |
diff --git a/Source/core/editing/FrameSelectionTest.cpp b/Source/core/editing/FrameSelectionTest.cpp |
index e40ed01019e3cce02718e89edbf67e8a956b3e46..478737d7faf97b25c01dcdac81dd63a0a6e234f1 100644 |
--- a/Source/core/editing/FrameSelectionTest.cpp |
+++ b/Source/core/editing/FrameSelectionTest.cpp |
@@ -10,6 +10,7 @@ |
#include "core/dom/Element.h" |
#include "core/dom/Text.h" |
#include "core/frame/FrameView.h" |
+#include "core/frame/Settings.h" |
#include "core/html/HTMLBodyElement.h" |
#include "core/html/HTMLDocument.h" |
#include "core/testing/DummyPageHolder.h" |
@@ -159,7 +160,8 @@ TEST_F(FrameSelectionTest, SelectWordAroundPosition) |
EXPECT_EQ_SELECTED_TEXT("Baz"); |
} |
-TEST_F(FrameSelectionTest, MoveRangeSelectionExtent) |
+// Test for MoveRangeSelectionExtent with the DefaultGranularityStrategy |
+TEST_F(FrameSelectionTest, MoveRangeSelectionExtentDefault) |
{ |
// "Foo Bar Baz," |
RefPtrWillBeRawPtr<Text> text = document().createTextNode("Foo Bar Baz,"); |
@@ -168,17 +170,130 @@ TEST_F(FrameSelectionTest, MoveRangeSelectionExtent) |
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, 9)), CharacterGranularity); |
- EXPECT_EQ_SELECTED_TEXT("ar B"); |
- // "Foo B|ar B>az," with the Word granularity. |
- selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 9)), WordGranularity); |
- EXPECT_EQ_SELECTED_TEXT("ar Baz"); |
- // "Fo<o B|ar Baz," with the Character granularity. |
- selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 2)), CharacterGranularity); |
- EXPECT_EQ_SELECTED_TEXT("o B"); |
- // "Fo<o B|ar Baz," with the Word granularity. |
- selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 2)), WordGranularity); |
- EXPECT_EQ_SELECTED_TEXT("Foo B"); |
+ selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 1))); |
+ EXPECT_EQ_SELECTED_TEXT("oo B"); |
+} |
+ |
+// Test for MoveRangeSelectionExtent with DirectionGranularityStrategy |
+TEST_F(FrameSelectionTest, MoveRangeSelectionExtentDirection) |
+{ |
+ RefPtrWillBeRawPtr<Text> text = document().createTextNode("abcdef ghij kl mnopqr stuvwx yzab,"); |
+ document().body()->appendChild(text); |
+ dummyPageHolder().frame().settings()->setSelectionStrategy(StrategyDirection); |
+ |
+ // "abcdef ghij kl mno|p>qr stuvwx yzab," (| 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))); |
+ EXPECT_EQ_SELECTED_TEXT("pq"); |
+ // "abcdef ghij kl mno|pqr> stuvwx yzab," |
+ selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 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))); |
+ 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))); |
+ 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 k<l mno|pqr stuvwx yzab," |
+ selection().moveRangeSelectionExtent(VisiblePosition(Position(text, 13))); |
+ EXPECT_EQ_SELECTED_TEXT("kl mno"); |
+ |
+ // 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). |
+ 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 "); |
} |
TEST_F(FrameSelectionTest, MoveRangeSelectionTest) |
@@ -203,5 +318,4 @@ TEST_F(FrameSelectionTest, MoveRangeSelectionTest) |
selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePosition(Position(text, 2)), WordGranularity); |
EXPECT_EQ_SELECTED_TEXT("Foo Bar"); |
} |
- |
} |