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

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

Issue 1310913004: Introduce composed tree version of inSameLine() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-07T17:11:39 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
11 namespace blink { 11 namespace blink {
12 12
13 namespace { 13 namespace {
14 14
15 PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, Tex tAffinity affinity = TextAffinity::Downstream) 15 PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, Tex tAffinity affinity = TextAffinity::Downstream)
16 { 16 {
17 return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset)), affinity); 17 return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset)), affinity);
18 } 18 }
19 19
20 VisiblePosition createVisiblePositionInDOMTree(Node& anchor, int offset, TextAff inity affinity = TextAffinity::Downstream)
21 {
22 return createVisiblePosition(Position(&anchor, offset), affinity);
23 }
24
20 PositionInComposedTreeWithAffinity positionWithAffinityInComposedTree(Node& anch or, int offset, TextAffinity affinity = TextAffinity::Downstream) 25 PositionInComposedTreeWithAffinity positionWithAffinityInComposedTree(Node& anch or, int offset, TextAffinity affinity = TextAffinity::Downstream)
21 { 26 {
22 return PositionInComposedTreeWithAffinity(canonicalPositionOf(PositionInComp osedTree(&anchor, offset)), affinity); 27 return PositionInComposedTreeWithAffinity(canonicalPositionOf(PositionInComp osedTree(&anchor, offset)), affinity);
23 } 28 }
24 29
30 VisiblePositionInComposedTree createVisiblePositionInComposedTree(Node& anchor, int offset, TextAffinity affinity = TextAffinity::Downstream)
31 {
32 return createVisiblePosition(PositionInComposedTree(&anchor, offset), affini ty);
33 }
34
25 } // namespace 35 } // namespace
26 36
27 class VisibleUnitsTest : public EditingTestBase { 37 class VisibleUnitsTest : public EditingTestBase {
28 }; 38 };
29 39
30 TEST_F(VisibleUnitsTest, inSameLine) 40 TEST_F(VisibleUnitsTest, inSameLine)
31 { 41 {
32 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>"; 42 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>"; 43 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); 44 setBodyContent(bodyContent);
35 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); 45 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host");
36 updateLayoutAndStyleForPainting(); 46 updateLayoutAndStyleForPainting();
37 47
38 RefPtrWillBeRawPtr<Element> body = document().body(); 48 RefPtrWillBeRawPtr<Element> body = document().body();
39 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION); 49 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION);
40 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE PTION); 50 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE PTION);
41 RefPtrWillBeRawPtr<Element> four = shadowRoot->querySelector("#s4", ASSERT_N O_EXCEPTION); 51 RefPtrWillBeRawPtr<Element> four = shadowRoot->querySelector("#s4", ASSERT_N O_EXCEPTION);
42 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N O_EXCEPTION); 52 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N O_EXCEPTION);
43 53
44 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one, 0), positionWithA ffinityInDOMTree(*two, 0))); 54 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one, 0), positionWithA ffinityInDOMTree(*two, 0)));
45 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0), positionWithAffinityInDOMTree(*two->firstChild(), 0))); 55 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0), positionWithAffinityInDOMTree(*two->firstChild(), 0)));
46 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0) , positionWithAffinityInDOMTree(*five->firstChild(), 0))); 56 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0) , positionWithAffinityInDOMTree(*five->firstChild(), 0)));
47 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*two->firstChild(), 0) , positionWithAffinityInDOMTree(*four->firstChild(), 0))); 57 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*two->firstChild(), 0) , positionWithAffinityInDOMTree(*four->firstChild(), 0)));
48 58
59 EXPECT_TRUE(inSameLine(createVisiblePositionInDOMTree(*one, 0), createVisibl ePositionInDOMTree(*two, 0)));
60 EXPECT_TRUE(inSameLine(createVisiblePositionInDOMTree(*one->firstChild(), 0) , createVisiblePositionInDOMTree(*two->firstChild(), 0)));
61 EXPECT_FALSE(inSameLine(createVisiblePositionInDOMTree(*one->firstChild(), 0 ), createVisiblePositionInDOMTree(*five->firstChild(), 0)));
62 EXPECT_FALSE(inSameLine(createVisiblePositionInDOMTree(*two->firstChild(), 0 ), createVisiblePositionInDOMTree(*four->firstChild(), 0)));
63
49 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one, 0), positio nWithAffinityInComposedTree(*two, 0))); 64 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one, 0), positio nWithAffinityInComposedTree(*two, 0)));
50 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild( ), 0), positionWithAffinityInComposedTree(*two->firstChild(), 0))); 65 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild( ), 0), positionWithAffinityInComposedTree(*two->firstChild(), 0)));
51 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild( ), 0), positionWithAffinityInComposedTree(*five->firstChild(), 0))); 66 EXPECT_FALSE(inSameLine(positionWithAffinityInComposedTree(*one->firstChild( ), 0), positionWithAffinityInComposedTree(*five->firstChild(), 0)));
52 EXPECT_TRUE(inSameLine(positionWithAffinityInComposedTree(*two->firstChild() , 0), positionWithAffinityInComposedTree(*four->firstChild(), 0))); 67 EXPECT_TRUE(inSameLine(positionWithAffinityInComposedTree(*two->firstChild() , 0), positionWithAffinityInComposedTree(*four->firstChild(), 0)));
68
69 EXPECT_FALSE(inSameLine(createVisiblePositionInComposedTree(*one, 0), create VisiblePositionInComposedTree(*two, 0)));
70 EXPECT_FALSE(inSameLine(createVisiblePositionInComposedTree(*one->firstChild (), 0), createVisiblePositionInComposedTree(*two->firstChild(), 0)));
71 EXPECT_FALSE(inSameLine(createVisiblePositionInComposedTree(*one->firstChild (), 0), createVisiblePositionInComposedTree(*five->firstChild(), 0)));
72 EXPECT_TRUE(inSameLine(createVisiblePositionInComposedTree(*two->firstChild( ), 0), createVisiblePositionInComposedTree(*four->firstChild(), 0)));
53 } 73 }
54 74
55 TEST_F(VisibleUnitsTest, localCaretRectOfPosition) 75 TEST_F(VisibleUnitsTest, localCaretRectOfPosition)
56 { 76 {
57 const char* bodyContent = "<p id='host'><b id='one'>1</b></p><b id='two'>22< /b>"; 77 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>"; 78 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten t><b id='three'>333</b>";
59 setBodyContent(bodyContent); 79 setBodyContent(bodyContent);
60 setShadowContent(shadowContent, "host"); 80 setShadowContent(shadowContent, "host");
61 updateLayoutAndStyleForPainting(); 81 updateLayoutAndStyleForPainting();
62 82
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 setBodyContent(bodyContent); 141 setBodyContent(bodyContent);
122 updateLayoutAndStyleForPainting(); 142 updateLayoutAndStyleForPainting();
123 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1"); 143 RefPtrWillBeRawPtr<Element> sample1 = document().getElementById("sample1");
124 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2"); 144 RefPtrWillBeRawPtr<Element> sample2 = document().getElementById("sample2");
125 145
126 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh ild()), Position(sample2->firstChild(), 0))); 146 EXPECT_FALSE(rendersInDifferentPosition(Position::afterNode(sample1->firstCh ild()), Position(sample2->firstChild(), 0)));
127 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1 ->firstChild()), Position(sample2->firstChild(), 0))); 147 EXPECT_FALSE(rendersInDifferentPosition(Position::lastPositionInNode(sample1 ->firstChild()), Position(sample2->firstChild(), 0)));
128 } 148 }
129 149
130 } // namespace blink 150 } // 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