OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "ui/gfx/point.h" | 6 #include "ui/gfx/point.h" |
7 #include "ui/gfx/rect.h" | 7 #include "ui/gfx/rect.h" |
8 #include "ui/gfx/render_text.h" | 8 #include "ui/gfx/render_text.h" |
9 #include "views/controls/textfield/native_textfield_views.h" | 9 #include "views/controls/textfield/native_textfield_views.h" |
10 #include "views/controls/textfield/textfield.h" | 10 #include "views/controls/textfield/textfield.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest); | 115 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest); |
116 }; | 116 }; |
117 | 117 |
118 // Tests that the selection handles are placed appropriately when selection in | 118 // Tests that the selection handles are placed appropriately when selection in |
119 // a Textfield changes. | 119 // a Textfield changes. |
120 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) { | 120 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) { |
121 CreateTextfield(); | 121 CreateTextfield(); |
122 textfield_->SetText(ASCIIToUTF16("some text")); | 122 textfield_->SetText(ASCIIToUTF16("some text")); |
123 | 123 |
124 // Test selecting a range. | 124 // Test selecting a range. |
125 textfield_->SelectSelectionModel(gfx::SelectionModel(3, 7)); | 125 textfield_->SelectRange(ui::Range(3, 7)); |
126 VerifySelectionHandlePositions(false); | 126 VerifySelectionHandlePositions(false); |
127 | 127 |
128 // Test selecting everything. | 128 // Test selecting everything. |
129 textfield_->SelectAll(); | 129 textfield_->SelectAll(); |
130 VerifySelectionHandlePositions(false); | 130 VerifySelectionHandlePositions(false); |
131 | 131 |
132 // Test with no selection. | 132 // Test with no selection. |
133 textfield_->ClearSelection(); | 133 textfield_->ClearSelection(); |
134 VerifySelectionHandlePositions(false); | 134 VerifySelectionHandlePositions(false); |
135 | 135 |
(...skipping 10 matching lines...) Expand all Loading... |
146 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) { | 146 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) { |
147 CreateTextfield(); | 147 CreateTextfield(); |
148 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); | 148 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); |
149 | 149 |
150 // Test cursor at run boundary and with empty selection. | 150 // Test cursor at run boundary and with empty selection. |
151 textfield_->SelectSelectionModel( | 151 textfield_->SelectSelectionModel( |
152 gfx::SelectionModel(3, 2, gfx::SelectionModel::TRAILING)); | 152 gfx::SelectionModel(3, 2, gfx::SelectionModel::TRAILING)); |
153 VerifySelectionHandlePositions(false); | 153 VerifySelectionHandlePositions(false); |
154 | 154 |
155 // Test selection range inside one run and starts or ends at run boundary. | 155 // Test selection range inside one run and starts or ends at run boundary. |
156 textfield_->SelectSelectionModel( | 156 textfield_->SelectRange(ui::Range(2, 3)); |
157 gfx::SelectionModel(2, 3, 2, gfx::SelectionModel::TRAILING)); | |
158 VerifySelectionHandlePositions(false); | 157 VerifySelectionHandlePositions(false); |
159 | 158 |
160 // TODO(xji): change to textfield_->SelectRange(3, 2). | 159 textfield_->SelectRange(ui::Range(3, 2)); |
161 textfield_->SelectSelectionModel( | |
162 gfx::SelectionModel(3, 2, 2, gfx::SelectionModel::LEADING)); | |
163 VerifySelectionHandlePositions(false); | 160 VerifySelectionHandlePositions(false); |
164 | 161 |
165 textfield_->SelectSelectionModel( | 162 textfield_->SelectRange(ui::Range(3, 4)); |
166 gfx::SelectionModel(3, 4, 3, gfx::SelectionModel::TRAILING)); | |
167 VerifySelectionHandlePositions(false); | 163 VerifySelectionHandlePositions(false); |
168 | 164 |
169 textfield_->SelectSelectionModel( | 165 textfield_->SelectRange(ui::Range(4, 3)); |
170 gfx::SelectionModel(4, 3, 3, gfx::SelectionModel::LEADING)); | |
171 VerifySelectionHandlePositions(false); | 166 VerifySelectionHandlePositions(false); |
172 | 167 |
173 textfield_->SelectSelectionModel( | 168 textfield_->SelectRange(ui::Range(3, 6)); |
174 gfx::SelectionModel(3, 6, 5, gfx::SelectionModel::TRAILING)); | |
175 VerifySelectionHandlePositions(false); | 169 VerifySelectionHandlePositions(false); |
176 | 170 |
177 textfield_->SelectSelectionModel( | 171 textfield_->SelectRange(ui::Range(6, 3)); |
178 gfx::SelectionModel(6, 3, 3, gfx::SelectionModel::LEADING)); | |
179 VerifySelectionHandlePositions(false); | 172 VerifySelectionHandlePositions(false); |
180 | 173 |
181 // Test selection range accross runs. | 174 // Test selection range accross runs. |
182 textfield_->SelectSelectionModel( | 175 textfield_->SelectRange(ui::Range(0, 6)); |
183 gfx::SelectionModel(0, 6, 5, gfx::SelectionModel::TRAILING)); | |
184 VerifySelectionHandlePositions(false); | 176 VerifySelectionHandlePositions(false); |
185 | 177 |
186 textfield_->SelectSelectionModel( | 178 textfield_->SelectRange(ui::Range(6, 0)); |
187 gfx::SelectionModel(6, 0, 0, gfx::SelectionModel::LEADING)); | |
188 VerifySelectionHandlePositions(false); | 179 VerifySelectionHandlePositions(false); |
189 | 180 |
190 textfield_->SelectSelectionModel( | 181 textfield_->SelectRange(ui::Range(1, 4)); |
191 gfx::SelectionModel(1, 4, 3, gfx::SelectionModel::TRAILING)); | |
192 VerifySelectionHandlePositions(false); | 182 VerifySelectionHandlePositions(false); |
193 | 183 |
194 textfield_->SelectSelectionModel( | 184 textfield_->SelectRange(ui::Range(4, 1)); |
195 gfx::SelectionModel(4, 1, 1, gfx::SelectionModel::LEADING)); | |
196 VerifySelectionHandlePositions(false); | 185 VerifySelectionHandlePositions(false); |
197 } | 186 } |
198 | 187 |
199 // Tests if the SelectRect callback is called appropriately when selection | 188 // Tests if the SelectRect callback is called appropriately when selection |
200 // handles are moved. | 189 // handles are moved. |
201 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) { | 190 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) { |
202 CreateTextfield(); | 191 CreateTextfield(); |
203 textfield_->SetText(ASCIIToUTF16("textfield with selected text")); | 192 textfield_->SetText(ASCIIToUTF16("textfield with selected text")); |
204 textfield_->SelectSelectionModel(gfx::SelectionModel(3, 7)); | 193 textfield_->SelectRange(ui::Range(3, 7)); |
205 | 194 |
206 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie"); | 195 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie"); |
207 VerifySelectionHandlePositions(false); | 196 VerifySelectionHandlePositions(false); |
208 | 197 |
209 // Drag selection handle 2 to right by 3 chars. | 198 // Drag selection handle 2 to right by 3 chars. |
210 int x = textfield_->font().GetStringWidth(ASCIIToUTF16("ld ")); | 199 int x = textfield_->font().GetStringWidth(ASCIIToUTF16("ld ")); |
211 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); | 200 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); |
212 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfield "); | 201 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfield "); |
213 VerifySelectionHandlePositions(false); | 202 VerifySelectionHandlePositions(false); |
214 | 203 |
(...skipping 10 matching lines...) Expand all Loading... |
225 VerifySelectionHandlePositions(true); | 214 VerifySelectionHandlePositions(true); |
226 | 215 |
227 // Drag selection handle 2 across selection handle 1. | 216 // Drag selection handle 2 across selection handle 1. |
228 x = textfield_->font().GetStringWidth(ASCIIToUTF16("with selected ")); | 217 x = textfield_->font().GetStringWidth(ASCIIToUTF16("with selected ")); |
229 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); | 218 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); |
230 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected "); | 219 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected "); |
231 VerifySelectionHandlePositions(false); | 220 VerifySelectionHandlePositions(false); |
232 } | 221 } |
233 | 222 |
234 } // namespace views | 223 } // namespace views |
OLD | NEW |