| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 TEST_F(FrameSelectionTest, SelectAllWithInputElement) { | 242 TEST_F(FrameSelectionTest, SelectAllWithInputElement) { |
| 243 SetBodyContent("<input>123"); | 243 SetBodyContent("<input>123"); |
| 244 Element* const input = GetDocument().QuerySelector("input"); | 244 Element* const input = GetDocument().QuerySelector("input"); |
| 245 Node* const last_child = GetDocument().body()->lastChild(); | 245 Node* const last_child = GetDocument().body()->lastChild(); |
| 246 Selection().SelectAll(); | 246 Selection().SelectAll(); |
| 247 const SelectionInDOMTree& result_in_dom_tree = | 247 const SelectionInDOMTree& result_in_dom_tree = |
| 248 Selection().ComputeVisibleSelectionInDOMTree().AsSelection(); | 248 Selection().ComputeVisibleSelectionInDOMTree().AsSelection(); |
| 249 const SelectionInFlatTree& result_in_flat_tree = | 249 const SelectionInFlatTree& result_in_flat_tree = |
| 250 Selection().ComputeVisibleSelectionInFlatTree().AsSelection(); | 250 Selection().ComputeVisibleSelectionInFlatTree().AsSelection(); |
| 251 EXPECT_EQ(SelectionInDOMTree::Builder(result_in_dom_tree) | 251 EXPECT_EQ(SelectionInDOMTree::Builder(result_in_dom_tree) |
| 252 .Collapse(Position::BeforeNode(input)) | 252 .Collapse(Position::BeforeNode(*input)) |
| 253 .Extend(Position(last_child, 3)) | 253 .Extend(Position(last_child, 3)) |
| 254 .Build(), | 254 .Build(), |
| 255 result_in_dom_tree); | 255 result_in_dom_tree); |
| 256 EXPECT_EQ(SelectionInFlatTree::Builder(result_in_flat_tree) | 256 EXPECT_EQ(SelectionInFlatTree::Builder(result_in_flat_tree) |
| 257 .Collapse(PositionInFlatTree::BeforeNode(input)) | 257 .Collapse(PositionInFlatTree::BeforeNode(*input)) |
| 258 .Extend(PositionInFlatTree(last_child, 3)) | 258 .Extend(PositionInFlatTree(last_child, 3)) |
| 259 .Build(), | 259 .Build(), |
| 260 result_in_flat_tree); | 260 result_in_flat_tree); |
| 261 } | 261 } |
| 262 | 262 |
| 263 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) { | 263 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) { |
| 264 Element* select = GetDocument().createElement("select"); | 264 Element* select = GetDocument().createElement("select"); |
| 265 GetDocument().ReplaceChild(select, GetDocument().documentElement()); | 265 GetDocument().ReplaceChild(select, GetDocument().documentElement()); |
| 266 GetDocument().UpdateStyleAndLayout(); | 266 GetDocument().UpdateStyleAndLayout(); |
| 267 Selection().SelectAll(); | 267 Selection().SelectAll(); |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 // crbug.com/725457 | 966 // crbug.com/725457 |
| 967 TEST_F(FrameSelectionTest, InconsistentVisibleSelectionNoCrash) { | 967 TEST_F(FrameSelectionTest, InconsistentVisibleSelectionNoCrash) { |
| 968 SetBodyContent("foo<div id=host><span id=anchor>bar</span></div>baz"); | 968 SetBodyContent("foo<div id=host><span id=anchor>bar</span></div>baz"); |
| 969 SetShadowContent("shadow", "host"); | 969 SetShadowContent("shadow", "host"); |
| 970 | 970 |
| 971 Element* anchor = GetDocument().getElementById("anchor"); | 971 Element* anchor = GetDocument().getElementById("anchor"); |
| 972 | 972 |
| 973 // |start| and |end| are valid Positions in DOM tree, but do not participate | 973 // |start| and |end| are valid Positions in DOM tree, but do not participate |
| 974 // in flat tree. They should be canonicalized to null VisiblePositions, but | 974 // in flat tree. They should be canonicalized to null VisiblePositions, but |
| 975 // are currently not. See crbug.com/729636 for details. | 975 // are currently not. See crbug.com/729636 for details. |
| 976 const Position& start = Position::BeforeNode(anchor); | 976 const Position& start = Position::BeforeNode(*anchor); |
| 977 const Position& end = Position::AfterNode(anchor); | 977 const Position& end = Position::AfterNode(anchor); |
| 978 Selection().SetSelection( | 978 Selection().SetSelection( |
| 979 SelectionInDOMTree::Builder().Collapse(start).Extend(end).Build()); | 979 SelectionInDOMTree::Builder().Collapse(start).Extend(end).Build()); |
| 980 | 980 |
| 981 // Shouldn't crash inside. | 981 // Shouldn't crash inside. |
| 982 EXPECT_FALSE(Selection().SelectionHasFocus()); | 982 EXPECT_FALSE(Selection().SelectionHasFocus()); |
| 983 } | 983 } |
| 984 | 984 |
| 985 } // namespace blink | 985 } // namespace blink |
| OLD | NEW |