| Index: third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp b/third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp
|
| index 08b4238aa408db33f546d2b059607693931ec3dd..34f228790b127c5258c5d8da6b9f21e1b1827a27 100644
|
| --- a/third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/VisibleSelectionTest.cpp
|
| @@ -56,6 +56,17 @@ static void testFlatTreePositionsToEqualToDOMTreePositions(
|
| toPositionInDOMTree(selectionInFlatTree.extent()));
|
| }
|
|
|
| +template <typename Strategy>
|
| +VisibleSelectionTemplate<Strategy> expandUsingGranularity(
|
| + const VisibleSelectionTemplate<Strategy>& selection,
|
| + TextGranularity granularity) {
|
| + return createVisibleSelection(
|
| + typename SelectionTemplate<Strategy>::Builder()
|
| + .setBaseAndExtent(selection.base(), selection.extent())
|
| + .setGranularity(granularity)
|
| + .build());
|
| +}
|
| +
|
| TEST_F(VisibleSelectionTest, expandUsingGranularity) {
|
| const char* bodyContent =
|
| "<span id=host><a id=one>1</a><a id=two>22</a></span>";
|
| @@ -78,12 +89,13 @@ TEST_F(VisibleSelectionTest, expandUsingGranularity) {
|
| // From a position at distributed node
|
| selection = createVisibleSelection(
|
| SelectionInDOMTree::Builder().collapse(Position(one, 1)).build());
|
| - selection.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| selectionInFlatTree =
|
| createVisibleSelection(SelectionInFlatTree::Builder()
|
| .collapse(PositionInFlatTree(one, 1))
|
| .build());
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| EXPECT_EQ(Position(one, 1), selection.base());
|
| EXPECT_EQ(Position(one, 1), selection.extent());
|
| @@ -98,12 +110,13 @@ TEST_F(VisibleSelectionTest, expandUsingGranularity) {
|
| // From a position at distributed node
|
| selection = createVisibleSelection(
|
| SelectionInDOMTree::Builder().collapse(Position(two, 1)).build());
|
| - selection.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| selectionInFlatTree =
|
| createVisibleSelection(SelectionInFlatTree::Builder()
|
| .collapse(PositionInFlatTree(two, 1))
|
| .build());
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| EXPECT_EQ(Position(two, 1), selection.base());
|
| EXPECT_EQ(Position(two, 1), selection.extent());
|
| @@ -118,12 +131,13 @@ TEST_F(VisibleSelectionTest, expandUsingGranularity) {
|
| // From a position at node in shadow tree
|
| selection = createVisibleSelection(
|
| SelectionInDOMTree::Builder().collapse(Position(three, 1)).build());
|
| - selection.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| selectionInFlatTree =
|
| createVisibleSelection(SelectionInFlatTree::Builder()
|
| .collapse(PositionInFlatTree(three, 1))
|
| .build());
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| EXPECT_EQ(Position(three, 1), selection.base());
|
| EXPECT_EQ(Position(three, 1), selection.extent());
|
| @@ -138,12 +152,13 @@ TEST_F(VisibleSelectionTest, expandUsingGranularity) {
|
| // From a position at node in shadow tree
|
| selection = createVisibleSelection(
|
| SelectionInDOMTree::Builder().collapse(Position(four, 1)).build());
|
| - selection.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| selectionInFlatTree =
|
| createVisibleSelection(SelectionInFlatTree::Builder()
|
| .collapse(PositionInFlatTree(four, 1))
|
| .build());
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| EXPECT_EQ(Position(four, 1), selection.base());
|
| EXPECT_EQ(Position(four, 1), selection.extent());
|
| @@ -158,12 +173,13 @@ TEST_F(VisibleSelectionTest, expandUsingGranularity) {
|
| // From a position at node in shadow tree
|
| selection = createVisibleSelection(
|
| SelectionInDOMTree::Builder().collapse(Position(five, 1)).build());
|
| - selection.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| selectionInFlatTree =
|
| createVisibleSelection(SelectionInFlatTree::Builder()
|
| .collapse(PositionInFlatTree(five, 1))
|
| .build());
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| EXPECT_EQ(Position(five, 1), selection.base());
|
| EXPECT_EQ(Position(five, 1), selection.extent());
|
| @@ -323,8 +339,9 @@ TEST_F(VisibleSelectionTest, WordGranularity) {
|
| {
|
| setSelection(selection, 0);
|
| setSelection(selectionInFlatTree, 0);
|
| - selection.expandUsingGranularity(WordGranularity);
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| Range* range = firstRangeOf(selection);
|
| EXPECT_EQ(0, range->startOffset());
|
| @@ -338,8 +355,9 @@ TEST_F(VisibleSelectionTest, WordGranularity) {
|
| {
|
| setSelection(selection, 8);
|
| setSelection(selectionInFlatTree, 8);
|
| - selection.expandUsingGranularity(WordGranularity);
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| Range* range = firstRangeOf(selection);
|
| EXPECT_EQ(6, range->startOffset());
|
| @@ -355,8 +373,9 @@ TEST_F(VisibleSelectionTest, WordGranularity) {
|
| {
|
| setSelection(selection, 5);
|
| setSelection(selectionInFlatTree, 5);
|
| - selection.expandUsingGranularity(WordGranularity);
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| Range* range = firstRangeOf(selection);
|
| EXPECT_EQ(5, range->startOffset());
|
| @@ -372,8 +391,9 @@ TEST_F(VisibleSelectionTest, WordGranularity) {
|
| {
|
| setSelection(selection, 26);
|
| setSelection(selectionInFlatTree, 26);
|
| - selection.expandUsingGranularity(WordGranularity);
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| Range* range = firstRangeOf(selection);
|
| EXPECT_EQ(26, range->startOffset());
|
| @@ -387,8 +407,9 @@ TEST_F(VisibleSelectionTest, WordGranularity) {
|
| {
|
| setSelection(selection, 27);
|
| setSelection(selectionInFlatTree, 27);
|
| - selection.expandUsingGranularity(WordGranularity);
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| Range* range = firstRangeOf(selection);
|
| EXPECT_EQ(27, range->startOffset());
|
| @@ -402,8 +423,9 @@ TEST_F(VisibleSelectionTest, WordGranularity) {
|
| {
|
| setSelection(selection, 0, 1);
|
| setSelection(selectionInFlatTree, 0, 1);
|
| - selection.expandUsingGranularity(WordGranularity);
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| Range* range = firstRangeOf(selection);
|
| EXPECT_EQ(0, range->startOffset());
|
| @@ -417,8 +439,9 @@ TEST_F(VisibleSelectionTest, WordGranularity) {
|
| {
|
| setSelection(selection, 2, 8);
|
| setSelection(selectionInFlatTree, 2, 8);
|
| - selection.expandUsingGranularity(WordGranularity);
|
| - selectionInFlatTree.expandUsingGranularity(WordGranularity);
|
| + selection = expandUsingGranularity(selection, WordGranularity);
|
| + selectionInFlatTree =
|
| + expandUsingGranularity(selectionInFlatTree, WordGranularity);
|
|
|
| Range* range = firstRangeOf(selection);
|
| EXPECT_EQ(0, range->startOffset());
|
|
|