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

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: Delay invalidation 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();
129 LayoutRect oldCaretRect = frameSelection.localCaretRectWithoutUpdateForTesti ng(); 117 forceLayoutFlag();
118 LayoutRect oldCaretRect = frameSelection.localCaretRect();
130 EXPECT_FALSE(oldCaretRect.isEmpty()); 119 EXPECT_FALSE(oldCaretRect.isEmpty());
131
132 forceLayoutFlag();
133 int startLayoutCount = layoutCount(); 120 int startLayoutCount = layoutCount();
134 input().setSelectionRange(1, 1); 121 input().setSelectionRange(1, 1);
135 EXPECT_EQ(startLayoutCount, layoutCount()); 122 EXPECT_EQ(startLayoutCount, layoutCount());
123 LayoutRect newCaretRect = frameSelection.localCaretRect();
124 EXPECT_EQ(oldCaretRect, newCaretRect);
136 125
137 LayoutRect newCaretRect = frameSelection.localCaretRectWithoutUpdateForTesti ng(); 126 forceLayoutFlag();
138 EXPECT_EQ(oldCaretRect, newCaretRect); 127 oldCaretRect = frameSelection.localCaretRect();
128 EXPECT_FALSE(oldCaretRect.isEmpty());
129 startLayoutCount = layoutCount();
130 input().setSelectionRange(2, 2);
131 EXPECT_EQ(startLayoutCount, layoutCount());
132 newCaretRect = frameSelection.localCaretRect();
133 EXPECT_NE(oldCaretRect, newCaretRect);
139 } 134 }
140 135
141 typedef Position (*PositionFunction)(const Position&); 136 typedef Position (*PositionFunction)(const Position&);
142 typedef VisiblePosition(*VisblePositionFunction)(const VisiblePosition&); 137 typedef VisiblePosition(*VisblePositionFunction)(const VisiblePosition&);
143 138
144 void testFunctionEquivalence(const Position& position, PositionFunction position Function, VisblePositionFunction visibleFunction) 139 void testFunctionEquivalence(const Position& position, PositionFunction position Function, VisblePositionFunction visibleFunction)
145 { 140 {
146 VisiblePosition visiblePosition(position); 141 VisiblePosition visiblePosition(position);
147 VisiblePosition expected = visibleFunction(visiblePosition); 142 VisiblePosition expected = visibleFunction(visiblePosition);
148 VisiblePosition actual = VisiblePosition(positionFunction(position)); 143 VisiblePosition actual = VisiblePosition(positionFunction(position));
149 EXPECT_EQ(expected, actual); 144 EXPECT_EQ(expected, actual);
150 } 145 }
151 146
152 static VisiblePosition startOfWord(const VisiblePosition& position) 147 static VisiblePosition startOfWord(const VisiblePosition& position)
153 { 148 {
154 return startOfWord(position, LeftWordIfOnBoundary); 149 return startOfWord(position, LeftWordIfOnBoundary);
155 } 150 }
156 151
157 static VisiblePosition endOfWord(const VisiblePosition& position) 152 static VisiblePosition endOfWord(const VisiblePosition& position)
158 { 153 {
159 return endOfWord(position, RightWordIfOnBoundary); 154 return endOfWord(position, RightWordIfOnBoundary);
160 } 155 }
161 156
162 void testBoundary(HTMLDocument& document, HTMLTextFormControlElement& textContro l) 157 void testBoundary(HTMLDocument& document, HTMLTextFormControlElement& textContro l)
163 { 158 {
164 for (unsigned i = 0; i < textControl.innerEditorValue().length(); i++) { 159 for (unsigned i = 0; i < textControl.innerEditorValue().length(); i++) {
165 textControl.setSelectionRange(i, i); 160 textControl.setSelectionRange(i, i);
166 Position position = document.frame()->selection().start(); 161 Position position = document.frame()->selection().start();
167 SCOPED_TRACE(testing::Message() << "offset " << position.deprecatedEditi ngOffset() << " of " << nodePositionAsStringForTesting(position.deprecatedNode() ).ascii().data()); 162 SCOPED_TRACE(::testing::Message() << "offset " << position.deprecatedEdi tingOffset() << " of " << nodePositionAsStringForTesting(position.deprecatedNode ()).ascii().data());
168 { 163 {
169 SCOPED_TRACE("HTMLTextFormControlElement::startOfWord"); 164 SCOPED_TRACE("HTMLTextFormControlElement::startOfWord");
170 testFunctionEquivalence(position, HTMLTextFormControlElement::startO fWord, startOfWord); 165 testFunctionEquivalence(position, HTMLTextFormControlElement::startO fWord, startOfWord);
171 } 166 }
172 { 167 {
173 SCOPED_TRACE("HTMLTextFormControlElement::endOfWord"); 168 SCOPED_TRACE("HTMLTextFormControlElement::endOfWord");
174 testFunctionEquivalence(position, HTMLTextFormControlElement::endOfW ord, endOfWord); 169 testFunctionEquivalence(position, HTMLTextFormControlElement::endOfW ord, endOfWord);
175 } 170 }
176 { 171 {
177 SCOPED_TRACE("HTMLTextFormControlElement::startOfSentence"); 172 SCOPED_TRACE("HTMLTextFormControlElement::startOfSentence");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 ASSERT_EQ(3, input->selectionStart()); 219 ASSERT_EQ(3, input->selectionStart());
225 220
226 OwnPtr<SpellChecker> spellChecker(SpellChecker::create(page().frame())); 221 OwnPtr<SpellChecker> spellChecker(SpellChecker::create(page().frame()));
227 forceLayoutFlag(); 222 forceLayoutFlag();
228 int startCount = layoutCount(); 223 int startCount = layoutCount();
229 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT yping | FrameSelection::ClearTypingStyle); 224 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT yping | FrameSelection::ClearTypingStyle);
230 EXPECT_EQ(startCount, layoutCount()); 225 EXPECT_EQ(startCount, layoutCount());
231 } 226 }
232 227
233 } 228 }
OLDNEW
« Source/core/frame/FrameView.cpp ('K') | « Source/core/frame/FrameView.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698