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 14 matching lines...) Expand all Loading... |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 class VisibleUnitsTest : public EditingTestBase { | 27 class VisibleUnitsTest : public EditingTestBase { |
28 }; | 28 }; |
29 | 29 |
30 TEST_F(VisibleUnitsTest, inSameLine) | 30 TEST_F(VisibleUnitsTest, inSameLine) |
31 { | 31 { |
32 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 32 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
33 const char* shadowContent = "<div><span id='s4'>44</span><content select=#tw
o></content><br><span id='s5'>55</span><br><content select=#one></content><span
id='s6'>66</span></div>"; | 33 const char* shadowContent = "<div><span id='s4'>44</span><content select=#tw
o></content><br><span id='s5'>55</span><br><content select=#one></content><span
id='s6'>66</span></div>"; |
34 setBodyContent(bodyContent); | 34 setBodyContent(bodyContent); |
35 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 35 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
36 updateLayoutAndStyleForPainting(); | 36 updateLayoutAndStyleForPainting(); |
37 | 37 |
38 RefPtrWillBeRawPtr<Element> body = document().body(); | 38 RefPtrWillBeRawPtr<Element> body = document().body(); |
39 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); | 39 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); |
40 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE
PTION); | 40 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE
PTION); |
41 RefPtrWillBeRawPtr<Element> four = shadowRoot->querySelector("#s4", ASSERT_N
O_EXCEPTION); | 41 RefPtrWillBeRawPtr<Element> four = shadowRoot->querySelector("#s4", ASSERT_N
O_EXCEPTION); |
42 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N
O_EXCEPTION); | 42 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N
O_EXCEPTION); |
43 | 43 |
44 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one, 0), positionWithA
ffinityInDOMTree(*two, 0))); | 44 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one, 0), positionWithA
ffinityInDOMTree(*two, 0))); |
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, localCaretRectOfPosition) | 55 TEST_F(VisibleUnitsTest, localCaretRectOfPosition) |
56 { | 56 { |
57 const char* bodyContent = "<p id='host'><b id='one'>1</b></p><b id='two'>22<
/b>"; | 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>"; | 58 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten
t><b id='three'>333</b>"; |
59 setBodyContent(bodyContent); | 59 setBodyContent(bodyContent); |
60 setShadowContent(shadowContent); | 60 setShadowContent(shadowContent, "host"); |
61 updateLayoutAndStyleForPainting(); | 61 updateLayoutAndStyleForPainting(); |
62 | 62 |
63 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); | 63 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); |
64 | 64 |
65 LayoutObject* layoutObjectFromDOMTree; | 65 LayoutObject* layoutObjectFromDOMTree; |
66 LayoutRect layoutRectFromDOMTree = localCaretRectOfPosition(Position(one->fi
rstChild(), 0), layoutObjectFromDOMTree); | 66 LayoutRect layoutRectFromDOMTree = localCaretRectOfPosition(Position(one->fi
rstChild(), 0), layoutObjectFromDOMTree); |
67 | 67 |
68 LayoutObject* layoutObjectFromComposedTree; | 68 LayoutObject* layoutObjectFromComposedTree; |
69 LayoutRect layoutRectFromComposedTree = localCaretRectOfPosition(PositionInC
omposedTree(one->firstChild(), 0), layoutObjectFromComposedTree); | 69 LayoutRect layoutRectFromComposedTree = localCaretRectOfPosition(PositionInC
omposedTree(one->firstChild(), 0), layoutObjectFromComposedTree); |
70 | 70 |
71 EXPECT_TRUE(layoutObjectFromDOMTree); | 71 EXPECT_TRUE(layoutObjectFromDOMTree); |
72 EXPECT_FALSE(layoutRectFromDOMTree.isEmpty()); | 72 EXPECT_FALSE(layoutRectFromDOMTree.isEmpty()); |
73 EXPECT_EQ(layoutObjectFromDOMTree, layoutObjectFromComposedTree); | 73 EXPECT_EQ(layoutObjectFromDOMTree, layoutObjectFromComposedTree); |
74 EXPECT_EQ(layoutRectFromDOMTree, layoutRectFromComposedTree); | 74 EXPECT_EQ(layoutRectFromDOMTree, layoutRectFromComposedTree); |
75 } | 75 } |
76 | 76 |
77 TEST_F(VisibleUnitsTest, mostBackwardCaretPositionAfterAnchor) | 77 TEST_F(VisibleUnitsTest, mostBackwardCaretPositionAfterAnchor) |
78 { | 78 { |
79 const char* bodyContent = "<p id='host'><b id='one'>1</b></p><b id='two'>22<
/b>"; | 79 const char* bodyContent = "<p id='host'><b id='one'>1</b></p><b id='two'>22<
/b>"; |
80 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten
t><b id='three'>333</b>"; | 80 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten
t><b id='three'>333</b>"; |
81 setBodyContent(bodyContent); | 81 setBodyContent(bodyContent); |
82 setShadowContent(shadowContent); | 82 setShadowContent(shadowContent, "host"); |
83 updateLayoutAndStyleForPainting(); | 83 updateLayoutAndStyleForPainting(); |
84 | 84 |
85 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); | 85 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); |
86 | 86 |
87 EXPECT_EQ(Position::lastPositionInNode(host.get()), mostForwardCaretPosition
(Position::afterNode(host.get()))); | 87 EXPECT_EQ(Position::lastPositionInNode(host.get()), mostForwardCaretPosition
(Position::afterNode(host.get()))); |
88 EXPECT_EQ(PositionInComposedTree::lastPositionInNode(host.get()), mostForwar
dCaretPosition(PositionInComposedTree::afterNode(host.get()))); | 88 EXPECT_EQ(PositionInComposedTree::lastPositionInNode(host.get()), mostForwar
dCaretPosition(PositionInComposedTree::afterNode(host.get()))); |
89 } | 89 } |
90 | 90 |
91 TEST_F(VisibleUnitsTest, mostForwardCaretPositionAfterAnchor) | 91 TEST_F(VisibleUnitsTest, mostForwardCaretPositionAfterAnchor) |
92 { | 92 { |
93 const char* bodyContent = "<p id='host'><b id='one'>1</b></p>"; | 93 const char* bodyContent = "<p id='host'><b id='one'>1</b></p>"; |
94 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten
t><b id='three'>333</b>"; | 94 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten
t><b id='three'>333</b>"; |
95 setBodyContent(bodyContent); | 95 setBodyContent(bodyContent); |
96 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 96 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
97 updateLayoutAndStyleForPainting(); | 97 updateLayoutAndStyleForPainting(); |
98 | 98 |
99 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); | 99 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); |
100 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); | 100 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); |
101 RefPtrWillBeRawPtr<Element> three = shadowRoot->getElementById("three"); | 101 RefPtrWillBeRawPtr<Element> three = shadowRoot->getElementById("three"); |
102 | 102 |
103 EXPECT_EQ(Position(one->firstChild(), 1), mostBackwardCaretPosition(Position
::afterNode(host.get()))); | 103 EXPECT_EQ(Position(one->firstChild(), 1), mostBackwardCaretPosition(Position
::afterNode(host.get()))); |
104 EXPECT_EQ(PositionInComposedTree(three->firstChild(), 3), mostBackwardCaretP
osition(PositionInComposedTree::afterNode(host.get()))); | 104 EXPECT_EQ(PositionInComposedTree(three->firstChild(), 3), mostBackwardCaretP
osition(PositionInComposedTree::afterNode(host.get()))); |
105 } | 105 } |
106 | 106 |
(...skipping 14 matching lines...) Expand all Loading... |
121 setBodyContent(bodyContent); | 121 setBodyContent(bodyContent); |
122 updateLayoutAndStyleForPainting(); | 122 updateLayoutAndStyleForPainting(); |
123 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); | 123 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); |
124 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); | 124 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); |
125 | 125 |
126 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh
ild()), Position(sample2->firstChild(), 0))); | 126 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh
ild()), Position(sample2->firstChild(), 0))); |
127 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1
->firstChild()), Position(sample2->firstChild(), 0))); | 127 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1
->firstChild()), Position(sample2->firstChild(), 0))); |
128 } | 128 } |
129 | 129 |
130 } // namespace blink | 130 } // namespace blink |
OLD | NEW |