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

Side by Side Diff: Source/core/editing/VisibleUnitsTest.cpp

Issue 1315443011: Introduce composed tree version of nextPositionOf() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-08T17:17:00 Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « Source/core/editing/VisibleUnits.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/VisibleUnits.h" 6 #include "core/editing/VisibleUnits.h"
7 7
8 #include "core/editing/EditingTestBase.h" 8 #include "core/editing/EditingTestBase.h"
9 #include "core/editing/VisiblePosition.h" 9 #include "core/editing/VisiblePosition.h"
10 10
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 updateLayoutAndStyleForPainting(); 154 updateLayoutAndStyleForPainting();
155 155
156 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); 156 RefPtrWillBeRawPtr<Element> host = document().getElementById("host");
157 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); 157 RefPtrWillBeRawPtr<Element> one = document().getElementById("one");
158 RefPtrWillBeRawPtr<Element> three = shadowRoot->getElementById("three"); 158 RefPtrWillBeRawPtr<Element> three = shadowRoot->getElementById("three");
159 159
160 EXPECT_EQ(Position(one->firstChild(), 1), mostBackwardCaretPosition(Position ::afterNode(host.get()))); 160 EXPECT_EQ(Position(one->firstChild(), 1), mostBackwardCaretPosition(Position ::afterNode(host.get())));
161 EXPECT_EQ(PositionInComposedTree(three->firstChild(), 3), mostBackwardCaretP osition(PositionInComposedTree::afterNode(host.get()))); 161 EXPECT_EQ(PositionInComposedTree(three->firstChild(), 3), mostBackwardCaretP osition(PositionInComposedTree::afterNode(host.get())));
162 } 162 }
163 163
164 TEST_F(VisibleUnitsTest, nextPositionOf)
165 {
166 const char* bodyContent = "<b id=zero>0</b><p id=host><b id=one>1</b><b id=t wo>22</b></p><b id=three>333</b>";
167 const char* shadowContent = "<b id=four>4444</b><content select=#two></conte nt><content select=#one></content><b id=five>55555</b>";
168 setBodyContent(bodyContent);
169 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host");
170 updateLayoutAndStyleForPainting();
171
172 Element* zero = document().getElementById("zero");
173 Element* one = document().getElementById("one");
174 Element* two = document().getElementById("two");
175 Element* three = document().getElementById("three");
176 Element* four = shadowRoot->getElementById("four");
177 Element* five = shadowRoot->getElementById("five");
178
179 EXPECT_EQ(Position(one->firstChild(), 0), nextPositionOf(createVisiblePositi on(Position(zero, 1))).deepEquivalent());
180 EXPECT_EQ(PositionInComposedTree(four->firstChild(), 0), nextPositionOf(crea teVisiblePosition(PositionInComposedTree(zero, 1))).deepEquivalent());
181
182 EXPECT_EQ(Position(one->firstChild(), 1), nextPositionOf(createVisiblePositi on(Position(one, 0))).deepEquivalent());
183 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 1), nextPositionOf(creat eVisiblePosition(PositionInComposedTree(one, 0))).deepEquivalent());
184
185 EXPECT_EQ(Position(two->firstChild(), 1), nextPositionOf(createVisiblePositi on(Position(one, 1))).deepEquivalent());
186 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 1), nextPositionOf(crea teVisiblePosition(PositionInComposedTree(one, 1))).deepEquivalent());
187
188 EXPECT_EQ(Position(three->firstChild(), 0), nextPositionOf(createVisiblePosi tion(Position(two, 2))).deepEquivalent());
189 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 1), nextPositionOf(creat eVisiblePosition(PositionInComposedTree(two, 2))).deepEquivalent());
190 }
191
164 TEST_F(VisibleUnitsTest, rendersInDifferentPositionAfterAnchor) 192 TEST_F(VisibleUnitsTest, rendersInDifferentPositionAfterAnchor)
165 { 193 {
166 const char* bodyContent = "<p id='sample'>00</p>"; 194 const char* bodyContent = "<p id='sample'>00</p>";
167 setBodyContent(bodyContent); 195 setBodyContent(bodyContent);
168 updateLayoutAndStyleForPainting(); 196 updateLayoutAndStyleForPainting();
169 RefPtrWillBeRawPtr<Element> sample = document().getElementById("sample"); 197 RefPtrWillBeRawPtr<Element> sample = document().getElementById("sample");
170 198
171 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample.get()), P osition(sample.get(), 1))); 199 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample.get()), P osition(sample.get(), 1)));
172 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample. get()), Position(sample.get(), 1))); 200 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample. get()), Position(sample.get(), 1)));
173 } 201 }
174 202
175 TEST_F(VisibleUnitsTest, renderedOffset) 203 TEST_F(VisibleUnitsTest, renderedOffset)
176 { 204 {
177 const char* bodyContent = "<div contenteditable><span id='sample1'>1</span>< span id='sample2'>22</span></div>"; 205 const char* bodyContent = "<div contenteditable><span id='sample1'>1</span>< span id='sample2'>22</span></div>";
178 setBodyContent(bodyContent); 206 setBodyContent(bodyContent);
179 updateLayoutAndStyleForPainting(); 207 updateLayoutAndStyleForPainting();
180 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); 208 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1");
181 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); 209 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2");
182 210
183 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh ild()), Position(sample2->firstChild(), 0))); 211 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh ild()), Position(sample2->firstChild(), 0)));
184 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1 ->firstChild()), Position(sample2->firstChild(), 0))); 212 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1 ->firstChild()), Position(sample2->firstChild(), 0)));
185 } 213 }
186 214
187 } // namespace blink 215 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleUnits.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698