Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(926)

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp

Issue 2953683004: Make Position::AfterNode() to take const Node& instead of Node* (Closed)
Patch Set: 2017-06-22T12:37:16 Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // Regression test for crbug.com/702756 364 // Regression test for crbug.com/702756
365 // Test case excerpted from editing/undo/redo_correct_selection.html 365 // Test case excerpted from editing/undo/redo_correct_selection.html
366 TEST_F(FrameSelectionTest, SelectInvalidPositionInFlatTreeDoesntCrash) { 366 TEST_F(FrameSelectionTest, SelectInvalidPositionInFlatTreeDoesntCrash) {
367 SetBodyContent("foo<option><select></select></option>"); 367 SetBodyContent("foo<option><select></select></option>");
368 Element* body = GetDocument().body(); 368 Element* body = GetDocument().body();
369 Element* select = GetDocument().QuerySelector("select"); 369 Element* select = GetDocument().QuerySelector("select");
370 Node* foo = body->firstChild(); 370 Node* foo = body->firstChild();
371 Selection().SetSelection(SelectionInDOMTree::Builder() 371 Selection().SetSelection(SelectionInDOMTree::Builder()
372 .Collapse(Position(body, 0)) 372 .Collapse(Position(body, 0))
373 // SELECT@AfterAnchor is invalid in flat tree. 373 // SELECT@AfterAnchor is invalid in flat tree.
374 .Extend(Position::AfterNode(select)) 374 .Extend(Position::AfterNode(*select))
375 .Build()); 375 .Build());
376 // Should not crash inside. 376 // Should not crash inside.
377 const VisibleSelectionInFlatTree& selection = 377 const VisibleSelectionInFlatTree& selection =
378 Selection().ComputeVisibleSelectionInFlatTree(); 378 Selection().ComputeVisibleSelectionInFlatTree();
379 379
380 // This only records the current behavior. It might be changed in the future. 380 // This only records the current behavior. It might be changed in the future.
381 EXPECT_EQ(PositionInFlatTree(foo, 0), selection.Base()); 381 EXPECT_EQ(PositionInFlatTree(foo, 0), selection.Base());
382 EXPECT_EQ(PositionInFlatTree(foo, 0), selection.Extent()); 382 EXPECT_EQ(PositionInFlatTree(foo, 0), selection.Extent());
383 } 383 }
384 384
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/EditingUtilitiesTest.cpp ('k') | third_party/WebKit/Source/core/editing/Position.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698