| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return text; | 56 return text; |
| 57 } | 57 } |
| 58 | 58 |
| 59 TEST_F(FrameSelectionTest, SetValidSelection) { | 59 TEST_F(FrameSelectionTest, SetValidSelection) { |
| 60 Text* text = appendTextNode("Hello, World!"); | 60 Text* text = appendTextNode("Hello, World!"); |
| 61 document().view()->updateAllLifecyclePhases(); | 61 document().view()->updateAllLifecyclePhases(); |
| 62 selection().setSelection( | 62 selection().setSelection( |
| 63 SelectionInDOMTree::Builder() | 63 SelectionInDOMTree::Builder() |
| 64 .setBaseAndExtent(Position(text, 0), Position(text, 5)) | 64 .setBaseAndExtent(Position(text, 0), Position(text, 5)) |
| 65 .build()); | 65 .build()); |
| 66 EXPECT_FALSE(selection().isNone()); | 66 EXPECT_FALSE( |
| 67 selection().computeVisibleSelectionInDOMTreeDeprecated().isNone()); |
| 67 } | 68 } |
| 68 | 69 |
| 69 TEST_F(FrameSelectionTest, PaintCaretShouldNotLayout) { | 70 TEST_F(FrameSelectionTest, PaintCaretShouldNotLayout) { |
| 70 Text* text = appendTextNode("Hello, World!"); | 71 Text* text = appendTextNode("Hello, World!"); |
| 71 document().view()->updateAllLifecyclePhases(); | 72 document().view()->updateAllLifecyclePhases(); |
| 72 | 73 |
| 73 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); | 74 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); |
| 74 document().body()->focus(); | 75 document().body()->focus(); |
| 75 EXPECT_TRUE(document().body()->isFocused()); | 76 EXPECT_TRUE(document().body()->isFocused()); |
| 76 | 77 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), | 202 selection().moveRangeSelection(createVisiblePosition(Position(text, 5)), |
| 202 createVisiblePosition(Position(text, 2)), | 203 createVisiblePosition(Position(text, 2)), |
| 203 WordGranularity); | 204 WordGranularity); |
| 204 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); | 205 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); |
| 205 } | 206 } |
| 206 | 207 |
| 207 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) { | 208 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) { |
| 208 Element* select = document().createElement("select"); | 209 Element* select = document().createElement("select"); |
| 209 document().replaceChild(select, document().documentElement()); | 210 document().replaceChild(select, document().documentElement()); |
| 210 selection().selectAll(); | 211 selection().selectAll(); |
| 211 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the " | 212 EXPECT_TRUE(selection().computeVisibleSelectionInDOMTreeDeprecated().isNone()) |
| 212 "content of the documentElement is not " | 213 << "Nothing should be selected if the " |
| 213 "selctable."; | 214 "content of the documentElement is not " |
| 215 "selctable."; |
| 214 } | 216 } |
| 215 | 217 |
| 216 TEST_F(FrameSelectionTest, SelectAllPreservesHandle) { | 218 TEST_F(FrameSelectionTest, SelectAllPreservesHandle) { |
| 217 setBodyContent("<div id=sample>abc</div>"); | 219 setBodyContent("<div id=sample>abc</div>"); |
| 218 Element* sample = document().getElementById("sample"); | 220 Element* sample = document().getElementById("sample"); |
| 219 const Position endOfText(sample->firstChild(), 3); | 221 const Position endOfText(sample->firstChild(), 3); |
| 220 selection().setSelection(SelectionInDOMTree::Builder() | 222 selection().setSelection(SelectionInDOMTree::Builder() |
| 221 .collapse(endOfText) | 223 .collapse(endOfText) |
| 222 .setIsHandleVisible(false) | 224 .setIsHandleVisible(false) |
| 223 .build()); | 225 .build()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 selection().updateIfNeeded(); | 263 selection().updateIfNeeded(); |
| 262 | 264 |
| 263 EXPECT_EQ(Position(), | 265 EXPECT_EQ(Position(), |
| 264 selection().computeVisibleSelectionInDOMTreeDeprecated().start()) | 266 selection().computeVisibleSelectionInDOMTreeDeprecated().start()) |
| 265 << "selection().updateIfNeeded() does nothing."; | 267 << "selection().updateIfNeeded() does nothing."; |
| 266 EXPECT_EQ(selection().computeVisibleSelectionInDOMTreeDeprecated().start(), | 268 EXPECT_EQ(selection().computeVisibleSelectionInDOMTreeDeprecated().start(), |
| 267 caretPosition().position()); | 269 caretPosition().position()); |
| 268 } | 270 } |
| 269 | 271 |
| 270 } // namespace blink | 272 } // namespace blink |
| OLD | NEW |