| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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/SelectionModifier.h" |
| 6 |
| 7 #include "core/editing/EditingTestBase.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 class SelectionModifierTest : public EditingTestBase {}; |
| 12 |
| 13 TEST_F(SelectionModifierTest, leftPositionOf) { |
| 14 const char* body_content = |
| 15 "<b id=zero>0</b><p id=host><b id=one>1</b><b id=two>22</b></p><b " |
| 16 "id=three>333</b>"; |
| 17 const char* shadow_content = |
| 18 "<b id=four>4444</b><content select=#two></content><content " |
| 19 "select=#one></content><b id=five>55555</b>"; |
| 20 SetBodyContent(body_content); |
| 21 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host"); |
| 22 |
| 23 Element* one = GetDocument().getElementById("one"); |
| 24 Element* two = GetDocument().getElementById("two"); |
| 25 Element* three = GetDocument().getElementById("three"); |
| 26 Element* four = shadow_root->getElementById("four"); |
| 27 Element* five = shadow_root->getElementById("five"); |
| 28 |
| 29 EXPECT_EQ( |
| 30 Position(two->firstChild(), 1), |
| 31 LeftPositionOf(CreateVisiblePosition(Position(one, 0))).DeepEquivalent()); |
| 32 EXPECT_EQ(PositionInFlatTree(two->firstChild(), 1), |
| 33 LeftPositionOf(CreateVisiblePosition(PositionInFlatTree(one, 0))) |
| 34 .DeepEquivalent()); |
| 35 |
| 36 EXPECT_EQ( |
| 37 Position(one->firstChild(), 0), |
| 38 LeftPositionOf(CreateVisiblePosition(Position(two, 0))).DeepEquivalent()); |
| 39 EXPECT_EQ(PositionInFlatTree(four->firstChild(), 3), |
| 40 LeftPositionOf(CreateVisiblePosition(PositionInFlatTree(two, 0))) |
| 41 .DeepEquivalent()); |
| 42 |
| 43 EXPECT_EQ(Position(two->firstChild(), 2), |
| 44 LeftPositionOf(CreateVisiblePosition(Position(three, 0))) |
| 45 .DeepEquivalent()); |
| 46 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 5), |
| 47 LeftPositionOf(CreateVisiblePosition(PositionInFlatTree(three, 0))) |
| 48 .DeepEquivalent()); |
| 49 } |
| 50 |
| 51 TEST_F(SelectionModifierTest, rightPositionOf) { |
| 52 const char* body_content = |
| 53 "<b id=zero>0</b><p id=host><b id=one>1</b><b id=two>22</b></p><b " |
| 54 "id=three>333</b>"; |
| 55 const char* shadow_content = |
| 56 "<p id=four>4444</p><content select=#two></content><content " |
| 57 "select=#one></content><p id=five>55555</p>"; |
| 58 SetBodyContent(body_content); |
| 59 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host"); |
| 60 |
| 61 Node* one = GetDocument().getElementById("one")->firstChild(); |
| 62 Node* two = GetDocument().getElementById("two")->firstChild(); |
| 63 Node* three = GetDocument().getElementById("three")->firstChild(); |
| 64 Node* four = shadow_root->getElementById("four")->firstChild(); |
| 65 Node* five = shadow_root->getElementById("five")->firstChild(); |
| 66 |
| 67 EXPECT_EQ(Position(), RightPositionOf(CreateVisiblePosition(Position(one, 1))) |
| 68 .DeepEquivalent()); |
| 69 EXPECT_EQ(PositionInFlatTree(five, 0), |
| 70 RightPositionOf(CreateVisiblePosition(PositionInFlatTree(one, 1))) |
| 71 .DeepEquivalent()); |
| 72 |
| 73 EXPECT_EQ(Position(one, 1), |
| 74 RightPositionOf(CreateVisiblePosition(Position(two, 2))) |
| 75 .DeepEquivalent()); |
| 76 EXPECT_EQ(PositionInFlatTree(one, 1), |
| 77 RightPositionOf(CreateVisiblePosition(PositionInFlatTree(two, 2))) |
| 78 .DeepEquivalent()); |
| 79 |
| 80 EXPECT_EQ(Position(five, 0), |
| 81 RightPositionOf(CreateVisiblePosition(Position(four, 4))) |
| 82 .DeepEquivalent()); |
| 83 EXPECT_EQ(PositionInFlatTree(two, 0), |
| 84 RightPositionOf(CreateVisiblePosition(PositionInFlatTree(four, 4))) |
| 85 .DeepEquivalent()); |
| 86 |
| 87 EXPECT_EQ(Position(), |
| 88 RightPositionOf(CreateVisiblePosition(Position(five, 5))) |
| 89 .DeepEquivalent()); |
| 90 EXPECT_EQ(PositionInFlatTree(three, 0), |
| 91 RightPositionOf(CreateVisiblePosition(PositionInFlatTree(five, 5))) |
| 92 .DeepEquivalent()); |
| 93 } |
| 94 |
| 95 } // namespace blink |
| OLD | NEW |