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

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

Issue 1295073002: Move serializer related files in core/editing/ related files into core/editing/serializers/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-17T15:24:31 Rebase for Source/web/WebPageSerializerImpl.cpp Created 5 years, 4 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/StyledMarkupSerializer.cpp ('k') | Source/core/editing/TextOffset.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/editing/StyledMarkupSerializer.h"
7
8 #include "core/dom/Text.h"
9 #include "core/editing/EditingTestBase.h"
10
11 namespace blink {
12
13 // This is smoke test of |StyledMarkupSerializer|. Full testing will be done
14 // in layout tests.
15 class StyledMarkupSerializerTest : public EditingTestBase {
16 protected:
17 template <typename Strategy>
18 std::string serialize(EAnnotateForInterchange = DoNotAnnotateForInterchange) ;
19
20 template <typename Strategy>
21 std::string serializePart(const PositionAlgorithm<Strategy>& start, const Po sitionAlgorithm<Strategy>& end, EAnnotateForInterchange = DoNotAnnotateForInterc hange);
22 };
23
24 template <typename Strategy>
25 std::string StyledMarkupSerializerTest::serialize(EAnnotateForInterchange should Annotate)
26 {
27 PositionAlgorithm<Strategy> start = PositionAlgorithm<Strategy>(document().b ody(), PositionAnchorType::BeforeChildren);
28 PositionAlgorithm<Strategy> end = PositionAlgorithm<Strategy>(document().bod y(), PositionAnchorType::AfterChildren);
29 return createMarkup(start, end, shouldAnnotate).utf8().data();
30 }
31
32 template <typename Strategy>
33 std::string StyledMarkupSerializerTest::serializePart(const PositionAlgorithm<St rategy>& start, const PositionAlgorithm<Strategy>& end, EAnnotateForInterchange shouldAnnotate)
34 {
35 return createMarkup(start, end, shouldAnnotate).utf8().data();
36 }
37
38 TEST_F(StyledMarkupSerializerTest, TextOnly)
39 {
40 const char* bodyContent = "Hello world!";
41 setBodyContent(bodyContent);
42 const char* expectedResult = "<span style=\"display: inline !important; floa t: none;\">Hello world!</span>";
43 EXPECT_EQ(expectedResult, serialize<EditingStrategy>());
44 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>());
45 }
46
47 TEST_F(StyledMarkupSerializerTest, BlockFormatting)
48 {
49 const char* bodyContent = "<div>Hello world!</div>";
50 setBodyContent(bodyContent);
51 EXPECT_EQ(bodyContent, serialize<EditingStrategy>());
52 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>());
53 }
54
55 TEST_F(StyledMarkupSerializerTest, FormControlInput)
56 {
57 const char* bodyContent = "<input value='foo'>";
58 setBodyContent(bodyContent);
59 const char* expectedResult = "<input value=\"foo\">";
60 EXPECT_EQ(expectedResult, serialize<EditingStrategy>());
61 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>());
62 }
63
64 TEST_F(StyledMarkupSerializerTest, FormControlInputRange)
65 {
66 const char* bodyContent = "<input type=range>";
67 setBodyContent(bodyContent);
68 const char* expectedResult = "<input type=\"range\">";
69 EXPECT_EQ(expectedResult, serialize<EditingStrategy>());
70 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>());
71 }
72
73 TEST_F(StyledMarkupSerializerTest, FormControlSelect)
74 {
75 const char* bodyContent = "<select><option value=\"1\">one</option><option v alue=\"2\">two</option></select>";
76 setBodyContent(bodyContent);
77 EXPECT_EQ(bodyContent, serialize<EditingStrategy>());
78 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>());
79 }
80
81 TEST_F(StyledMarkupSerializerTest, FormControlTextArea)
82 {
83 const char* bodyContent = "<textarea>foo bar</textarea>";
84 setBodyContent(bodyContent);
85 const char* expectedResult = "<textarea></textarea>";
86 EXPECT_EQ(expectedResult, serialize<EditingStrategy>())
87 << "contents of TEXTAREA element should not be appeared.";
88 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>());
89 }
90
91 TEST_F(StyledMarkupSerializerTest, HeadingFormatting)
92 {
93 const char* bodyContent = "<h4>Hello world!</h4>";
94 setBodyContent(bodyContent);
95 EXPECT_EQ(bodyContent, serialize<EditingStrategy>());
96 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>());
97 }
98
99 TEST_F(StyledMarkupSerializerTest, InlineFormatting)
100 {
101 const char* bodyContent = "<b>Hello world!</b>";
102 setBodyContent(bodyContent);
103 EXPECT_EQ(bodyContent, serialize<EditingStrategy>());
104 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>());
105 }
106
107 TEST_F(StyledMarkupSerializerTest, Mixed)
108 {
109 const char* bodyContent = "<i>foo<b>bar</b>baz</i>";
110 setBodyContent(bodyContent);
111 EXPECT_EQ(bodyContent, serialize<EditingStrategy>());
112 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>());
113 }
114
115 TEST_F(StyledMarkupSerializerTest, ShadowTreeDistributeOrder)
116 {
117 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\ ">22</b>33</p>";
118 const char* shadowContent = "<a><content select=#two></content><content sele ct=#one></content></a>";
119 setBodyContent(bodyContent);
120 setShadowContent(shadowContent);
121 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\">22</b></p>", ser ialize<EditingStrategy>())
122 << "00 and 33 aren't appeared since they aren't distributed.";
123 EXPECT_EQ("<p id=\"host\"><a><b id=\"two\">22</b><b id=\"one\">11</b></a></p >", serialize<EditingInComposedTreeStrategy>())
124 << "00 and 33 aren't appeared since they aren't distributed.";
125 }
126
127 TEST_F(StyledMarkupSerializerTest, ShadowTreeInput)
128 {
129 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\ "><input value=\"22\"></b>33</p>";
130 const char* shadowContent = "<a><content select=#two></content><content sele ct=#one></content></a>";
131 setBodyContent(bodyContent);
132 setShadowContent(shadowContent);
133 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\"><input value=\"2 2\"></b></p>", serialize<EditingStrategy>())
134 << "00 and 33 aren't appeared since they aren't distributed.";
135 EXPECT_EQ("<p id=\"host\"><a><b id=\"two\"><input value=\"22\"></b><b id=\"o ne\">11</b></a></p>", serialize<EditingInComposedTreeStrategy>())
136 << "00 and 33 aren't appeared since they aren't distributed.";
137 }
138
139 TEST_F(StyledMarkupSerializerTest, ShadowTreeNested)
140 {
141 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\ ">22</b>33</p>";
142 const char* shadowContent1 = "<a><content select=#two></content><b id=host2> </b><content select=#one></content></a>";
143 const char* shadowContent2 = "NESTED";
144 setBodyContent(bodyContent);
145 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = setShadowContent(shadowContent1 );
146 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host2", shado wContent2);
147
148 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\">22</b></p>", ser ialize<EditingStrategy>())
149 << "00 and 33 aren't appeared since they aren't distributed.";
150 EXPECT_EQ("<p id=\"host\"><a><b id=\"two\">22</b><b id=\"host2\">NESTED</b>< b id=\"one\">11</b></a></p>", serialize<EditingInComposedTreeStrategy>())
151 << "00 and 33 aren't appeared since they aren't distributed.";
152 }
153
154 TEST_F(StyledMarkupSerializerTest, StyleDisplayNone)
155 {
156 const char* bodyContent = "<b>00<i style='display:none'>11</i>22</b>";
157 setBodyContent(bodyContent);
158 const char* expectedResult = "<b>0022</b>";
159 EXPECT_EQ(expectedResult, serialize<EditingStrategy>());
160 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>());
161 }
162
163 TEST_F(StyledMarkupSerializerTest, StyleDisplayNoneAndNewLines)
164 {
165 const char* bodyContent = "<div style='display:none'>11</div>\n\n";
166 setBodyContent(bodyContent);
167 EXPECT_EQ("", serialize<EditingStrategy>());
168 EXPECT_EQ("", serialize<EditingInComposedTreeStrategy>());
169 }
170
171 TEST_F(StyledMarkupSerializerTest, ShadowTreeStyle)
172 {
173 const char* bodyContent = "<p id='host' style='color: red'><span style='font -weight: bold;'><span id='one'>11</span></span></p>\n";
174 setBodyContent(bodyContent);
175 RefPtrWillBeRawPtr<Element> one = document().getElementById("one");
176 RefPtrWillBeRawPtr<Text> text = toText(one->firstChild());
177 Position startDOM(text, 0);
178 Position endDOM(text, 2);
179 const std::string& serializedDOM = serializePart<EditingStrategy>(startDOM, endDOM, AnnotateForInterchange);
180
181 bodyContent = "<p id='host' style='color: red'>00<span id='one'>11</span>22< /p>\n";
182 const char* shadowContent = "<span style='font-weight: bold'><content select =#one></content></span>";
183 setBodyContent(bodyContent);
184 setShadowContent(shadowContent);
185 one = document().getElementById("one");
186 text = toText(one->firstChild());
187 PositionInComposedTree startICT(text, 0);
188 PositionInComposedTree endICT(text, 2);
189 const std::string& serializedICT = serializePart<EditingInComposedTreeStrate gy>(startICT, endICT, AnnotateForInterchange);
190
191 EXPECT_EQ(serializedDOM, serializedICT);
192 }
193
194 TEST_F(StyledMarkupSerializerTest, AcrossShadow)
195 {
196 const char* bodyContent = "<p id='host1'>[<span id='one'>11</span>]</p><p id ='host2'>[<span id='two'>22</span>]</p>";
197 setBodyContent(bodyContent);
198 RefPtrWillBeRawPtr<Element> one = document().getElementById("one");
199 RefPtrWillBeRawPtr<Element> two = document().getElementById("two");
200 Position startDOM(toText(one->firstChild()), 0);
201 Position endDOM(toText(two->firstChild()), 2);
202 const std::string& serializedDOM = serializePart<EditingStrategy>(startDOM, endDOM, AnnotateForInterchange);
203
204 bodyContent = "<p id='host1'><span id='one'>11</span></p><p id='host2'><span id='two'>22</span></p>";
205 const char* shadowContent1 = "[<content select=#one></content>]";
206 const char* shadowContent2 = "[<content select=#two></content>]";
207 setBodyContent(bodyContent);
208 setShadowContent(shadowContent1, "host1");
209 setShadowContent(shadowContent2, "host2");
210 one = document().getElementById("one");
211 two = document().getElementById("two");
212 PositionInComposedTree startICT(toText(one->firstChild()), 0);
213 PositionInComposedTree endICT(toText(two->firstChild()), 2);
214 const std::string& serializedICT = serializePart<EditingInComposedTreeStrate gy>(startICT, endICT, AnnotateForInterchange);
215
216 EXPECT_EQ(serializedDOM, serializedICT);
217 }
218
219 TEST_F(StyledMarkupSerializerTest, AcrossInvisibleElements)
220 {
221 const char* bodyContent = "<span id='span1' style='display: none'>11</span>< span id='span2' style='display: none'>22</span>";
222 setBodyContent(bodyContent);
223 RefPtrWillBeRawPtr<Element> span1 = document().getElementById("span1");
224 RefPtrWillBeRawPtr<Element> span2 = document().getElementById("span2");
225 Position startDOM = Position::firstPositionInNode(span1.get());
226 Position endDOM = Position::lastPositionInNode(span2.get());
227 EXPECT_EQ("", serializePart<EditingStrategy>(startDOM, endDOM));
228 PositionInComposedTree startICT = PositionInComposedTree::firstPositionInNod e(span1.get());
229 PositionInComposedTree endICT = PositionInComposedTree::lastPositionInNode(s pan2.get());
230 EXPECT_EQ("", serializePart<EditingInComposedTreeStrategy>(startICT, endICT) );
231 }
232
233 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/StyledMarkupSerializer.cpp ('k') | Source/core/editing/TextOffset.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698