OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/editing/SelectionAdjuster.h" | |
6 | |
7 #include "core/editing/EditingTestBase.h" | |
8 | |
9 namespace blink { | |
10 | |
11 class SelectionAdjusterTest : public EditingTestBase {}; | |
12 | |
13 TEST_F(SelectionAdjusterTest, adjustSelectionInFlatTree) { | |
14 setBodyContent("<div id=sample>foo</div>"); | |
15 VisibleSelectionInFlatTree selectionInFlatTree; | |
16 | |
17 Node* const sample = document().getElementById("sample"); | |
18 Node* const foo = sample->firstChild(); | |
19 // Select "foo" | |
20 VisibleSelection selection = | |
21 createVisibleSelection(SelectionInDOMTree::Builder() | |
22 .collapse(Position(foo, 0)) | |
23 .extend(Position(foo, 3)) | |
24 .build()); | |
25 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection); | |
26 EXPECT_EQ(PositionInFlatTree(foo, 0), selectionInFlatTree.start()); | |
27 EXPECT_EQ(PositionInFlatTree(foo, 3), selectionInFlatTree.end()); | |
28 } | |
29 | |
30 TEST_F(SelectionAdjusterTest, adjustSelectionInDOMTree) { | |
31 setBodyContent("<div id=sample>foo</div>"); | |
32 VisibleSelection selection; | |
33 | |
34 Node* const sample = document().getElementById("sample"); | |
35 Node* const foo = sample->firstChild(); | |
36 // Select "foo" | |
37 VisibleSelectionInFlatTree selectionInFlatTree = | |
38 createVisibleSelection(SelectionInFlatTree::Builder() | |
39 .collapse(PositionInFlatTree(foo, 0)) | |
40 .extend(PositionInFlatTree(foo, 3)) | |
41 .build()); | |
42 SelectionAdjuster::adjustSelectionInDOMTree(&selection, selectionInFlatTree); | |
43 EXPECT_EQ(Position(foo, 0), selection.start()); | |
44 EXPECT_EQ(Position(foo, 3), selection.end()); | |
45 } | |
46 | |
47 } // namespace blink | |
OLD | NEW |