Chromium Code Reviews| 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/FrameSelection.h" | 5 #include "core/editing/FrameSelection.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
| 10 #include "core/dom/Text.h" | 10 #include "core/dom/Text.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 // Select "two" for selection in DOM tree | 171 // Select "two" for selection in DOM tree |
| 172 // Select "twoone" for selection in Flat tree | 172 // Select "twoone" for selection in Flat tree |
| 173 selection().setSelection(VisibleSelectionInFlatTree(PositionInFlatTree(host, 0), PositionInFlatTree(document().body(), 2))); | 173 selection().setSelection(VisibleSelectionInFlatTree(PositionInFlatTree(host, 0), PositionInFlatTree(document().body(), 2))); |
| 174 selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordG ranularity); | 174 selection().modify(FrameSelection::AlterationExtend, DirectionForward, WordG ranularity); |
| 175 EXPECT_EQ(Position(two, 0), visibleSelectionInDOMTree().start()); | 175 EXPECT_EQ(Position(two, 0), visibleSelectionInDOMTree().start()); |
| 176 EXPECT_EQ(Position(two, 3), visibleSelectionInDOMTree().end()); | 176 EXPECT_EQ(Position(two, 3), visibleSelectionInDOMTree().end()); |
| 177 EXPECT_EQ(PositionInFlatTree(two, 0), visibleSelectionInFlatTree().start()); | 177 EXPECT_EQ(PositionInFlatTree(two, 0), visibleSelectionInFlatTree().start()); |
| 178 EXPECT_EQ(PositionInFlatTree(two, 3), visibleSelectionInFlatTree().end()); | 178 EXPECT_EQ(PositionInFlatTree(two, 3), visibleSelectionInFlatTree().end()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 TEST_F(FrameSelectionTest, ModifyWithUserTriggered) | |
| 182 { | |
| 183 setBodyContent("<div id=sample>abc</div>"); | |
| 184 Element* sample = document().getElementById("sample"); | |
| 185 const Position endOfText(sample->firstChild(), 3); | |
| 186 selection().setSelection(VisibleSelection(endOfText)); | |
| 187 | |
| 188 EXPECT_FALSE(selection().modify(FrameSelection::AlterationMove, DirectionFor ward, CharacterGranularity, NotUserTriggered)) | |
| 189 << "Selection.modify() returns false for user triggered call when select ion isn't modified."; | |
|
Xiaocheng
2016/08/05 01:51:25
non-user-triggered call
Reference: https://en.wik
yosin_UTC9
2016/08/05 04:03:12
Done
| |
| 190 EXPECT_EQ(endOfText, selection().start()) | |
| 191 << "Selection isn't modified"; | |
| 192 | |
| 193 EXPECT_TRUE(selection().modify(FrameSelection::AlterationMove, DirectionForw ard, CharacterGranularity, UserTriggered)) | |
| 194 << "Selection.modify() returns true for user triggered call"; | |
|
Xiaocheng
2016/08/05 01:51:25
ditto: user-triggered call
yosin_UTC9
2016/08/05 04:03:12
Done.
| |
| 195 EXPECT_EQ(endOfText, selection().start()) | |
| 196 << "Selection isn't modified"; | |
| 197 } | |
| 198 | |
| 181 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) | 199 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) |
| 182 { | 200 { |
| 183 // "Foo Bar Baz," | 201 // "Foo Bar Baz," |
| 184 Text* text = appendTextNode("Foo Bar Baz,"); | 202 Text* text = appendTextNode("Foo Bar Baz,"); |
| 185 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). | 203 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). |
| 186 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); | 204 selection().setSelection(VisibleSelection(Position(text, 5), Position(text, 6))); |
| 187 EXPECT_EQ_SELECTED_TEXT("a"); | 205 EXPECT_EQ_SELECTED_TEXT("a"); |
| 188 | 206 |
| 189 // "Foo B|ar B>az," with the Character granularity. | 207 // "Foo B|ar B>az," with the Character granularity. |
| 190 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 9)), CharacterGranularity); | 208 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), cre ateVisiblePosition(Position(text, 9)), CharacterGranularity); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 selection().updateIfNeeded(); | 278 selection().updateIfNeeded(); |
| 261 | 279 |
| 262 // TODO(yosin): Once lazy canonicalization implemented, selection.start | 280 // TODO(yosin): Once lazy canonicalization implemented, selection.start |
| 263 // should be Position(HTML, 0). | 281 // should be Position(HTML, 0). |
| 264 EXPECT_EQ(Position(), selection().start()) | 282 EXPECT_EQ(Position(), selection().start()) |
| 265 << "updateIfNeeded() makes selection to null."; | 283 << "updateIfNeeded() makes selection to null."; |
| 266 EXPECT_EQ(selection().start(), caretPosition().position()); | 284 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 267 } | 285 } |
| 268 | 286 |
| 269 } // namespace blink | 287 } // namespace blink |
| OLD | NEW |