| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/Position.h" | 5 #include "core/editing/Position.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 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 EXPECT_EQ(t2, Position::inParentAfterNode(*n2).nodeAsRangeLastNode()); | 90 EXPECT_EQ(t2, Position::inParentAfterNode(*n2).nodeAsRangeLastNode()); |
| 91 EXPECT_EQ(t3, Position::afterNode(host).nodeAsRangeLastNode()); | 91 EXPECT_EQ(t3, Position::afterNode(host).nodeAsRangeLastNode()); |
| 92 | 92 |
| 93 EXPECT_EQ(t2, PositionInFlatTree::inParentBeforeNode(*n1).nodeAsRangeLastNod
e()); | 93 EXPECT_EQ(t2, PositionInFlatTree::inParentBeforeNode(*n1).nodeAsRangeLastNod
e()); |
| 94 EXPECT_EQ(a, PositionInFlatTree::inParentBeforeNode(*n2).nodeAsRangeLastNode
()); | 94 EXPECT_EQ(a, PositionInFlatTree::inParentBeforeNode(*n2).nodeAsRangeLastNode
()); |
| 95 EXPECT_EQ(t1, PositionInFlatTree::inParentAfterNode(*n1).nodeAsRangeLastNode
()); | 95 EXPECT_EQ(t1, PositionInFlatTree::inParentAfterNode(*n1).nodeAsRangeLastNode
()); |
| 96 EXPECT_EQ(t2, PositionInFlatTree::inParentAfterNode(*n2).nodeAsRangeLastNode
()); | 96 EXPECT_EQ(t2, PositionInFlatTree::inParentAfterNode(*n2).nodeAsRangeLastNode
()); |
| 97 EXPECT_EQ(t1, PositionInFlatTree::afterNode(host).nodeAsRangeLastNode()); | 97 EXPECT_EQ(t1, PositionInFlatTree::afterNode(host).nodeAsRangeLastNode()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(PositionTest, normalize) |
| 101 { |
| 102 setBodyContent("<div id=one>11<b id=two>22</b>33<i id=four></i></div>"); |
| 103 Node* one = document().getElementById("one"); |
| 104 Node* two = document().getElementById("two"); |
| 105 Node* three = two->nextSibling(); |
| 106 Node* four = document().getElementById("four"); |
| 107 |
| 108 EXPECT_EQ(Position::beforeNode(one), Position::normalize(Position(document()
.body(), 0))) |
| 109 << "OffsetInContainer becomes BeforeNode."; |
| 110 |
| 111 EXPECT_EQ(Position::afterNode(one), Position::normalize(Position(document().
body(), 1))) |
| 112 << "OffsetInContainer becomes AfterNode if there are no next siblings."; |
| 113 |
| 114 EXPECT_EQ(Position::beforeNode(one), Position::normalize(Position::beforeNod
e(one))) |
| 115 << "BeforeNode of non-Text node is normalized position."; |
| 116 |
| 117 EXPECT_EQ(Position::afterNode(one), Position::normalize(Position::afterNode(
one))) |
| 118 << "AfterNode w/o next sibling is normalized position."; |
| 119 |
| 120 EXPECT_EQ(Position(one->firstChild(), 0), Position::normalize(Position(one,
0))) |
| 121 << "OffsetInAnchor to Text node becomes Text position."; |
| 122 |
| 123 EXPECT_EQ(Position(one->firstChild(), 0), Position::normalize(Position::firs
tPositionInNode(one))) |
| 124 << "BeforeChildren becomes BeforeNode of first child."; |
| 125 |
| 126 EXPECT_EQ(Position::afterNode(four), Position::normalize(Position::lastPosit
ionInNode(one))) |
| 127 << "AfterChildren becomes AfterNode of last child."; |
| 128 |
| 129 EXPECT_EQ(Position(one->firstChild(), 1), Position::normalize(Position(one->
firstChild(), 1))) |
| 130 << "Inbound Text node position is normalized position"; |
| 131 |
| 132 EXPECT_EQ(Position::beforeNode(two), Position::normalize(Position(one->first
Child(), 2))) |
| 133 << "End of Text node becomes BeforeNode of next sibling"; |
| 134 |
| 135 EXPECT_EQ(Position(two->firstChild(), 0), Position::normalize(Position::befo
reNode(two->firstChild()))) |
| 136 << "BeforeNode of Text node is first position at Text node."; |
| 137 |
| 138 EXPECT_EQ(Position(two->firstChild(), 2), Position::normalize(Position::afte
rNode(two->firstChild()))) |
| 139 << "AfterNode of Text node becomes end of Text node if no next sibling."
; |
| 140 |
| 141 EXPECT_EQ(Position(two->firstChild(), 2), Position::normalize(Position(two->
firstChild(), 2))) |
| 142 << "End of text is normalized position if there are no next siblings."; |
| 143 |
| 144 EXPECT_EQ(Position::beforeNode(four), Position::normalize(Position(three, 2)
)) |
| 145 << "End of Text node => BeforeNode of next sibling."; |
| 146 |
| 147 EXPECT_EQ(Position::beforeNode(four), Position::normalize(Position::afterNod
e(three))) |
| 148 << "AfterAnchor => BeforeAnchor if there is a next sibling."; |
| 149 |
| 150 EXPECT_EQ(Position::firstPositionInNode(four), Position::normalize(Position:
:firstPositionInNode(four))) |
| 151 << "Since container has no children, BeforeChildren is normalized positi
on."; |
| 152 |
| 153 EXPECT_EQ(Position::firstPositionInNode(four), Position::normalize(Position:
:lastPositionInNode(four))) |
| 154 << "Since container has no children, AfterChildren == BeforeChildren."; |
| 155 } |
| 156 |
| 100 TEST_F(PositionTest, ToPositionInFlatTreeWithActiveInsertionPoint) | 157 TEST_F(PositionTest, ToPositionInFlatTreeWithActiveInsertionPoint) |
| 101 { | 158 { |
| 102 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; | 159 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; |
| 103 const char* shadowContent = "<a id='a'><content select=#one id='content'></c
ontent><content></content></a>"; | 160 const char* shadowContent = "<a id='a'><content select=#one id='content'></c
ontent><content></content></a>"; |
| 104 setBodyContent(bodyContent); | 161 setBodyContent(bodyContent); |
| 105 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 162 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 106 Element* anchor = shadowRoot->getElementById("a"); | 163 Element* anchor = shadowRoot->getElementById("a"); |
| 107 | 164 |
| 108 EXPECT_EQ(PositionInFlatTree(anchor, 0), toPositionInFlatTree(Position(ancho
r, 0))); | 165 EXPECT_EQ(PositionInFlatTree(anchor, 0), toPositionInFlatTree(Position(ancho
r, 0))); |
| 109 EXPECT_EQ(PositionInFlatTree(anchor, 1), toPositionInFlatTree(Position(ancho
r, 1))); | 166 EXPECT_EQ(PositionInFlatTree(anchor, 1), toPositionInFlatTree(Position(ancho
r, 1))); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; | 215 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; |
| 159 const char* shadowContent = ""; | 216 const char* shadowContent = ""; |
| 160 setBodyContent(bodyContent); | 217 setBodyContent(bodyContent); |
| 161 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 218 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 162 Element* host = document().getElementById("host"); | 219 Element* host = document().getElementById("host"); |
| 163 | 220 |
| 164 EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::AfterChildren), toPos
itionInFlatTree(Position(shadowRoot, 0))); | 221 EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::AfterChildren), toPos
itionInFlatTree(Position(shadowRoot, 0))); |
| 165 } | 222 } |
| 166 | 223 |
| 167 } // namespace blink | 224 } // namespace blink |
| OLD | NEW |