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 "config.h" | 5 #include "config.h" |
6 #include "core/editing/Position.h" | 6 #include "core/editing/Position.h" |
7 | 7 |
8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 EXPECT_EQ(p2, PositionInComposedTree::inParentAfterNode(*p2).nodeAsRangeLast
Node()); | 44 EXPECT_EQ(p2, PositionInComposedTree::inParentAfterNode(*p2).nodeAsRangeLast
Node()); |
45 EXPECT_EQ(t3, PositionInComposedTree::inParentAfterNode(*p3).nodeAsRangeLast
Node()); | 45 EXPECT_EQ(t3, PositionInComposedTree::inParentAfterNode(*p3).nodeAsRangeLast
Node()); |
46 EXPECT_EQ(t3, PositionInComposedTree::afterNode(p3).nodeAsRangeLastNode()); | 46 EXPECT_EQ(t3, PositionInComposedTree::afterNode(p3).nodeAsRangeLastNode()); |
47 } | 47 } |
48 | 48 |
49 TEST_F(PositionTest, NodeAsRangeLastNodeShadow) | 49 TEST_F(PositionTest, NodeAsRangeLastNodeShadow) |
50 { | 50 { |
51 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 51 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
52 const char* shadowContent = "<a id='a'><content select=#two></content><conte
nt select=#one></content></a>"; | 52 const char* shadowContent = "<a id='a'><content select=#two></content><conte
nt select=#one></content></a>"; |
53 setBodyContent(bodyContent); | 53 setBodyContent(bodyContent); |
54 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 54 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
55 | 55 |
56 Node* host = document().getElementById("host"); | 56 Node* host = document().getElementById("host"); |
57 Node* n1 = document().getElementById("one"); | 57 Node* n1 = document().getElementById("one"); |
58 Node* n2 = document().getElementById("two"); | 58 Node* n2 = document().getElementById("two"); |
59 Node* t0 = EditingStrategy::firstChild(*host); | 59 Node* t0 = EditingStrategy::firstChild(*host); |
60 Node* t1 = EditingStrategy::firstChild(*n1); | 60 Node* t1 = EditingStrategy::firstChild(*n1); |
61 Node* t2 = EditingStrategy::firstChild(*n2); | 61 Node* t2 = EditingStrategy::firstChild(*n2); |
62 Node* t3 = EditingStrategy::lastChild(*host); | 62 Node* t3 = EditingStrategy::lastChild(*host); |
63 Node* a = shadowRoot->getElementById("a"); | 63 Node* a = shadowRoot->getElementById("a"); |
64 | 64 |
65 EXPECT_EQ(t0, Position::inParentBeforeNode(*n1).nodeAsRangeLastNode()); | 65 EXPECT_EQ(t0, Position::inParentBeforeNode(*n1).nodeAsRangeLastNode()); |
66 EXPECT_EQ(t1, Position::inParentBeforeNode(*n2).nodeAsRangeLastNode()); | 66 EXPECT_EQ(t1, Position::inParentBeforeNode(*n2).nodeAsRangeLastNode()); |
67 EXPECT_EQ(t1, Position::inParentAfterNode(*n1).nodeAsRangeLastNode()); | 67 EXPECT_EQ(t1, Position::inParentAfterNode(*n1).nodeAsRangeLastNode()); |
68 EXPECT_EQ(t2, Position::inParentAfterNode(*n2).nodeAsRangeLastNode()); | 68 EXPECT_EQ(t2, Position::inParentAfterNode(*n2).nodeAsRangeLastNode()); |
69 EXPECT_EQ(t3, Position::afterNode(host).nodeAsRangeLastNode()); | 69 EXPECT_EQ(t3, Position::afterNode(host).nodeAsRangeLastNode()); |
70 | 70 |
71 EXPECT_EQ(t2, PositionInComposedTree::inParentBeforeNode(*n1).nodeAsRangeLas
tNode()); | 71 EXPECT_EQ(t2, PositionInComposedTree::inParentBeforeNode(*n1).nodeAsRangeLas
tNode()); |
72 EXPECT_EQ(a, PositionInComposedTree::inParentBeforeNode(*n2).nodeAsRangeLast
Node()); | 72 EXPECT_EQ(a, PositionInComposedTree::inParentBeforeNode(*n2).nodeAsRangeLast
Node()); |
73 EXPECT_EQ(t1, PositionInComposedTree::inParentAfterNode(*n1).nodeAsRangeLast
Node()); | 73 EXPECT_EQ(t1, PositionInComposedTree::inParentAfterNode(*n1).nodeAsRangeLast
Node()); |
74 EXPECT_EQ(t2, PositionInComposedTree::inParentAfterNode(*n2).nodeAsRangeLast
Node()); | 74 EXPECT_EQ(t2, PositionInComposedTree::inParentAfterNode(*n2).nodeAsRangeLast
Node()); |
75 EXPECT_EQ(t1, PositionInComposedTree::afterNode(host).nodeAsRangeLastNode())
; | 75 EXPECT_EQ(t1, PositionInComposedTree::afterNode(host).nodeAsRangeLastNode())
; |
76 } | 76 } |
77 | 77 |
78 TEST_F(PositionTest, ToPositionInComposedTreeWithActiveInsertionPoint) | 78 TEST_F(PositionTest, ToPositionInComposedTreeWithActiveInsertionPoint) |
79 { | 79 { |
80 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; | 80 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; |
81 const char* shadowContent = "<a id='a'><content select=#one id='content'></c
ontent><content></content></a>"; | 81 const char* shadowContent = "<a id='a'><content select=#one id='content'></c
ontent><content></content></a>"; |
82 setBodyContent(bodyContent); | 82 setBodyContent(bodyContent); |
83 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 83 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
84 RefPtrWillBeRawPtr<Element> anchor = shadowRoot->getElementById("a"); | 84 RefPtrWillBeRawPtr<Element> anchor = shadowRoot->getElementById("a"); |
85 | 85 |
86 EXPECT_EQ(PositionInComposedTree(anchor.get(), 0), toPositionInComposedTree(
Position(anchor.get(), 0))); | 86 EXPECT_EQ(PositionInComposedTree(anchor.get(), 0), toPositionInComposedTree(
Position(anchor.get(), 0))); |
87 EXPECT_EQ(PositionInComposedTree(anchor.get(), 1), toPositionInComposedTree(
Position(anchor.get(), 1))); | 87 EXPECT_EQ(PositionInComposedTree(anchor.get(), 1), toPositionInComposedTree(
Position(anchor.get(), 1))); |
88 EXPECT_EQ(PositionInComposedTree(anchor, PositionAnchorType::AfterChildren),
toPositionInComposedTree(Position(anchor.get(), 2))); | 88 EXPECT_EQ(PositionInComposedTree(anchor, PositionAnchorType::AfterChildren),
toPositionInComposedTree(Position(anchor.get(), 2))); |
89 } | 89 } |
90 | 90 |
91 TEST_F(PositionTest, ToPositionInComposedTreeWithInactiveInsertionPoint) | 91 TEST_F(PositionTest, ToPositionInComposedTreeWithInactiveInsertionPoint) |
92 { | 92 { |
93 const char* bodyContent = "<p id='p'><content></content></p>"; | 93 const char* bodyContent = "<p id='p'><content></content></p>"; |
94 setBodyContent(bodyContent); | 94 setBodyContent(bodyContent); |
95 RefPtrWillBeRawPtr<Element> anchor = document().getElementById("p"); | 95 RefPtrWillBeRawPtr<Element> anchor = document().getElementById("p"); |
96 | 96 |
97 EXPECT_EQ(PositionInComposedTree(anchor.get(), 0), toPositionInComposedTree(
Position(anchor.get(), 0))); | 97 EXPECT_EQ(PositionInComposedTree(anchor.get(), 0), toPositionInComposedTree(
Position(anchor.get(), 0))); |
98 EXPECT_EQ(PositionInComposedTree(anchor, PositionAnchorType::AfterChildren),
toPositionInComposedTree(Position(anchor.get(), 1))); | 98 EXPECT_EQ(PositionInComposedTree(anchor, PositionAnchorType::AfterChildren),
toPositionInComposedTree(Position(anchor.get(), 1))); |
99 } | 99 } |
100 | 100 |
101 TEST_F(PositionTest, ToPositionInComposedTreeWithShadowRoot) | 101 TEST_F(PositionTest, ToPositionInComposedTreeWithShadowRoot) |
102 { | 102 { |
103 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; | 103 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; |
104 const char* shadowContent = "<a><content select=#one></content></a>"; | 104 const char* shadowContent = "<a><content select=#one></content></a>"; |
105 setBodyContent(bodyContent); | 105 setBodyContent(bodyContent); |
106 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 106 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
107 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); | 107 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); |
108 | 108 |
109 EXPECT_EQ(PositionInComposedTree(host.get(), 0), toPositionInComposedTree(Po
sition(shadowRoot.get(), 0))); | 109 EXPECT_EQ(PositionInComposedTree(host.get(), 0), toPositionInComposedTree(Po
sition(shadowRoot.get(), 0))); |
110 EXPECT_EQ(PositionInComposedTree(host.get(), PositionAnchorType::AfterChildr
en), toPositionInComposedTree(Position(shadowRoot.get(), 1))); | 110 EXPECT_EQ(PositionInComposedTree(host.get(), PositionAnchorType::AfterChildr
en), toPositionInComposedTree(Position(shadowRoot.get(), 1))); |
111 } | 111 } |
112 | 112 |
113 TEST_F(PositionTest, ToPositionInComposedTreeWithShadowRootContainingSingleConte
nt) | 113 TEST_F(PositionTest, ToPositionInComposedTreeWithShadowRootContainingSingleConte
nt) |
114 { | 114 { |
115 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; | 115 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; |
116 const char* shadowContent = "<content select=#one></content>"; | 116 const char* shadowContent = "<content select=#one></content>"; |
117 setBodyContent(bodyContent); | 117 setBodyContent(bodyContent); |
118 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 118 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
119 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); | 119 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); |
120 | 120 |
121 EXPECT_EQ(PositionInComposedTree(host.get(), 0), toPositionInComposedTree(Po
sition(shadowRoot.get(), 0))); | 121 EXPECT_EQ(PositionInComposedTree(host.get(), 0), toPositionInComposedTree(Po
sition(shadowRoot.get(), 0))); |
122 EXPECT_EQ(PositionInComposedTree(host.get(), PositionAnchorType::AfterChildr
en), toPositionInComposedTree(Position(shadowRoot.get(), 1))); | 122 EXPECT_EQ(PositionInComposedTree(host.get(), PositionAnchorType::AfterChildr
en), toPositionInComposedTree(Position(shadowRoot.get(), 1))); |
123 } | 123 } |
124 | 124 |
125 TEST_F(PositionTest, ToPositionInComposedTreeWithEmptyShadowRoot) | 125 TEST_F(PositionTest, ToPositionInComposedTreeWithEmptyShadowRoot) |
126 { | 126 { |
127 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; | 127 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; |
128 const char* shadowContent = ""; | 128 const char* shadowContent = ""; |
129 setBodyContent(bodyContent); | 129 setBodyContent(bodyContent); |
130 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 130 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
131 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); | 131 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); |
132 | 132 |
133 EXPECT_EQ(PositionInComposedTree(host, PositionAnchorType::AfterChildren), t
oPositionInComposedTree(Position(shadowRoot.get(), 0))); | 133 EXPECT_EQ(PositionInComposedTree(host, PositionAnchorType::AfterChildren), t
oPositionInComposedTree(Position(shadowRoot.get(), 0))); |
134 } | 134 } |
135 | 135 |
136 } // namespace blink | 136 } // namespace blink |
OLD | NEW |