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

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

Issue 1202863003: Use EditingTestBase for VisibleSelectionTest (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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
« 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/VisibleSelection.h" 6 #include "core/editing/VisibleSelection.h"
7 7
8 #include "core/dom/Document.h"
9 #include "core/dom/Range.h" 8 #include "core/dom/Range.h"
10 #include "core/dom/Text.h" 9 #include "core/editing/EditingTestBase.h"
11 #include "core/html/HTMLElement.h"
12 #include "core/testing/CoreTestHelpers.h"
13 #include "core/testing/DummyPageHolder.h"
14 #include <gtest/gtest.h>
15 10
16 #define LOREM_IPSUM \ 11 #define LOREM_IPSUM \
17 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod te mpor " \ 12 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod te mpor " \
18 "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " \ 13 "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " \
19 "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " \ 14 "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " \
20 "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat null a pariatur." \ 15 "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat null a pariatur." \
21 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia d eserunt " \ 16 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia d eserunt " \
22 "mollit anim id est laborum." 17 "mollit anim id est laborum."
23 18
24 namespace blink { 19 namespace blink {
25 20
26 class VisibleSelectionTest : public ::testing::Test { 21 class VisibleSelectionTest : public EditingTestBase {
27 protected: 22 protected:
28 void SetUp() override;
29
30 Document& document() const { return m_dummyPageHolder->document(); }
31
32 static PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAn dSetInnerHTML(TreeScope&, const char* hostElementID, const char* shadowRootConte nt);
33
34 void setBodyContent(const char*);
35 PassRefPtrWillBeRawPtr<ShadowRoot> setShadowContent(const char*);
36
37 // Helper function to set the VisibleSelection base/extent. 23 // Helper function to set the VisibleSelection base/extent.
38 void setSelection(VisibleSelection& selection, int base) { setSelection(sele ction, base, base); } 24 void setSelection(VisibleSelection& selection, int base) { setSelection(sele ction, base, base); }
39 25
40 // Helper function to set the VisibleSelection base/extent. 26 // Helper function to set the VisibleSelection base/extent.
41 void setSelection(VisibleSelection& selection, int base, int extend) 27 void setSelection(VisibleSelection& selection, int base, int extend)
42 { 28 {
43 Node* node = document().body()->firstChild(); 29 Node* node = document().body()->firstChild();
44 selection.setBase(Position(node, base, Position::PositionIsOffsetInAncho r)); 30 selection.setBase(Position(node, base, Position::PositionIsOffsetInAncho r));
45 selection.setExtent(Position(node, extend, Position::PositionIsOffsetInA nchor)); 31 selection.setExtent(Position(node, extend, Position::PositionIsOffsetInA nchor));
46 } 32 }
47 33
48 static bool equalPositions(const Position&, const PositionInComposedTree&); 34 static bool equalPositions(const Position&, const PositionInComposedTree&);
49 static void testComposedTreePositionsToEqualToDOMTreePositions(const Visible Selection&); 35 static void testComposedTreePositionsToEqualToDOMTreePositions(const Visible Selection&);
50
51 private:
52 OwnPtr<DummyPageHolder> m_dummyPageHolder;
53 }; 36 };
54 37
55 void VisibleSelectionTest::SetUp()
56 {
57 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
58 }
59
60 PassRefPtrWillBeRawPtr<ShadowRoot> VisibleSelectionTest::createShadowRootForElem entWithIDAndSetInnerHTML(TreeScope& scope, const char* hostElementID, const char * shadowRootContent)
61 {
62 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicStrin g::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION);
63 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE PTION);
64 return shadowRoot.release();
65 }
66
67 void VisibleSelectionTest::setBodyContent(const char* bodyContent)
68 {
69 document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXC EPTION);
70 }
71
72 PassRefPtrWillBeRawPtr<ShadowRoot> VisibleSelectionTest::setShadowContent(const char* shadowContent)
73 {
74 return createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", s hadowContent);
75 }
76
77 bool VisibleSelectionTest::equalPositions(const Position& positionInDOMTree, con st PositionInComposedTree& positionInComposedTree) 38 bool VisibleSelectionTest::equalPositions(const Position& positionInDOMTree, con st PositionInComposedTree& positionInComposedTree)
78 { 39 {
79 // Since DOM tree positions can't be map to composed tree version, e.g. 40 // Since DOM tree positions can't be map to composed tree version, e.g.
80 // shadow root, not distributed node, we map a position in composed tree 41 // shadow root, not distributed node, we map a position in composed tree
81 // to DOM tree position. 42 // to DOM tree position.
82 return positionInDOMTree == toPositionInDOMTree(positionInComposedTree); 43 return positionInDOMTree == toPositionInDOMTree(positionInComposedTree);
83 } 44 }
84 45
85 void VisibleSelectionTest::testComposedTreePositionsToEqualToDOMTreePositions(co nst VisibleSelection& selection) 46 void VisibleSelectionTest::testComposedTreePositionsToEqualToDOMTreePositions(co nst VisibleSelection& selection)
86 { 47 {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 221
261 RefPtrWillBeRawPtr<Range> range = selection.firstRange(); 222 RefPtrWillBeRawPtr<Range> range = selection.firstRange();
262 EXPECT_EQ(0, range->startOffset()); 223 EXPECT_EQ(0, range->startOffset());
263 EXPECT_EQ(11, range->endOffset()); 224 EXPECT_EQ(11, range->endOffset());
264 EXPECT_EQ("Lorem ipsum", range->text()); 225 EXPECT_EQ("Lorem ipsum", range->text());
265 testComposedTreePositionsToEqualToDOMTreePositions(selection); 226 testComposedTreePositionsToEqualToDOMTreePositions(selection);
266 } 227 }
267 } 228 }
268 229
269 } // namespace blink 230 } // 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