Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Unified Diff: third_party/WebKit/Source/core/editing/PositionTest.cpp

Issue 1756763002: 2016-03-02T18:53:01 LayoutPosition Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-04-25T19:02:18 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/PositionTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/PositionTest.cpp b/third_party/WebKit/Source/core/editing/PositionTest.cpp
index 97c036feea3e7f50af452ae4ea0c2a26563d0e98..a23d2067768a58a2aa5eb2ef5812934de2e575c0 100644
--- a/third_party/WebKit/Source/core/editing/PositionTest.cpp
+++ b/third_party/WebKit/Source/core/editing/PositionTest.cpp
@@ -97,6 +97,63 @@ TEST_F(PositionTest, NodeAsRangeLastNodeShadow)
EXPECT_EQ(t1, PositionInFlatTree::afterNode(host).nodeAsRangeLastNode());
}
+TEST_F(PositionTest, normalize)
+{
+ setBodyContent("<div id=one>11<b id=two>22</b>33<i id=four></i></div>");
+ Node* one = document().getElementById("one");
+ Node* two = document().getElementById("two");
+ Node* three = two->nextSibling();
+ Node* four = document().getElementById("four");
+
+ EXPECT_EQ(Position::beforeNode(one), Position::normalize(Position(document().body(), 0)))
+ << "OffsetInContainer becomes BeforeNode.";
+
+ EXPECT_EQ(Position::afterNode(one), Position::normalize(Position(document().body(), 1)))
+ << "OffsetInContainer becomes AfterNode if there are no next siblings.";
+
+ EXPECT_EQ(Position::beforeNode(one), Position::normalize(Position::beforeNode(one)))
+ << "BeforeNode of non-Text node is normalized position.";
+
+ EXPECT_EQ(Position::afterNode(one), Position::normalize(Position::afterNode(one)))
+ << "AfterNode w/o next sibling is normalized position.";
+
+ EXPECT_EQ(Position(one->firstChild(), 0), Position::normalize(Position(one, 0)))
+ << "OffsetInAnchor to Text node becomes Text position.";
+
+ EXPECT_EQ(Position(one->firstChild(), 0), Position::normalize(Position::firstPositionInNode(one)))
+ << "BeforeChildren becomes BeforeNode of first child.";
+
+ EXPECT_EQ(Position::afterNode(four), Position::normalize(Position::lastPositionInNode(one)))
+ << "AfterChildren becomes AfterNode of last child.";
+
+ EXPECT_EQ(Position(one->firstChild(), 1), Position::normalize(Position(one->firstChild(), 1)))
+ << "Inbound Text node position is normalized position";
+
+ EXPECT_EQ(Position::beforeNode(two), Position::normalize(Position(one->firstChild(), 2)))
+ << "End of Text node becomes BeforeNode of next sibling";
+
+ EXPECT_EQ(Position(two->firstChild(), 0), Position::normalize(Position::beforeNode(two->firstChild())))
+ << "BeforeNode of Text node is first position at Text node.";
+
+ EXPECT_EQ(Position(two->firstChild(), 2), Position::normalize(Position::afterNode(two->firstChild())))
+ << "AfterNode of Text node becomes end of Text node if no next sibling.";
+
+ EXPECT_EQ(Position(two->firstChild(), 2), Position::normalize(Position(two->firstChild(), 2)))
+ << "End of text is normalized position if there are no next siblings.";
+
+ EXPECT_EQ(Position::beforeNode(four), Position::normalize(Position(three, 2)))
+ << "End of Text node => BeforeNode of next sibling.";
+
+ EXPECT_EQ(Position::beforeNode(four), Position::normalize(Position::afterNode(three)))
+ << "AfterAnchor => BeforeAnchor if there is a next sibling.";
+
+ EXPECT_EQ(Position::firstPositionInNode(four), Position::normalize(Position::firstPositionInNode(four)))
+ << "Since container has no children, BeforeChildren is normalized position.";
+
+ EXPECT_EQ(Position::firstPositionInNode(four), Position::normalize(Position::lastPositionInNode(four)))
+ << "Since container has no children, AfterChildren == BeforeChildren.";
+}
+
TEST_F(PositionTest, ToPositionInFlatTreeWithActiveInsertionPoint)
{
const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>";
« no previous file with comments | « third_party/WebKit/Source/core/editing/Position.cpp ('k') | third_party/WebKit/Source/core/editing/PositionWithAffinity.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698