| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/editing/SelectionAdjuster.h" | 5 #include "core/editing/SelectionAdjuster.h" |
| 6 | 6 |
| 7 #include "core/editing/EditingTestBase.h" | 7 #include "core/editing/EditingTestBase.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 class SelectionAdjusterTest : public EditingTestBase {}; | 11 class SelectionAdjusterTest : public EditingTestBase {}; |
| 12 | 12 |
| 13 TEST_F(SelectionAdjusterTest, adjustSelectionInFlatTree) { | 13 TEST_F(SelectionAdjusterTest, adjustSelectionInFlatTree) { |
| 14 setBodyContent("<div id=sample>foo</div>"); | 14 setBodyContent("<div id=sample>foo</div>"); |
| 15 VisibleSelectionInFlatTree selectionInFlatTree; | 15 VisibleSelectionInFlatTree selectionInFlatTree; |
| 16 | 16 |
| 17 Node* const sample = document().getElementById("sample"); | 17 Node* const sample = document().getElementById("sample"); |
| 18 Node* const foo = sample->firstChild(); | 18 Node* const foo = sample->firstChild(); |
| 19 // Select "foo" | 19 // Select "foo" |
| 20 VisibleSelection selection = | 20 VisibleSelection selection = |
| 21 createVisibleSelection(Position(foo, 0), Position(foo, 3)); | 21 createVisibleSelection(SelectionInDOMTree::Builder() |
| 22 .collapse(Position(foo, 0)) |
| 23 .extend(Position(foo, 3)) |
| 24 .build()); |
| 22 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection); | 25 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection); |
| 23 EXPECT_EQ(PositionInFlatTree(foo, 0), selectionInFlatTree.start()); | 26 EXPECT_EQ(PositionInFlatTree(foo, 0), selectionInFlatTree.start()); |
| 24 EXPECT_EQ(PositionInFlatTree(foo, 3), selectionInFlatTree.end()); | 27 EXPECT_EQ(PositionInFlatTree(foo, 3), selectionInFlatTree.end()); |
| 25 } | 28 } |
| 26 | 29 |
| 27 TEST_F(SelectionAdjusterTest, adjustSelectionInDOMTree) { | 30 TEST_F(SelectionAdjusterTest, adjustSelectionInDOMTree) { |
| 28 setBodyContent("<div id=sample>foo</div>"); | 31 setBodyContent("<div id=sample>foo</div>"); |
| 29 VisibleSelection selection; | 32 VisibleSelection selection; |
| 30 | 33 |
| 31 Node* const sample = document().getElementById("sample"); | 34 Node* const sample = document().getElementById("sample"); |
| 32 Node* const foo = sample->firstChild(); | 35 Node* const foo = sample->firstChild(); |
| 33 // Select "foo" | 36 // Select "foo" |
| 34 VisibleSelectionInFlatTree selectionInFlatTree = | 37 VisibleSelectionInFlatTree selectionInFlatTree = |
| 35 createVisibleSelection(SelectionInFlatTree::Builder() | 38 createVisibleSelection(SelectionInFlatTree::Builder() |
| 36 .collapse(PositionInFlatTree(foo, 0)) | 39 .collapse(PositionInFlatTree(foo, 0)) |
| 37 .extend(PositionInFlatTree(foo, 3)) | 40 .extend(PositionInFlatTree(foo, 3)) |
| 38 .build()); | 41 .build()); |
| 39 SelectionAdjuster::adjustSelectionInDOMTree(&selection, selectionInFlatTree); | 42 SelectionAdjuster::adjustSelectionInDOMTree(&selection, selectionInFlatTree); |
| 40 EXPECT_EQ(Position(foo, 0), selection.start()); | 43 EXPECT_EQ(Position(foo, 0), selection.start()); |
| 41 EXPECT_EQ(Position(foo, 3), selection.end()); | 44 EXPECT_EQ(Position(foo, 3), selection.end()); |
| 42 } | 45 } |
| 43 | 46 |
| 44 } // namespace blink | 47 } // namespace blink |
| OLD | NEW |