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

Side by Side Diff: Source/core/dom/PositionTest.cpp

Issue 1202263004: Use EditingTestBase for PositionTest (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review 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 | Source/core/editing/EditingTestBase.cpp » ('j') | 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/dom/Position.h" 6 #include "core/dom/Position.h"
7 7
8 #include "core/html/HTMLBodyElement.h" 8 #include "core/editing/EditingTestBase.h"
9 #include "core/html/HTMLDocument.h"
10 #include "core/html/HTMLElement.h"
11 #include "core/html/HTMLHtmlElement.h"
12 #include "core/testing/CoreTestHelpers.h"
13 #include "wtf/RefPtr.h"
14 #include <gtest/gtest.h>
15 9
16 namespace blink { 10 namespace blink {
17 11
18 class PositionTest : public ::testing::Test { 12 class PositionTest : public EditingTestBase {
19 protected:
20 void SetUp() override;
21
22 HTMLDocument& document() const;
23 void setBodyContent(const char*);
24 PassRefPtrWillBeRawPtr<ShadowRoot> setShadowContent(const char*);
25
26 private:
27 RefPtrWillBePersistent<HTMLDocument> m_document;
28 }; 13 };
29 14
30 void PositionTest::SetUp()
31 {
32 m_document = HTMLDocument::create();
33 RefPtrWillBeRawPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(*m_docume nt);
34 html->appendChild(HTMLBodyElement::create(*m_document));
35 m_document->appendChild(html.release());
36 }
37
38 HTMLDocument& PositionTest::document() const
39 {
40 return *m_document;
41 }
42
43 void PositionTest::setBodyContent(const char* bodyContent)
44 {
45 document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXC EPTION);
46 }
47
48 static PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSet InnerHTML(TreeScope& scope, const char* hostElementID, const char* shadowRootCon tent)
49 {
50 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicStrin g::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION);
51 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE PTION);
52 return shadowRoot.release();
53 }
54
55 PassRefPtrWillBeRawPtr<ShadowRoot> PositionTest::setShadowContent(const char* sh adowContent)
56 {
57 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithID AndSetInnerHTML(document(), "host", shadowContent);
58 document().recalcDistribution();
59 return shadowRoot;
60 }
61
62 TEST_F(PositionTest, NodeAsRangeLastNodeNull) 15 TEST_F(PositionTest, NodeAsRangeLastNodeNull)
63 { 16 {
64 EXPECT_EQ(nullptr, Position().nodeAsRangeLastNode()); 17 EXPECT_EQ(nullptr, Position().nodeAsRangeLastNode());
65 EXPECT_EQ(nullptr, PositionInComposedTree().nodeAsRangeLastNode()); 18 EXPECT_EQ(nullptr, PositionInComposedTree().nodeAsRangeLastNode());
66 } 19 }
67 20
68 TEST_F(PositionTest, NodeAsRangeLastNode) 21 TEST_F(PositionTest, NodeAsRangeLastNode)
69 { 22 {
70 const char* bodyContent = "<p id='p1'>11</p><p id='p2'></p><p id='p3'>33</p> "; 23 const char* bodyContent = "<p id='p1'>11</p><p id='p2'></p><p id='p3'>33</p> ";
71 setBodyContent(bodyContent); 24 setBodyContent(bodyContent);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 EXPECT_EQ(t3, Position::afterNode(host).nodeAsRangeLastNode()); 69 EXPECT_EQ(t3, Position::afterNode(host).nodeAsRangeLastNode());
117 70
118 EXPECT_EQ(t2, PositionInComposedTree::inParentBeforeNode(*n1).nodeAsRangeLas tNode()); 71 EXPECT_EQ(t2, PositionInComposedTree::inParentBeforeNode(*n1).nodeAsRangeLas tNode());
119 EXPECT_EQ(a, PositionInComposedTree::inParentBeforeNode(*n2).nodeAsRangeLast Node()); 72 EXPECT_EQ(a, PositionInComposedTree::inParentBeforeNode(*n2).nodeAsRangeLast Node());
120 EXPECT_EQ(t1, PositionInComposedTree::inParentAfterNode(*n1).nodeAsRangeLast Node()); 73 EXPECT_EQ(t1, PositionInComposedTree::inParentAfterNode(*n1).nodeAsRangeLast Node());
121 EXPECT_EQ(t2, PositionInComposedTree::inParentAfterNode(*n2).nodeAsRangeLast Node()); 74 EXPECT_EQ(t2, PositionInComposedTree::inParentAfterNode(*n2).nodeAsRangeLast Node());
122 EXPECT_EQ(t1, PositionInComposedTree::afterNode(host).nodeAsRangeLastNode()) ; 75 EXPECT_EQ(t1, PositionInComposedTree::afterNode(host).nodeAsRangeLastNode()) ;
123 } 76 }
124 77
125 } // namespace blink 78 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/core/editing/EditingTestBase.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698