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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0),
positionWithAffinityInDOMTree(*two->firstChild(), 0))); | 45 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0),
positionWithAffinityInDOMTree(*two->firstChild(), 0))); |
46 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0)
, positionWithAffinityInDOMTree(*five->firstChild(), 0))); | 46 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0)
, positionWithAffinityInDOMTree(*five->firstChild(), 0))); |
47 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*two->firstChild(), 0)
, positionWithAffinityInDOMTree(*four->firstChild(), 0))); | 47 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*two->firstChild(), 0)
, positionWithAffinityInDOMTree(*four->firstChild(), 0))); |
48 | 48 |
49 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one, 0), positio
nWithAffinityInComposedTree(*two, 0))); | 49 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one, 0), positio
nWithAffinityInComposedTree(*two, 0))); |
50 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild(
), 0), positionWithAffinityInComposedTree(*two->firstChild(), 0))); | 50 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild(
), 0), positionWithAffinityInComposedTree(*two->firstChild(), 0))); |
51 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild(
), 0), positionWithAffinityInComposedTree(*five->firstChild(), 0))); | 51 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild(
), 0), positionWithAffinityInComposedTree(*five->firstChild(), 0))); |
52 EXPECT_TRUE(inSameLine(positionWithAffinityInComposedTree(*two->firstChild()
, 0), positionWithAffinityInComposedTree(*four->firstChild(), 0))); | 52 EXPECT_TRUE(inSameLine(positionWithAffinityInComposedTree(*two->firstChild()
, 0), positionWithAffinityInComposedTree(*four->firstChild(), 0))); |
53 } | 53 } |
54 | 54 |
| 55 TEST_F(VisibleUnitsTest, mostBackwardCaretPositionAfterAnchor) |
| 56 { |
| 57 const char* bodyContent = "<p id='host'><b id='one'>1</b></p><b id='two'>22<
/b>"; |
| 58 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten
t><b id='three'>333</b>"; |
| 59 setBodyContent(bodyContent); |
| 60 setShadowContent(shadowContent); |
| 61 updateLayoutAndStyleForPainting(); |
| 62 |
| 63 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); |
| 64 |
| 65 EXPECT_EQ(Position::lastPositionInNode(host.get()), mostForwardCaretPosition
(Position::afterNode(host.get()))); |
| 66 EXPECT_EQ(PositionInComposedTree::lastPositionInNode(host.get()), mostForwar
dCaretPosition(PositionInComposedTree::afterNode(host.get()))); |
| 67 } |
| 68 |
| 69 TEST_F(VisibleUnitsTest, mostForwardCaretPositionAfterAnchor) |
| 70 { |
| 71 const char* bodyContent = "<p id='host'><b id='one'>1</b></p>"; |
| 72 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten
t><b id='three'>333</b>"; |
| 73 setBodyContent(bodyContent); |
| 74 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); |
| 75 updateLayoutAndStyleForPainting(); |
| 76 |
| 77 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); |
| 78 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); |
| 79 RefPtrWillBeRawPtr<Element> three = shadowRoot->getElementById("three"); |
| 80 |
| 81 EXPECT_EQ(Position(one->firstChild(), 1), mostBackwardCaretPosition(Position
::afterNode(host.get()))); |
| 82 EXPECT_EQ(PositionInComposedTree(three->firstChild(), 3), mostBackwardCaretP
osition(PositionInComposedTree::afterNode(host.get()))); |
| 83 } |
| 84 |
55 TEST_F(VisibleUnitsTest, rendersInDifferentPositionAfterAnchor) | 85 TEST_F(VisibleUnitsTest, rendersInDifferentPositionAfterAnchor) |
56 { | 86 { |
57 const char* bodyContent = "<p id='sample'>00</p>"; | 87 const char* bodyContent = "<p id='sample'>00</p>"; |
58 setBodyContent(bodyContent); | 88 setBodyContent(bodyContent); |
59 updateLayoutAndStyleForPainting(); | 89 updateLayoutAndStyleForPainting(); |
60 RefPtrWillBeRawPtr<Element> sample = document().getElementById("sample"); | 90 RefPtrWillBeRawPtr<Element> sample = document().getElementById("sample"); |
61 | 91 |
62 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample.get()), P
osition(sample.get(), 1))); | 92 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample.get()), P
osition(sample.get(), 1))); |
63 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample.
get()), Position(sample.get(), 1))); | 93 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample.
get()), Position(sample.get(), 1))); |
64 } | 94 } |
65 | 95 |
66 TEST_F(VisibleUnitsTest, renderedOffset) | 96 TEST_F(VisibleUnitsTest, renderedOffset) |
67 { | 97 { |
68 const char* bodyContent = "<div contenteditable><span id='sample1'>1</span><
span id='sample2'>22</span></div>"; | 98 const char* bodyContent = "<div contenteditable><span id='sample1'>1</span><
span id='sample2'>22</span></div>"; |
69 setBodyContent(bodyContent); | 99 setBodyContent(bodyContent); |
70 updateLayoutAndStyleForPainting(); | 100 updateLayoutAndStyleForPainting(); |
71 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); | 101 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); |
72 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); | 102 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); |
73 | 103 |
74 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh
ild()), Position(sample2->firstChild(), 0))); | 104 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh
ild()), Position(sample2->firstChild(), 0))); |
75 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1
->firstChild()), Position(sample2->firstChild(), 0))); | 105 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1
->firstChild()), Position(sample2->firstChild(), 0))); |
76 } | 106 } |
77 | 107 |
78 } // namespace blink | 108 } // namespace blink |
OLD | NEW |