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 <memory> |
7 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
8 #include "core/dom/Range.h" | 9 #include "core/dom/Range.h" |
9 #include "core/dom/Text.h" | 10 #include "core/dom/Text.h" |
10 #include "core/editing/Position.h" | 11 #include "core/editing/Position.h" |
11 #include "core/editing/VisibleSelection.h" | 12 #include "core/editing/VisibleSelection.h" |
12 #include "core/html/HTMLElement.h" | 13 #include "core/html/HTMLElement.h" |
| 14 #include "core/html/TextControlElement.h" |
13 #include "core/testing/DummyPageHolder.h" | 15 #include "core/testing/DummyPageHolder.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 #include <memory> | |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 class SurroundingTextTest : public ::testing::Test { | 20 class SurroundingTextTest : public ::testing::Test { |
20 protected: | 21 protected: |
21 Document& GetDocument() const { return dummy_page_holder_->GetDocument(); } | 22 Document& GetDocument() const { return dummy_page_holder_->GetDocument(); } |
22 void SetHTML(const String&); | 23 void SetHTML(const String&); |
23 VisibleSelection Select(int offset) { return Select(offset, offset); } | 24 VisibleSelection Select(int offset) { return Select(offset, offset); } |
24 VisibleSelection Select(int start, int end); | 25 VisibleSelection Select(int start, int end); |
25 | 26 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 SurroundingText surrounding_text( | 270 SurroundingText surrounding_text( |
270 *CreateRange(FirstEphemeralRangeOf(selection)), 1337); | 271 *CreateRange(FirstEphemeralRangeOf(selection)), 1337); |
271 | 272 |
272 EXPECT_EQ("This is outside of foo bar the selected node", | 273 EXPECT_EQ("This is outside of foo bar the selected node", |
273 surrounding_text.Content().SimplifyWhiteSpace()); | 274 surrounding_text.Content().SimplifyWhiteSpace()); |
274 EXPECT_EQ(20u, surrounding_text.StartOffsetInContent()); | 275 EXPECT_EQ(20u, surrounding_text.StartOffsetInContent()); |
275 EXPECT_EQ(27u, surrounding_text.EndOffsetInContent()); | 276 EXPECT_EQ(27u, surrounding_text.EndOffsetInContent()); |
276 } | 277 } |
277 } | 278 } |
278 | 279 |
| 280 TEST_F(SurroundingTextTest, TextAreaSelection) { |
| 281 SetHTML( |
| 282 String("<p>First paragraph</p>" |
| 283 "<textarea id='selection'>abc def ghi</textarea>" |
| 284 "<p>Second paragraph</p>")); |
| 285 |
| 286 TextControlElement* text_ctrl = |
| 287 (TextControlElement*)GetDocument().getElementById("selection"); |
| 288 |
| 289 text_ctrl->SetSelectionRange(4, 7); |
| 290 VisibleSelection selection = CreateVisibleSelection(text_ctrl->Selection()); |
| 291 |
| 292 SurroundingText surrounding_text( |
| 293 *CreateRange(FirstEphemeralRangeOf(selection)), 20); |
| 294 |
| 295 EXPECT_EQ("abc def ghi", surrounding_text.Content().SimplifyWhiteSpace()); |
| 296 EXPECT_EQ(4u, surrounding_text.StartOffsetInContent()); |
| 297 EXPECT_EQ(7u, surrounding_text.EndOffsetInContent()); |
| 298 } |
| 299 |
279 } // namespace blink | 300 } // namespace blink |
OLD | NEW |