| 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, SelectAllPreservesHandle) { |
| 312 setBodyContent("<div id=sample>abc</div>"); |
| 313 Element* sample = document().getElementById("sample"); |
| 314 const Position endOfText(sample->firstChild(), 3); |
| 315 selection().setSelection(SelectionInDOMTree::Builder() |
| 316 .collapse(endOfText) |
| 317 .setIsHandleVisible(false) |
| 318 .build()); |
| 319 EXPECT_FALSE(selection().isHandleVisible()); |
| 320 selection().selectAll(); |
| 321 EXPECT_FALSE(selection().isHandleVisible()) |
| 322 << "If handles weren't present before" |
| 323 "selectAll. Then they shouldn't be present" |
| 324 "after it."; |
| 325 |
| 326 selection().setSelection(SelectionInDOMTree::Builder() |
| 327 .collapse(endOfText) |
| 328 .setIsHandleVisible(true) |
| 329 .build()); |
| 330 EXPECT_TRUE(selection().isHandleVisible()); |
| 331 selection().selectAll(); |
| 332 EXPECT_TRUE(selection().isHandleVisible()) |
| 333 << "If handles were present before" |
| 334 "selectAll. Then they should be present" |
| 335 "after it."; |
| 336 } |
| 337 |
| 311 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret) { | 338 TEST_F(FrameSelectionTest, updateIfNeededAndFrameCaret) { |
| 312 setBodyContent("<style id=sample></style>"); | 339 setBodyContent("<style id=sample></style>"); |
| 313 document().setDesignMode("on"); | 340 document().setDesignMode("on"); |
| 314 updateAllLifecyclePhases(); | 341 updateAllLifecyclePhases(); |
| 315 Element* sample = document().getElementById("sample"); | 342 Element* sample = document().getElementById("sample"); |
| 316 selection().setSelection( | 343 selection().setSelection( |
| 317 SelectionInDOMTree::Builder().collapse(Position(sample, 0)).build()); | 344 SelectionInDOMTree::Builder().collapse(Position(sample, 0)).build()); |
| 318 EXPECT_EQ(Position(document().body(), 0), selection().start()); | 345 EXPECT_EQ(Position(document().body(), 0), selection().start()); |
| 319 EXPECT_EQ(selection().start(), caretPosition().position()); | 346 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 320 document().body()->remove(); | 347 document().body()->remove(); |
| 321 // TODO(yosin): Once lazy canonicalization implemented, selection.start | 348 // TODO(yosin): Once lazy canonicalization implemented, selection.start |
| 322 // should be Position(HTML, 0). | 349 // should be Position(HTML, 0). |
| 323 EXPECT_EQ(Position(document().documentElement(), 1), selection().start()); | 350 EXPECT_EQ(Position(document().documentElement(), 1), selection().start()); |
| 324 EXPECT_EQ(selection().start(), caretPosition().position()); | 351 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 325 document().updateStyleAndLayout(); | 352 document().updateStyleAndLayout(); |
| 326 selection().updateIfNeeded(); | 353 selection().updateIfNeeded(); |
| 327 | 354 |
| 328 // TODO(yosin): Once lazy canonicalization implemented, selection.start | 355 // TODO(yosin): Once lazy canonicalization implemented, selection.start |
| 329 // should be Position(HTML, 0). | 356 // should be Position(HTML, 0). |
| 330 EXPECT_EQ(Position(), selection().start()) | 357 EXPECT_EQ(Position(), selection().start()) |
| 331 << "updateIfNeeded() makes selection to null."; | 358 << "updateIfNeeded() makes selection to null."; |
| 332 EXPECT_EQ(selection().start(), caretPosition().position()); | 359 EXPECT_EQ(selection().start(), caretPosition().position()); |
| 333 } | 360 } |
| 334 | 361 |
| 335 } // namespace blink | 362 } // namespace blink |
| OLD | NEW |