Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1006)

Side by Side Diff: Source/core/html/HTMLTextFormControlElementTest.cpp

Issue 431983005: FrameSelection::updateApperance for caret should not cause layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add updateLocalCaretRect function Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/html/HTMLTextFormControlElement.h" 6 #include "core/html/HTMLTextFormControlElement.h"
7 7
8 #include "core/dom/Position.h" 8 #include "core/dom/Position.h"
9 #include "core/dom/Text.h" 9 #include "core/dom/Text.h"
10 #include "core/editing/FrameSelection.h" 10 #include "core/editing/FrameSelection.h"
11 #include "core/editing/SpellChecker.h" 11 #include "core/editing/SpellChecker.h"
12 #include "core/editing/VisibleSelection.h" 12 #include "core/editing/VisibleSelection.h"
13 #include "core/editing/VisibleUnits.h" 13 #include "core/editing/VisibleUnits.h"
14 #include "core/frame/FrameView.h" 14 #include "core/frame/FrameView.h"
15 #include "core/html/HTMLBRElement.h" 15 #include "core/html/HTMLBRElement.h"
16 #include "core/html/HTMLDocument.h" 16 #include "core/html/HTMLDocument.h"
17 #include "core/html/HTMLInputElement.h" 17 #include "core/html/HTMLInputElement.h"
18 #include "core/html/HTMLTextAreaElement.h" 18 #include "core/html/HTMLTextAreaElement.h"
19 #include "core/loader/EmptyClients.h" 19 #include "core/loader/EmptyClients.h"
20 #include "core/page/SpellCheckerClient.h" 20 #include "core/page/SpellCheckerClient.h"
21 #include "core/rendering/RenderTreeAsText.h" 21 #include "core/rendering/RenderTreeAsText.h"
22 #include "core/testing/DummyPageHolder.h" 22 #include "core/testing/DummyPageHolder.h"
23 #include "core/testing/UnitTestHelpers.h"
23 #include "wtf/OwnPtr.h" 24 #include "wtf/OwnPtr.h"
24 #include <gtest/gtest.h> 25 #include <gtest/gtest.h>
25 26
26 using namespace blink; 27 using namespace blink;
27 28
28 namespace { 29 namespace {
29 30
30 class HTMLTextFormControlElementTest : public ::testing::Test { 31 class HTMLTextFormControlElementTest : public ::testing::Test {
31 protected: 32 protected:
32 virtual void SetUp() OVERRIDE; 33 virtual void SetUp() OVERRIDE;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 101
101 textControl().setInnerEditorValue("Hello, text form."); 102 textControl().setInnerEditorValue("Hello, text form.");
102 EXPECT_EQ(0, textControl().selectionStart()); 103 EXPECT_EQ(0, textControl().selectionStart());
103 EXPECT_EQ(0, textControl().selectionEnd()); 104 EXPECT_EQ(0, textControl().selectionEnd());
104 105
105 textControl().setSelectionRange(1, 3); 106 textControl().setSelectionRange(1, 3);
106 EXPECT_EQ(1, textControl().selectionStart()); 107 EXPECT_EQ(1, textControl().selectionStart());
107 EXPECT_EQ(3, textControl().selectionEnd()); 108 EXPECT_EQ(3, textControl().selectionEnd());
108 } 109 }
109 110
110 TEST_F(HTMLTextFormControlElementTest, FrameSelectionLocalCaretRectDoesNotCauseL ayout) 111 TEST_F(HTMLTextFormControlElementTest, SetSelectionRangeDoesNotCauseLayout)
111 {
112 input().focus();
113 input().setValue("Hello, input form.");
114 FrameSelection& frameSelection = document().frame()->selection();
115 frameSelection.setCaretRectNeedsUpdate();
116
117 forceLayoutFlag();
118 int startLayoutCount = layoutCount();
119 frameSelection.localCaretRect();
120 EXPECT_EQ(startLayoutCount, layoutCount());
121 }
122
123 TEST_F(HTMLTextFormControlElementTest, SetSameSelectionRangeDoesNotCauseLayout)
124 { 112 {
125 input().focus(); 113 input().focus();
126 input().setValue("Hello, input form."); 114 input().setValue("Hello, input form.");
127 input().setSelectionRange(1, 1); 115 input().setSelectionRange(1, 1);
128 FrameSelection& frameSelection = document().frame()->selection(); 116 FrameSelection& frameSelection = document().frame()->selection();
117 forceLayoutFlag();
118 frameSelection.updateLocalCaretRect();
129 LayoutRect oldCaretRect = frameSelection.localCaretRectWithoutUpdateForTesti ng(); 119 LayoutRect oldCaretRect = frameSelection.localCaretRectWithoutUpdateForTesti ng();
130 EXPECT_FALSE(oldCaretRect.isEmpty()); 120 EXPECT_FALSE(oldCaretRect.isEmpty());
131
132 forceLayoutFlag();
133 int startLayoutCount = layoutCount(); 121 int startLayoutCount = layoutCount();
134 input().setSelectionRange(1, 1); 122 input().setSelectionRange(1, 1);
135 EXPECT_EQ(startLayoutCount, layoutCount()); 123 EXPECT_EQ(startLayoutCount, layoutCount());
136 124 frameSelection.updateLocalCaretRect();
137 LayoutRect newCaretRect = frameSelection.localCaretRectWithoutUpdateForTesti ng(); 125 LayoutRect newCaretRect = frameSelection.localCaretRectWithoutUpdateForTesti ng();
138 EXPECT_EQ(oldCaretRect, newCaretRect); 126 EXPECT_EQ(oldCaretRect, newCaretRect);
127
128 forceLayoutFlag();
129 frameSelection.updateLocalCaretRect();
130 oldCaretRect = frameSelection.localCaretRectWithoutUpdateForTesting();
131 EXPECT_FALSE(oldCaretRect.isEmpty());
132 startLayoutCount = layoutCount();
133 input().setSelectionRange(2, 2);
134 EXPECT_EQ(startLayoutCount, layoutCount());
135 frameSelection.updateLocalCaretRect();
136 newCaretRect = frameSelection.localCaretRectWithoutUpdateForTesting();
137 EXPECT_NE(oldCaretRect, newCaretRect);
139 } 138 }
140 139
141 typedef Position (*PositionFunction)(const Position&); 140 typedef Position (*PositionFunction)(const Position&);
142 typedef VisiblePosition(*VisblePositionFunction)(const VisiblePosition&); 141 typedef VisiblePosition(*VisblePositionFunction)(const VisiblePosition&);
143 142
144 void testFunctionEquivalence(const Position& position, PositionFunction position Function, VisblePositionFunction visibleFunction) 143 void testFunctionEquivalence(const Position& position, PositionFunction position Function, VisblePositionFunction visibleFunction)
145 { 144 {
146 VisiblePosition visiblePosition(position); 145 VisiblePosition visiblePosition(position);
147 VisiblePosition expected = visibleFunction(visiblePosition); 146 VisiblePosition expected = visibleFunction(visiblePosition);
148 VisiblePosition actual = VisiblePosition(positionFunction(position)); 147 VisiblePosition actual = VisiblePosition(positionFunction(position));
149 EXPECT_EQ(expected, actual); 148 EXPECT_EQ(expected, actual);
150 } 149 }
151 150
152 static VisiblePosition startOfWord(const VisiblePosition& position) 151 static VisiblePosition startOfWord(const VisiblePosition& position)
153 { 152 {
154 return startOfWord(position, LeftWordIfOnBoundary); 153 return startOfWord(position, LeftWordIfOnBoundary);
155 } 154 }
156 155
157 static VisiblePosition endOfWord(const VisiblePosition& position) 156 static VisiblePosition endOfWord(const VisiblePosition& position)
158 { 157 {
159 return endOfWord(position, RightWordIfOnBoundary); 158 return endOfWord(position, RightWordIfOnBoundary);
160 } 159 }
161 160
162 void testBoundary(HTMLDocument& document, HTMLTextFormControlElement& textContro l) 161 void testBoundary(HTMLDocument& document, HTMLTextFormControlElement& textContro l)
163 { 162 {
164 for (unsigned i = 0; i < textControl.innerEditorValue().length(); i++) { 163 for (unsigned i = 0; i < textControl.innerEditorValue().length(); i++) {
165 textControl.setSelectionRange(i, i); 164 textControl.setSelectionRange(i, i);
166 Position position = document.frame()->selection().start(); 165 Position position = document.frame()->selection().start();
167 SCOPED_TRACE(testing::Message() << "offset " << position.deprecatedEditi ngOffset() << " of " << nodePositionAsStringForTesting(position.deprecatedNode() ).ascii().data()); 166 SCOPED_TRACE(::testing::Message() << "offset " << position.deprecatedEdi tingOffset() << " of " << nodePositionAsStringForTesting(position.deprecatedNode ()).ascii().data());
168 { 167 {
169 SCOPED_TRACE("HTMLTextFormControlElement::startOfWord"); 168 SCOPED_TRACE("HTMLTextFormControlElement::startOfWord");
170 testFunctionEquivalence(position, HTMLTextFormControlElement::startO fWord, startOfWord); 169 testFunctionEquivalence(position, HTMLTextFormControlElement::startO fWord, startOfWord);
171 } 170 }
172 { 171 {
173 SCOPED_TRACE("HTMLTextFormControlElement::endOfWord"); 172 SCOPED_TRACE("HTMLTextFormControlElement::endOfWord");
174 testFunctionEquivalence(position, HTMLTextFormControlElement::endOfW ord, endOfWord); 173 testFunctionEquivalence(position, HTMLTextFormControlElement::endOfW ord, endOfWord);
175 } 174 }
176 { 175 {
177 SCOPED_TRACE("HTMLTextFormControlElement::startOfSentence"); 176 SCOPED_TRACE("HTMLTextFormControlElement::startOfSentence");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 ASSERT_EQ(3, input->selectionStart()); 223 ASSERT_EQ(3, input->selectionStart());
225 224
226 OwnPtr<SpellChecker> spellChecker(SpellChecker::create(page().frame())); 225 OwnPtr<SpellChecker> spellChecker(SpellChecker::create(page().frame()));
227 forceLayoutFlag(); 226 forceLayoutFlag();
228 int startCount = layoutCount(); 227 int startCount = layoutCount();
229 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT yping | FrameSelection::ClearTypingStyle); 228 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT yping | FrameSelection::ClearTypingStyle);
230 EXPECT_EQ(startCount, layoutCount()); 229 EXPECT_EQ(startCount, layoutCount());
231 } 230 }
232 231
233 } 232 }
OLDNEW
« Source/core/editing/FrameSelection.cpp ('K') | « Source/core/editing/FrameSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698