| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/editing/FrameSelection.h" | 6 #include "core/editing/FrameSelection.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 8 #include "bindings/core/v8/ExceptionStatePlaceholder.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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 VisibleSelection invalidSelection; | 95 VisibleSelection invalidSelection; |
| 96 invalidSelection.setWithoutValidation(Position(anotherText, 0), Position(ano
therText, 5)); | 96 invalidSelection.setWithoutValidation(Position(anotherText, 0), Position(ano
therText, 5)); |
| 97 setSelection(invalidSelection); | 97 setSelection(invalidSelection); |
| 98 | 98 |
| 99 EXPECT_TRUE(selection().isNone()); | 99 EXPECT_TRUE(selection().isNone()); |
| 100 } | 100 } |
| 101 | 101 |
| 102 TEST_F(FrameSelectionTest, InvalidateCaretRect) | 102 TEST_F(FrameSelectionTest, InvalidateCaretRect) |
| 103 { | 103 { |
| 104 RefPtrWillBeRawPtr<Text> text = appendTextNode("Hello, World!"); | 104 RefPtrWillBeRawPtr<Text> text = appendTextNode("Hello, World!"); |
| 105 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 105 document().view()->updateLayoutAndStyleForPainting(); |
| 106 | 106 |
| 107 VisibleSelection validSelection(Position(text, 0), Position(text, 0)); | 107 VisibleSelection validSelection(Position(text, 0), Position(text, 0)); |
| 108 setSelection(validSelection); | 108 setSelection(validSelection); |
| 109 selection().setCaretRectNeedsUpdate(); | 109 selection().setCaretRectNeedsUpdate(); |
| 110 EXPECT_TRUE(selection().isCaretBoundsDirty()); | 110 EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| 111 selection().invalidateCaretRect(); | 111 selection().invalidateCaretRect(); |
| 112 EXPECT_FALSE(selection().isCaretBoundsDirty()); | 112 EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| 113 | 113 |
| 114 document().body()->removeChild(text); | 114 document().body()->removeChild(text); |
| 115 document().updateLayoutIgnorePendingStylesheets(); | 115 document().updateLayoutIgnorePendingStylesheets(); |
| 116 selection().setCaretRectNeedsUpdate(); | 116 selection().setCaretRectNeedsUpdate(); |
| 117 EXPECT_TRUE(selection().isCaretBoundsDirty()); | 117 EXPECT_TRUE(selection().isCaretBoundsDirty()); |
| 118 selection().invalidateCaretRect(); | 118 selection().invalidateCaretRect(); |
| 119 EXPECT_FALSE(selection().isCaretBoundsDirty()); | 119 EXPECT_FALSE(selection().isCaretBoundsDirty()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 TEST_F(FrameSelectionTest, PaintCaretShouldNotLayout) | 122 TEST_F(FrameSelectionTest, PaintCaretShouldNotLayout) |
| 123 { | 123 { |
| 124 RefPtrWillBeRawPtr<Text> text = appendTextNode("Hello, World!"); | 124 RefPtrWillBeRawPtr<Text> text = appendTextNode("Hello, World!"); |
| 125 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 125 document().view()->updateLayoutAndStyleForPainting(); |
| 126 | 126 |
| 127 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); | 127 document().body()->setContentEditable("true", ASSERT_NO_EXCEPTION); |
| 128 document().body()->focus(); | 128 document().body()->focus(); |
| 129 EXPECT_TRUE(document().body()->focused()); | 129 EXPECT_TRUE(document().body()->focused()); |
| 130 | 130 |
| 131 VisibleSelection validSelection(Position(text, 0), Position(text, 0)); | 131 VisibleSelection validSelection(Position(text, 0), Position(text, 0)); |
| 132 selection().setCaretVisible(true); | 132 selection().setCaretVisible(true); |
| 133 setSelection(validSelection); | 133 setSelection(validSelection); |
| 134 EXPECT_TRUE(selection().isCaret()); | 134 EXPECT_TRUE(selection().isCaret()); |
| 135 EXPECT_TRUE(selection().ShouldPaintCaretForTesting()); | 135 EXPECT_TRUE(selection().ShouldPaintCaretForTesting()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 9)), WordGranularity); | 317 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 9)), WordGranularity); |
| 318 EXPECT_EQ_SELECTED_TEXT("Bar Baz"); | 318 EXPECT_EQ_SELECTED_TEXT("Bar Baz"); |
| 319 // "Fo<o B|ar Baz," with the Character granularity. | 319 // "Fo<o B|ar Baz," with the Character granularity. |
| 320 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 2)), CharacterGranularity); | 320 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 2)), CharacterGranularity); |
| 321 EXPECT_EQ_SELECTED_TEXT("o B"); | 321 EXPECT_EQ_SELECTED_TEXT("o B"); |
| 322 // "Fo<o B|ar Baz," with the Word granularity. | 322 // "Fo<o B|ar Baz," with the Word granularity. |
| 323 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 2)), WordGranularity); | 323 selection().moveRangeSelection(VisiblePosition(Position(text, 5)), VisiblePo
sition(Position(text, 2)), WordGranularity); |
| 324 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); | 324 EXPECT_EQ_SELECTED_TEXT("Foo Bar"); |
| 325 } | 325 } |
| 326 } | 326 } |
| OLD | NEW |