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

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

Issue 1204933003: Add StyledMarkupSerializerTest.ShadowTreeStyle (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 "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"
11 #include "core/dom/Node.h" 11 #include "core/dom/Node.h"
12 #include "core/dom/Range.h" 12 #include "core/dom/Range.h"
13 #include "core/dom/Text.h"
13 #include "core/dom/shadow/ShadowRoot.h" 14 #include "core/dom/shadow/ShadowRoot.h"
14 #include "core/editing/markup.h" 15 #include "core/editing/markup.h"
15 #include "core/frame/FrameView.h" 16 #include "core/frame/FrameView.h"
16 #include "core/html/HTMLDocument.h" 17 #include "core/html/HTMLDocument.h"
17 #include "core/html/HTMLElement.h" 18 #include "core/html/HTMLElement.h"
18 #include "core/testing/DummyPageHolder.h" 19 #include "core/testing/DummyPageHolder.h"
19 #include "platform/geometry/IntSize.h" 20 #include "platform/geometry/IntSize.h"
20 #include "wtf/Compiler.h" 21 #include "wtf/Compiler.h"
21 #include "wtf/OwnPtr.h" 22 #include "wtf/OwnPtr.h"
22 #include "wtf/PassRefPtr.h" 23 #include "wtf/PassRefPtr.h"
23 #include "wtf/RefPtr.h" 24 #include "wtf/RefPtr.h"
24 #include "wtf/StdLibExtras.h" 25 #include "wtf/StdLibExtras.h"
25 #include "wtf/testing/WTFTestHelpers.h" 26 #include "wtf/testing/WTFTestHelpers.h"
26 #include <gtest/gtest.h> 27 #include <gtest/gtest.h>
27 #include <string> 28 #include <string>
28 29
29 namespace blink { 30 namespace blink {
30 31
31 // This is smoke test of |StyledMarkupSerializer|. Full testing will be done 32 // This is smoke test of |StyledMarkupSerializer|. Full testing will be done
32 // in layout tests. 33 // in layout tests.
33 class StyledMarkupSerializerTest : public ::testing::Test { 34 class StyledMarkupSerializerTest : public ::testing::Test {
34 protected: 35 protected:
35 void SetUp() override; 36 void SetUp() override;
36 37
37 HTMLDocument& document() const { return *m_document; } 38 HTMLDocument& document() const { return *m_document; }
38 39
39 template <typename Tree> 40 template <typename Tree>
40 std::string serialize(); 41 std::string serialize(EAnnotateForInterchange = DoNotAnnotateForInterchange) ;
42
43 template <typename Tree>
44 std::string serializePart(const typename Tree::PositionType& start, const ty pename Tree::PositionType& end, EAnnotateForInterchange = DoNotAnnotateForInterc hange);
41 45
42 void setBodyContent(const char*); 46 void setBodyContent(const char*);
43 PassRefPtrWillBeRawPtr<ShadowRoot> setShadowContent(const char*); 47 PassRefPtrWillBeRawPtr<ShadowRoot> setShadowContent(const char*);
44 48
45 private: 49 private:
46 OwnPtr<DummyPageHolder> m_dummyPageHolder; 50 OwnPtr<DummyPageHolder> m_dummyPageHolder;
47 HTMLDocument* m_document; 51 HTMLDocument* m_document;
48 }; 52 };
49 53
50 void StyledMarkupSerializerTest::SetUp() 54 void StyledMarkupSerializerTest::SetUp()
51 { 55 {
52 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); 56 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
53 m_document = toHTMLDocument(&m_dummyPageHolder->document()); 57 m_document = toHTMLDocument(&m_dummyPageHolder->document());
54 ASSERT(m_document); 58 ASSERT(m_document);
55 } 59 }
56 60
57 template <typename Tree> 61 template <typename Tree>
58 std::string StyledMarkupSerializerTest::serialize() 62 std::string StyledMarkupSerializerTest::serialize(EAnnotateForInterchange should Annotate)
59 { 63 {
60 using PositionType = typename Tree::PositionType; 64 using PositionType = typename Tree::PositionType;
61 PositionType start = PositionType(m_document->body(), PositionType::Position IsBeforeChildren); 65 PositionType start = PositionType(m_document->body(), PositionType::Position IsBeforeChildren);
62 PositionType end = PositionType(m_document->body(), PositionType::PositionIs AfterChildren); 66 PositionType end = PositionType(m_document->body(), PositionType::PositionIs AfterChildren);
63 return createMarkup(start, end).utf8().data(); 67 return createMarkup(start, end, shouldAnnotate).utf8().data();
68 }
69
70 template <typename Tree>
71 std::string StyledMarkupSerializerTest::serializePart(const typename Tree::Posit ionType& start, const typename Tree::PositionType& end, EAnnotateForInterchange shouldAnnotate)
72 {
73 return createMarkup(start, end, shouldAnnotate).utf8().data();
64 } 74 }
65 75
66 static PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSet InnerHTML(TreeScope& scope, const char* hostElementID, const char* shadowRootCon tent) 76 static PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSet InnerHTML(TreeScope& scope, const char* hostElementID, const char* shadowRootCon tent)
67 { 77 {
68 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicStrin g::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION); 78 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicStrin g::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION);
69 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE PTION); 79 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE PTION);
70 return shadowRoot.release(); 80 return shadowRoot.release();
71 } 81 }
72 82
73 void StyledMarkupSerializerTest::setBodyContent(const char* bodyContent) 83 void StyledMarkupSerializerTest::setBodyContent(const char* bodyContent)
74 { 84 {
75 document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXC EPTION); 85 document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXC EPTION);
76 } 86 }
77 87
78 PassRefPtrWillBeRawPtr<ShadowRoot> StyledMarkupSerializerTest::setShadowContent( const char* shadowContent) 88 PassRefPtrWillBeRawPtr<ShadowRoot> StyledMarkupSerializerTest::setShadowContent( const char* shadowContent)
79 { 89 {
80 return createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", s hadowContent); 90 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithID AndSetInnerHTML(document(), "host", shadowContent);
91 document().recalcDistribution();
92 return shadowRoot;
81 } 93 }
82 94
83 TEST_F(StyledMarkupSerializerTest, TextOnly) 95 TEST_F(StyledMarkupSerializerTest, TextOnly)
84 { 96 {
85 const char* bodyContent = "Hello world!"; 97 const char* bodyContent = "Hello world!";
86 setBodyContent(bodyContent); 98 setBodyContent(bodyContent);
87 const char* expectedResult = "<span style=\"display: inline !important; floa t: none;\">Hello world!</span>"; 99 const char* expectedResult = "<span style=\"display: inline !important; floa t: none;\">Hello world!</span>";
88 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); 100 EXPECT_EQ(expectedResult, serialize<EditingStrategy>());
89 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>()); 101 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>());
90 } 102 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 218 }
207 219
208 TEST_F(StyledMarkupSerializerTest, StyleDisplayNoneAndNewLines) 220 TEST_F(StyledMarkupSerializerTest, StyleDisplayNoneAndNewLines)
209 { 221 {
210 const char* bodyContent = "<div style='display:none'>11</div>\n\n"; 222 const char* bodyContent = "<div style='display:none'>11</div>\n\n";
211 setBodyContent(bodyContent); 223 setBodyContent(bodyContent);
212 EXPECT_EQ("", serialize<EditingStrategy>()); 224 EXPECT_EQ("", serialize<EditingStrategy>());
213 EXPECT_EQ("", serialize<EditingInComposedTreeStrategy>()); 225 EXPECT_EQ("", serialize<EditingInComposedTreeStrategy>());
214 } 226 }
215 227
228 TEST_F(StyledMarkupSerializerTest, ShadowTreeStyle)
229 {
230 const char* bodyContent = "<p id='host' style='color: red'><span style='font -weight: bold;'><span id='one'>11</span></span></p>\n";
231 setBodyContent(bodyContent);
232 Element* one = document().getElementById("one");
yosin_UTC9 2015/06/24 06:15:21 Could you use |RefPtrWillBeRawPtr<Element>|?
hajimehoshi 2015/06/24 06:23:29 Done.
233 Text* text = toText(one->firstChild());
yosin_UTC9 2015/06/24 06:15:21 Could you use |RefPtrWillBeRawPtr<Element>|?
hajimehoshi 2015/06/24 06:23:29 Done.
234 Position startDOM(text, 0);
235 Position endDOM(text, 2);
236 const std::string& serializedDOM = serializePart<EditingStrategy>(startDOM, endDOM, AnnotateForInterchange);
237
238 bodyContent = "<p id='host' style='color: red'>00<span id='one'>11</span>22< /p>\n";
239 const char* shadowContent = "<span style='font-weight: bold'><content select =#one></content></span>";
240 setBodyContent(bodyContent);
241 setShadowContent(shadowContent);
242 one = document().getElementById("one");
243 text = toText(one->firstChild());
244 PositionInComposedTree startICT(text, 0);
245 PositionInComposedTree endICT(text, 2);
246 const std::string& serializedICT = serializePart<EditingInComposedTreeStrate gy>(startICT, endICT, AnnotateForInterchange);
247
248 EXPECT_EQ(serializedDOM, serializedICT);
249 }
250
216 } // namespace blink 251 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698