| 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 "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
| 10 #include "core/dom/Text.h" | 10 #include "core/dom/Text.h" |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 301 |
| 302 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) { | 302 TEST_F(FrameSelectionTest, SelectAllWithUnselectableRoot) { |
| 303 Element* select = document().createElement("select"); | 303 Element* select = document().createElement("select"); |
| 304 document().replaceChild(select, document().documentElement()); | 304 document().replaceChild(select, document().documentElement()); |
| 305 selection().selectAll(); | 305 selection().selectAll(); |
| 306 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the " | 306 EXPECT_TRUE(selection().isNone()) << "Nothing should be selected if the " |
| 307 "content of the documentElement is not " | 307 "content of the documentElement is not " |
| 308 "selctable."; | 308 "selctable."; |
| 309 } | 309 } |
| 310 | 310 |
| 311 TEST_F(FrameSelectionTest, SelectAllKeepsHandle) { |
| 312 setBodyContent("<div id=sample>abc</div>"); |
| 313 Element* sample = document().getElementById("sample"); |
| 314 const Position endOfText(sample->firstChild(), 3); |
| 315 FrameSelection::SetSelectionOptions options = |
| 316 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | |
| 317 FrameSelection::ShowHandle; |
| 318 selection().setSelection( |
| 319 SelectionInDOMTree::Builder().collapse(endOfText).build(), options); |
| 320 EXPECT_TRUE(selection().isHandleVisible()); |
| 321 selection().selectAll(); |
| 322 EXPECT_TRUE(selection().isHandleVisible()) |
| 323 << "If handles were present before" |
| 324 "selectAll. Then they should be present" |
| 325 "after it."; |
| 326 } |
| 327 |
| 311 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret) { | 328 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret) { |
| 312 setBodyContent("<style id=sample></style>"); | 329 setBodyContent("<style id=sample></style>"); |
| 313 document().setDesignMode("on"); | 330 document().setDesignMode("on"); |
| 314 updateAllLifecyclePhases(); | 331 updateAllLifecyclePhases(); |
| 315 Element* sample = document().getElementById("sample"); | 332 Element* sample = document().getElementById("sample"); |
| 316 selection().setSelection( | 333 selection().setSelection( |
| 317 SelectionInDOMTree::Builder().collapse(Position(sample, 0)).build()); | 334 SelectionInDOMTree::Builder().collapse(Position(sample, 0)).build()); |
| 318 EXPECT_EQ(Position(document().body(), 0), selection().start()); | 335 EXPECT_EQ(Position(document().body(), 0), selection().start()); |
| 319 EXPECT_EQ(selection().start(), caretPosition().position()); | 336 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 320 document().body()->remove(); | 337 document().body()->remove(); |
| 321 // TODO(yosin): Once lazy canonicalization implemented, selection.start | 338 // TODO(yosin): Once lazy canonicalization implemented, selection.start |
| 322 // should be Position(HTML, 0). | 339 // should be Position(HTML, 0). |
| 323 EXPECT_EQ(Position(document().documentElement(), 1), selection().start()); | 340 EXPECT_EQ(Position(document().documentElement(), 1), selection().start()); |
| 324 EXPECT_EQ(selection().start(), caretPosition().position()); | 341 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 325 document().updateStyleAndLayout(); | 342 document().updateStyleAndLayout(); |
| 326 selection().updateIfNeeded(); | 343 selection().updateIfNeeded(); |
| 327 | 344 |
| 328 // TODO(yosin): Once lazy canonicalization implemented, selection.start | 345 // TODO(yosin): Once lazy canonicalization implemented, selection.start |
| 329 // should be Position(HTML, 0). | 346 // should be Position(HTML, 0). |
| 330 EXPECT_EQ(Position(), selection().start()) | 347 EXPECT_EQ(Position(), selection().start()) |
| 331 << "updateIfNeeded() makes selection to null."; | 348 << "updateIfNeeded() makes selection to null."; |
| 332 EXPECT_EQ(selection().start(), caretPosition().position()); | 349 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 333 } | 350 } |
| 334 | 351 |
| 335 } // namespace blink | 352 } // namespace blink |
| OLD | NEW |