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

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

Issue 2972753002: Make FrameSelection::MoveRangeSelection() not to set live granularity selection (Closed)
Patch Set: 2017-07-05T18:14:38 Created 3 years, 5 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 CreateVisiblePosition(Position(text, 2)), 231 CreateVisiblePosition(Position(text, 2)),
232 kCharacterGranularity); 232 kCharacterGranularity);
233 EXPECT_EQ_SELECTED_TEXT("o B"); 233 EXPECT_EQ_SELECTED_TEXT("o B");
234 // "Fo<o B|ar Baz," with the Word granularity. 234 // "Fo<o B|ar Baz," with the Word granularity.
235 Selection().MoveRangeSelection(CreateVisiblePosition(Position(text, 5)), 235 Selection().MoveRangeSelection(CreateVisiblePosition(Position(text, 5)),
236 CreateVisiblePosition(Position(text, 2)), 236 CreateVisiblePosition(Position(text, 2)),
237 kWordGranularity); 237 kWordGranularity);
238 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); 238 EXPECT_EQ_SELECTED_TEXT("Foo Bar");
239 } 239 }
240 240
241 TEST_F(FrameSelectionTest, MoveRangeSelectionNoLiveness) {
242 SetBodyContent("<span id=sample>xyz</span>");
243 Element* const sample = GetDocument().getElementById("sample");
244 // Select as: <span id=sample>^xyz|</span>
245 Selection().MoveRangeSelection(
246 CreateVisiblePosition(Position(sample->firstChild(), 1)),
247 CreateVisiblePosition(Position(sample->firstChild(), 1)),
248 kWordGranularity);
249 EXPECT_EQ("xyz", Selection().SelectedText());
250 sample->insertBefore(Text::Create(GetDocument(), "abc"),
251 sample->firstChild());
252 GetDocument().UpdateStyleAndLayout();
253 const VisibleSelection& selection =
254 Selection().ComputeVisibleSelectionInDOMTree();
255 // Inserting "abc" before "xyz" should not affect to selection.
256 EXPECT_EQ(Position(sample->lastChild(), 0), selection.Start());
257 EXPECT_EQ(Position(sample->lastChild(), 3), selection.End());
258 EXPECT_EQ("xyz", Selection().SelectedText());
259 EXPECT_EQ("abcxyz", sample->innerText());
260 }
261
241 // For http://crbug.com/695317 262 // For http://crbug.com/695317
242 TEST_F(FrameSelectionTest, SelectAllWithInputElement) { 263 TEST_F(FrameSelectionTest, SelectAllWithInputElement) {
243 SetBodyContent("<input>123"); 264 SetBodyContent("<input>123");
244 Element* const input = GetDocument().QuerySelector("input"); 265 Element* const input = GetDocument().QuerySelector("input");
245 Node* const last_child = GetDocument().body()->lastChild(); 266 Node* const last_child = GetDocument().body()->lastChild();
246 Selection().SelectAll(); 267 Selection().SelectAll();
247 const SelectionInDOMTree& result_in_dom_tree = 268 const SelectionInDOMTree& result_in_dom_tree =
248 Selection().ComputeVisibleSelectionInDOMTree().AsSelection(); 269 Selection().ComputeVisibleSelectionInDOMTree().AsSelection();
249 const SelectionInFlatTree& result_in_flat_tree = 270 const SelectionInFlatTree& result_in_flat_tree =
250 Selection().ComputeVisibleSelectionInFlatTree().AsSelection(); 271 Selection().ComputeVisibleSelectionInFlatTree().AsSelection();
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 const Position& start = Position::BeforeNode(*anchor); 997 const Position& start = Position::BeforeNode(*anchor);
977 const Position& end = Position::AfterNode(*anchor); 998 const Position& end = Position::AfterNode(*anchor);
978 Selection().SetSelection( 999 Selection().SetSelection(
979 SelectionInDOMTree::Builder().Collapse(start).Extend(end).Build()); 1000 SelectionInDOMTree::Builder().Collapse(start).Extend(end).Build());
980 1001
981 // Shouldn't crash inside. 1002 // Shouldn't crash inside.
982 EXPECT_FALSE(Selection().SelectionHasFocus()); 1003 EXPECT_FALSE(Selection().SelectionHasFocus());
983 } 1004 }
984 1005
985 } // namespace blink 1006 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698