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/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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 EXPECT_EQ(Position(one->firstChild(), 1), nextPositionOf(createVisiblePositi
on(Position(one, 0))).deepEquivalent()); | 225 EXPECT_EQ(Position(one->firstChild(), 1), nextPositionOf(createVisiblePositi
on(Position(one, 0))).deepEquivalent()); |
226 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 1), nextPositionOf(creat
eVisiblePosition(PositionInComposedTree(one, 0))).deepEquivalent()); | 226 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 1), nextPositionOf(creat
eVisiblePosition(PositionInComposedTree(one, 0))).deepEquivalent()); |
227 | 227 |
228 EXPECT_EQ(Position(two->firstChild(), 1), nextPositionOf(createVisiblePositi
on(Position(one, 1))).deepEquivalent()); | 228 EXPECT_EQ(Position(two->firstChild(), 1), nextPositionOf(createVisiblePositi
on(Position(one, 1))).deepEquivalent()); |
229 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 1), nextPositionOf(crea
teVisiblePosition(PositionInComposedTree(one, 1))).deepEquivalent()); | 229 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 1), nextPositionOf(crea
teVisiblePosition(PositionInComposedTree(one, 1))).deepEquivalent()); |
230 | 230 |
231 EXPECT_EQ(Position(three->firstChild(), 0), nextPositionOf(createVisiblePosi
tion(Position(two, 2))).deepEquivalent()); | 231 EXPECT_EQ(Position(three->firstChild(), 0), nextPositionOf(createVisiblePosi
tion(Position(two, 2))).deepEquivalent()); |
232 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 1), nextPositionOf(creat
eVisiblePosition(PositionInComposedTree(two, 2))).deepEquivalent()); | 232 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 1), nextPositionOf(creat
eVisiblePosition(PositionInComposedTree(two, 2))).deepEquivalent()); |
233 } | 233 } |
234 | 234 |
| 235 TEST_F(VisibleUnitsTest, previousPositionOf) |
| 236 { |
| 237 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>"; |
| 238 const char* shadowContent = "<b id=four>4444</b><content select=#two></conte
nt><content select=#one></content><b id=five>55555</b>"; |
| 239 setBodyContent(bodyContent); |
| 240 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
| 241 updateLayoutAndStyleForPainting(); |
| 242 |
| 243 Node* zero = document().getElementById("zero")->firstChild(); |
| 244 Node* one = document().getElementById("one")->firstChild(); |
| 245 Node* two = document().getElementById("two")->firstChild(); |
| 246 Node* three = document().getElementById("three")->firstChild(); |
| 247 Node* four = shadowRoot->getElementById("four")->firstChild(); |
| 248 Node* five = shadowRoot->getElementById("five")->firstChild(); |
| 249 |
| 250 EXPECT_EQ(Position(zero, 0), previousPositionOf(createVisiblePosition(Positi
on(zero, 1))).deepEquivalent()); |
| 251 EXPECT_EQ(PositionInComposedTree(zero, 0), previousPositionOf(createVisibleP
osition(PositionInComposedTree(zero, 1))).deepEquivalent()); |
| 252 |
| 253 EXPECT_EQ(Position(zero, 1), previousPositionOf(createVisiblePosition(Positi
on(one, 0))).deepEquivalent()); |
| 254 EXPECT_EQ(PositionInComposedTree(two, 1), previousPositionOf(createVisiblePo
sition(PositionInComposedTree(one, 0))).deepEquivalent()); |
| 255 |
| 256 EXPECT_EQ(Position(one, 0), previousPositionOf(createVisiblePosition(Positio
n(one, 1))).deepEquivalent()); |
| 257 EXPECT_EQ(PositionInComposedTree(two, 2), previousPositionOf(createVisiblePo
sition(PositionInComposedTree(one, 1))).deepEquivalent()); |
| 258 |
| 259 EXPECT_EQ(Position(one, 0), previousPositionOf(createVisiblePosition(Positio
n(two, 0))).deepEquivalent()); |
| 260 EXPECT_EQ(PositionInComposedTree(four, 3), previousPositionOf(createVisibleP
osition(PositionInComposedTree(two, 0))).deepEquivalent()); |
| 261 |
| 262 // DOM tree to shadow tree |
| 263 EXPECT_EQ(Position(two, 2), previousPositionOf(createVisiblePosition(Positio
n(three, 0))).deepEquivalent()); |
| 264 EXPECT_EQ(PositionInComposedTree(five, 5), previousPositionOf(createVisibleP
osition(PositionInComposedTree(three, 0))).deepEquivalent()); |
| 265 |
| 266 // Shadow tree to DOM tree |
| 267 EXPECT_EQ(Position(), previousPositionOf(createVisiblePosition(Position(four
, 0))).deepEquivalent()); |
| 268 EXPECT_EQ(PositionInComposedTree(zero, 1), previousPositionOf(createVisibleP
osition(PositionInComposedTree(four, 0))).deepEquivalent()); |
| 269 |
| 270 // Note: Canonicalization maps (five, 0) to (four, 4) in DOM tree and |
| 271 // (one, 1) in composed tree. |
| 272 EXPECT_EQ(Position(four, 4), previousPositionOf(createVisiblePosition(Positi
on(five, 1))).deepEquivalent()); |
| 273 EXPECT_EQ(PositionInComposedTree(one, 1), previousPositionOf(createVisiblePo
sition(PositionInComposedTree(five, 1))).deepEquivalent()); |
| 274 } |
| 275 |
235 TEST_F(VisibleUnitsTest, rendersInDifferentPositionAfterAnchor) | 276 TEST_F(VisibleUnitsTest, rendersInDifferentPositionAfterAnchor) |
236 { | 277 { |
237 const char* bodyContent = "<p id='sample'>00</p>"; | 278 const char* bodyContent = "<p id='sample'>00</p>"; |
238 setBodyContent(bodyContent); | 279 setBodyContent(bodyContent); |
239 updateLayoutAndStyleForPainting(); | 280 updateLayoutAndStyleForPainting(); |
240 RefPtrWillBeRawPtr<Element> sample = document().getElementById("sample"); | 281 RefPtrWillBeRawPtr<Element> sample = document().getElementById("sample"); |
241 | 282 |
242 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample.get()), P
osition(sample.get(), 1))); | 283 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample.get()), P
osition(sample.get(), 1))); |
243 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample.
get()), Position(sample.get(), 1))); | 284 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample.
get()), Position(sample.get(), 1))); |
244 } | 285 } |
245 | 286 |
246 TEST_F(VisibleUnitsTest, renderedOffset) | 287 TEST_F(VisibleUnitsTest, renderedOffset) |
247 { | 288 { |
248 const char* bodyContent = "<div contenteditable><span id='sample1'>1</span><
span id='sample2'>22</span></div>"; | 289 const char* bodyContent = "<div contenteditable><span id='sample1'>1</span><
span id='sample2'>22</span></div>"; |
249 setBodyContent(bodyContent); | 290 setBodyContent(bodyContent); |
250 updateLayoutAndStyleForPainting(); | 291 updateLayoutAndStyleForPainting(); |
251 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); | 292 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); |
252 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); | 293 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); |
253 | 294 |
254 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh
ild()), Position(sample2->firstChild(), 0))); | 295 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh
ild()), Position(sample2->firstChild(), 0))); |
255 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1
->firstChild()), Position(sample2->firstChild(), 0))); | 296 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1
->firstChild()), Position(sample2->firstChild(), 0))); |
256 } | 297 } |
257 | 298 |
258 } // namespace blink | 299 } // namespace blink |
OLD | NEW |