| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 Element* sample = document().getElementById("sample"); | 150 Element* sample = document().getElementById("sample"); |
| 151 const Position endOfText(sample->firstChild(), 3); | 151 const Position endOfText(sample->firstChild(), 3); |
| 152 selection().setSelection( | 152 selection().setSelection( |
| 153 SelectionInDOMTree::Builder().collapse(endOfText).build()); | 153 SelectionInDOMTree::Builder().collapse(endOfText).build()); |
| 154 | 154 |
| 155 EXPECT_FALSE(selection().modify(FrameSelection::AlterationMove, | 155 EXPECT_FALSE(selection().modify(FrameSelection::AlterationMove, |
| 156 DirectionForward, CharacterGranularity, | 156 DirectionForward, CharacterGranularity, |
| 157 NotUserTriggered)) | 157 NotUserTriggered)) |
| 158 << "Selection.modify() returns false for non-user-triggered call when " | 158 << "Selection.modify() returns false for non-user-triggered call when " |
| 159 "selection isn't modified."; | 159 "selection isn't modified."; |
| 160 EXPECT_EQ(endOfText, selection().start()) << "Selection isn't modified"; | 160 EXPECT_EQ(endOfText, |
| 161 selection().computeVisibleSelectionInDOMTreeDeprecated().start()) |
| 162 << "Selection isn't modified"; |
| 161 | 163 |
| 162 EXPECT_TRUE(selection().modify(FrameSelection::AlterationMove, | 164 EXPECT_TRUE(selection().modify(FrameSelection::AlterationMove, |
| 163 DirectionForward, CharacterGranularity, | 165 DirectionForward, CharacterGranularity, |
| 164 UserTriggered)) | 166 UserTriggered)) |
| 165 << "Selection.modify() returns true for user-triggered call"; | 167 << "Selection.modify() returns true for user-triggered call"; |
| 166 EXPECT_EQ(endOfText, selection().start()) << "Selection isn't modified"; | 168 EXPECT_EQ(endOfText, |
| 169 selection().computeVisibleSelectionInDOMTreeDeprecated().start()) |
| 170 << "Selection isn't modified"; |
| 167 } | 171 } |
| 168 | 172 |
| 169 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) { | 173 TEST_F(FrameSelectionTest, MoveRangeSelectionTest) { |
| 170 // "Foo Bar Baz," | 174 // "Foo Bar Baz," |
| 171 Text* text = appendTextNode("Foo Bar Baz,"); | 175 Text* text = appendTextNode("Foo Bar Baz,"); |
| 172 updateAllLifecyclePhases(); | 176 updateAllLifecyclePhases(); |
| 173 | 177 |
| 174 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). | 178 // Itinitializes with "Foo B|a>r Baz," (| means start and > means end). |
| 175 selection().setSelection( | 179 selection().setSelection( |
| 176 SelectionInDOMTree::Builder() | 180 SelectionInDOMTree::Builder() |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 "after it."; | 261 "after it."; |
| 258 } | 262 } |
| 259 | 263 |
| 260 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret) { | 264 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret) { |
| 261 setBodyContent("<style id=sample></style>"); | 265 setBodyContent("<style id=sample></style>"); |
| 262 document().setDesignMode("on"); | 266 document().setDesignMode("on"); |
| 263 updateAllLifecyclePhases(); | 267 updateAllLifecyclePhases(); |
| 264 Element* sample = document().getElementById("sample"); | 268 Element* sample = document().getElementById("sample"); |
| 265 selection().setSelection( | 269 selection().setSelection( |
| 266 SelectionInDOMTree::Builder().collapse(Position(sample, 0)).build()); | 270 SelectionInDOMTree::Builder().collapse(Position(sample, 0)).build()); |
| 267 EXPECT_EQ(Position(document().body(), 0), selection().start()); | 271 EXPECT_EQ(Position(document().body(), 0), |
| 268 EXPECT_EQ(selection().start(), caretPosition().position()); | 272 selection().computeVisibleSelectionInDOMTreeDeprecated().start()); |
| 273 EXPECT_EQ(selection().computeVisibleSelectionInDOMTreeDeprecated().start(), |
| 274 caretPosition().position()); |
| 269 document().body()->remove(); | 275 document().body()->remove(); |
| 270 EXPECT_EQ(Position(), selection().start()) | 276 EXPECT_EQ(Position(), |
| 277 selection().computeVisibleSelectionInDOMTreeDeprecated().start()) |
| 271 << "Selection has been removed by BODY.remove()."; | 278 << "Selection has been removed by BODY.remove()."; |
| 272 EXPECT_EQ(selection().start(), caretPosition().position()); | 279 EXPECT_EQ(selection().computeVisibleSelectionInDOMTreeDeprecated().start(), |
| 280 caretPosition().position()); |
| 273 document().updateStyleAndLayout(); | 281 document().updateStyleAndLayout(); |
| 274 selection().updateIfNeeded(); | 282 selection().updateIfNeeded(); |
| 275 | 283 |
| 276 EXPECT_EQ(Position(), selection().start()) | 284 EXPECT_EQ(Position(), |
| 285 selection().computeVisibleSelectionInDOMTreeDeprecated().start()) |
| 277 << "selection().updateIfNeeded() does nothing."; | 286 << "selection().updateIfNeeded() does nothing."; |
| 278 EXPECT_EQ(selection().start(), caretPosition().position()); | 287 EXPECT_EQ(selection().computeVisibleSelectionInDOMTreeDeprecated().start(), |
| 288 caretPosition().position()); |
| 279 } | 289 } |
| 280 | 290 |
| 281 } // namespace blink | 291 } // namespace blink |
| OLD | NEW |