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 <memory> | 7 #include <memory> |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 321 |
322 Selection().SetSelectedRange( | 322 Selection().SetSelectedRange( |
323 EphemeralRange(Position(text, 0), Position(text, 12)), | 323 EphemeralRange(Position(text, 0), Position(text, 12)), |
324 VP_DEFAULT_AFFINITY, SelectionDirectionalMode::kNonDirectional, 0); | 324 VP_DEFAULT_AFFINITY, SelectionDirectionalMode::kNonDirectional, 0); |
325 | 325 |
326 EXPECT_TRUE(Selection().IsHandleVisible()) | 326 EXPECT_TRUE(Selection().IsHandleVisible()) |
327 << "If handles were present before" | 327 << "If handles were present before" |
328 "selectSetSelectedRange they should be present after it."; | 328 "selectSetSelectedRange they should be present after it."; |
329 } | 329 } |
330 | 330 |
| 331 // Regression test for crbug.com/702756 |
| 332 // Test case excerpted from editing/undo/redo_correct_selection.html |
| 333 TEST_F(FrameSelectionTest, SelectInvalidPositionInFlatTreeDoesntCrash) { |
| 334 SetBodyContent("foo<option><select></select></option>"); |
| 335 Element* body = GetDocument().body(); |
| 336 Element* select = GetDocument().QuerySelector("select"); |
| 337 Node* foo = body->firstChild(); |
| 338 Selection().SetSelection(SelectionInDOMTree::Builder() |
| 339 .Collapse(Position(body, 0)) |
| 340 // SELECT@AfterAnchor is invalid in flat tree. |
| 341 .Extend(Position::AfterNode(select)) |
| 342 .Build()); |
| 343 // Should not crash inside. |
| 344 const VisibleSelectionInFlatTree& selection = |
| 345 Selection().ComputeVisibleSelectionInFlatTree(); |
| 346 |
| 347 // This only records the current behavior. It might be changed in the future. |
| 348 EXPECT_EQ(PositionInFlatTree(foo, 0), selection.Base()); |
| 349 EXPECT_EQ(PositionInFlatTree(foo, 0), selection.Extent()); |
| 350 } |
| 351 |
331 } // namespace blink | 352 } // namespace blink |
OLD | NEW |