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/EditingUtilities.h" | 6 #include "core/editing/EditingUtilities.h" |
7 | 7 |
8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position(
host, 2)))); | 98 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position(
host, 2)))); |
99 EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInC
omposedTree(host, 2)))); | 99 EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInC
omposedTree(host, 2)))); |
100 | 100 |
101 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position:
:afterNode(host)))); | 101 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position:
:afterNode(host)))); |
102 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(PositionI
nComposedTree::afterNode(host)))); | 102 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(PositionI
nComposedTree::afterNode(host)))); |
103 | 103 |
104 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position:
:lastPositionInNode(host)))); | 104 EXPECT_EQ(nullptr, isFirstPositionAfterTable(createVisiblePosition(Position:
:lastPositionInNode(host)))); |
105 EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInC
omposedTree::lastPositionInNode(host)))); | 105 EXPECT_EQ(table, isFirstPositionAfterTable(createVisiblePosition(PositionInC
omposedTree::lastPositionInNode(host)))); |
106 } | 106 } |
107 | 107 |
| 108 TEST_F(EditingUtilitiesTest, lastEditablePositionBeforePositionInRoot) |
| 109 { |
| 110 const char* bodyContent = "<p id='host' contenteditable><b id='one'>1</b><b
id='two'>22</b></p>"; |
| 111 const char* shadowContent = "<content select=#two></content><content select=
#one></content><b id='three'>333</b>"; |
| 112 setBodyContent(bodyContent); |
| 113 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
| 114 updateLayoutAndStyleForPainting(); |
| 115 Element* host = document().getElementById("host"); |
| 116 Node* one = document().getElementById("one"); |
| 117 Node* two = document().getElementById("two"); |
| 118 Node* three = shadowRoot->getElementById("three"); |
| 119 |
| 120 EXPECT_EQ(Position(one, 0), lastEditablePositionBeforePositionInRoot(Positio
n(one, 0), host)); |
| 121 EXPECT_EQ(Position(one->firstChild(), 0), lastEditableVisiblePositionBeforeP
ositionInRoot(Position(one, 0), host).deepEquivalent()); |
| 122 |
| 123 EXPECT_EQ(PositionInComposedTree(one, 0), lastEditablePositionBeforePosition
InRoot(PositionInComposedTree(one, 0), host)); |
| 124 EXPECT_EQ(PositionInComposedTree(two->firstChild(), 2), lastEditableVisibleP
ositionBeforePositionInRoot(PositionInComposedTree(one, 0), host).deepEquivalent
()); |
| 125 |
| 126 EXPECT_EQ(Position::firstPositionInNode(host), lastEditablePositionBeforePos
itionInRoot(Position(three, 0), host)); |
| 127 EXPECT_EQ(Position(one->firstChild(), 0), lastEditableVisiblePositionBeforeP
ositionInRoot(Position(three, 0), host).deepEquivalent()); |
| 128 EXPECT_EQ(PositionInComposedTree::firstPositionInNode(host), lastEditablePos
itionBeforePositionInRoot(PositionInComposedTree(three, 0), host)); |
| 129 EXPECT_EQ(PositionInComposedTree(two->firstChild(), 0), lastEditableVisibleP
ositionBeforePositionInRoot(PositionInComposedTree(three, 0), host).deepEquivale
nt()); |
| 130 } |
| 131 |
108 TEST_F(EditingUtilitiesTest, NextNodeIndex) | 132 TEST_F(EditingUtilitiesTest, NextNodeIndex) |
109 { | 133 { |
110 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 134 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
111 const char* shadowContent = "<content select=#two></content><content select=
#one></content>"; | 135 const char* shadowContent = "<content select=#two></content><content select=
#one></content>"; |
112 setBodyContent(bodyContent); | 136 setBodyContent(bodyContent); |
113 setShadowContent(shadowContent, "host"); | 137 setShadowContent(shadowContent, "host"); |
114 Node* host = document().getElementById("host"); | 138 Node* host = document().getElementById("host"); |
115 Node* two = document().getElementById("two"); | 139 Node* two = document().getElementById("two"); |
116 | 140 |
117 EXPECT_EQ(Position(host, 3), nextPositionOf(Position(two, 2), PositionMoveTy
pe::CodePoint)); | 141 EXPECT_EQ(Position(host, 3), nextPositionOf(Position(two, 2), PositionMoveTy
pe::CodePoint)); |
118 EXPECT_EQ(PositionInComposedTree(host, 1), nextPositionOf(PositionInComposed
Tree(two, 2), PositionMoveType::CodePoint)); | 142 EXPECT_EQ(PositionInComposedTree(host, 1), nextPositionOf(PositionInComposed
Tree(two, 2), PositionMoveType::CodePoint)); |
119 } | 143 } |
120 | 144 |
121 TEST_F(EditingUtilitiesTest, NextVisuallyDistinctCandidate) | 145 TEST_F(EditingUtilitiesTest, NextVisuallyDistinctCandidate) |
122 { | 146 { |
123 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b><b id='three'>33</b></p>"; | 147 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b><b id='three'>33</b></p>"; |
124 const char* shadowContent = "<content select=#two></content><content select=
#one></content><content select=#three></content>"; | 148 const char* shadowContent = "<content select=#two></content><content select=
#one></content><content select=#three></content>"; |
125 setBodyContent(bodyContent); | 149 setBodyContent(bodyContent); |
126 setShadowContent(shadowContent, "host"); | 150 setShadowContent(shadowContent, "host"); |
127 updateLayoutAndStyleForPainting(); | 151 updateLayoutAndStyleForPainting(); |
128 Node* one = document().getElementById("one"); | 152 Node* one = document().getElementById("one"); |
129 Node* two = document().getElementById("two"); | 153 Node* two = document().getElementById("two"); |
130 Node* three = document().getElementById("three"); | 154 Node* three = document().getElementById("three"); |
131 | 155 |
132 EXPECT_EQ(Position(two->firstChild(), 1), nextVisuallyDistinctCandidate(Posi
tion(one, 1))); | 156 EXPECT_EQ(Position(two->firstChild(), 1), nextVisuallyDistinctCandidate(Posi
tion(one, 1))); |
133 EXPECT_EQ(PositionInComposedTree(three->firstChild(), 1), nextVisuallyDistin
ctCandidate(PositionInComposedTree(one, 1))); | 157 EXPECT_EQ(PositionInComposedTree(three->firstChild(), 1), nextVisuallyDistin
ctCandidate(PositionInComposedTree(one, 1))); |
134 } | 158 } |
135 | 159 |
136 } // namespace blink | 160 } // namespace blink |
OLD | NEW |