| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 createVisiblePosition(Position(text, 2)), | 211 createVisiblePosition(Position(text, 2)), |
| 212 CharacterGranularity); | 212 CharacterGranularity); |
| 213 EXPECT_EQ_SELECTED_TEXT("o B"); | 213 EXPECT_EQ_SELECTED_TEXT("o B"); |
| 214 // "Fo<o B|ar Baz," with the Word granularity. | 214 // "Fo<o B|ar Baz," with the Word granularity. |
| 215 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), | 215 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), |
| 216 createVisiblePosition(Position(text, 2)), | 216 createVisiblePosition(Position(text, 2)), |
| 217 WordGranularity); | 217 WordGranularity); |
| 218 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); | 218 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); |
| 219 } | 219 } |
| 220 | 220 |
| 221 // For http://crbug.com/695317 |
| 222 TEST_F(FrameSelectionTest, SelectAllWithInputElement) { |
| 223 setBodyContent("<input>123"); |
| 224 Element* const input = document().querySelector("input"); |
| 225 Node* const lastChild = document().body()->lastChild(); |
| 226 selection().selectAll(); |
| 227 const SelectionInDOMTree& resultInDOMTree = |
| 228 selection().computeVisibleSelectionInDOMTree().asSelection(); |
| 229 const SelectionInFlatTree& resultInFlatTree = |
| 230 selection().computeVisibleSelectionInFlatTree().asSelection(); |
| 231 EXPECT_EQ(SelectionInDOMTree::Builder(resultInDOMTree) |
| 232 .collapse(Position::beforeNode(input)) |
| 233 .extend(Position(lastChild, 3)) |
| 234 .build(), |
| 235 resultInDOMTree); |
| 236 EXPECT_EQ(SelectionInFlatTree::Builder(resultInFlatTree) |
| 237 .collapse(PositionInFlatTree::beforeNode(input)) |
| 238 .extend(PositionInFlatTree(lastChild, 3)) |
| 239 .build(), |
| 240 resultInFlatTree); |
| 241 } |
| 242 |
| 221 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) { | 243 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) { |
| 222 Element* select = document().createElement("select"); | 244 Element* select = document().createElement("select"); |
| 223 document().replaceChild(select, document().documentElement()); | 245 document().replaceChild(select, document().documentElement()); |
| 224 selection().selectAll(); | 246 selection().selectAll(); |
| 225 EXPECT_TRUE(selection().computeVisibleSelectionInDOMTreeDeprecated().isNone()) | 247 EXPECT_TRUE(selection().computeVisibleSelectionInDOMTreeDeprecated().isNone()) |
| 226 << "Nothing should be selected if the " | 248 << "Nothing should be selected if the " |
| 227 "content of the documentElement is not " | 249 "content of the documentElement is not " |
| 228 "selctable."; | 250 "selctable."; |
| 229 } | 251 } |
| 230 | 252 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 249 .build()); | 271 .build()); |
| 250 EXPECT_TRUE(selection().isHandleVisible()); | 272 EXPECT_TRUE(selection().isHandleVisible()); |
| 251 selection().selectAll(); | 273 selection().selectAll(); |
| 252 EXPECT_TRUE(selection().isHandleVisible()) | 274 EXPECT_TRUE(selection().isHandleVisible()) |
| 253 << "If handles were present before" | 275 << "If handles were present before" |
| 254 "selectAll. Then they should be present" | 276 "selectAll. Then they should be present" |
| 255 "after it."; | 277 "after it."; |
| 256 } | 278 } |
| 257 | 279 |
| 258 } // namespace blink | 280 } // namespace blink |
| OLD | NEW |