| 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" | |
| 9 #include "core/dom/Document.h" | |
| 10 #include "core/dom/Element.h" | |
| 11 #include "core/dom/Node.h" | |
| 12 #include "core/dom/Range.h" | |
| 13 #include "core/dom/Text.h" | 8 #include "core/dom/Text.h" |
| 14 #include "core/dom/shadow/ShadowRoot.h" | 9 #include "core/editing/EditingTestBase.h" |
| 15 #include "core/editing/markup.h" | |
| 16 #include "core/frame/FrameView.h" | |
| 17 #include "core/html/HTMLDocument.h" | |
| 18 #include "core/html/HTMLElement.h" | |
| 19 #include "core/testing/DummyPageHolder.h" | |
| 20 #include "platform/geometry/IntSize.h" | |
| 21 #include "wtf/Compiler.h" | |
| 22 #include "wtf/OwnPtr.h" | |
| 23 #include "wtf/PassRefPtr.h" | |
| 24 #include "wtf/RefPtr.h" | |
| 25 #include "wtf/StdLibExtras.h" | |
| 26 #include "wtf/testing/WTFTestHelpers.h" | |
| 27 #include <gtest/gtest.h> | |
| 28 #include <string> | |
| 29 | 10 |
| 30 namespace blink { | 11 namespace blink { |
| 31 | 12 |
| 32 // This is smoke test of |StyledMarkupSerializer|. Full testing will be done | 13 // This is smoke test of |StyledMarkupSerializer|. Full testing will be done |
| 33 // in layout tests. | 14 // in layout tests. |
| 34 class StyledMarkupSerializerTest : public ::testing::Test { | 15 class StyledMarkupSerializerTest : public EditingTestBase { |
| 35 protected: | 16 protected: |
| 36 void SetUp() override; | |
| 37 | |
| 38 HTMLDocument& document() const { return *m_document; } | |
| 39 | |
| 40 template <typename Tree> | 17 template <typename Tree> |
| 41 std::string serialize(EAnnotateForInterchange = DoNotAnnotateForInterchange)
; | 18 std::string serialize(EAnnotateForInterchange = DoNotAnnotateForInterchange)
; |
| 42 | 19 |
| 43 template <typename Tree> | 20 template <typename Tree> |
| 44 std::string serializePart(const typename Tree::PositionType& start, const ty
pename Tree::PositionType& end, EAnnotateForInterchange = DoNotAnnotateForInterc
hange); | 21 std::string serializePart(const typename Tree::PositionType& start, const ty
pename Tree::PositionType& end, EAnnotateForInterchange = DoNotAnnotateForInterc
hange); |
| 45 | |
| 46 void setBodyContent(const char*); | |
| 47 PassRefPtrWillBeRawPtr<ShadowRoot> setShadowContent(const char*); | |
| 48 | |
| 49 private: | |
| 50 OwnPtr<DummyPageHolder> m_dummyPageHolder; | |
| 51 HTMLDocument* m_document; | |
| 52 }; | 22 }; |
| 53 | 23 |
| 54 void StyledMarkupSerializerTest::SetUp() | |
| 55 { | |
| 56 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | |
| 57 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | |
| 58 ASSERT(m_document); | |
| 59 } | |
| 60 | |
| 61 template <typename Tree> | 24 template <typename Tree> |
| 62 std::string StyledMarkupSerializerTest::serialize(EAnnotateForInterchange should
Annotate) | 25 std::string StyledMarkupSerializerTest::serialize(EAnnotateForInterchange should
Annotate) |
| 63 { | 26 { |
| 64 using PositionType = typename Tree::PositionType; | 27 using PositionType = typename Tree::PositionType; |
| 65 PositionType start = PositionType(m_document->body(), PositionType::Position
IsBeforeChildren); | 28 PositionType start = PositionType(document().body(), PositionType::PositionI
sBeforeChildren); |
| 66 PositionType end = PositionType(m_document->body(), PositionType::PositionIs
AfterChildren); | 29 PositionType end = PositionType(document().body(), PositionType::PositionIsA
fterChildren); |
| 67 return createMarkup(start, end, shouldAnnotate).utf8().data(); | 30 return createMarkup(start, end, shouldAnnotate).utf8().data(); |
| 68 } | 31 } |
| 69 | 32 |
| 70 template <typename Tree> | 33 template <typename Tree> |
| 71 std::string StyledMarkupSerializerTest::serializePart(const typename Tree::Posit
ionType& start, const typename Tree::PositionType& end, EAnnotateForInterchange
shouldAnnotate) | 34 std::string StyledMarkupSerializerTest::serializePart(const typename Tree::Posit
ionType& start, const typename Tree::PositionType& end, EAnnotateForInterchange
shouldAnnotate) |
| 72 { | 35 { |
| 73 return createMarkup(start, end, shouldAnnotate).utf8().data(); | 36 return createMarkup(start, end, shouldAnnotate).utf8().data(); |
| 74 } | 37 } |
| 75 | 38 |
| 76 static PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSet
InnerHTML(TreeScope& scope, const char* hostElementID, const char* shadowRootCon
tent) | |
| 77 { | |
| 78 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicStrin
g::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION); | |
| 79 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE
PTION); | |
| 80 return shadowRoot.release(); | |
| 81 } | |
| 82 | |
| 83 void StyledMarkupSerializerTest::setBodyContent(const char* bodyContent) | |
| 84 { | |
| 85 document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXC
EPTION); | |
| 86 } | |
| 87 | |
| 88 PassRefPtrWillBeRawPtr<ShadowRoot> StyledMarkupSerializerTest::setShadowContent(
const char* shadowContent) | |
| 89 { | |
| 90 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithID
AndSetInnerHTML(document(), "host", shadowContent); | |
| 91 document().recalcDistribution(); | |
| 92 return shadowRoot; | |
| 93 } | |
| 94 | |
| 95 TEST_F(StyledMarkupSerializerTest, TextOnly) | 39 TEST_F(StyledMarkupSerializerTest, TextOnly) |
| 96 { | 40 { |
| 97 const char* bodyContent = "Hello world!"; | 41 const char* bodyContent = "Hello world!"; |
| 98 setBodyContent(bodyContent); | 42 setBodyContent(bodyContent); |
| 99 const char* expectedResult = "<span style=\"display: inline !important; floa
t: none;\">Hello world!</span>"; | 43 const char* expectedResult = "<span style=\"display: inline !important; floa
t: none;\">Hello world!</span>"; |
| 100 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); | 44 EXPECT_EQ(expectedResult, serialize<EditingStrategy>()); |
| 101 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>()); | 45 EXPECT_EQ(expectedResult, serialize<EditingInComposedTreeStrategy>()); |
| 102 } | 46 } |
| 103 | 47 |
| 104 TEST_F(StyledMarkupSerializerTest, BlockFormatting) | 48 TEST_F(StyledMarkupSerializerTest, BlockFormatting) |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 one = document().getElementById("one"); | 186 one = document().getElementById("one"); |
| 243 text = toText(one->firstChild()); | 187 text = toText(one->firstChild()); |
| 244 PositionInComposedTree startICT(text, 0); | 188 PositionInComposedTree startICT(text, 0); |
| 245 PositionInComposedTree endICT(text, 2); | 189 PositionInComposedTree endICT(text, 2); |
| 246 const std::string& serializedICT = serializePart<EditingInComposedTreeStrate
gy>(startICT, endICT, AnnotateForInterchange); | 190 const std::string& serializedICT = serializePart<EditingInComposedTreeStrate
gy>(startICT, endICT, AnnotateForInterchange); |
| 247 | 191 |
| 248 EXPECT_EQ(serializedDOM, serializedICT); | 192 EXPECT_EQ(serializedDOM, serializedICT); |
| 249 } | 193 } |
| 250 | 194 |
| 251 } // namespace blink | 195 } // namespace blink |
| OLD | NEW |