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 "core/editing/iterators/SimplifiedBackwardsTextIterator.h" | 5 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h" |
6 | 6 |
7 #include "core/editing/EditingTestBase.h" | 7 #include "core/editing/EditingTestBase.h" |
8 #include "core/editing/EphemeralRange.h" | 8 #include "core/editing/EphemeralRange.h" |
9 #include "wtf/Vector.h" | 9 #include "wtf/Vector.h" |
10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 setBodyContent(bodyContent); | 32 setBodyContent(bodyContent); |
33 setShadowContent(shadowContent, "host"); | 33 setShadowContent(shadowContent, "host"); |
34 updateLayoutAndStyleForPainting(); | 34 updateLayoutAndStyleForPainting(); |
35 | 35 |
36 Element* host = document().getElementById("host"); | 36 Element* host = document().getElementById("host"); |
37 | 37 |
38 // We should not apply DOM tree version to containing shadow tree in | 38 // We should not apply DOM tree version to containing shadow tree in |
39 // general. To record current behavior, we have this test. even if it | 39 // general. To record current behavior, we have this test. even if it |
40 // isn't intuitive. | 40 // isn't intuitive. |
41 EXPECT_EQ("onetwo", extractString<EditingStrategy>(*host)); | 41 EXPECT_EQ("onetwo", extractString<EditingStrategy>(*host)); |
42 EXPECT_EQ("three two one zero", extractString<EditingInComposedTreeStrategy>
(*host)); | 42 EXPECT_EQ("three two one zero", extractString<EditingInFlatTreeStrategy>(*ho
st)); |
43 } | 43 } |
44 | 44 |
45 TEST_F(SimplifiedBackwardsTextIteratorTest, characterAt) | 45 TEST_F(SimplifiedBackwardsTextIteratorTest, characterAt) |
46 { | 46 { |
47 const char* bodyContent = "<a id=host><b id=one>one</b> not appeared <b id=t
wo>two</b></a>"; | 47 const char* bodyContent = "<a id=host><b id=one>one</b> not appeared <b id=t
wo>two</b></a>"; |
48 const char* shadowContent = "three <content select=#two></content> <content
select=#one></content> zero"; | 48 const char* shadowContent = "three <content select=#two></content> <content
select=#one></content> zero"; |
49 setBodyContent(bodyContent); | 49 setBodyContent(bodyContent); |
50 setShadowContent(shadowContent, "host"); | 50 setShadowContent(shadowContent, "host"); |
51 updateLayoutAndStyleForPainting(); | 51 updateLayoutAndStyleForPainting(); |
52 | 52 |
53 Element* host = document().getElementById("host"); | 53 Element* host = document().getElementById("host"); |
54 | 54 |
55 EphemeralRangeTemplate<EditingStrategy> range1(EphemeralRangeTemplate<Editin
gStrategy>::rangeOfContents(*host)); | 55 EphemeralRangeTemplate<EditingStrategy> range1(EphemeralRangeTemplate<Editin
gStrategy>::rangeOfContents(*host)); |
56 SimplifiedBackwardsTextIteratorAlgorithm<EditingStrategy> backIter1(range1.s
tartPosition(), range1.endPosition()); | 56 SimplifiedBackwardsTextIteratorAlgorithm<EditingStrategy> backIter1(range1.s
tartPosition(), range1.endPosition()); |
57 const char* message1 = "|backIter1| should emit 'one' and 'two' in reverse o
rder."; | 57 const char* message1 = "|backIter1| should emit 'one' and 'two' in reverse o
rder."; |
58 EXPECT_EQ('o', backIter1.characterAt(0)) << message1; | 58 EXPECT_EQ('o', backIter1.characterAt(0)) << message1; |
59 EXPECT_EQ('w', backIter1.characterAt(1)) << message1; | 59 EXPECT_EQ('w', backIter1.characterAt(1)) << message1; |
60 EXPECT_EQ('t', backIter1.characterAt(2)) << message1; | 60 EXPECT_EQ('t', backIter1.characterAt(2)) << message1; |
61 backIter1.advance(); | 61 backIter1.advance(); |
62 EXPECT_EQ('e', backIter1.characterAt(0)) << message1; | 62 EXPECT_EQ('e', backIter1.characterAt(0)) << message1; |
63 EXPECT_EQ('n', backIter1.characterAt(1)) << message1; | 63 EXPECT_EQ('n', backIter1.characterAt(1)) << message1; |
64 EXPECT_EQ('o', backIter1.characterAt(2)) << message1; | 64 EXPECT_EQ('o', backIter1.characterAt(2)) << message1; |
65 | 65 |
66 EphemeralRangeTemplate<EditingInComposedTreeStrategy> range2(EphemeralRangeT
emplate<EditingInComposedTreeStrategy>::rangeOfContents(*host)); | 66 EphemeralRangeTemplate<EditingInFlatTreeStrategy> range2(EphemeralRangeTempl
ate<EditingInFlatTreeStrategy>::rangeOfContents(*host)); |
67 SimplifiedBackwardsTextIteratorAlgorithm<EditingInComposedTreeStrategy> back
Iter2(range2.startPosition(), range2.endPosition()); | 67 SimplifiedBackwardsTextIteratorAlgorithm<EditingInFlatTreeStrategy> backIter
2(range2.startPosition(), range2.endPosition()); |
68 const char* message2 = "|backIter2| should emit 'three ', 'two', ' ', 'one'
and ' zero' in reverse order."; | 68 const char* message2 = "|backIter2| should emit 'three ', 'two', ' ', 'one'
and ' zero' in reverse order."; |
69 EXPECT_EQ('o', backIter2.characterAt(0)) << message2; | 69 EXPECT_EQ('o', backIter2.characterAt(0)) << message2; |
70 EXPECT_EQ('r', backIter2.characterAt(1)) << message2; | 70 EXPECT_EQ('r', backIter2.characterAt(1)) << message2; |
71 EXPECT_EQ('e', backIter2.characterAt(2)) << message2; | 71 EXPECT_EQ('e', backIter2.characterAt(2)) << message2; |
72 EXPECT_EQ('z', backIter2.characterAt(3)) << message2; | 72 EXPECT_EQ('z', backIter2.characterAt(3)) << message2; |
73 EXPECT_EQ(' ', backIter2.characterAt(4)) << message2; | 73 EXPECT_EQ(' ', backIter2.characterAt(4)) << message2; |
74 backIter2.advance(); | 74 backIter2.advance(); |
75 EXPECT_EQ('e', backIter2.characterAt(0)) << message2; | 75 EXPECT_EQ('e', backIter2.characterAt(0)) << message2; |
76 EXPECT_EQ('n', backIter2.characterAt(1)) << message2; | 76 EXPECT_EQ('n', backIter2.characterAt(1)) << message2; |
77 EXPECT_EQ('o', backIter2.characterAt(2)) << message2; | 77 EXPECT_EQ('o', backIter2.characterAt(2)) << message2; |
(...skipping 29 matching lines...) Expand all Loading... |
107 backIter1.copyTextTo(&output1, 0, 2); | 107 backIter1.copyTextTo(&output1, 0, 2); |
108 EXPECT_EQ("wo", String(output1.data(), output1.size())) << String::format(me
ssage, 1, "wo").utf8().data(); | 108 EXPECT_EQ("wo", String(output1.data(), output1.size())) << String::format(me
ssage, 1, "wo").utf8().data(); |
109 backIter1.copyTextTo(&output1, 2, 1); | 109 backIter1.copyTextTo(&output1, 2, 1); |
110 EXPECT_EQ("two", String(output1.data(), output1.size())) << String::format(m
essage, 1, "two").utf8().data(); | 110 EXPECT_EQ("two", String(output1.data(), output1.size())) << String::format(m
essage, 1, "two").utf8().data(); |
111 backIter1.advance(); | 111 backIter1.advance(); |
112 backIter1.copyTextTo(&output1, 0, 1); | 112 backIter1.copyTextTo(&output1, 0, 1); |
113 EXPECT_EQ("etwo", String(output1.data(), output1.size())) << String::format(
message, 1, "etwo").utf8().data(); | 113 EXPECT_EQ("etwo", String(output1.data(), output1.size())) << String::format(
message, 1, "etwo").utf8().data(); |
114 backIter1.copyTextTo(&output1, 1, 2); | 114 backIter1.copyTextTo(&output1, 1, 2); |
115 EXPECT_EQ("onetwo", String(output1.data(), output1.size())) << String::forma
t(message, 1, "onetwo").utf8().data(); | 115 EXPECT_EQ("onetwo", String(output1.data(), output1.size())) << String::forma
t(message, 1, "onetwo").utf8().data(); |
116 | 116 |
117 EphemeralRangeTemplate<EditingInComposedTreeStrategy> range2(EphemeralRangeT
emplate<EditingInComposedTreeStrategy>::rangeOfContents(*host)); | 117 EphemeralRangeTemplate<EditingInFlatTreeStrategy> range2(EphemeralRangeTempl
ate<EditingInFlatTreeStrategy>::rangeOfContents(*host)); |
118 SimplifiedBackwardsTextIteratorAlgorithm<EditingInComposedTreeStrategy> back
Iter2(range2.startPosition(), range2.endPosition()); | 118 SimplifiedBackwardsTextIteratorAlgorithm<EditingInFlatTreeStrategy> backIter
2(range2.startPosition(), range2.endPosition()); |
119 BackwardsTextBuffer output2; | 119 BackwardsTextBuffer output2; |
120 backIter2.copyTextTo(&output2, 0, 2); | 120 backIter2.copyTextTo(&output2, 0, 2); |
121 EXPECT_EQ("ro", String(output2.data(), output2.size())) << String::format(me
ssage, 2, "ro").utf8().data(); | 121 EXPECT_EQ("ro", String(output2.data(), output2.size())) << String::format(me
ssage, 2, "ro").utf8().data(); |
122 backIter2.copyTextTo(&output2, 2, 3); | 122 backIter2.copyTextTo(&output2, 2, 3); |
123 EXPECT_EQ(" zero", String(output2.data(), output2.size())) << String::format
(message, 2, " zero").utf8().data(); | 123 EXPECT_EQ(" zero", String(output2.data(), output2.size())) << String::format
(message, 2, " zero").utf8().data(); |
124 backIter2.advance(); | 124 backIter2.advance(); |
125 backIter2.copyTextTo(&output2, 0, 1); | 125 backIter2.copyTextTo(&output2, 0, 1); |
126 EXPECT_EQ("e zero", String(output2.data(), output2.size())) << String::forma
t(message, 2, "e zero").utf8().data(); | 126 EXPECT_EQ("e zero", String(output2.data(), output2.size())) << String::forma
t(message, 2, "e zero").utf8().data(); |
127 backIter2.copyTextTo(&output2, 1, 2); | 127 backIter2.copyTextTo(&output2, 1, 2); |
128 EXPECT_EQ("one zero", String(output2.data(), output2.size())) << String::for
mat(message, 2, "one zero").utf8().data(); | 128 EXPECT_EQ("one zero", String(output2.data(), output2.size())) << String::for
mat(message, 2, "one zero").utf8().data(); |
(...skipping 26 matching lines...) Expand all Loading... |
155 EXPECT_EQ(1, iter.copyTextTo(&buffer, 0, 1)) << "Should emit 1 UChar for '.'
."; | 155 EXPECT_EQ(1, iter.copyTextTo(&buffer, 0, 1)) << "Should emit 1 UChar for '.'
."; |
156 EXPECT_EQ(2, iter.copyTextTo(&buffer, 1, 1)) << "Should emit 2 UChars for 'U
+13141'."; | 156 EXPECT_EQ(2, iter.copyTextTo(&buffer, 1, 1)) << "Should emit 2 UChars for 'U
+13141'."; |
157 EXPECT_EQ(2, iter.copyTextTo(&buffer, 3, 2)) << "Should emit 2 UChars for 'U
+13140'."; | 157 EXPECT_EQ(2, iter.copyTextTo(&buffer, 3, 2)) << "Should emit 2 UChars for 'U
+13140'."; |
158 EXPECT_EQ(5, iter.copyTextTo(&buffer, 5, 4)) << "Should emit 5 UChars for 'U
+13001U+13002 '."; | 158 EXPECT_EQ(5, iter.copyTextTo(&buffer, 5, 4)) << "Should emit 5 UChars for 'U
+13001U+13002 '."; |
159 EXPECT_EQ(2, iter.copyTextTo(&buffer, 10, 2)) << "Should emit 2 UChars for '
U+13000'."; | 159 EXPECT_EQ(2, iter.copyTextTo(&buffer, 10, 2)) << "Should emit 2 UChars for '
U+13000'."; |
160 for (int i = 0; i < 12; i++) | 160 for (int i = 0; i < 12; i++) |
161 EXPECT_EQ(expected[i], buffer[i]); | 161 EXPECT_EQ(expected[i], buffer[i]); |
162 } | 162 } |
163 | 163 |
164 } // namespace blink | 164 } // namespace blink |
OLD | NEW |