| 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/serializers/StyledMarkupSerializer.h" | 5 #include "core/editing/serializers/StyledMarkupSerializer.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 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 EXPECT_EQ("<p id=\"host\"><a><b id=\"two\"><input value=\"22\"></b><b id=\"o
ne\">11</b></a></p>", serialize<EditingInFlatTreeStrategy>()) | 146 EXPECT_EQ("<p id=\"host\"><a><b id=\"two\"><input value=\"22\"></b><b id=\"o
ne\">11</b></a></p>", serialize<EditingInFlatTreeStrategy>()) |
| 147 << "00 and 33 aren't appeared since they aren't distributed."; | 147 << "00 and 33 aren't appeared since they aren't distributed."; |
| 148 } | 148 } |
| 149 | 149 |
| 150 TEST_F(StyledMarkupSerializerTest, ShadowTreeNested) | 150 TEST_F(StyledMarkupSerializerTest, ShadowTreeNested) |
| 151 { | 151 { |
| 152 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\
">22</b>33</p>"; | 152 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\
">22</b>33</p>"; |
| 153 const char* shadowContent1 = "<a><content select=#two></content><b id=host2>
</b><content select=#one></content></a>"; | 153 const char* shadowContent1 = "<a><content select=#two></content><b id=host2>
</b><content select=#one></content></a>"; |
| 154 const char* shadowContent2 = "NESTED"; | 154 const char* shadowContent2 = "NESTED"; |
| 155 setBodyContent(bodyContent); | 155 setBodyContent(bodyContent); |
| 156 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = setShadowContent(shadowContent1
, "host"); | 156 RawPtr<ShadowRoot> shadowRoot1 = setShadowContent(shadowContent1, "host"); |
| 157 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host2", shado
wContent2); | 157 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host2", shado
wContent2); |
| 158 | 158 |
| 159 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\">22</b></p>", ser
ialize<EditingStrategy>()) | 159 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\">22</b></p>", ser
ialize<EditingStrategy>()) |
| 160 << "00 and 33 aren't appeared since they aren't distributed."; | 160 << "00 and 33 aren't appeared since they aren't distributed."; |
| 161 EXPECT_EQ("<p id=\"host\"><a><b id=\"two\">22</b><b id=\"host2\">NESTED</b><
b id=\"one\">11</b></a></p>", serialize<EditingInFlatTreeStrategy>()) | 161 EXPECT_EQ("<p id=\"host\"><a><b id=\"two\">22</b><b id=\"host2\">NESTED</b><
b id=\"one\">11</b></a></p>", serialize<EditingInFlatTreeStrategy>()) |
| 162 << "00 and 33 aren't appeared since they aren't distributed."; | 162 << "00 and 33 aren't appeared since they aren't distributed."; |
| 163 } | 163 } |
| 164 | 164 |
| 165 TEST_F(StyledMarkupSerializerTest, ShadowTreeInterchangedNewline) | 165 TEST_F(StyledMarkupSerializerTest, ShadowTreeInterchangedNewline) |
| 166 { | 166 { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 194 const char* bodyContent = "<div style='display:none'>11</div>\n\n"; | 194 const char* bodyContent = "<div style='display:none'>11</div>\n\n"; |
| 195 setBodyContent(bodyContent); | 195 setBodyContent(bodyContent); |
| 196 EXPECT_EQ("", serialize<EditingStrategy>()); | 196 EXPECT_EQ("", serialize<EditingStrategy>()); |
| 197 EXPECT_EQ("", serialize<EditingInFlatTreeStrategy>()); | 197 EXPECT_EQ("", serialize<EditingInFlatTreeStrategy>()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 TEST_F(StyledMarkupSerializerTest, ShadowTreeStyle) | 200 TEST_F(StyledMarkupSerializerTest, ShadowTreeStyle) |
| 201 { | 201 { |
| 202 const char* bodyContent = "<p id='host' style='color: red'><span style='font
-weight: bold;'><span id='one'>11</span></span></p>\n"; | 202 const char* bodyContent = "<p id='host' style='color: red'><span style='font
-weight: bold;'><span id='one'>11</span></span></p>\n"; |
| 203 setBodyContent(bodyContent); | 203 setBodyContent(bodyContent); |
| 204 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); | 204 RawPtr<Element> one = document().getElementById("one"); |
| 205 RefPtrWillBeRawPtr<Text> text = toText(one->firstChild()); | 205 RawPtr<Text> text = toText(one->firstChild()); |
| 206 Position startDOM(text, 0); | 206 Position startDOM(text, 0); |
| 207 Position endDOM(text, 2); | 207 Position endDOM(text, 2); |
| 208 const std::string& serializedDOM = serializePart<EditingStrategy>(startDOM,
endDOM, AnnotateForInterchange); | 208 const std::string& serializedDOM = serializePart<EditingStrategy>(startDOM,
endDOM, AnnotateForInterchange); |
| 209 | 209 |
| 210 bodyContent = "<p id='host' style='color: red'>00<span id='one'>11</span>22<
/p>\n"; | 210 bodyContent = "<p id='host' style='color: red'>00<span id='one'>11</span>22<
/p>\n"; |
| 211 const char* shadowContent = "<span style='font-weight: bold'><content select
=#one></content></span>"; | 211 const char* shadowContent = "<span style='font-weight: bold'><content select
=#one></content></span>"; |
| 212 setBodyContent(bodyContent); | 212 setBodyContent(bodyContent); |
| 213 setShadowContent(shadowContent, "host"); | 213 setShadowContent(shadowContent, "host"); |
| 214 one = document().getElementById("one"); | 214 one = document().getElementById("one"); |
| 215 text = toText(one->firstChild()); | 215 text = toText(one->firstChild()); |
| 216 PositionInFlatTree startICT(text, 0); | 216 PositionInFlatTree startICT(text, 0); |
| 217 PositionInFlatTree endICT(text, 2); | 217 PositionInFlatTree endICT(text, 2); |
| 218 const std::string& serializedICT = serializePart<EditingInFlatTreeStrategy>(
startICT, endICT, AnnotateForInterchange); | 218 const std::string& serializedICT = serializePart<EditingInFlatTreeStrategy>(
startICT, endICT, AnnotateForInterchange); |
| 219 | 219 |
| 220 EXPECT_EQ(serializedDOM, serializedICT); | 220 EXPECT_EQ(serializedDOM, serializedICT); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(StyledMarkupSerializerTest, AcrossShadow) | 223 TEST_F(StyledMarkupSerializerTest, AcrossShadow) |
| 224 { | 224 { |
| 225 const char* bodyContent = "<p id='host1'>[<span id='one'>11</span>]</p><p id
='host2'>[<span id='two'>22</span>]</p>"; | 225 const char* bodyContent = "<p id='host1'>[<span id='one'>11</span>]</p><p id
='host2'>[<span id='two'>22</span>]</p>"; |
| 226 setBodyContent(bodyContent); | 226 setBodyContent(bodyContent); |
| 227 RefPtrWillBeRawPtr<Element> one = document().getElementById("one"); | 227 RawPtr<Element> one = document().getElementById("one"); |
| 228 RefPtrWillBeRawPtr<Element> two = document().getElementById("two"); | 228 RawPtr<Element> two = document().getElementById("two"); |
| 229 Position startDOM(toText(one->firstChild()), 0); | 229 Position startDOM(toText(one->firstChild()), 0); |
| 230 Position endDOM(toText(two->firstChild()), 2); | 230 Position endDOM(toText(two->firstChild()), 2); |
| 231 const std::string& serializedDOM = serializePart<EditingStrategy>(startDOM,
endDOM, AnnotateForInterchange); | 231 const std::string& serializedDOM = serializePart<EditingStrategy>(startDOM,
endDOM, AnnotateForInterchange); |
| 232 | 232 |
| 233 bodyContent = "<p id='host1'><span id='one'>11</span></p><p id='host2'><span
id='two'>22</span></p>"; | 233 bodyContent = "<p id='host1'><span id='one'>11</span></p><p id='host2'><span
id='two'>22</span></p>"; |
| 234 const char* shadowContent1 = "[<content select=#one></content>]"; | 234 const char* shadowContent1 = "[<content select=#one></content>]"; |
| 235 const char* shadowContent2 = "[<content select=#two></content>]"; | 235 const char* shadowContent2 = "[<content select=#two></content>]"; |
| 236 setBodyContent(bodyContent); | 236 setBodyContent(bodyContent); |
| 237 setShadowContent(shadowContent1, "host1"); | 237 setShadowContent(shadowContent1, "host1"); |
| 238 setShadowContent(shadowContent2, "host2"); | 238 setShadowContent(shadowContent2, "host2"); |
| 239 one = document().getElementById("one"); | 239 one = document().getElementById("one"); |
| 240 two = document().getElementById("two"); | 240 two = document().getElementById("two"); |
| 241 PositionInFlatTree startICT(toText(one->firstChild()), 0); | 241 PositionInFlatTree startICT(toText(one->firstChild()), 0); |
| 242 PositionInFlatTree endICT(toText(two->firstChild()), 2); | 242 PositionInFlatTree endICT(toText(two->firstChild()), 2); |
| 243 const std::string& serializedICT = serializePart<EditingInFlatTreeStrategy>(
startICT, endICT, AnnotateForInterchange); | 243 const std::string& serializedICT = serializePart<EditingInFlatTreeStrategy>(
startICT, endICT, AnnotateForInterchange); |
| 244 | 244 |
| 245 EXPECT_EQ(serializedDOM, serializedICT); | 245 EXPECT_EQ(serializedDOM, serializedICT); |
| 246 } | 246 } |
| 247 | 247 |
| 248 TEST_F(StyledMarkupSerializerTest, AcrossInvisibleElements) | 248 TEST_F(StyledMarkupSerializerTest, AcrossInvisibleElements) |
| 249 { | 249 { |
| 250 const char* bodyContent = "<span id='span1' style='display: none'>11</span><
span id='span2' style='display: none'>22</span>"; | 250 const char* bodyContent = "<span id='span1' style='display: none'>11</span><
span id='span2' style='display: none'>22</span>"; |
| 251 setBodyContent(bodyContent); | 251 setBodyContent(bodyContent); |
| 252 RefPtrWillBeRawPtr<Element> span1 = document().getElementById("span1"); | 252 RawPtr<Element> span1 = document().getElementById("span1"); |
| 253 RefPtrWillBeRawPtr<Element> span2 = document().getElementById("span2"); | 253 RawPtr<Element> span2 = document().getElementById("span2"); |
| 254 Position startDOM = Position::firstPositionInNode(span1.get()); | 254 Position startDOM = Position::firstPositionInNode(span1.get()); |
| 255 Position endDOM = Position::lastPositionInNode(span2.get()); | 255 Position endDOM = Position::lastPositionInNode(span2.get()); |
| 256 EXPECT_EQ("", serializePart<EditingStrategy>(startDOM, endDOM)); | 256 EXPECT_EQ("", serializePart<EditingStrategy>(startDOM, endDOM)); |
| 257 PositionInFlatTree startICT = PositionInFlatTree::firstPositionInNode(span1.
get()); | 257 PositionInFlatTree startICT = PositionInFlatTree::firstPositionInNode(span1.
get()); |
| 258 PositionInFlatTree endICT = PositionInFlatTree::lastPositionInNode(span2.get
()); | 258 PositionInFlatTree endICT = PositionInFlatTree::lastPositionInNode(span2.get
()); |
| 259 EXPECT_EQ("", serializePart<EditingInFlatTreeStrategy>(startICT, endICT)); | 259 EXPECT_EQ("", serializePart<EditingInFlatTreeStrategy>(startICT, endICT)); |
| 260 } | 260 } |
| 261 | 261 |
| 262 } // namespace blink | 262 } // namespace blink |
| OLD | NEW |