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 <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 Loading... | |
| 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); | |
|
yoichio
2017/07/05 08:57:24
Could you expect_eq(SelectText(), 'xyz')?
yosin_UTC9
2017/07/05 09:15:49
Done.
| |
| 249 sample->insertBefore(Text::Create(GetDocument(), "abc"), | |
| 250 sample->firstChild()); | |
| 251 GetDocument().UpdateStyleAndLayout(); | |
| 252 const VisibleSelection& selection = | |
| 253 Selection().ComputeVisibleSelectionInDOMTree(); | |
| 254 // Inserting "abc" before "xyz" should not affect to selection. | |
| 255 EXPECT_EQ(Position(sample->lastChild(), 0), selection.Start()); | |
| 256 EXPECT_EQ(Position(sample->lastChild(), 3), selection.End()); | |
|
yoichio
2017/07/05 08:57:24
Could you expect_eq(SelectText(), 'xyz') and expe
yosin_UTC9
2017/07/05 09:15:49
Done.
| |
| 257 } | |
| 258 | |
| 241 // For http://crbug.com/695317 | 259 // For http://crbug.com/695317 |
| 242 TEST_F(FrameSelectionTest, SelectAllWithInputElement) { | 260 TEST_F(FrameSelectionTest, SelectAllWithInputElement) { |
| 243 SetBodyContent("<input>123"); | 261 SetBodyContent("<input>123"); |
| 244 Element* const input = GetDocument().QuerySelector("input"); | 262 Element* const input = GetDocument().QuerySelector("input"); |
| 245 Node* const last_child = GetDocument().body()->lastChild(); | 263 Node* const last_child = GetDocument().body()->lastChild(); |
| 246 Selection().SelectAll(); | 264 Selection().SelectAll(); |
| 247 const SelectionInDOMTree& result_in_dom_tree = | 265 const SelectionInDOMTree& result_in_dom_tree = |
| 248 Selection().ComputeVisibleSelectionInDOMTree().AsSelection(); | 266 Selection().ComputeVisibleSelectionInDOMTree().AsSelection(); |
| 249 const SelectionInFlatTree& result_in_flat_tree = | 267 const SelectionInFlatTree& result_in_flat_tree = |
| 250 Selection().ComputeVisibleSelectionInFlatTree().AsSelection(); | 268 Selection().ComputeVisibleSelectionInFlatTree().AsSelection(); |
| (...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 976 const Position& start = Position::BeforeNode(*anchor); | 994 const Position& start = Position::BeforeNode(*anchor); |
| 977 const Position& end = Position::AfterNode(*anchor); | 995 const Position& end = Position::AfterNode(*anchor); |
| 978 Selection().SetSelection( | 996 Selection().SetSelection( |
| 979 SelectionInDOMTree::Builder().Collapse(start).Extend(end).Build()); | 997 SelectionInDOMTree::Builder().Collapse(start).Extend(end).Build()); |
| 980 | 998 |
| 981 // Shouldn't crash inside. | 999 // Shouldn't crash inside. |
| 982 EXPECT_FALSE(Selection().SelectionHasFocus()); | 1000 EXPECT_FALSE(Selection().SelectionHasFocus()); |
| 983 } | 1001 } |
| 984 | 1002 |
| 985 } // namespace blink | 1003 } // namespace blink |
| OLD | NEW |