OLD | NEW |
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 "core/editing/SurroundingText.h" | 5 #include "core/editing/SurroundingText.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/dom/Range.h" | 8 #include "core/dom/Range.h" |
9 #include "core/dom/Text.h" | 9 #include "core/dom/Text.h" |
10 #include "core/editing/Position.h" | 10 #include "core/editing/Position.h" |
11 #include "core/editing/VisibleSelection.h" | 11 #include "core/editing/VisibleSelection.h" |
12 #include "core/html/HTMLElement.h" | 12 #include "core/html/HTMLElement.h" |
13 #include "core/testing/DummyPageHolder.h" | 13 #include "core/testing/DummyPageHolder.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include <memory> | |
16 | 15 |
17 namespace blink { | 16 namespace blink { |
18 | 17 |
19 class SurroundingTextTest : public ::testing::Test { | 18 class SurroundingTextTest : public ::testing::Test { |
20 protected: | 19 protected: |
21 Document& document() const { return m_dummyPageHolder->document(); } | 20 Document& document() const { return m_dummyPageHolder->document(); } |
22 void setHTML(const String&); | 21 void setHTML(const String&); |
23 VisibleSelection select(int offset) { return select(offset, offset); } | 22 VisibleSelection select(int offset) { return select(offset, offset); } |
24 VisibleSelection select(int start, int end); | 23 VisibleSelection select(int start, int end); |
25 | 24 |
26 private: | 25 private: |
27 void SetUp() override; | 26 void SetUp() override; |
28 | 27 |
29 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 28 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
30 }; | 29 }; |
31 | 30 |
32 void SurroundingTextTest::SetUp() | 31 void SurroundingTextTest::SetUp() |
33 { | 32 { |
34 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 33 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
35 } | 34 } |
36 | 35 |
37 void SurroundingTextTest::setHTML(const String& content) | 36 void SurroundingTextTest::setHTML(const String& content) |
38 { | 37 { |
39 document().body()->setInnerHTML(content, ASSERT_NO_EXCEPTION); | 38 document().body()->setInnerHTML(content, ASSERT_NO_EXCEPTION); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 VisibleSelection selection = select(0, 7); | 253 VisibleSelection selection = select(0, 7); |
255 SurroundingText surroundingText(*firstRangeOf(selection), 1337); | 254 SurroundingText surroundingText(*firstRangeOf(selection), 1337); |
256 | 255 |
257 EXPECT_EQ("This is outside of foo bar the selected node", surroundingTex
t.content().simplifyWhiteSpace()); | 256 EXPECT_EQ("This is outside of foo bar the selected node", surroundingTex
t.content().simplifyWhiteSpace()); |
258 EXPECT_EQ(20u, surroundingText.startOffsetInContent()); | 257 EXPECT_EQ(20u, surroundingText.startOffsetInContent()); |
259 EXPECT_EQ(27u, surroundingText.endOffsetInContent()); | 258 EXPECT_EQ(27u, surroundingText.endOffsetInContent()); |
260 } | 259 } |
261 } | 260 } |
262 | 261 |
263 } // namespace blink | 262 } // namespace blink |
OLD | NEW |