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

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

Issue 299353004: Oilpan: move editing objects to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Make test wrapper class finalized Created 6 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
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" 8 #include "core/dom/Document.h"
9 #include "core/dom/Range.h" 9 #include "core/dom/Range.h"
10 #include "core/dom/Text.h" 10 #include "core/dom/Text.h"
11 #include "core/html/HTMLElement.h" 11 #include "core/html/HTMLElement.h"
12 #include "core/testing/DummyPageHolder.h" 12 #include "core/testing/DummyPageHolder.h"
13 #include <gtest/gtest.h> 13 #include <gtest/gtest.h>
14 14
15 #define LOREM_IPSUM \ 15 #define LOREM_IPSUM \
16 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod te mpor " \ 16 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod te mpor " \
17 "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " \ 17 "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " \
18 "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " \ 18 "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " \
19 "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat null a pariatur." \ 19 "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat null a pariatur." \
20 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia d eserunt " \ 20 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia d eserunt " \
21 "mollit anim id est laborum." 21 "mollit anim id est laborum."
22 22
23 namespace WebCore { 23 namespace WebCore {
24 24
25 class VisibleSelectionTest : public ::testing::Test { 25 class VisibleSelectionTest : public ::testing::Test {
26 protected: 26 protected:
27 virtual void SetUp() OVERRIDE; 27 virtual void SetUp() OVERRIDE;
28 28
29 // Oilpan: wrapper object needed to be able to trace VisibleSelection.
30 class VisibleSelectionWrapper : public NoBaseWillBeGarbageCollectedFinalized <VisibleSelectionWrapper> {
31 public:
32 void trace(Visitor* visitor)
33 {
34 visitor->trace(m_selection);
35 }
36
37 VisibleSelection m_selection;
38 };
39
29 Document& document() const { return m_dummyPageHolder->document(); } 40 Document& document() const { return m_dummyPageHolder->document(); }
30 Text* textNode() const { return m_textNode.get(); } 41 Text* textNode() const { return m_textNode.get(); }
31 VisibleSelection& selection() { return m_selection; } 42 VisibleSelection& selection() { return m_wrap->m_selection; }
32 43
33 // Helper function to set the VisibleSelection base/extent. 44 // Helper function to set the VisibleSelection base/extent.
34 void setSelection(int base) { setSelection(base, base); } 45 void setSelection(int base) { setSelection(base, base); }
35 46
36 // Helper function to set the VisibleSelection base/extent. 47 // Helper function to set the VisibleSelection base/extent.
37 void setSelection(int base, int extend) 48 void setSelection(int base, int extend)
38 { 49 {
39 m_selection.setBase(Position(textNode(), base)); 50 m_wrap->m_selection.setBase(Position(textNode(), base));
40 m_selection.setExtent(Position(textNode(), extend)); 51 m_wrap->m_selection.setExtent(Position(textNode(), extend));
41 } 52 }
42 53
43 private: 54 private:
44 OwnPtr<DummyPageHolder> m_dummyPageHolder; 55 OwnPtr<DummyPageHolder> m_dummyPageHolder;
45 RefPtr<Text> m_textNode; 56 RefPtrWillBePersistent<Text> m_textNode;
46 VisibleSelection m_selection; 57 OwnPtrWillBePersistent<VisibleSelectionWrapper> m_wrap;
47 }; 58 };
48 59
49 void WebCore::VisibleSelectionTest::SetUp() 60 void WebCore::VisibleSelectionTest::SetUp()
50 { 61 {
51 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); 62 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
52 m_textNode = document().createTextNode(LOREM_IPSUM); 63 m_textNode = document().createTextNode(LOREM_IPSUM);
64 m_wrap = adoptPtrWillBeNoop(new VisibleSelectionWrapper());
53 document().body()->appendChild(m_textNode.get()); 65 document().body()->appendChild(m_textNode.get());
54 } 66 }
55 67
56 } // namespace WebCore 68 } // namespace WebCore
57 69
58 namespace { 70 namespace {
59 71
60 using namespace WebCore; 72 using namespace WebCore;
61 73
62 TEST_F(VisibleSelectionTest, Initialisation) 74 TEST_F(VisibleSelectionTest, Initialisation)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 selection().expandUsingGranularity(WordGranularity); 162 selection().expandUsingGranularity(WordGranularity);
151 163
152 RefPtrWillBeRawPtr<Range> range = selection().firstRange(); 164 RefPtrWillBeRawPtr<Range> range = selection().firstRange();
153 EXPECT_EQ(0, range->startOffset()); 165 EXPECT_EQ(0, range->startOffset());
154 EXPECT_EQ(11, range->endOffset()); 166 EXPECT_EQ(11, range->endOffset());
155 EXPECT_EQ("Lorem ipsum", range->text()); 167 EXPECT_EQ("Lorem ipsum", range->text());
156 } 168 }
157 } 169 }
158 170
159 } // namespace WebCore 171 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleSelection.cpp ('k') | Source/core/editing/WrapContentsInDummySpanCommand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698