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