| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/editing/StyledMarkupSerializer.h" | 6 #include "core/editing/StyledMarkupSerializer.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 { | 79 { |
| 80 return createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", s
hadowContent); | 80 return createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", s
hadowContent); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST_F(StyledMarkupSerializerTest, TextOnly) | 83 TEST_F(StyledMarkupSerializerTest, TextOnly) |
| 84 { | 84 { |
| 85 const char* bodyContent = "Hello world!"; | 85 const char* bodyContent = "Hello world!"; |
| 86 setBodyContent(bodyContent); | 86 setBodyContent(bodyContent); |
| 87 const char* expectedResult = "<span style=\"display: inline !important; floa
t: none;\">Hello world!</span>"; | 87 const char* expectedResult = "<span style=\"display: inline !important; floa
t: none;\">Hello world!</span>"; |
| 88 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); | 88 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); |
| 89 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>()); |
| 89 } | 90 } |
| 90 | 91 |
| 91 TEST_F(StyledMarkupSerializerTest, BlockFormatting) | 92 TEST_F(StyledMarkupSerializerTest, BlockFormatting) |
| 92 { | 93 { |
| 93 const char* bodyContent = "<div>Hello world!</div>"; | 94 const char* bodyContent = "<div>Hello world!</div>"; |
| 94 setBodyContent(bodyContent); | 95 setBodyContent(bodyContent); |
| 95 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); | 96 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); |
| 97 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>()); |
| 96 } | 98 } |
| 97 | 99 |
| 98 TEST_F(StyledMarkupSerializerTest, FormControlInput) | 100 TEST_F(StyledMarkupSerializerTest, FormControlInput) |
| 99 { | 101 { |
| 100 const char* bodyContent = "<input value='foo'>"; | 102 const char* bodyContent = "<input value='foo'>"; |
| 101 setBodyContent(bodyContent); | 103 setBodyContent(bodyContent); |
| 102 const char* expectedResult = "<input value=\"foo\">"; | 104 const char* expectedResult = "<input value=\"foo\">"; |
| 103 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); | 105 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); |
| 106 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>()); |
| 104 } | 107 } |
| 105 | 108 |
| 106 TEST_F(StyledMarkupSerializerTest, FormControlInputRange) | 109 TEST_F(StyledMarkupSerializerTest, FormControlInputRange) |
| 107 { | 110 { |
| 108 const char* bodyContent = "<input type=range>"; | 111 const char* bodyContent = "<input type=range>"; |
| 109 setBodyContent(bodyContent); | 112 setBodyContent(bodyContent); |
| 110 const char* expectedResult = "<input type=\"range\">"; | 113 const char* expectedResult = "<input type=\"range\">"; |
| 111 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); | 114 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); |
| 115 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>()); |
| 112 } | 116 } |
| 113 | 117 |
| 114 TEST_F(StyledMarkupSerializerTest, FormControlSelect) | 118 TEST_F(StyledMarkupSerializerTest, FormControlSelect) |
| 115 { | 119 { |
| 116 const char* bodyContent = "<select><option value=\"1\">one</option><option v
alue=\"2\">two</option></select>"; | 120 const char* bodyContent = "<select><option value=\"1\">one</option><option v
alue=\"2\">two</option></select>"; |
| 117 setBodyContent(bodyContent); | 121 setBodyContent(bodyContent); |
| 118 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); | 122 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); |
| 123 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>()); |
| 119 } | 124 } |
| 120 | 125 |
| 121 TEST_F(StyledMarkupSerializerTest, FormControlTextArea) | 126 TEST_F(StyledMarkupSerializerTest, FormControlTextArea) |
| 122 { | 127 { |
| 123 const char* bodyContent = "<textarea>foo bar</textarea>"; | 128 const char* bodyContent = "<textarea>foo bar</textarea>"; |
| 124 setBodyContent(bodyContent); | 129 setBodyContent(bodyContent); |
| 125 const char* expectedResult = "<textarea></textarea>"; | 130 const char* expectedResult = "<textarea></textarea>"; |
| 126 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()) | 131 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()) |
| 127 << "contents of TEXTAREA element should not be appeared."; | 132 << "contents of TEXTAREA element should not be appeared."; |
| 133 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>()); |
| 128 } | 134 } |
| 129 | 135 |
| 130 TEST_F(StyledMarkupSerializerTest, HeadingFormatting) | 136 TEST_F(StyledMarkupSerializerTest, HeadingFormatting) |
| 131 { | 137 { |
| 132 const char* bodyContent = "<h4>Hello world!</h4>"; | 138 const char* bodyContent = "<h4>Hello world!</h4>"; |
| 133 setBodyContent(bodyContent); | 139 setBodyContent(bodyContent); |
| 134 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); | 140 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); |
| 141 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>()); |
| 135 } | 142 } |
| 136 | 143 |
| 137 TEST_F(StyledMarkupSerializerTest, InlineFormatting) | 144 TEST_F(StyledMarkupSerializerTest, InlineFormatting) |
| 138 { | 145 { |
| 139 const char* bodyContent = "<b>Hello world!</b>"; | 146 const char* bodyContent = "<b>Hello world!</b>"; |
| 140 setBodyContent(bodyContent); | 147 setBodyContent(bodyContent); |
| 141 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); | 148 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); |
| 149 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>()); |
| 142 } | 150 } |
| 143 | 151 |
| 144 TEST_F(StyledMarkupSerializerTest, Mixed) | 152 TEST_F(StyledMarkupSerializerTest, Mixed) |
| 145 { | 153 { |
| 146 const char* bodyContent = "<i>foo<b>bar</b>baz</i>"; | 154 const char* bodyContent = "<i>foo<b>bar</b>baz</i>"; |
| 147 setBodyContent(bodyContent); | 155 setBodyContent(bodyContent); |
| 148 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); | 156 EXPECT_EQ(bodyContent, serialize<EditingStrategy>()); |
| 157 EXPECT_EQ(bodyContent, serialize<EditingInComposedTreeStrategy>()); |
| 149 } | 158 } |
| 150 | 159 |
| 151 TEST_F(StyledMarkupSerializerTest, ShadowTreeDistributeOrder) | 160 TEST_F(StyledMarkupSerializerTest, ShadowTreeDistributeOrder) |
| 152 { | 161 { |
| 153 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\
">22</b>33</p>"; | 162 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\
">22</b>33</p>"; |
| 154 const char* shadowContent = "<a><content select=#two></content><content sele
ct=#one></content></a>"; | 163 const char* shadowContent = "<a><content select=#two></content><content sele
ct=#one></content></a>"; |
| 155 setBodyContent(bodyContent); | 164 setBodyContent(bodyContent); |
| 156 setShadowContent(shadowContent); | 165 setShadowContent(shadowContent); |
| 157 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\">22</b></p>", ser
ialize<EditingStrategy>()) | 166 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\">22</b></p>", ser
ialize<EditingStrategy>()) |
| 158 << "00 and 33 aren't appeared since they aren't distributed."; | 167 << "00 and 33 aren't appeared since they aren't distributed."; |
| 168 EXPECT_EQ("<p id=\"host\"><a><b id=\"two\">22</b><b id=\"one\">11</b></a></p
>", serialize<EditingInComposedTreeStrategy>()) |
| 169 << "00 and 33 aren't appeared since they aren't distributed."; |
| 170 } |
| 171 |
| 172 TEST_F(StyledMarkupSerializerTest, ShadowTreeInput) |
| 173 { |
| 174 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\
"><input value=\"22\"></b>33</p>"; |
| 175 const char* shadowContent = "<a><content select=#two></content><content sele
ct=#one></content></a>"; |
| 176 setBodyContent(bodyContent); |
| 177 setShadowContent(shadowContent); |
| 178 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\"><input value=\"2
2\"></b></p>", serialize<EditingStrategy>()) |
| 179 << "00 and 33 aren't appeared since they aren't distributed."; |
| 180 EXPECT_EQ("<p id=\"host\"><a><b id=\"two\"><input value=\"22\"></b><b id=\"o
ne\">11</b></a></p>", serialize<EditingInComposedTreeStrategy>()) |
| 181 << "00 and 33 aren't appeared since they aren't distributed."; |
| 159 } | 182 } |
| 160 | 183 |
| 161 TEST_F(StyledMarkupSerializerTest, ShadowTreeNested) | 184 TEST_F(StyledMarkupSerializerTest, ShadowTreeNested) |
| 162 { | 185 { |
| 163 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\
">22</b>33</p>"; | 186 const char* bodyContent = "<p id=\"host\">00<b id=\"one\">11</b><b id=\"two\
">22</b>33</p>"; |
| 164 const char* shadowContent1 = "<a><content select=#two></content><b id=host2>
</b><content select=#one></content></a>"; | 187 const char* shadowContent1 = "<a><content select=#two></content><b id=host2>
</b><content select=#one></content></a>"; |
| 165 const char* shadowContent2 = "NESTED"; | 188 const char* shadowContent2 = "NESTED"; |
| 166 setBodyContent(bodyContent); | 189 setBodyContent(bodyContent); |
| 167 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = setShadowContent(shadowContent1
); | 190 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = setShadowContent(shadowContent1
); |
| 168 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host2", shado
wContent2); | 191 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host2", shado
wContent2); |
| 169 | 192 |
| 170 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\">22</b></p>", ser
ialize<EditingStrategy>()) | 193 EXPECT_EQ("<p id=\"host\"><b id=\"one\">11</b><b id=\"two\">22</b></p>", ser
ialize<EditingStrategy>()) |
| 171 << "00 and 33 aren't appeared since they aren't distributed."; | 194 << "00 and 33 aren't appeared since they aren't distributed."; |
| 195 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>()) |
| 196 << "00 and 33 aren't appeared since they aren't distributed."; |
| 172 } | 197 } |
| 173 | 198 |
| 174 TEST_F(StyledMarkupSerializerTest, StyleDisplayNone) | 199 TEST_F(StyledMarkupSerializerTest, StyleDisplayNone) |
| 175 { | 200 { |
| 176 const char* bodyContent = "<b>00<i style='display:none'>11</i>22</b>"; | 201 const char* bodyContent = "<b>00<i style='display:none'>11</i>22</b>"; |
| 177 setBodyContent(bodyContent); | 202 setBodyContent(bodyContent); |
| 178 const char* expectedResult = "<b>0022</b>"; | 203 const char* expectedResult = "<b>0022</b>"; |
| 179 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); | 204 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); |
| 205 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>()); |
| 180 } | 206 } |
| 181 | 207 |
| 182 } // namespace blink | 208 } // namespace blink |
| OLD | NEW |