| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/editing/FrameSelection.h" | 6 #include "core/editing/FrameSelection.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 144 } |
| 145 | 145 |
| 146 #define EXPECT_EQ_SELECTED_TEXT(text) \ | 146 #define EXPECT_EQ_SELECTED_TEXT(text) \ |
| 147 EXPECT_EQ(text, WebString(selection().selectedText()).utf8()) | 147 EXPECT_EQ(text, WebString(selection().selectedText()).utf8()) |
| 148 | 148 |
| 149 TEST_F(FrameSelectionTest, SelectWordAroundPosition) | 149 TEST_F(FrameSelectionTest, SelectWordAroundPosition) |
| 150 { | 150 { |
| 151 // "Foo Bar Baz," | 151 // "Foo Bar Baz," |
| 152 RefPtrWillBeRawPtr<Text> text = appendTextNode("Foo Bar Baz,"); | 152 RefPtrWillBeRawPtr<Text> text = appendTextNode("Foo Bar Baz,"); |
| 153 // "Fo|o Bar Baz," | 153 // "Fo|o Bar Baz," |
| 154 EXPECT_TRUE(selection().selectWordAroundPosition(VisiblePosition(Position(te
xt, 2)))); | 154 EXPECT_TRUE(selection().selectWordAroundPosition(createVisiblePosition(Posit
ion(text, 2)))); |
| 155 EXPECT_EQ_SELECTED_TEXT("Foo"); | 155 EXPECT_EQ_SELECTED_TEXT("Foo"); |
| 156 // "Foo| Bar Baz," | 156 // "Foo| Bar Baz," |
| 157 EXPECT_TRUE(selection().selectWordAroundPosition(VisiblePosition(Position(te
xt, 3)))); | 157 EXPECT_TRUE(selection().selectWordAroundPosition(createVisiblePosition(Posit
ion(text, 3)))); |
| 158 EXPECT_EQ_SELECTED_TEXT("Foo"); | 158 EXPECT_EQ_SELECTED_TEXT("Foo"); |
| 159 // "Foo Bar | Baz," | 159 // "Foo Bar | Baz," |
| 160 EXPECT_FALSE(selection().selectWordAroundPosition(VisiblePosition(Position(t
ext, 13)))); | 160 EXPECT_FALSE(selection().selectWordAroundPosition(createVisiblePosition(Posi
tion(text, 13)))); |
| 161 // "Foo Bar Baz|," | 161 // "Foo Bar Baz|," |
| 162 EXPECT_TRUE(selection().selectWordAroundPosition(VisiblePosition(Position(te
xt, 22)))); | 162 EXPECT_TRUE(selection().selectWordAroundPosition(createVisiblePosition(Posit
ion(text, 22)))); |
| 163 EXPECT_EQ_SELECTED_TEXT("Baz"); | 163 EXPECT_EQ_SELECTED_TEXT("Baz"); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) | 166 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) |
| 167 { | 167 { |
| 168 // "Foo Bar Baz," | 168 // "Foo Bar Baz," |
| 169 RefPtrWillBeRawPtr<Text> text = appendTextNode("Foo Bar Baz,"); | 169 RefPtrWillBeRawPtr<Text> text = appendTextNode("Foo Bar Baz,"); |
| 170 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). | 170 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). |
| 171 selection().setSelection(VisibleSelection(Position(text, 5), Position(text,
6))); | 171 selection().setSelection(VisibleSelection(Position(text, 5), Position(text,
6))); |
| 172 EXPECT_EQ_SELECTED_TEXT("a"); | 172 EXPECT_EQ_SELECTED_TEXT("a"); |
| 173 | 173 |
| 174 // "Foo B|ar B>az," with the Character granularity. | 174 // "Foo B|ar B>az," with the Character granularity. |
| 175 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 9)), CharacterGranularity); | 175 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre
ateVisiblePosition(Position(text, 9)), CharacterGranularity); |
| 176 EXPECT_EQ_SELECTED_TEXT("ar B"); | 176 EXPECT_EQ_SELECTED_TEXT("ar B"); |
| 177 // "Foo B|ar B>az," with the Word granularity. | 177 // "Foo B|ar B>az," with the Word granularity. |
| 178 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 9)), WordGranularity); | 178 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre
ateVisiblePosition(Position(text, 9)), WordGranularity); |
| 179 EXPECT_EQ_SELECTED_TEXT("Bar Baz"); | 179 EXPECT_EQ_SELECTED_TEXT("Bar Baz"); |
| 180 // "Fo<o B|ar Baz," with the Character granularity. | 180 // "Fo<o B|ar Baz," with the Character granularity. |
| 181 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 2)), CharacterGranularity); | 181 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre
ateVisiblePosition(Position(text, 2)), CharacterGranularity); |
| 182 EXPECT_EQ_SELECTED_TEXT("o B"); | 182 EXPECT_EQ_SELECTED_TEXT("o B"); |
| 183 // "Fo<o B|ar Baz," with the Word granularity. | 183 // "Fo<o B|ar Baz," with the Word granularity. |
| 184 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 2)), WordGranularity); | 184 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre
ateVisiblePosition(Position(text, 2)), WordGranularity); |
| 185 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); | 185 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); |
| 186 } | 186 } |
| 187 | 187 |
| 188 } // namespace blink | 188 } // namespace blink |
| OLD | NEW |