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

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

Issue 1636373002: Make associatedLayoutObjectOf() to handle ::first-letter pseudo-element correctly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-01-29T15:21:03 Get rid of unused variable Created 4 years, 10 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 | « third_party/WebKit/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 "core/editing/VisibleUnits.h" 5 #include "core/editing/VisibleUnits.h"
6 6
7 #include "core/dom/Text.h" 7 #include "core/dom/Text.h"
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 #include "core/html/HTMLTextFormControlElement.h" 10 #include "core/html/HTMLTextFormControlElement.h"
11 #include "core/layout/LayoutTextFragment.h"
11 #include "core/layout/line/InlineBox.h" 12 #include "core/layout/line/InlineBox.h"
12 #include <ostream> // NOLINT 13 #include <ostream> // NOLINT
13 14
14 namespace blink { 15 namespace blink {
15 16
16 namespace { 17 namespace {
17 18
18 PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, Tex tAffinity affinity = TextAffinity::Downstream) 19 PositionWithAffinity positionWithAffinityInDOMTree(Node& anchor, int offset, Tex tAffinity affinity = TextAffinity::Downstream)
19 { 20 {
20 return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset)), affinity); 21 return PositionWithAffinity(canonicalPositionOf(Position(&anchor, offset)), affinity);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 RefPtrWillBeRawPtr<Element> body = document().body(); 60 RefPtrWillBeRawPtr<Element> body = document().body();
60 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION); 61 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION);
61 62
62 IntRect boundsInDOMTree = absoluteCaretBoundsOf(createVisiblePosition(Positi on(one.get(), 0))); 63 IntRect boundsInDOMTree = absoluteCaretBoundsOf(createVisiblePosition(Positi on(one.get(), 0)));
63 IntRect boundsInComposedTree = absoluteCaretBoundsOf(createVisiblePosition(P ositionInComposedTree(one.get(), 0))); 64 IntRect boundsInComposedTree = absoluteCaretBoundsOf(createVisiblePosition(P ositionInComposedTree(one.get(), 0)));
64 65
65 EXPECT_FALSE(boundsInDOMTree.isEmpty()); 66 EXPECT_FALSE(boundsInDOMTree.isEmpty());
66 EXPECT_EQ(boundsInDOMTree, boundsInComposedTree); 67 EXPECT_EQ(boundsInDOMTree, boundsInComposedTree);
67 } 68 }
68 69
70 TEST_F(VisibleUnitsTest, associatedLayoutObjectOfFirstLetterPunctuations)
71 {
72 const char* bodyContent = "<style>p:first-letter {color:red;}</style><p id=s ample>(a)bc</p>";
73 setBodyContent(bodyContent);
74 updateLayoutAndStyleForPainting();
75
76 Node* sample = document().getElementById("sample");
77 Node* text = sample->firstChild();
78
79 LayoutTextFragment* layoutObject0 = toLayoutTextFragment(associatedLayoutObj ectOf(*text, 0));
80 EXPECT_FALSE(layoutObject0->isRemainingTextLayoutObject());
81
82 LayoutTextFragment* layoutObject1 = toLayoutTextFragment(associatedLayoutObj ectOf(*text, 1));
83 EXPECT_EQ(layoutObject0, layoutObject1) << "A character 'a' should be part o f first letter.";
84
85 LayoutTextFragment* layoutObject2 = toLayoutTextFragment(associatedLayoutObj ectOf(*text, 2));
86 EXPECT_EQ(layoutObject0, layoutObject2) << "close parenthesis should be part of first letter.";
87
88 LayoutTextFragment* layoutObject3 = toLayoutTextFragment(associatedLayoutObj ectOf(*text, 3));
89 EXPECT_TRUE(layoutObject3->isRemainingTextLayoutObject());
90 }
91
92 TEST_F(VisibleUnitsTest, associatedLayoutObjectOfFirstLetterSplit)
93 {
94 const char* bodyContent = "<style>p:first-letter {color:red;}</style><p id=s ample>abc</p>";
95 setBodyContent(bodyContent);
96 updateLayoutAndStyleForPainting();
97
98 Node* sample = document().getElementById("sample");
99 Node* firstLetter = sample->firstChild();
100 // Split "abc" into "a" "bc"
101 toText(firstLetter)->splitText(1, ASSERT_NO_EXCEPTION);
102 updateLayoutAndStyleForPainting();
103
104 LayoutTextFragment* layoutObject0 = toLayoutTextFragment(associatedLayoutObj ectOf(*firstLetter, 0));
105 EXPECT_FALSE(layoutObject0->isRemainingTextLayoutObject());
106
107 LayoutTextFragment* layoutObject1 = toLayoutTextFragment(associatedLayoutObj ectOf(*firstLetter, 1));
108 EXPECT_EQ(layoutObject0, layoutObject1);
109 }
110
111 TEST_F(VisibleUnitsTest, associatedLayoutObjectOfFirstLetterWithTrailingWhitespa ce)
112 {
113 const char* bodyContent = "<style>div:first-letter {color:red;}</style><div id=sample>a\n <div></div></div>";
114 setBodyContent(bodyContent);
115 updateLayoutAndStyleForPainting();
116
117 Node* sample = document().getElementById("sample");
118 Node* text = sample->firstChild();
119
120 LayoutTextFragment* layoutObject0 = toLayoutTextFragment(associatedLayoutObj ectOf(*text, 0));
121 EXPECT_FALSE(layoutObject0->isRemainingTextLayoutObject());
122
123 LayoutTextFragment* layoutObject1 = toLayoutTextFragment(associatedLayoutObj ectOf(*text, 1));
124 EXPECT_TRUE(layoutObject1->isRemainingTextLayoutObject());
125
126 LayoutTextFragment* layoutObject2 = toLayoutTextFragment(associatedLayoutObj ectOf(*text, 2));
127 EXPECT_EQ(layoutObject1, layoutObject2);
128 }
129
69 TEST_F(VisibleUnitsTest, caretMinOffset) 130 TEST_F(VisibleUnitsTest, caretMinOffset)
70 { 131 {
71 const char* bodyContent = "<p id=one>one</p>"; 132 const char* bodyContent = "<p id=one>one</p>";
72 setBodyContent(bodyContent); 133 setBodyContent(bodyContent);
73 134
74 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); 135 RefPtrWillBeRawPtr<Element> one = document().getElementById("one");
75 136
76 EXPECT_EQ(0, caretMinOffset(one->firstChild())); 137 EXPECT_EQ(0, caretMinOffset(one->firstChild()));
77 } 138 }
78 139
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 EXPECT_EQ(Position(sample, 3), mostBackwardCaretPosition(Position(sample, 3) )); 857 EXPECT_EQ(Position(sample, 3), mostBackwardCaretPosition(Position(sample, 3) ));
797 EXPECT_EQ(Position(sample, 4), mostBackwardCaretPosition(Position(sample, 4) )); 858 EXPECT_EQ(Position(sample, 4), mostBackwardCaretPosition(Position(sample, 4) ));
798 EXPECT_EQ(Position(sample, 5), mostBackwardCaretPosition(Position(sample, 5) )); 859 EXPECT_EQ(Position(sample, 5), mostBackwardCaretPosition(Position(sample, 5) ));
799 EXPECT_EQ(Position(sample, 6), mostBackwardCaretPosition(Position(sample, 6) )); 860 EXPECT_EQ(Position(sample, 6), mostBackwardCaretPosition(Position(sample, 6) ));
800 EXPECT_EQ(Position(sample, 6), mostBackwardCaretPosition(Position(sample, 7) )); 861 EXPECT_EQ(Position(sample, 6), mostBackwardCaretPosition(Position(sample, 7) ));
801 EXPECT_EQ(Position(sample, 6), mostBackwardCaretPosition(Position::lastPosit ionInNode(sample->parentNode()))); 862 EXPECT_EQ(Position(sample, 6), mostBackwardCaretPosition(Position::lastPosit ionInNode(sample->parentNode())));
802 EXPECT_EQ(Position(sample, 6), mostBackwardCaretPosition(Position::afterNode (sample->parentNode()))); 863 EXPECT_EQ(Position(sample, 6), mostBackwardCaretPosition(Position::afterNode (sample->parentNode())));
803 EXPECT_EQ(Position::lastPositionInNode(document().body()), mostBackwardCaret Position(Position::lastPositionInNode(document().body()))); 864 EXPECT_EQ(Position::lastPositionInNode(document().body()), mostBackwardCaret Position(Position::lastPositionInNode(document().body())));
804 } 865 }
805 866
867 TEST_F(VisibleUnitsTest, mostBackwardCaretPositionFirstLetterSplit)
868 {
869 const char* bodyContent = "<style>p:first-letter {color:red;}</style><p id=s ample>abc</p>";
870 setBodyContent(bodyContent);
871 updateLayoutAndStyleForPainting();
872
873 Node* sample = document().getElementById("sample");
874 Node* firstLetter = sample->firstChild();
875 // Split "abc" into "a" "bc"
876 RefPtrWillBeRawPtr<Text> remaining = toText(firstLetter)->splitText(1, ASSER T_NO_EXCEPTION);
877 updateLayoutAndStyleForPainting();
878
879 EXPECT_EQ(Position(sample, 0), mostBackwardCaretPosition(Position(firstLette r, 0)));
880 EXPECT_EQ(Position(firstLetter, 1), mostBackwardCaretPosition(Position(first Letter, 1)));
881 EXPECT_EQ(Position(firstLetter, 1), mostBackwardCaretPosition(Position(remai ning, 0)));
882 EXPECT_EQ(Position(remaining, 1), mostBackwardCaretPosition(Position(remaini ng, 1)));
883 EXPECT_EQ(Position(remaining, 2), mostBackwardCaretPosition(Position(remaini ng, 2)));
884 EXPECT_EQ(Position(remaining, 2), mostBackwardCaretPosition(Position::lastPo sitionInNode(sample)));
885 EXPECT_EQ(Position(remaining, 2), mostBackwardCaretPosition(Position::afterN ode(sample)));
886 }
887
806 TEST_F(VisibleUnitsTest, mostForwardCaretPositionAfterAnchor) 888 TEST_F(VisibleUnitsTest, mostForwardCaretPositionAfterAnchor)
807 { 889 {
808 const char* bodyContent = "<p id='host'><b id='one'>1</b></p>"; 890 const char* bodyContent = "<p id='host'><b id='one'>1</b></p>";
809 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten t><b id='three'>333</b>"; 891 const char* shadowContent = "<b id='two'>22</b><content select=#one></conten t><b id='three'>333</b>";
810 setBodyContent(bodyContent); 892 setBodyContent(bodyContent);
811 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); 893 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host");
812 updateLayoutAndStyleForPainting(); 894 updateLayoutAndStyleForPainting();
813 895
814 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); 896 RefPtrWillBeRawPtr<Element> host = document().getElementById("host");
815 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); 897 RefPtrWillBeRawPtr<Element> one = document().getElementById("one");
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 EXPECT_EQ(PositionInComposedTree(space, 1), startOfWord(createVisiblePositio nInComposedTree(*three, 1)).deepEquivalent()); 1225 EXPECT_EQ(PositionInComposedTree(space, 1), startOfWord(createVisiblePositio nInComposedTree(*three, 1)).deepEquivalent());
1144 1226
1145 EXPECT_EQ(Position(four, 0), startOfWord(createVisiblePositionInDOMTree(*fou r, 1)).deepEquivalent()); 1227 EXPECT_EQ(Position(four, 0), startOfWord(createVisiblePositionInDOMTree(*fou r, 1)).deepEquivalent());
1146 EXPECT_EQ(PositionInComposedTree(four, 0), startOfWord(createVisiblePosition InComposedTree(*four, 1)).deepEquivalent()); 1228 EXPECT_EQ(PositionInComposedTree(four, 0), startOfWord(createVisiblePosition InComposedTree(*four, 1)).deepEquivalent());
1147 1229
1148 EXPECT_EQ(Position(space, 1), startOfWord(createVisiblePositionInDOMTree(*fi ve, 1)).deepEquivalent()); 1230 EXPECT_EQ(Position(space, 1), startOfWord(createVisiblePositionInDOMTree(*fi ve, 1)).deepEquivalent());
1149 EXPECT_EQ(PositionInComposedTree(space, 1), startOfWord(createVisiblePositio nInComposedTree(*five, 1)).deepEquivalent()); 1231 EXPECT_EQ(PositionInComposedTree(space, 1), startOfWord(createVisiblePositio nInComposedTree(*five, 1)).deepEquivalent());
1150 } 1232 }
1151 1233
1152 } // namespace blink 1234 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleUnits.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698