| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 33 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void SurroundingTextTest::setHTML(const String& content) { | 36 void SurroundingTextTest::setHTML(const String& content) { |
| 37 document().body()->setInnerHTML(content, ASSERT_NO_EXCEPTION); | 37 document().body()->setInnerHTML(content, ASSERT_NO_EXCEPTION); |
| 38 document().updateStyleAndLayout(); | 38 document().updateStyleAndLayout(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 VisibleSelection SurroundingTextTest::select(int start, int end) { | 41 VisibleSelection SurroundingTextTest::select(int start, int end) { |
| 42 Element* element = document().getElementById("selection"); | 42 Element* element = document().getElementById("selection"); |
| 43 VisibleSelection selection; | 43 return createVisibleSelection( |
| 44 selection.setBase(Position(toText(element->firstChild()), start)); | 44 SelectionInDOMTree::Builder() |
| 45 selection.setExtent(Position(toText(element->firstChild()), end)); | 45 .collapse(Position(toText(element->firstChild()), start)) |
| 46 return selection; | 46 .extend(Position(toText(element->firstChild()), end)) |
| 47 .build()); |
| 47 } | 48 } |
| 48 | 49 |
| 49 TEST_F(SurroundingTextTest, BasicCaretSelection) { | 50 TEST_F(SurroundingTextTest, BasicCaretSelection) { |
| 50 setHTML(String("<p id='selection'>foo bar</p>")); | 51 setHTML(String("<p id='selection'>foo bar</p>")); |
| 51 | 52 |
| 52 { | 53 { |
| 53 VisibleSelection selection = select(0); | 54 VisibleSelection selection = select(0); |
| 54 SurroundingText surroundingText(selection.start(), 1); | 55 SurroundingText surroundingText(selection.start(), 1); |
| 55 | 56 |
| 56 EXPECT_EQ("f", surroundingText.content()); | 57 EXPECT_EQ("f", surroundingText.content()); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 SurroundingText surroundingText(*firstRangeOf(selection), 1337); | 259 SurroundingText surroundingText(*firstRangeOf(selection), 1337); |
| 259 | 260 |
| 260 EXPECT_EQ("This is outside of foo bar the selected node", | 261 EXPECT_EQ("This is outside of foo bar the selected node", |
| 261 surroundingText.content().simplifyWhiteSpace()); | 262 surroundingText.content().simplifyWhiteSpace()); |
| 262 EXPECT_EQ(20u, surroundingText.startOffsetInContent()); | 263 EXPECT_EQ(20u, surroundingText.startOffsetInContent()); |
| 263 EXPECT_EQ(27u, surroundingText.endOffsetInContent()); | 264 EXPECT_EQ(27u, surroundingText.endOffsetInContent()); |
| 264 } | 265 } |
| 265 } | 266 } |
| 266 | 267 |
| 267 } // namespace blink | 268 } // namespace blink |
| OLD | NEW |