OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/textfield/native_textfield_views.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "grit/ui_strings.h" | 20 #include "grit/ui_strings.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/base/clipboard/clipboard.h" | 22 #include "ui/base/clipboard/clipboard.h" |
23 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 23 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
24 #include "ui/base/dragdrop/drag_drop_types.h" | 24 #include "ui/base/dragdrop/drag_drop_types.h" |
25 #include "ui/base/ime/text_input_client.h" | 25 #include "ui/base/ime/text_input_client.h" |
26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
27 #include "ui/base/ui_base_switches.h" | 27 #include "ui/base/ui_base_switches.h" |
| 28 #include "ui/base/ui_base_switches_util.h" |
28 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
29 #include "ui/events/keycodes/keyboard_codes.h" | 30 #include "ui/events/keycodes/keyboard_codes.h" |
30 #include "ui/gfx/render_text.h" | 31 #include "ui/gfx/render_text.h" |
31 #include "ui/views/controls/textfield/textfield.h" | |
32 #include "ui/views/controls/textfield/textfield_controller.h" | 32 #include "ui/views/controls/textfield/textfield_controller.h" |
33 #include "ui/views/controls/textfield/textfield_views_model.h" | 33 #include "ui/views/controls/textfield/textfield_views_model.h" |
34 #include "ui/views/focus/focus_manager.h" | 34 #include "ui/views/focus/focus_manager.h" |
35 #include "ui/views/ime/mock_input_method.h" | 35 #include "ui/views/ime/mock_input_method.h" |
36 #include "ui/views/test/test_views_delegate.h" | 36 #include "ui/views/test/test_views_delegate.h" |
37 #include "ui/views/test/views_test_base.h" | 37 #include "ui/views/test/views_test_base.h" |
38 #include "ui/views/widget/native_widget_private.h" | 38 #include "ui/views/widget/native_widget_private.h" |
39 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
40 #include "url/gurl.h" | 40 #include "url/gurl.h" |
41 | 41 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 | 111 |
112 private: | 112 private: |
113 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); | 113 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); |
114 }; | 114 }; |
115 | 115 |
116 } // namespace | 116 } // namespace |
117 | 117 |
118 namespace views { | 118 namespace views { |
119 | 119 |
120 // TODO(oshima): Move tests that are independent of TextfieldViews to | 120 class TextfieldTest : public ViewsTestBase, public TextfieldController { |
121 // textfield_unittests.cc once we move the test utility functions | |
122 // from chrome/browser/automation/ to ui/base/test/. | |
123 class NativeTextfieldViewsTest : public ViewsTestBase, | |
124 public TextfieldController { | |
125 public: | 121 public: |
126 NativeTextfieldViewsTest() | 122 TextfieldTest() |
127 : widget_(NULL), | 123 : widget_(NULL), |
128 textfield_(NULL), | 124 textfield_(NULL), |
129 textfield_view_(NULL), | |
130 model_(NULL), | 125 model_(NULL), |
131 input_method_(NULL), | 126 input_method_(NULL), |
132 on_before_user_action_(0), | 127 on_before_user_action_(0), |
133 on_after_user_action_(0) { | 128 on_after_user_action_(0) { |
134 } | 129 } |
135 | 130 |
136 // ::testing::Test: | 131 // ::testing::Test: |
137 virtual void SetUp() { | 132 virtual void SetUp() { |
138 ViewsTestBase::SetUp(); | 133 ViewsTestBase::SetUp(); |
139 } | 134 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 ASSERT_FALSE(textfield_); | 170 ASSERT_FALSE(textfield_); |
176 textfield_ = new TestTextfield(style); | 171 textfield_ = new TestTextfield(style); |
177 textfield_->SetController(this); | 172 textfield_->SetController(this); |
178 widget_ = new Widget(); | 173 widget_ = new Widget(); |
179 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 174 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
180 params.bounds = gfx::Rect(100, 100, 100, 100); | 175 params.bounds = gfx::Rect(100, 100, 100, 100); |
181 widget_->Init(params); | 176 widget_->Init(params); |
182 View* container = new View(); | 177 View* container = new View(); |
183 widget_->SetContentsView(container); | 178 widget_->SetContentsView(container); |
184 container->AddChildView(textfield_); | 179 container->AddChildView(textfield_); |
185 | 180 textfield_->SetBoundsRect(params.bounds); |
186 textfield_view_ = textfield_->GetTextfieldViewForTesting(); | |
187 DCHECK(textfield_view_); | |
188 textfield_view_->SetBoundsRect(params.bounds); | |
189 textfield_->set_id(1); | 181 textfield_->set_id(1); |
190 | 182 |
191 for (int i = 1; i < count; i++) { | 183 for (int i = 1; i < count; i++) { |
192 Textfield* textfield = new Textfield(style); | 184 Textfield* textfield = new Textfield(style); |
193 container->AddChildView(textfield); | 185 container->AddChildView(textfield); |
194 textfield->set_id(i + 1); | 186 textfield->set_id(i + 1); |
195 } | 187 } |
196 | 188 |
197 model_ = textfield_view_->model_.get(); | 189 model_ = textfield_->model_.get(); |
198 model_->ClearEditHistory(); | 190 model_->ClearEditHistory(); |
199 | 191 |
200 input_method_ = new MockInputMethod(); | 192 input_method_ = new MockInputMethod(); |
201 widget_->ReplaceInputMethod(input_method_); | 193 widget_->ReplaceInputMethod(input_method_); |
202 | 194 |
203 // Activate the widget and focus the textfield for input handling. | 195 // Activate the widget and focus the textfield for input handling. |
204 widget_->Activate(); | 196 widget_->Activate(); |
205 textfield_->RequestFocus(); | 197 textfield_->RequestFocus(); |
206 } | 198 } |
207 | 199 |
208 ui::MenuModel* GetContextMenuModel() { | 200 ui::MenuModel* GetContextMenuModel() { |
209 textfield_view_->UpdateContextMenu(); | 201 textfield_->UpdateContextMenu(); |
210 return textfield_view_->context_menu_contents_.get(); | 202 return textfield_->context_menu_contents_.get(); |
211 } | 203 } |
212 | 204 |
213 ui::TouchSelectionController* GetTouchSelectionController() { | 205 ui::TouchSelectionController* GetTouchSelectionController() { |
214 return textfield_view_->touch_selection_controller_.get(); | 206 return textfield_->touch_selection_controller_.get(); |
215 } | 207 } |
216 | 208 |
217 protected: | 209 protected: |
218 void SendKeyEvent(ui::KeyboardCode key_code, | 210 void SendKeyEvent(ui::KeyboardCode key_code, |
219 bool alt, | 211 bool alt, |
220 bool shift, | 212 bool shift, |
221 bool control, | 213 bool control, |
222 bool caps_lock) { | 214 bool caps_lock) { |
223 int flags = (alt ? ui::EF_ALT_DOWN : 0) | | 215 int flags = (alt ? ui::EF_ALT_DOWN : 0) | |
224 (shift ? ui::EF_SHIFT_DOWN : 0) | | 216 (shift ? ui::EF_SHIFT_DOWN : 0) | |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 ui::Clipboard::GetForCurrentThread(), | 253 ui::Clipboard::GetForCurrentThread(), |
262 ui::CLIPBOARD_TYPE_COPY_PASTE); | 254 ui::CLIPBOARD_TYPE_COPY_PASTE); |
263 clipboard_writer.WriteText(ASCIIToUTF16(text)); | 255 clipboard_writer.WriteText(ASCIIToUTF16(text)); |
264 } | 256 } |
265 | 257 |
266 View* GetFocusedView() { | 258 View* GetFocusedView() { |
267 return widget_->GetFocusManager()->GetFocusedView(); | 259 return widget_->GetFocusManager()->GetFocusedView(); |
268 } | 260 } |
269 | 261 |
270 int GetCursorPositionX(int cursor_pos) { | 262 int GetCursorPositionX(int cursor_pos) { |
271 gfx::RenderText* render_text = textfield_view_->GetRenderText(); | 263 return textfield_->GetRenderText()->GetCursorBounds( |
272 return render_text->GetCursorBounds( | |
273 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); | 264 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); |
274 } | 265 } |
275 | 266 |
276 // Get the current cursor bounds. | 267 // Get the current cursor bounds. |
277 gfx::Rect GetCursorBounds() { | 268 gfx::Rect GetCursorBounds() { |
278 gfx::RenderText* render_text = textfield_view_->GetRenderText(); | 269 return textfield_->GetRenderText()->GetUpdatedCursorBounds(); |
279 gfx::Rect bounds = render_text->GetUpdatedCursorBounds(); | |
280 return bounds; | |
281 } | 270 } |
282 | 271 |
283 // Get the cursor bounds of |sel|. | 272 // Get the cursor bounds of |sel|. |
284 gfx::Rect GetCursorBounds(const gfx::SelectionModel& sel) { | 273 gfx::Rect GetCursorBounds(const gfx::SelectionModel& sel) { |
285 gfx::RenderText* render_text = textfield_view_->GetRenderText(); | 274 return textfield_->GetRenderText()->GetCursorBounds(sel, true); |
286 gfx::Rect bounds = render_text->GetCursorBounds(sel, true); | |
287 return bounds; | |
288 } | 275 } |
289 | 276 |
290 gfx::Rect GetDisplayRect() { | 277 gfx::Rect GetDisplayRect() { |
291 return textfield_view_->GetRenderText()->display_rect(); | 278 return textfield_->GetRenderText()->display_rect(); |
292 } | 279 } |
293 | 280 |
294 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and | 281 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and |
295 // y-axis is in the middle of |bound|'s vertical range. | 282 // y-axis is in the middle of |bound|'s vertical range. |
296 void MouseClick(const gfx::Rect bound, int x_offset) { | 283 void MouseClick(const gfx::Rect bound, int x_offset) { |
297 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); | 284 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); |
298 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 285 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, |
299 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 286 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
300 textfield_view_->OnMousePressed(click); | 287 textfield_->OnMousePressed(click); |
301 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, | 288 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, |
302 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 289 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
303 textfield_view_->OnMouseReleased(release); | 290 textfield_->OnMouseReleased(release); |
304 } | 291 } |
305 | 292 |
306 // This is to avoid double/triple click. | 293 // This is to avoid double/triple click. |
307 void NonClientMouseClick() { | 294 void NonClientMouseClick() { |
308 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 295 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
309 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 296 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
310 ui::EF_LEFT_MOUSE_BUTTON); | 297 ui::EF_LEFT_MOUSE_BUTTON); |
311 textfield_view_->OnMousePressed(click); | 298 textfield_->OnMousePressed(click); |
312 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 299 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
313 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 300 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
314 ui::EF_LEFT_MOUSE_BUTTON); | 301 ui::EF_LEFT_MOUSE_BUTTON); |
315 textfield_view_->OnMouseReleased(release); | 302 textfield_->OnMouseReleased(release); |
316 } | 303 } |
317 | 304 |
318 // Wrap for visibility in test classes. | 305 // Wrap for visibility in test classes. |
319 ui::TextInputType GetTextInputType() { | 306 ui::TextInputType GetTextInputType() { |
320 return textfield_view_->GetTextInputType(); | 307 return textfield_->GetTextInputType(); |
321 } | 308 } |
322 | 309 |
323 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, | 310 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, |
324 bool can_undo, | 311 bool can_undo, |
325 ui::MenuModel* menu) { | 312 ui::MenuModel* menu) { |
326 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); | 313 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); |
327 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); | 314 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); |
328 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); | 315 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); |
329 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); | 316 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); |
330 EXPECT_NE(GetClipboardText().empty(), menu->IsEnabledAt(4 /* PASTE */)); | 317 EXPECT_NE(GetClipboardText().empty(), menu->IsEnabledAt(4 /* PASTE */)); |
331 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); | 318 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); |
332 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); | 319 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); |
333 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); | 320 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); |
334 } | 321 } |
335 | 322 |
336 // We need widget to populate wrapper class. | 323 // We need widget to populate wrapper class. |
337 Widget* widget_; | 324 Widget* widget_; |
338 | 325 |
339 TestTextfield* textfield_; | 326 TestTextfield* textfield_; |
340 NativeTextfieldViews* textfield_view_; | |
341 TextfieldViewsModel* model_; | 327 TextfieldViewsModel* model_; |
342 | 328 |
343 // The string from Controller::ContentsChanged callback. | 329 // The string from Controller::ContentsChanged callback. |
344 base::string16 last_contents_; | 330 base::string16 last_contents_; |
345 | 331 |
346 // For testing input method related behaviors. | 332 // For testing input method related behaviors. |
347 MockInputMethod* input_method_; | 333 MockInputMethod* input_method_; |
348 | 334 |
349 // Indicates how many times OnBeforeUserAction() is called. | 335 // Indicates how many times OnBeforeUserAction() is called. |
350 int on_before_user_action_; | 336 int on_before_user_action_; |
351 | 337 |
352 // Indicates how many times OnAfterUserAction() is called. | 338 // Indicates how many times OnAfterUserAction() is called. |
353 int on_after_user_action_; | 339 int on_after_user_action_; |
354 | 340 |
355 private: | 341 private: |
356 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViewsTest); | 342 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); |
357 }; | 343 }; |
358 | 344 |
359 TEST_F(NativeTextfieldViewsTest, ModelChangesTest) { | 345 TEST_F(TextfieldTest, ModelChangesTest) { |
360 InitTextfield(Textfield::STYLE_DEFAULT); | 346 InitTextfield(Textfield::STYLE_DEFAULT); |
361 | 347 |
362 // TextfieldController::ContentsChanged() shouldn't be called when changing | 348 // TextfieldController::ContentsChanged() shouldn't be called when changing |
363 // text programmatically. | 349 // text programmatically. |
364 last_contents_.clear(); | 350 last_contents_.clear(); |
365 textfield_->SetText(ASCIIToUTF16("this is")); | 351 textfield_->SetText(ASCIIToUTF16("this is")); |
366 | 352 |
367 EXPECT_STR_EQ("this is", model_->GetText()); | 353 EXPECT_STR_EQ("this is", model_->text()); |
368 EXPECT_STR_EQ("this is", textfield_->text()); | 354 EXPECT_STR_EQ("this is", textfield_->text()); |
369 EXPECT_TRUE(last_contents_.empty()); | 355 EXPECT_TRUE(last_contents_.empty()); |
370 | 356 |
371 textfield_->AppendText(ASCIIToUTF16(" a test")); | 357 textfield_->AppendText(ASCIIToUTF16(" a test")); |
372 EXPECT_STR_EQ("this is a test", model_->GetText()); | 358 EXPECT_STR_EQ("this is a test", model_->text()); |
373 EXPECT_STR_EQ("this is a test", textfield_->text()); | 359 EXPECT_STR_EQ("this is a test", textfield_->text()); |
374 EXPECT_TRUE(last_contents_.empty()); | 360 EXPECT_TRUE(last_contents_.empty()); |
375 | 361 |
376 EXPECT_EQ(base::string16(), textfield_->GetSelectedText()); | 362 EXPECT_EQ(base::string16(), textfield_->GetSelectedText()); |
377 textfield_->SelectAll(false); | 363 textfield_->SelectAll(false); |
378 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); | 364 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); |
379 EXPECT_TRUE(last_contents_.empty()); | 365 EXPECT_TRUE(last_contents_.empty()); |
380 } | 366 } |
381 | 367 |
382 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCase) { | 368 TEST_F(TextfieldTest, ModelChangesTestLowerCase) { |
383 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE. | 369 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE. |
384 InitTextfield(Textfield::STYLE_LOWERCASE); | 370 InitTextfield(Textfield::STYLE_LOWERCASE); |
385 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 371 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
386 | 372 |
387 last_contents_.clear(); | 373 last_contents_.clear(); |
388 textfield_->SetText(ASCIIToUTF16("THIS IS")); | 374 textfield_->SetText(ASCIIToUTF16("THIS IS")); |
389 EXPECT_EQ(7U, textfield_->GetCursorPosition()); | 375 EXPECT_EQ(7U, textfield_->GetCursorPosition()); |
390 | 376 |
391 EXPECT_STR_EQ("this is", model_->GetText()); | 377 EXPECT_STR_EQ("this is", textfield_->text()); |
392 EXPECT_STR_EQ("THIS IS", textfield_->text()); | |
393 EXPECT_TRUE(last_contents_.empty()); | 378 EXPECT_TRUE(last_contents_.empty()); |
394 | 379 |
395 textfield_->AppendText(ASCIIToUTF16(" A TEST")); | 380 textfield_->AppendText(ASCIIToUTF16(" A TEST")); |
396 EXPECT_EQ(7U, textfield_->GetCursorPosition()); | 381 EXPECT_EQ(7U, textfield_->GetCursorPosition()); |
397 EXPECT_STR_EQ("this is a test", model_->GetText()); | 382 EXPECT_STR_EQ("this is a test", textfield_->text()); |
398 EXPECT_STR_EQ("THIS IS A TEST", textfield_->text()); | |
399 | 383 |
400 EXPECT_TRUE(last_contents_.empty()); | 384 EXPECT_TRUE(last_contents_.empty()); |
401 } | 385 } |
402 | 386 |
403 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseI18n) { | 387 TEST_F(TextfieldTest, ModelChangesTestLowerCaseI18n) { |
404 // Check if lower case conversion works for non-ASCII characters. | 388 // Check if lower case conversion works for non-ASCII characters. |
405 InitTextfield(Textfield::STYLE_LOWERCASE); | 389 InitTextfield(Textfield::STYLE_LOWERCASE); |
406 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 390 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
407 | 391 |
408 last_contents_.clear(); | 392 last_contents_.clear(); |
409 // Zenkaku Japanese "ABCabc" | 393 // Zenkaku Japanese "ABCabc" |
410 textfield_->SetText(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43")); | 394 textfield_->SetText(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43")); |
411 EXPECT_EQ(6U, textfield_->GetCursorPosition()); | 395 EXPECT_EQ(6U, textfield_->GetCursorPosition()); |
412 // Zenkaku Japanese "abcabc" | 396 // Zenkaku Japanese "abcabc" |
413 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"), | 397 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"), |
414 model_->GetText()); | |
415 // Zenkaku Japanese "ABCabc" | |
416 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43"), | |
417 textfield_->text()); | 398 textfield_->text()); |
418 EXPECT_TRUE(last_contents_.empty()); | 399 EXPECT_TRUE(last_contents_.empty()); |
419 | 400 |
420 // Zenkaku Japanese "XYZxyz" | 401 // Zenkaku Japanese "XYZxyz" |
421 textfield_->AppendText(WideToUTF16(L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A")); | 402 textfield_->AppendText(WideToUTF16(L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A")); |
422 EXPECT_EQ(6U, textfield_->GetCursorPosition()); | 403 EXPECT_EQ(6U, textfield_->GetCursorPosition()); |
423 // Zenkaku Japanese "abcabcxyzxyz" | 404 // Zenkaku Japanese "abcabcxyzxyz" |
424 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43" | 405 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43" |
425 L"\xFF58\xFF59\xFF5A\xFF58\xFF59\xFF5A"), | 406 L"\xFF58\xFF59\xFF5A\xFF58\xFF59\xFF5A"), |
426 model_->GetText()); | |
427 // Zenkaku Japanese "ABCabcXYZxyz" | |
428 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43" | |
429 L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A"), | |
430 textfield_->text()); | 407 textfield_->text()); |
431 EXPECT_TRUE(last_contents_.empty()); | 408 EXPECT_TRUE(last_contents_.empty()); |
432 } | 409 } |
433 | 410 |
434 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseWithLocale) { | 411 TEST_F(TextfieldTest, ModelChangesTestLowerCaseWithLocale) { |
435 // Check if lower case conversion honors locale properly. | 412 // Check if lower case conversion honors locale properly. |
436 std::string locale = l10n_util::GetApplicationLocale(""); | 413 std::string locale = l10n_util::GetApplicationLocale(""); |
437 base::i18n::SetICUDefaultLocale("tr"); | 414 base::i18n::SetICUDefaultLocale("tr"); |
438 | 415 |
439 InitTextfield(Textfield::STYLE_LOWERCASE); | 416 InitTextfield(Textfield::STYLE_LOWERCASE); |
440 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 417 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
441 | 418 |
442 last_contents_.clear(); | 419 last_contents_.clear(); |
443 // Turkish 'I' should be converted to dotless 'i' (U+0131). | 420 // Turkish 'I' should be converted to dotless 'i' (U+0131). |
444 textfield_->SetText(WideToUTF16(L"I")); | 421 textfield_->SetText(WideToUTF16(L"I")); |
445 EXPECT_EQ(1U, textfield_->GetCursorPosition()); | 422 EXPECT_EQ(1U, textfield_->GetCursorPosition()); |
446 EXPECT_EQ(WideToUTF16(L"\x0131"), model_->GetText()); | 423 EXPECT_EQ(WideToUTF16(L"\x0131"), textfield_->text()); |
447 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); | |
448 EXPECT_TRUE(last_contents_.empty()); | 424 EXPECT_TRUE(last_contents_.empty()); |
449 | 425 |
450 base::i18n::SetICUDefaultLocale(locale); | 426 base::i18n::SetICUDefaultLocale(locale); |
451 | 427 |
452 // On default (en) locale, 'I' should be converted to 'i'. | 428 // On default (en) locale, 'I' should be converted to 'i'. |
453 textfield_->SetText(WideToUTF16(L"I")); | 429 textfield_->SetText(WideToUTF16(L"I")); |
454 EXPECT_EQ(1U, textfield_->GetCursorPosition()); | 430 EXPECT_EQ(1U, textfield_->GetCursorPosition()); |
455 EXPECT_EQ(WideToUTF16(L"i"), model_->GetText()); | 431 EXPECT_EQ(WideToUTF16(L"i"), textfield_->text()); |
456 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); | |
457 EXPECT_TRUE(last_contents_.empty()); | 432 EXPECT_TRUE(last_contents_.empty()); |
458 } | 433 } |
459 | 434 |
460 TEST_F(NativeTextfieldViewsTest, KeyTest) { | 435 TEST_F(TextfieldTest, KeyTest) { |
461 InitTextfield(Textfield::STYLE_DEFAULT); | 436 InitTextfield(Textfield::STYLE_DEFAULT); |
462 // Event flags: key, alt, shift, ctrl, caps-lock. | 437 // Event flags: key, alt, shift, ctrl, caps-lock. |
463 SendKeyEvent(ui::VKEY_T, false, true, false, false); | 438 SendKeyEvent(ui::VKEY_T, false, true, false, false); |
464 SendKeyEvent(ui::VKEY_E, false, false, false, false); | 439 SendKeyEvent(ui::VKEY_E, false, false, false, false); |
465 SendKeyEvent(ui::VKEY_X, false, true, false, true); | 440 SendKeyEvent(ui::VKEY_X, false, true, false, true); |
466 SendKeyEvent(ui::VKEY_T, false, false, false, true); | 441 SendKeyEvent(ui::VKEY_T, false, false, false, true); |
467 SendKeyEvent(ui::VKEY_1, false, true, false, false); | 442 SendKeyEvent(ui::VKEY_1, false, true, false, false); |
468 SendKeyEvent(ui::VKEY_1, false, false, false, false); | 443 SendKeyEvent(ui::VKEY_1, false, false, false, false); |
469 SendKeyEvent(ui::VKEY_1, false, true, false, true); | 444 SendKeyEvent(ui::VKEY_1, false, true, false, true); |
470 SendKeyEvent(ui::VKEY_1, false, false, false, true); | 445 SendKeyEvent(ui::VKEY_1, false, false, false, true); |
471 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); | 446 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); |
472 } | 447 } |
473 | 448 |
474 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { | 449 TEST_F(TextfieldTest, ControlAndSelectTest) { |
475 // Insert a test string in a textfield. | 450 // Insert a test string in a textfield. |
476 InitTextfield(Textfield::STYLE_DEFAULT); | 451 InitTextfield(Textfield::STYLE_DEFAULT); |
477 textfield_->SetText(ASCIIToUTF16("one two three")); | 452 textfield_->SetText(ASCIIToUTF16("one two three")); |
478 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); | 453 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); |
479 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 454 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
480 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 455 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
481 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 456 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
482 | 457 |
483 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); | 458 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); |
484 | 459 |
(...skipping 14 matching lines...) Expand all Loading... |
499 SendKeyEvent(ui::VKEY_O, true, false); | 474 SendKeyEvent(ui::VKEY_O, true, false); |
500 SendKeyEvent(ui::VKEY_SPACE, false, false); | 475 SendKeyEvent(ui::VKEY_SPACE, false, false); |
501 EXPECT_STR_EQ("ZERO two three", textfield_->text()); | 476 EXPECT_STR_EQ("ZERO two three", textfield_->text()); |
502 | 477 |
503 SendKeyEvent(ui::VKEY_END, true, false); | 478 SendKeyEvent(ui::VKEY_END, true, false); |
504 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); | 479 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); |
505 SendKeyEvent(ui::VKEY_HOME, true, false); | 480 SendKeyEvent(ui::VKEY_HOME, true, false); |
506 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); | 481 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); |
507 } | 482 } |
508 | 483 |
509 TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) { | 484 TEST_F(TextfieldTest, InsertionDeletionTest) { |
510 // Insert a test string in a textfield. | 485 // Insert a test string in a textfield. |
511 InitTextfield(Textfield::STYLE_DEFAULT); | 486 InitTextfield(Textfield::STYLE_DEFAULT); |
512 for (size_t i = 0; i < 10; i++) | 487 for (size_t i = 0; i < 10; i++) |
513 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); | 488 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); |
514 EXPECT_STR_EQ("abcdefghij", textfield_->text()); | 489 EXPECT_STR_EQ("abcdefghij", textfield_->text()); |
515 | 490 |
516 // Test the delete and backspace keys. | 491 // Test the delete and backspace keys. |
517 textfield_->SelectRange(gfx::Range(5)); | 492 textfield_->SelectRange(gfx::Range(5)); |
518 for (int i = 0; i < 3; i++) | 493 for (int i = 0; i < 3; i++) |
519 SendKeyEvent(ui::VKEY_BACK); | 494 SendKeyEvent(ui::VKEY_BACK); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // Delete text following the cursor in chromeos, do nothing in windows. | 526 // Delete text following the cursor in chromeos, do nothing in windows. |
552 SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); | 527 SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); |
553 SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); | 528 SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); |
554 #if defined(OS_WIN) | 529 #if defined(OS_WIN) |
555 EXPECT_STR_EQ(" two three four", textfield_->text()); | 530 EXPECT_STR_EQ(" two three four", textfield_->text()); |
556 #else | 531 #else |
557 EXPECT_STR_EQ(" two", textfield_->text()); | 532 EXPECT_STR_EQ(" two", textfield_->text()); |
558 #endif | 533 #endif |
559 } | 534 } |
560 | 535 |
561 TEST_F(NativeTextfieldViewsTest, PasswordTest) { | 536 TEST_F(TextfieldTest, PasswordTest) { |
562 InitTextfield(Textfield::STYLE_OBSCURED); | 537 InitTextfield(Textfield::STYLE_OBSCURED); |
563 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 538 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
564 EXPECT_TRUE(textfield_->enabled()); | 539 EXPECT_TRUE(textfield_->enabled()); |
565 EXPECT_TRUE(textfield_->focusable()); | 540 EXPECT_TRUE(textfield_->focusable()); |
566 | 541 |
567 last_contents_.clear(); | 542 last_contents_.clear(); |
568 textfield_->SetText(ASCIIToUTF16("password")); | 543 textfield_->SetText(ASCIIToUTF16("password")); |
569 // Ensure text() and the callback returns the actual text instead of "*". | 544 // Ensure text() and the callback returns the actual text instead of "*". |
570 EXPECT_STR_EQ("password", textfield_->text()); | 545 EXPECT_STR_EQ("password", textfield_->text()); |
571 EXPECT_TRUE(last_contents_.empty()); | 546 EXPECT_TRUE(last_contents_.empty()); |
572 model_->SelectAll(false); | 547 model_->SelectAll(false); |
573 SetClipboardText("foo"); | 548 SetClipboardText("foo"); |
574 | 549 |
575 // Cut and copy should be disabled. | 550 // Cut and copy should be disabled. |
576 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); | 551 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
577 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); | 552 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
578 SendKeyEvent(ui::VKEY_X, false, true); | 553 SendKeyEvent(ui::VKEY_X, false, true); |
579 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); | 554 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
580 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); | 555 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
581 SendKeyEvent(ui::VKEY_C, false, true); | 556 SendKeyEvent(ui::VKEY_C, false, true); |
582 SendKeyEvent(ui::VKEY_INSERT, false, true); | 557 SendKeyEvent(ui::VKEY_INSERT, false, true); |
583 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); | 558 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); |
584 EXPECT_STR_EQ("password", textfield_->text()); | 559 EXPECT_STR_EQ("password", textfield_->text()); |
585 // [Shift]+[Delete] should just delete without copying text to the clipboard. | 560 // [Shift]+[Delete] should just delete without copying text to the clipboard. |
586 textfield_->SelectAll(false); | 561 textfield_->SelectAll(false); |
587 SendKeyEvent(ui::VKEY_DELETE, true, false); | 562 SendKeyEvent(ui::VKEY_DELETE, true, false); |
588 | 563 |
589 // Paste should work normally. | 564 // Paste should work normally. |
590 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); | 565 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
591 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); | 566 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
592 SendKeyEvent(ui::VKEY_V, false, true); | 567 SendKeyEvent(ui::VKEY_V, false, true); |
593 SendKeyEvent(ui::VKEY_INSERT, true, false); | 568 SendKeyEvent(ui::VKEY_INSERT, true, false); |
594 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); | 569 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); |
595 EXPECT_STR_EQ("foofoofoo", textfield_->text()); | 570 EXPECT_STR_EQ("foofoofoo", textfield_->text()); |
596 } | 571 } |
597 | 572 |
598 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) { | 573 TEST_F(TextfieldTest, InputTypeSetsObscured) { |
599 InitTextfield(Textfield::STYLE_DEFAULT); | 574 InitTextfield(Textfield::STYLE_DEFAULT); |
600 | 575 |
601 // Defaults to TEXT | 576 // Defaults to TEXT |
602 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 577 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
603 | 578 |
604 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. | 579 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. |
605 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 580 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
606 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 581 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
607 EXPECT_TRUE(textfield_->IsObscured()); | 582 EXPECT_TRUE(textfield_->IsObscured()); |
608 } | 583 } |
609 | 584 |
610 TEST_F(NativeTextfieldViewsTest, ObscuredSetsInputType) { | 585 TEST_F(TextfieldTest, ObscuredSetsInputType) { |
611 InitTextfield(Textfield::STYLE_DEFAULT); | 586 InitTextfield(Textfield::STYLE_DEFAULT); |
612 | 587 |
613 // Defaults to TEXT | 588 // Defaults to TEXT |
614 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 589 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
615 | 590 |
616 textfield_->SetObscured(true); | 591 textfield_->SetObscured(true); |
617 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 592 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
618 | 593 |
619 textfield_->SetObscured(false); | 594 textfield_->SetObscured(false); |
620 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 595 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
621 } | 596 } |
622 | 597 |
623 TEST_F(NativeTextfieldViewsTest, TextInputType) { | 598 TEST_F(TextfieldTest, TextInputType) { |
624 InitTextfield(Textfield::STYLE_DEFAULT); | 599 InitTextfield(Textfield::STYLE_DEFAULT); |
625 | 600 |
626 // Defaults to TEXT | 601 // Defaults to TEXT |
627 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 602 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
628 | 603 |
629 // And can be set. | 604 // And can be set. |
630 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 605 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
631 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); | 606 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); |
632 | 607 |
633 // Readonly textfields have type NONE | 608 // Readonly textfields have type NONE |
634 textfield_->SetReadOnly(true); | 609 textfield_->SetReadOnly(true); |
635 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 610 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); |
636 | 611 |
637 textfield_->SetReadOnly(false); | 612 textfield_->SetReadOnly(false); |
638 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); | 613 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); |
639 | 614 |
640 // As do disabled textfields | 615 // As do disabled textfields |
641 textfield_->SetEnabled(false); | 616 textfield_->SetEnabled(false); |
642 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 617 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); |
643 } | 618 } |
644 | 619 |
645 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) { | 620 TEST_F(TextfieldTest, OnKeyPressReturnValueTest) { |
646 InitTextfield(Textfield::STYLE_DEFAULT); | 621 InitTextfield(Textfield::STYLE_DEFAULT); |
647 | 622 |
648 // Character keys will be handled by input method. | 623 // Character keys will be handled by input method. |
649 SendKeyEvent(ui::VKEY_A); | 624 SendKeyEvent(ui::VKEY_A); |
650 EXPECT_TRUE(textfield_->key_received()); | 625 EXPECT_TRUE(textfield_->key_received()); |
651 EXPECT_FALSE(textfield_->key_handled()); | 626 EXPECT_FALSE(textfield_->key_handled()); |
652 textfield_->clear(); | 627 textfield_->clear(); |
653 | 628 |
654 // Home will be handled. | 629 // Home will be handled. |
655 SendKeyEvent(ui::VKEY_HOME); | 630 SendKeyEvent(ui::VKEY_HOME); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 EXPECT_TRUE(textfield_->key_handled()); | 673 EXPECT_TRUE(textfield_->key_handled()); |
699 textfield_->clear(); | 674 textfield_->clear(); |
700 | 675 |
701 // Now left key should not be handled. | 676 // Now left key should not be handled. |
702 SendKeyEvent(ui::VKEY_LEFT); | 677 SendKeyEvent(ui::VKEY_LEFT); |
703 EXPECT_TRUE(textfield_->key_received()); | 678 EXPECT_TRUE(textfield_->key_received()); |
704 EXPECT_FALSE(textfield_->key_handled()); | 679 EXPECT_FALSE(textfield_->key_handled()); |
705 textfield_->clear(); | 680 textfield_->clear(); |
706 } | 681 } |
707 | 682 |
708 TEST_F(NativeTextfieldViewsTest, CursorMovement) { | 683 TEST_F(TextfieldTest, CursorMovement) { |
709 InitTextfield(Textfield::STYLE_DEFAULT); | 684 InitTextfield(Textfield::STYLE_DEFAULT); |
710 | 685 |
711 // Test with trailing whitespace. | 686 // Test with trailing whitespace. |
712 textfield_->SetText(ASCIIToUTF16("one two hre ")); | 687 textfield_->SetText(ASCIIToUTF16("one two hre ")); |
713 | 688 |
714 // Send the cursor at the end. | 689 // Send the cursor at the end. |
715 SendKeyEvent(ui::VKEY_END); | 690 SendKeyEvent(ui::VKEY_END); |
716 | 691 |
717 // Ctrl+Left should move the cursor just before the last word. | 692 // Ctrl+Left should move the cursor just before the last word. |
718 SendKeyEvent(ui::VKEY_LEFT, false, true); | 693 SendKeyEvent(ui::VKEY_LEFT, false, true); |
(...skipping 29 matching lines...) Expand all Loading... |
748 | 723 |
749 // Ctrl+Left to move the cursor to the beginning of the first word. | 724 // Ctrl+Left to move the cursor to the beginning of the first word. |
750 SendKeyEvent(ui::VKEY_LEFT, false, true); | 725 SendKeyEvent(ui::VKEY_LEFT, false, true); |
751 // Ctrl+Left again should move the cursor back to the very beginning. | 726 // Ctrl+Left again should move the cursor back to the very beginning. |
752 SendKeyEvent(ui::VKEY_LEFT, false, true); | 727 SendKeyEvent(ui::VKEY_LEFT, false, true); |
753 SendKeyEvent(ui::VKEY_DELETE); | 728 SendKeyEvent(ui::VKEY_DELETE); |
754 EXPECT_STR_EQ("one two", textfield_->text()); | 729 EXPECT_STR_EQ("one two", textfield_->text()); |
755 EXPECT_STR_EQ("one two", last_contents_); | 730 EXPECT_STR_EQ("one two", last_contents_); |
756 } | 731 } |
757 | 732 |
758 TEST_F(NativeTextfieldViewsTest, FocusTraversalTest) { | 733 TEST_F(TextfieldTest, FocusTraversalTest) { |
759 InitTextfields(Textfield::STYLE_DEFAULT, 3); | 734 InitTextfields(Textfield::STYLE_DEFAULT, 3); |
760 textfield_->RequestFocus(); | 735 textfield_->RequestFocus(); |
761 | 736 |
762 EXPECT_EQ(1, GetFocusedView()->id()); | 737 EXPECT_EQ(1, GetFocusedView()->id()); |
763 widget_->GetFocusManager()->AdvanceFocus(false); | 738 widget_->GetFocusManager()->AdvanceFocus(false); |
764 EXPECT_EQ(2, GetFocusedView()->id()); | 739 EXPECT_EQ(2, GetFocusedView()->id()); |
765 widget_->GetFocusManager()->AdvanceFocus(false); | 740 widget_->GetFocusManager()->AdvanceFocus(false); |
766 EXPECT_EQ(3, GetFocusedView()->id()); | 741 EXPECT_EQ(3, GetFocusedView()->id()); |
767 // Cycle back to the first textfield. | 742 // Cycle back to the first textfield. |
768 widget_->GetFocusManager()->AdvanceFocus(false); | 743 widget_->GetFocusManager()->AdvanceFocus(false); |
(...skipping 11 matching lines...) Expand all Loading... |
780 | 755 |
781 // Request focus should still work. | 756 // Request focus should still work. |
782 textfield_->RequestFocus(); | 757 textfield_->RequestFocus(); |
783 EXPECT_EQ(1, GetFocusedView()->id()); | 758 EXPECT_EQ(1, GetFocusedView()->id()); |
784 | 759 |
785 // Test if clicking on textfield view sets the focus to textfield_. | 760 // Test if clicking on textfield view sets the focus to textfield_. |
786 widget_->GetFocusManager()->AdvanceFocus(true); | 761 widget_->GetFocusManager()->AdvanceFocus(true); |
787 EXPECT_EQ(3, GetFocusedView()->id()); | 762 EXPECT_EQ(3, GetFocusedView()->id()); |
788 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 763 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
789 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 764 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
790 textfield_view_->OnMousePressed(click); | 765 textfield_->OnMousePressed(click); |
791 EXPECT_EQ(1, GetFocusedView()->id()); | 766 EXPECT_EQ(1, GetFocusedView()->id()); |
792 } | 767 } |
793 | 768 |
794 TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) { | 769 TEST_F(TextfieldTest, ContextMenuDisplayTest) { |
795 InitTextfield(Textfield::STYLE_DEFAULT); | 770 InitTextfield(Textfield::STYLE_DEFAULT); |
796 EXPECT_TRUE(textfield_->context_menu_controller()); | 771 EXPECT_TRUE(textfield_->context_menu_controller()); |
797 textfield_->SetText(ASCIIToUTF16("hello world")); | 772 textfield_->SetText(ASCIIToUTF16("hello world")); |
798 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); | 773 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); |
799 textfield_view_->ClearEditHistory(); | 774 textfield_->ClearEditHistory(); |
800 EXPECT_TRUE(GetContextMenuModel()); | 775 EXPECT_TRUE(GetContextMenuModel()); |
801 VerifyTextfieldContextMenuContents(false, false, GetContextMenuModel()); | 776 VerifyTextfieldContextMenuContents(false, false, GetContextMenuModel()); |
802 | 777 |
803 textfield_->SelectAll(false); | 778 textfield_->SelectAll(false); |
804 VerifyTextfieldContextMenuContents(true, false, GetContextMenuModel()); | 779 VerifyTextfieldContextMenuContents(true, false, GetContextMenuModel()); |
805 | 780 |
806 SendKeyEvent(ui::VKEY_T); | 781 SendKeyEvent(ui::VKEY_T); |
807 VerifyTextfieldContextMenuContents(false, true, GetContextMenuModel()); | 782 VerifyTextfieldContextMenuContents(false, true, GetContextMenuModel()); |
808 | 783 |
809 textfield_->SelectAll(false); | 784 textfield_->SelectAll(false); |
810 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); | 785 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); |
811 | 786 |
812 // Exercise the "paste enabled?" check in the verifier. | 787 // Exercise the "paste enabled?" check in the verifier. |
813 SetClipboardText("Test"); | 788 SetClipboardText("Test"); |
814 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); | 789 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); |
815 } | 790 } |
816 | 791 |
817 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) { | 792 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { |
818 InitTextfield(Textfield::STYLE_DEFAULT); | 793 InitTextfield(Textfield::STYLE_DEFAULT); |
819 textfield_->SetText(ASCIIToUTF16("hello world")); | 794 textfield_->SetText(ASCIIToUTF16("hello world")); |
820 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 795 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
821 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 796 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
822 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 797 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
823 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 798 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
824 ui::MouseEvent double_click( | 799 ui::MouseEvent double_click( |
825 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 800 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
826 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, | 801 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, |
827 ui::EF_LEFT_MOUSE_BUTTON); | 802 ui::EF_LEFT_MOUSE_BUTTON); |
828 | 803 |
829 // Test for double click. | 804 // Test for double click. |
830 textfield_view_->OnMousePressed(click); | 805 textfield_->OnMousePressed(click); |
831 textfield_view_->OnMouseReleased(release); | 806 textfield_->OnMouseReleased(release); |
832 EXPECT_TRUE(textfield_->GetSelectedText().empty()); | 807 EXPECT_TRUE(textfield_->GetSelectedText().empty()); |
833 textfield_view_->OnMousePressed(double_click); | 808 textfield_->OnMousePressed(double_click); |
834 textfield_view_->OnMouseReleased(release); | 809 textfield_->OnMouseReleased(release); |
835 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 810 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
836 | 811 |
837 // Test for triple click. | 812 // Test for triple click. |
838 textfield_view_->OnMousePressed(click); | 813 textfield_->OnMousePressed(click); |
839 textfield_view_->OnMouseReleased(release); | 814 textfield_->OnMouseReleased(release); |
840 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); | 815 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); |
841 | 816 |
842 // Another click should reset back to double click. | 817 // Another click should reset back to double click. |
843 textfield_view_->OnMousePressed(click); | 818 textfield_->OnMousePressed(click); |
844 textfield_view_->OnMouseReleased(release); | 819 textfield_->OnMouseReleased(release); |
845 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 820 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
846 } | 821 } |
847 | 822 |
848 TEST_F(NativeTextfieldViewsTest, DragToSelect) { | 823 TEST_F(TextfieldTest, DragToSelect) { |
849 InitTextfield(Textfield::STYLE_DEFAULT); | 824 InitTextfield(Textfield::STYLE_DEFAULT); |
850 textfield_->SetText(ASCIIToUTF16("hello world")); | 825 textfield_->SetText(ASCIIToUTF16("hello world")); |
851 const int kStart = GetCursorPositionX(5); | 826 const int kStart = GetCursorPositionX(5); |
852 const int kEnd = 500; | 827 const int kEnd = 500; |
853 gfx::Point start_point(kStart, 0); | 828 gfx::Point start_point(kStart, 0); |
854 gfx::Point end_point(kEnd, 0); | 829 gfx::Point end_point(kEnd, 0); |
855 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, | 830 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, |
856 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 831 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
857 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, | 832 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, |
858 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 833 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
859 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), | 834 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), |
860 ui::EF_LEFT_MOUSE_BUTTON, 0); | 835 ui::EF_LEFT_MOUSE_BUTTON, 0); |
861 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point, | 836 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point, |
862 ui::EF_LEFT_MOUSE_BUTTON, 0); | 837 ui::EF_LEFT_MOUSE_BUTTON, 0); |
863 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point, | 838 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point, |
864 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 839 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
865 textfield_view_->OnMousePressed(click_a); | 840 textfield_->OnMousePressed(click_a); |
866 EXPECT_TRUE(textfield_->GetSelectedText().empty()); | 841 EXPECT_TRUE(textfield_->GetSelectedText().empty()); |
867 // Check that dragging left selects the beginning of the string. | 842 // Check that dragging left selects the beginning of the string. |
868 textfield_view_->OnMouseDragged(drag_left); | 843 textfield_->OnMouseDragged(drag_left); |
869 base::string16 text_left = textfield_->GetSelectedText(); | 844 base::string16 text_left = textfield_->GetSelectedText(); |
870 EXPECT_STR_EQ("hello", text_left); | 845 EXPECT_STR_EQ("hello", text_left); |
871 // Check that dragging right selects the rest of the string. | 846 // Check that dragging right selects the rest of the string. |
872 textfield_view_->OnMouseDragged(drag_right); | 847 textfield_->OnMouseDragged(drag_right); |
873 base::string16 text_right = textfield_->GetSelectedText(); | 848 base::string16 text_right = textfield_->GetSelectedText(); |
874 EXPECT_STR_EQ(" world", text_right); | 849 EXPECT_STR_EQ(" world", text_right); |
875 // Check that releasing in the same location does not alter the selection. | 850 // Check that releasing in the same location does not alter the selection. |
876 textfield_view_->OnMouseReleased(release); | 851 textfield_->OnMouseReleased(release); |
877 EXPECT_EQ(text_right, textfield_->GetSelectedText()); | 852 EXPECT_EQ(text_right, textfield_->GetSelectedText()); |
878 // Check that dragging from beyond the text length works too. | 853 // Check that dragging from beyond the text length works too. |
879 textfield_view_->OnMousePressed(click_b); | 854 textfield_->OnMousePressed(click_b); |
880 textfield_view_->OnMouseDragged(drag_left); | 855 textfield_->OnMouseDragged(drag_left); |
881 textfield_view_->OnMouseReleased(release); | 856 textfield_->OnMouseReleased(release); |
882 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); | 857 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); |
883 } | 858 } |
884 | 859 |
885 #if defined(OS_WIN) | 860 #if defined(OS_WIN) |
886 TEST_F(NativeTextfieldViewsTest, DragAndDrop_AcceptDrop) { | 861 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { |
887 InitTextfield(Textfield::STYLE_DEFAULT); | 862 InitTextfield(Textfield::STYLE_DEFAULT); |
888 textfield_->SetText(ASCIIToUTF16("hello world")); | 863 textfield_->SetText(ASCIIToUTF16("hello world")); |
889 | 864 |
890 ui::OSExchangeData data; | 865 ui::OSExchangeData data; |
891 base::string16 string(ASCIIToUTF16("string ")); | 866 base::string16 string(ASCIIToUTF16("string ")); |
892 data.SetString(string); | 867 data.SetString(string); |
893 int formats = 0; | 868 int formats = 0; |
894 std::set<OSExchangeData::CustomFormat> custom_formats; | 869 std::set<OSExchangeData::CustomFormat> custom_formats; |
895 | 870 |
896 // Ensure that disabled textfields do not accept drops. | 871 // Ensure that disabled textfields do not accept drops. |
897 textfield_->SetEnabled(false); | 872 textfield_->SetEnabled(false); |
898 EXPECT_FALSE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 873 EXPECT_FALSE(textfield_->GetDropFormats(&formats, &custom_formats)); |
899 EXPECT_EQ(0, formats); | 874 EXPECT_EQ(0, formats); |
900 EXPECT_TRUE(custom_formats.empty()); | 875 EXPECT_TRUE(custom_formats.empty()); |
901 EXPECT_FALSE(textfield_view_->CanDrop(data)); | 876 EXPECT_FALSE(textfield_->CanDrop(data)); |
902 textfield_->SetEnabled(true); | 877 textfield_->SetEnabled(true); |
903 | 878 |
904 // Ensure that read-only textfields do not accept drops. | 879 // Ensure that read-only textfields do not accept drops. |
905 textfield_->SetReadOnly(true); | 880 textfield_->SetReadOnly(true); |
906 EXPECT_FALSE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 881 EXPECT_FALSE(textfield_->GetDropFormats(&formats, &custom_formats)); |
907 EXPECT_EQ(0, formats); | 882 EXPECT_EQ(0, formats); |
908 EXPECT_TRUE(custom_formats.empty()); | 883 EXPECT_TRUE(custom_formats.empty()); |
909 EXPECT_FALSE(textfield_view_->CanDrop(data)); | 884 EXPECT_FALSE(textfield_->CanDrop(data)); |
910 textfield_->SetReadOnly(false); | 885 textfield_->SetReadOnly(false); |
911 | 886 |
912 // Ensure that enabled and editable textfields do accept drops. | 887 // Ensure that enabled and editable textfields do accept drops. |
913 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 888 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); |
914 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 889 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
915 EXPECT_TRUE(custom_formats.empty()); | 890 EXPECT_TRUE(custom_formats.empty()); |
916 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 891 EXPECT_TRUE(textfield_->CanDrop(data)); |
917 gfx::Point drop_point(GetCursorPositionX(6), 0); | 892 gfx::Point drop_point(GetCursorPositionX(6), 0); |
918 ui::DropTargetEvent drop(data, drop_point, drop_point, | 893 ui::DropTargetEvent drop(data, drop_point, drop_point, |
919 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE); | 894 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE); |
920 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE, | 895 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE, |
921 textfield_view_->OnDragUpdated(drop)); | 896 textfield_->OnDragUpdated(drop)); |
922 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, textfield_view_->OnPerformDrop(drop)); | 897 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, textfield_->OnPerformDrop(drop)); |
923 EXPECT_STR_EQ("hello string world", textfield_->text()); | 898 EXPECT_STR_EQ("hello string world", textfield_->text()); |
924 | 899 |
925 // Ensure that textfields do not accept non-OSExchangeData::STRING types. | 900 // Ensure that textfields do not accept non-OSExchangeData::STRING types. |
926 ui::OSExchangeData bad_data; | 901 ui::OSExchangeData bad_data; |
927 bad_data.SetFilename(base::FilePath(FILE_PATH_LITERAL("x"))); | 902 bad_data.SetFilename(base::FilePath(FILE_PATH_LITERAL("x"))); |
928 #if defined(OS_WIN) | 903 #if defined(OS_WIN) |
929 ui::OSExchangeData::CustomFormat fmt = ui::Clipboard::GetBitmapFormatType(); | 904 ui::OSExchangeData::CustomFormat fmt = ui::Clipboard::GetBitmapFormatType(); |
930 bad_data.SetPickledData(fmt, Pickle()); | 905 bad_data.SetPickledData(fmt, Pickle()); |
931 bad_data.SetFileContents(base::FilePath(L"x"), "x"); | 906 bad_data.SetFileContents(base::FilePath(L"x"), "x"); |
932 bad_data.SetHtml(base::string16(ASCIIToUTF16("x")), GURL("x.org")); | 907 bad_data.SetHtml(base::string16(ASCIIToUTF16("x")), GURL("x.org")); |
933 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL); | 908 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL); |
934 bad_data.SetDownloadFileInfo(download); | 909 bad_data.SetDownloadFileInfo(download); |
935 #endif | 910 #endif |
936 EXPECT_FALSE(textfield_view_->CanDrop(bad_data)); | 911 EXPECT_FALSE(textfield_->CanDrop(bad_data)); |
937 } | 912 } |
938 #endif | 913 #endif |
939 | 914 |
940 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) { | 915 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { |
941 InitTextfield(Textfield::STYLE_DEFAULT); | 916 InitTextfield(Textfield::STYLE_DEFAULT); |
942 textfield_->SetText(ASCIIToUTF16("hello string world")); | 917 textfield_->SetText(ASCIIToUTF16("hello string world")); |
943 | 918 |
944 // Ensure the textfield will provide selected text for drag data. | 919 // Ensure the textfield will provide selected text for drag data. |
945 base::string16 string; | 920 base::string16 string; |
946 ui::OSExchangeData data; | 921 ui::OSExchangeData data; |
947 const gfx::Range kStringRange(6, 12); | 922 const gfx::Range kStringRange(6, 12); |
948 textfield_->SelectRange(kStringRange); | 923 textfield_->SelectRange(kStringRange); |
949 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 924 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
950 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data); | 925 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); |
951 EXPECT_TRUE(data.GetString(&string)); | 926 EXPECT_TRUE(data.GetString(&string)); |
952 EXPECT_EQ(textfield_->GetSelectedText(), string); | 927 EXPECT_EQ(textfield_->GetSelectedText(), string); |
953 | 928 |
954 // Ensure that disabled textfields do not support drag operations. | 929 // Ensure that disabled textfields do not support drag operations. |
955 textfield_->SetEnabled(false); | 930 textfield_->SetEnabled(false); |
956 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 931 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
957 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 932 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
958 textfield_->SetEnabled(true); | 933 textfield_->SetEnabled(true); |
959 // Ensure that textfields without selections do not support drag operations. | 934 // Ensure that textfields without selections do not support drag operations. |
960 textfield_->ClearSelection(); | 935 textfield_->ClearSelection(); |
961 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 936 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
962 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 937 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
963 textfield_->SelectRange(kStringRange); | 938 textfield_->SelectRange(kStringRange); |
964 // Ensure that password textfields do not support drag operations. | 939 // Ensure that password textfields do not support drag operations. |
965 textfield_->SetObscured(true); | 940 textfield_->SetObscured(true); |
966 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 941 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
967 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 942 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
968 textfield_->SetObscured(false); | 943 textfield_->SetObscured(false); |
969 // Ensure that textfields only initiate drag operations inside the selection. | 944 // Ensure that textfields only initiate drag operations inside the selection. |
970 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, | 945 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, |
971 ui::EF_LEFT_MOUSE_BUTTON, | 946 ui::EF_LEFT_MOUSE_BUTTON, |
972 ui::EF_LEFT_MOUSE_BUTTON); | 947 ui::EF_LEFT_MOUSE_BUTTON); |
973 textfield_view_->OnMousePressed(press_event); | 948 textfield_->OnMousePressed(press_event); |
974 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 949 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
975 textfield_view_->GetDragOperationsForView(NULL, gfx::Point())); | 950 textfield_->GetDragOperationsForView(NULL, gfx::Point())); |
976 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(), | 951 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(), |
977 gfx::Point())); | 952 gfx::Point())); |
978 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, | 953 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, |
979 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 954 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
980 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint, | 955 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, |
981 gfx::Point())); | 956 gfx::Point())); |
982 // Ensure that textfields support local moves. | 957 // Ensure that textfields support local moves. |
983 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 958 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
984 textfield_view_->GetDragOperationsForView(textfield_view_, kStringPoint)); | 959 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); |
985 } | 960 } |
986 | 961 |
987 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheRight) { | 962 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { |
988 InitTextfield(Textfield::STYLE_DEFAULT); | 963 InitTextfield(Textfield::STYLE_DEFAULT); |
989 textfield_->SetText(ASCIIToUTF16("hello world")); | 964 textfield_->SetText(ASCIIToUTF16("hello world")); |
990 | 965 |
991 base::string16 string; | 966 base::string16 string; |
992 ui::OSExchangeData data; | 967 ui::OSExchangeData data; |
993 int formats = 0; | 968 int formats = 0; |
994 int operations = 0; | 969 int operations = 0; |
995 std::set<OSExchangeData::CustomFormat> custom_formats; | 970 std::set<OSExchangeData::CustomFormat> custom_formats; |
996 | 971 |
997 // Start dragging "ello". | 972 // Start dragging "ello". |
998 textfield_->SelectRange(gfx::Range(1, 5)); | 973 textfield_->SelectRange(gfx::Range(1, 5)); |
999 gfx::Point point(GetCursorPositionX(3), 0); | 974 gfx::Point point(GetCursorPositionX(3), 0); |
1000 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, | 975 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, |
1001 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 976 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
1002 textfield_view_->OnMousePressed(click_a); | 977 textfield_->OnMousePressed(click_a); |
1003 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, | 978 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), |
1004 click_a.location(), gfx::Point())); | 979 gfx::Point())); |
1005 operations = textfield_view_->GetDragOperationsForView(textfield_view_, | 980 operations = textfield_->GetDragOperationsForView(textfield_, |
1006 click_a.location()); | 981 click_a.location()); |
1007 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 982 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
1008 operations); | 983 operations); |
1009 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 984 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); |
1010 EXPECT_TRUE(data.GetString(&string)); | 985 EXPECT_TRUE(data.GetString(&string)); |
1011 EXPECT_EQ(textfield_->GetSelectedText(), string); | 986 EXPECT_EQ(textfield_->GetSelectedText(), string); |
1012 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 987 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); |
1013 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 988 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
1014 EXPECT_TRUE(custom_formats.empty()); | 989 EXPECT_TRUE(custom_formats.empty()); |
1015 | 990 |
1016 // Drop "ello" after "w". | 991 // Drop "ello" after "w". |
1017 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); | 992 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); |
1018 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 993 EXPECT_TRUE(textfield_->CanDrop(data)); |
1019 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); | 994 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); |
1020 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | 995 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); |
1021 textfield_view_->OnDragUpdated(drop_a)); | 996 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); |
1022 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | |
1023 textfield_view_->OnPerformDrop(drop_a)); | |
1024 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 997 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
1025 textfield_view_->OnDragDone(); | 998 textfield_->OnDragDone(); |
1026 | 999 |
1027 // Undo/Redo the drag&drop change. | 1000 // Undo/Redo the drag&drop change. |
1028 SendKeyEvent(ui::VKEY_Z, false, true); | 1001 SendKeyEvent(ui::VKEY_Z, false, true); |
1029 EXPECT_STR_EQ("hello world", textfield_->text()); | 1002 EXPECT_STR_EQ("hello world", textfield_->text()); |
1030 SendKeyEvent(ui::VKEY_Z, false, true); | 1003 SendKeyEvent(ui::VKEY_Z, false, true); |
1031 EXPECT_STR_EQ("", textfield_->text()); | 1004 EXPECT_STR_EQ("", textfield_->text()); |
1032 SendKeyEvent(ui::VKEY_Z, false, true); | 1005 SendKeyEvent(ui::VKEY_Z, false, true); |
1033 EXPECT_STR_EQ("", textfield_->text()); | 1006 EXPECT_STR_EQ("", textfield_->text()); |
1034 SendKeyEvent(ui::VKEY_Y, false, true); | 1007 SendKeyEvent(ui::VKEY_Y, false, true); |
1035 EXPECT_STR_EQ("hello world", textfield_->text()); | 1008 EXPECT_STR_EQ("hello world", textfield_->text()); |
1036 SendKeyEvent(ui::VKEY_Y, false, true); | 1009 SendKeyEvent(ui::VKEY_Y, false, true); |
1037 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 1010 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
1038 SendKeyEvent(ui::VKEY_Y, false, true); | 1011 SendKeyEvent(ui::VKEY_Y, false, true); |
1039 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 1012 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
1040 } | 1013 } |
1041 | 1014 |
1042 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheLeft) { | 1015 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { |
1043 InitTextfield(Textfield::STYLE_DEFAULT); | 1016 InitTextfield(Textfield::STYLE_DEFAULT); |
1044 textfield_->SetText(ASCIIToUTF16("hello world")); | 1017 textfield_->SetText(ASCIIToUTF16("hello world")); |
1045 | 1018 |
1046 base::string16 string; | 1019 base::string16 string; |
1047 ui::OSExchangeData data; | 1020 ui::OSExchangeData data; |
1048 int formats = 0; | 1021 int formats = 0; |
1049 int operations = 0; | 1022 int operations = 0; |
1050 std::set<OSExchangeData::CustomFormat> custom_formats; | 1023 std::set<OSExchangeData::CustomFormat> custom_formats; |
1051 | 1024 |
1052 // Start dragging " worl". | 1025 // Start dragging " worl". |
1053 textfield_->SelectRange(gfx::Range(5, 10)); | 1026 textfield_->SelectRange(gfx::Range(5, 10)); |
1054 gfx::Point point(GetCursorPositionX(7), 0); | 1027 gfx::Point point(GetCursorPositionX(7), 0); |
1055 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, | 1028 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, |
1056 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1029 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
1057 textfield_view_->OnMousePressed(click_a); | 1030 textfield_->OnMousePressed(click_a); |
1058 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, | 1031 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), |
1059 click_a.location(), gfx::Point())); | 1032 gfx::Point())); |
1060 operations = textfield_view_->GetDragOperationsForView(textfield_view_, | 1033 operations = textfield_->GetDragOperationsForView(textfield_, |
1061 click_a.location()); | 1034 click_a.location()); |
1062 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 1035 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
1063 operations); | 1036 operations); |
1064 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 1037 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); |
1065 EXPECT_TRUE(data.GetString(&string)); | 1038 EXPECT_TRUE(data.GetString(&string)); |
1066 EXPECT_EQ(textfield_->GetSelectedText(), string); | 1039 EXPECT_EQ(textfield_->GetSelectedText(), string); |
1067 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 1040 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); |
1068 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 1041 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
1069 EXPECT_TRUE(custom_formats.empty()); | 1042 EXPECT_TRUE(custom_formats.empty()); |
1070 | 1043 |
1071 // Drop " worl" after "h". | 1044 // Drop " worl" after "h". |
1072 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 1045 EXPECT_TRUE(textfield_->CanDrop(data)); |
1073 gfx::Point drop_point(GetCursorPositionX(1), 0); | 1046 gfx::Point drop_point(GetCursorPositionX(1), 0); |
1074 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); | 1047 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); |
1075 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | 1048 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); |
1076 textfield_view_->OnDragUpdated(drop_a)); | 1049 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); |
1077 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | |
1078 textfield_view_->OnPerformDrop(drop_a)); | |
1079 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1050 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
1080 textfield_view_->OnDragDone(); | 1051 textfield_->OnDragDone(); |
1081 | 1052 |
1082 // Undo/Redo the drag&drop change. | 1053 // Undo/Redo the drag&drop change. |
1083 SendKeyEvent(ui::VKEY_Z, false, true); | 1054 SendKeyEvent(ui::VKEY_Z, false, true); |
1084 EXPECT_STR_EQ("hello world", textfield_->text()); | 1055 EXPECT_STR_EQ("hello world", textfield_->text()); |
1085 SendKeyEvent(ui::VKEY_Z, false, true); | 1056 SendKeyEvent(ui::VKEY_Z, false, true); |
1086 EXPECT_STR_EQ("", textfield_->text()); | 1057 EXPECT_STR_EQ("", textfield_->text()); |
1087 SendKeyEvent(ui::VKEY_Z, false, true); | 1058 SendKeyEvent(ui::VKEY_Z, false, true); |
1088 EXPECT_STR_EQ("", textfield_->text()); | 1059 EXPECT_STR_EQ("", textfield_->text()); |
1089 SendKeyEvent(ui::VKEY_Y, false, true); | 1060 SendKeyEvent(ui::VKEY_Y, false, true); |
1090 EXPECT_STR_EQ("hello world", textfield_->text()); | 1061 EXPECT_STR_EQ("hello world", textfield_->text()); |
1091 SendKeyEvent(ui::VKEY_Y, false, true); | 1062 SendKeyEvent(ui::VKEY_Y, false, true); |
1092 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1063 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
1093 SendKeyEvent(ui::VKEY_Y, false, true); | 1064 SendKeyEvent(ui::VKEY_Y, false, true); |
1094 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1065 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
1095 } | 1066 } |
1096 | 1067 |
1097 TEST_F(NativeTextfieldViewsTest, DragAndDrop_Canceled) { | 1068 TEST_F(TextfieldTest, DragAndDrop_Canceled) { |
1098 InitTextfield(Textfield::STYLE_DEFAULT); | 1069 InitTextfield(Textfield::STYLE_DEFAULT); |
1099 textfield_->SetText(ASCIIToUTF16("hello world")); | 1070 textfield_->SetText(ASCIIToUTF16("hello world")); |
1100 | 1071 |
1101 // Start dragging "worl". | 1072 // Start dragging "worl". |
1102 textfield_->SelectRange(gfx::Range(6, 10)); | 1073 textfield_->SelectRange(gfx::Range(6, 10)); |
1103 gfx::Point point(GetCursorPositionX(8), 0); | 1074 gfx::Point point(GetCursorPositionX(8), 0); |
1104 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 1075 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, |
1105 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1076 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
1106 textfield_view_->OnMousePressed(click); | 1077 textfield_->OnMousePressed(click); |
1107 ui::OSExchangeData data; | 1078 ui::OSExchangeData data; |
1108 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); | 1079 textfield_->WriteDragDataForView(NULL, click.location(), &data); |
1109 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 1080 EXPECT_TRUE(textfield_->CanDrop(data)); |
1110 // Drag the text over somewhere valid, outside the current selection. | 1081 // Drag the text over somewhere valid, outside the current selection. |
1111 gfx::Point drop_point(GetCursorPositionX(2), 0); | 1082 gfx::Point drop_point(GetCursorPositionX(2), 0); |
1112 ui::DropTargetEvent drop(data, drop_point, drop_point, | 1083 ui::DropTargetEvent drop(data, drop_point, drop_point, |
1113 ui::DragDropTypes::DRAG_MOVE); | 1084 ui::DragDropTypes::DRAG_MOVE); |
1114 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); | 1085 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); |
1115 // "Cancel" the drag, via move and release over the selection, and OnDragDone. | 1086 // "Cancel" the drag, via move and release over the selection, and OnDragDone. |
1116 gfx::Point drag_point(GetCursorPositionX(9), 0); | 1087 gfx::Point drag_point(GetCursorPositionX(9), 0); |
1117 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, | 1088 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, |
1118 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1089 ui::EF_LEFT_MOUSE_BUTTON, 0); |
1119 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, | 1090 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, |
1120 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1091 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
1121 textfield_view_->OnMouseDragged(drag); | 1092 textfield_->OnMouseDragged(drag); |
1122 textfield_view_->OnMouseReleased(release); | 1093 textfield_->OnMouseReleased(release); |
1123 textfield_view_->OnDragDone(); | 1094 textfield_->OnDragDone(); |
1124 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); | 1095 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); |
1125 } | 1096 } |
1126 | 1097 |
1127 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { | 1098 TEST_F(TextfieldTest, ReadOnlyTest) { |
1128 InitTextfield(Textfield::STYLE_DEFAULT); | 1099 InitTextfield(Textfield::STYLE_DEFAULT); |
1129 textfield_->SetText(ASCIIToUTF16("read only")); | 1100 textfield_->SetText(ASCIIToUTF16("read only")); |
1130 textfield_->SetReadOnly(true); | 1101 textfield_->SetReadOnly(true); |
1131 EXPECT_TRUE(textfield_->enabled()); | 1102 EXPECT_TRUE(textfield_->enabled()); |
1132 EXPECT_TRUE(textfield_->focusable()); | 1103 EXPECT_TRUE(textfield_->focusable()); |
1133 | 1104 |
1134 SendKeyEvent(ui::VKEY_HOME); | 1105 SendKeyEvent(ui::VKEY_HOME); |
1135 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1106 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
1136 SendKeyEvent(ui::VKEY_END); | 1107 SendKeyEvent(ui::VKEY_END); |
1137 EXPECT_EQ(9U, textfield_->GetCursorPosition()); | 1108 EXPECT_EQ(9U, textfield_->GetCursorPosition()); |
1138 | 1109 |
1139 SendKeyEvent(ui::VKEY_LEFT, false, false); | 1110 SendKeyEvent(ui::VKEY_LEFT, false, false); |
1140 EXPECT_EQ(8U, textfield_->GetCursorPosition()); | 1111 EXPECT_EQ(8U, textfield_->GetCursorPosition()); |
1141 SendKeyEvent(ui::VKEY_LEFT, false, true); | 1112 SendKeyEvent(ui::VKEY_LEFT, false, true); |
1142 EXPECT_EQ(5U, textfield_->GetCursorPosition()); | 1113 EXPECT_EQ(5U, textfield_->GetCursorPosition()); |
1143 SendKeyEvent(ui::VKEY_LEFT, true, true); | 1114 SendKeyEvent(ui::VKEY_LEFT, true, true); |
1144 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1115 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
1145 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); | 1116 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); |
1146 textfield_->SelectAll(false); | 1117 textfield_->SelectAll(false); |
1147 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); | 1118 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); |
1148 | 1119 |
1149 // Cut should be disabled. | 1120 // Cut should be disabled. |
1150 SetClipboardText("Test"); | 1121 SetClipboardText("Test"); |
1151 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); | 1122 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
1152 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); | 1123 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
1153 SendKeyEvent(ui::VKEY_X, false, true); | 1124 SendKeyEvent(ui::VKEY_X, false, true); |
1154 SendKeyEvent(ui::VKEY_DELETE, true, false); | 1125 SendKeyEvent(ui::VKEY_DELETE, true, false); |
1155 EXPECT_STR_EQ("Test", base::string16(GetClipboardText())); | 1126 EXPECT_STR_EQ("Test", base::string16(GetClipboardText())); |
1156 EXPECT_STR_EQ("read only", textfield_->text()); | 1127 EXPECT_STR_EQ("read only", textfield_->text()); |
1157 | 1128 |
1158 // Paste should be disabled. | 1129 // Paste should be disabled. |
1159 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); | 1130 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
1160 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); | 1131 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
1161 SendKeyEvent(ui::VKEY_V, false, true); | 1132 SendKeyEvent(ui::VKEY_V, false, true); |
1162 SendKeyEvent(ui::VKEY_INSERT, true, false); | 1133 SendKeyEvent(ui::VKEY_INSERT, true, false); |
1163 EXPECT_STR_EQ("read only", textfield_->text()); | 1134 EXPECT_STR_EQ("read only", textfield_->text()); |
1164 | 1135 |
1165 // Copy should work normally. | 1136 // Copy should work normally. |
1166 SetClipboardText("Test"); | 1137 SetClipboardText("Test"); |
1167 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); | 1138 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
1168 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); | 1139 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
1169 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); | 1140 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); |
1170 SetClipboardText("Test"); | 1141 SetClipboardText("Test"); |
1171 SendKeyEvent(ui::VKEY_C, false, true); | 1142 SendKeyEvent(ui::VKEY_C, false, true); |
1172 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); | 1143 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); |
1173 SetClipboardText("Test"); | 1144 SetClipboardText("Test"); |
1174 SendKeyEvent(ui::VKEY_INSERT, false, true); | 1145 SendKeyEvent(ui::VKEY_INSERT, false, true); |
1175 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); | 1146 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); |
1176 | 1147 |
1177 // SetText should work even in read only mode. | 1148 // SetText should work even in read only mode. |
1178 textfield_->SetText(ASCIIToUTF16(" four five six ")); | 1149 textfield_->SetText(ASCIIToUTF16(" four five six ")); |
1179 EXPECT_STR_EQ(" four five six ", textfield_->text()); | 1150 EXPECT_STR_EQ(" four five six ", textfield_->text()); |
1180 | 1151 |
1181 textfield_->SelectAll(false); | 1152 textfield_->SelectAll(false); |
1182 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1153 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1183 | 1154 |
1184 // Text field is unmodifiable and selection shouldn't change. | 1155 // Text field is unmodifiable and selection shouldn't change. |
1185 SendKeyEvent(ui::VKEY_DELETE); | 1156 SendKeyEvent(ui::VKEY_DELETE); |
1186 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1157 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1187 SendKeyEvent(ui::VKEY_BACK); | 1158 SendKeyEvent(ui::VKEY_BACK); |
1188 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1159 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1189 SendKeyEvent(ui::VKEY_T); | 1160 SendKeyEvent(ui::VKEY_T); |
1190 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1161 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1191 } | 1162 } |
1192 | 1163 |
1193 TEST_F(NativeTextfieldViewsTest, TextInputClientTest) { | 1164 TEST_F(TextfieldTest, TextInputClientTest) { |
1194 InitTextfield(Textfield::STYLE_DEFAULT); | 1165 InitTextfield(Textfield::STYLE_DEFAULT); |
1195 ui::TextInputClient* client = textfield_->GetTextInputClient(); | 1166 ui::TextInputClient* client = textfield_->GetTextInputClient(); |
1196 EXPECT_TRUE(client); | 1167 EXPECT_TRUE(client); |
1197 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); | 1168 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); |
1198 | 1169 |
1199 textfield_->SetText(ASCIIToUTF16("0123456789")); | 1170 textfield_->SetText(ASCIIToUTF16("0123456789")); |
1200 gfx::Range range; | 1171 gfx::Range range; |
1201 EXPECT_TRUE(client->GetTextRange(&range)); | 1172 EXPECT_TRUE(client->GetTextRange(&range)); |
1202 EXPECT_EQ(0U, range.start()); | 1173 EXPECT_EQ(0U, range.start()); |
1203 EXPECT_EQ(10U, range.end()); | 1174 EXPECT_EQ(10U, range.end()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1259 EXPECT_TRUE(input_method_->text_input_type_changed()); |
1289 EXPECT_FALSE(textfield_->GetTextInputClient()); | 1260 EXPECT_FALSE(textfield_->GetTextInputClient()); |
1290 | 1261 |
1291 textfield_->SetReadOnly(false); | 1262 textfield_->SetReadOnly(false); |
1292 input_method_->Clear(); | 1263 input_method_->Clear(); |
1293 textfield_->SetObscured(true); | 1264 textfield_->SetObscured(true); |
1294 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1265 EXPECT_TRUE(input_method_->text_input_type_changed()); |
1295 EXPECT_TRUE(textfield_->GetTextInputClient()); | 1266 EXPECT_TRUE(textfield_->GetTextInputClient()); |
1296 } | 1267 } |
1297 | 1268 |
1298 TEST_F(NativeTextfieldViewsTest, UndoRedoTest) { | 1269 TEST_F(TextfieldTest, UndoRedoTest) { |
1299 InitTextfield(Textfield::STYLE_DEFAULT); | 1270 InitTextfield(Textfield::STYLE_DEFAULT); |
1300 SendKeyEvent(ui::VKEY_A); | 1271 SendKeyEvent(ui::VKEY_A); |
1301 EXPECT_STR_EQ("a", textfield_->text()); | 1272 EXPECT_STR_EQ("a", textfield_->text()); |
1302 SendKeyEvent(ui::VKEY_Z, false, true); | 1273 SendKeyEvent(ui::VKEY_Z, false, true); |
1303 EXPECT_STR_EQ("", textfield_->text()); | 1274 EXPECT_STR_EQ("", textfield_->text()); |
1304 SendKeyEvent(ui::VKEY_Z, false, true); | 1275 SendKeyEvent(ui::VKEY_Z, false, true); |
1305 EXPECT_STR_EQ("", textfield_->text()); | 1276 EXPECT_STR_EQ("", textfield_->text()); |
1306 SendKeyEvent(ui::VKEY_Y, false, true); | 1277 SendKeyEvent(ui::VKEY_Y, false, true); |
1307 EXPECT_STR_EQ("a", textfield_->text()); | 1278 EXPECT_STR_EQ("a", textfield_->text()); |
1308 SendKeyEvent(ui::VKEY_Y, false, true); | 1279 SendKeyEvent(ui::VKEY_Y, false, true); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 SendKeyEvent(ui::VKEY_Y, false, true); | 1354 SendKeyEvent(ui::VKEY_Y, false, true); |
1384 EXPECT_STR_EQ("ab", textfield_->text()); | 1355 EXPECT_STR_EQ("ab", textfield_->text()); |
1385 SendKeyEvent(ui::VKEY_Y, false, true); | 1356 SendKeyEvent(ui::VKEY_Y, false, true); |
1386 EXPECT_STR_EQ("b", textfield_->text()); | 1357 EXPECT_STR_EQ("b", textfield_->text()); |
1387 SendKeyEvent(ui::VKEY_Y, false, true); | 1358 SendKeyEvent(ui::VKEY_Y, false, true); |
1388 EXPECT_STR_EQ("", textfield_->text()); | 1359 EXPECT_STR_EQ("", textfield_->text()); |
1389 SendKeyEvent(ui::VKEY_Y, false, true); | 1360 SendKeyEvent(ui::VKEY_Y, false, true); |
1390 EXPECT_STR_EQ("", textfield_->text()); | 1361 EXPECT_STR_EQ("", textfield_->text()); |
1391 } | 1362 } |
1392 | 1363 |
1393 TEST_F(NativeTextfieldViewsTest, CutCopyPaste) { | 1364 TEST_F(TextfieldTest, CutCopyPaste) { |
1394 InitTextfield(Textfield::STYLE_DEFAULT); | 1365 InitTextfield(Textfield::STYLE_DEFAULT); |
1395 | 1366 |
1396 // Ensure IDS_APP_CUT cuts. | 1367 // Ensure IDS_APP_CUT cuts. |
1397 textfield_->SetText(ASCIIToUTF16("123")); | 1368 textfield_->SetText(ASCIIToUTF16("123")); |
1398 textfield_->SelectAll(false); | 1369 textfield_->SelectAll(false); |
1399 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); | 1370 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
1400 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); | 1371 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
1401 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1372 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); |
1402 EXPECT_STR_EQ("", textfield_->text()); | 1373 EXPECT_STR_EQ("", textfield_->text()); |
1403 | 1374 |
1404 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. | 1375 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. |
1405 textfield_->SetText(ASCIIToUTF16("456")); | 1376 textfield_->SetText(ASCIIToUTF16("456")); |
1406 textfield_->SelectAll(false); | 1377 textfield_->SelectAll(false); |
1407 SendKeyEvent(ui::VKEY_X, true, false, true, false); | 1378 SendKeyEvent(ui::VKEY_X, true, false, true, false); |
1408 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1379 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); |
1409 EXPECT_STR_EQ("456", textfield_->text()); | 1380 EXPECT_STR_EQ("456", textfield_->text()); |
1410 SendKeyEvent(ui::VKEY_X, false, true); | 1381 SendKeyEvent(ui::VKEY_X, false, true); |
1411 EXPECT_STR_EQ("456", base::string16(GetClipboardText())); | 1382 EXPECT_STR_EQ("456", base::string16(GetClipboardText())); |
1412 EXPECT_STR_EQ("", textfield_->text()); | 1383 EXPECT_STR_EQ("", textfield_->text()); |
1413 | 1384 |
1414 // Ensure [Shift]+[Delete] cuts. | 1385 // Ensure [Shift]+[Delete] cuts. |
1415 textfield_->SetText(ASCIIToUTF16("123")); | 1386 textfield_->SetText(ASCIIToUTF16("123")); |
1416 textfield_->SelectAll(false); | 1387 textfield_->SelectAll(false); |
1417 SendKeyEvent(ui::VKEY_DELETE, true, false); | 1388 SendKeyEvent(ui::VKEY_DELETE, true, false); |
1418 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1389 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); |
1419 EXPECT_STR_EQ("", textfield_->text()); | 1390 EXPECT_STR_EQ("", textfield_->text()); |
1420 | 1391 |
1421 // Ensure IDS_APP_COPY copies. | 1392 // Ensure IDS_APP_COPY copies. |
1422 textfield_->SetText(ASCIIToUTF16("789")); | 1393 textfield_->SetText(ASCIIToUTF16("789")); |
1423 textfield_->SelectAll(false); | 1394 textfield_->SelectAll(false); |
1424 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); | 1395 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
1425 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); | 1396 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
1426 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); | 1397 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); |
1427 | 1398 |
1428 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. | 1399 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. |
1429 textfield_->SetText(ASCIIToUTF16("012")); | 1400 textfield_->SetText(ASCIIToUTF16("012")); |
1430 textfield_->SelectAll(false); | 1401 textfield_->SelectAll(false); |
1431 SendKeyEvent(ui::VKEY_C, true, false, true, false); | 1402 SendKeyEvent(ui::VKEY_C, true, false, true, false); |
1432 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); | 1403 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); |
1433 SendKeyEvent(ui::VKEY_C, false, true); | 1404 SendKeyEvent(ui::VKEY_C, false, true); |
1434 EXPECT_STR_EQ("012", base::string16(GetClipboardText())); | 1405 EXPECT_STR_EQ("012", base::string16(GetClipboardText())); |
1435 | 1406 |
1436 // Ensure [Ctrl]+[Insert] copies. | 1407 // Ensure [Ctrl]+[Insert] copies. |
1437 textfield_->SetText(ASCIIToUTF16("345")); | 1408 textfield_->SetText(ASCIIToUTF16("345")); |
1438 textfield_->SelectAll(false); | 1409 textfield_->SelectAll(false); |
1439 SendKeyEvent(ui::VKEY_INSERT, false, true); | 1410 SendKeyEvent(ui::VKEY_INSERT, false, true); |
1440 EXPECT_STR_EQ("345", base::string16(GetClipboardText())); | 1411 EXPECT_STR_EQ("345", base::string16(GetClipboardText())); |
1441 EXPECT_STR_EQ("345", textfield_->text()); | 1412 EXPECT_STR_EQ("345", textfield_->text()); |
1442 | 1413 |
1443 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; | 1414 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; |
1444 // also ensure that [Ctrl]+[Alt]+[V] does nothing. | 1415 // also ensure that [Ctrl]+[Alt]+[V] does nothing. |
1445 SetClipboardText("abc"); | 1416 SetClipboardText("abc"); |
1446 textfield_->SetText(base::string16()); | 1417 textfield_->SetText(base::string16()); |
1447 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); | 1418 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
1448 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); | 1419 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
1449 EXPECT_STR_EQ("abc", textfield_->text()); | 1420 EXPECT_STR_EQ("abc", textfield_->text()); |
1450 SendKeyEvent(ui::VKEY_V, false, true); | 1421 SendKeyEvent(ui::VKEY_V, false, true); |
1451 EXPECT_STR_EQ("abcabc", textfield_->text()); | 1422 EXPECT_STR_EQ("abcabc", textfield_->text()); |
1452 SendKeyEvent(ui::VKEY_INSERT, true, false); | 1423 SendKeyEvent(ui::VKEY_INSERT, true, false); |
1453 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1424 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
1454 SendKeyEvent(ui::VKEY_V, true, false, true, false); | 1425 SendKeyEvent(ui::VKEY_V, true, false, true, false); |
1455 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1426 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
1456 | 1427 |
1457 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. | 1428 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. |
1458 textfield_->SelectAll(false); | 1429 textfield_->SelectAll(false); |
1459 SendKeyEvent(ui::VKEY_INSERT, true, true); | 1430 SendKeyEvent(ui::VKEY_INSERT, true, true); |
1460 EXPECT_STR_EQ("abc", base::string16(GetClipboardText())); | 1431 EXPECT_STR_EQ("abc", base::string16(GetClipboardText())); |
1461 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1432 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
1462 } | 1433 } |
1463 | 1434 |
1464 TEST_F(NativeTextfieldViewsTest, OvertypeMode) { | 1435 TEST_F(TextfieldTest, OvertypeMode) { |
1465 InitTextfield(Textfield::STYLE_DEFAULT); | 1436 InitTextfield(Textfield::STYLE_DEFAULT); |
1466 // Overtype mode should be disabled (no-op [Insert]). | 1437 // Overtype mode should be disabled (no-op [Insert]). |
1467 textfield_->SetText(ASCIIToUTF16("2")); | 1438 textfield_->SetText(ASCIIToUTF16("2")); |
1468 SendKeyEvent(ui::VKEY_HOME); | 1439 SendKeyEvent(ui::VKEY_HOME); |
1469 SendKeyEvent(ui::VKEY_INSERT); | 1440 SendKeyEvent(ui::VKEY_INSERT); |
1470 SendKeyEvent(ui::VKEY_1, false, false); | 1441 SendKeyEvent(ui::VKEY_1, false, false); |
1471 EXPECT_STR_EQ("12", textfield_->text()); | 1442 EXPECT_STR_EQ("12", textfield_->text()); |
1472 } | 1443 } |
1473 | 1444 |
1474 TEST_F(NativeTextfieldViewsTest, TextCursorDisplayTest) { | 1445 TEST_F(TextfieldTest, TextCursorDisplayTest) { |
1475 InitTextfield(Textfield::STYLE_DEFAULT); | 1446 InitTextfield(Textfield::STYLE_DEFAULT); |
1476 // LTR-RTL string in LTR context. | 1447 // LTR-RTL string in LTR context. |
1477 SendKeyEvent('a'); | 1448 SendKeyEvent('a'); |
1478 EXPECT_STR_EQ("a", textfield_->text()); | 1449 EXPECT_STR_EQ("a", textfield_->text()); |
1479 int x = GetCursorBounds().x(); | 1450 int x = GetCursorBounds().x(); |
1480 int prev_x = x; | 1451 int prev_x = x; |
1481 | 1452 |
1482 SendKeyEvent('b'); | 1453 SendKeyEvent('b'); |
1483 EXPECT_STR_EQ("ab", textfield_->text()); | 1454 EXPECT_STR_EQ("ab", textfield_->text()); |
1484 x = GetCursorBounds().x(); | 1455 x = GetCursorBounds().x(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 x = GetCursorBounds().x(); | 1487 x = GetCursorBounds().x(); |
1517 EXPECT_LT(prev_x, x); | 1488 EXPECT_LT(prev_x, x); |
1518 prev_x = x; | 1489 prev_x = x; |
1519 | 1490 |
1520 SendKeyEvent('b'); | 1491 SendKeyEvent('b'); |
1521 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); | 1492 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); |
1522 x = GetCursorBounds().x(); | 1493 x = GetCursorBounds().x(); |
1523 EXPECT_LT(prev_x, x); | 1494 EXPECT_LT(prev_x, x); |
1524 } | 1495 } |
1525 | 1496 |
1526 TEST_F(NativeTextfieldViewsTest, TextCursorDisplayInRTLTest) { | 1497 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) { |
1527 std::string locale = l10n_util::GetApplicationLocale(""); | 1498 std::string locale = l10n_util::GetApplicationLocale(""); |
1528 base::i18n::SetICUDefaultLocale("he"); | 1499 base::i18n::SetICUDefaultLocale("he"); |
1529 | 1500 |
1530 InitTextfield(Textfield::STYLE_DEFAULT); | 1501 InitTextfield(Textfield::STYLE_DEFAULT); |
1531 // LTR-RTL string in RTL context. | 1502 // LTR-RTL string in RTL context. |
1532 SendKeyEvent('a'); | 1503 SendKeyEvent('a'); |
1533 EXPECT_STR_EQ("a", textfield_->text()); | 1504 EXPECT_STR_EQ("a", textfield_->text()); |
1534 int x = GetCursorBounds().x(); | 1505 int x = GetCursorBounds().x(); |
1535 EXPECT_EQ(GetDisplayRect().right() - 1, x); | 1506 EXPECT_EQ(GetDisplayRect().right() - 1, x); |
1536 int prev_x = x; | 1507 int prev_x = x; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 | 1545 |
1575 SendKeyEvent('b'); | 1546 SendKeyEvent('b'); |
1576 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); | 1547 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); |
1577 x = GetCursorBounds().x(); | 1548 x = GetCursorBounds().x(); |
1578 EXPECT_EQ(prev_x, x); | 1549 EXPECT_EQ(prev_x, x); |
1579 | 1550 |
1580 // Reset locale. | 1551 // Reset locale. |
1581 base::i18n::SetICUDefaultLocale(locale); | 1552 base::i18n::SetICUDefaultLocale(locale); |
1582 } | 1553 } |
1583 | 1554 |
1584 TEST_F(NativeTextfieldViewsTest, HitInsideTextAreaTest) { | 1555 TEST_F(TextfieldTest, HitInsideTextAreaTest) { |
1585 InitTextfield(Textfield::STYLE_DEFAULT); | 1556 InitTextfield(Textfield::STYLE_DEFAULT); |
1586 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1557 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
1587 std::vector<gfx::Rect> cursor_bounds; | 1558 std::vector<gfx::Rect> cursor_bounds; |
1588 | 1559 |
1589 // Save each cursor bound. | 1560 // Save each cursor bound. |
1590 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD); | 1561 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD); |
1591 cursor_bounds.push_back(GetCursorBounds(sel)); | 1562 cursor_bounds.push_back(GetCursorBounds(sel)); |
1592 | 1563 |
1593 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD); | 1564 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD); |
1594 gfx::Rect bound = GetCursorBounds(sel); | 1565 gfx::Rect bound = GetCursorBounds(sel); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 // for the test to run if using sleep(). | 1600 // for the test to run if using sleep(). |
1630 NonClientMouseClick(); | 1601 NonClientMouseClick(); |
1631 | 1602 |
1632 MouseClick(cursor_bounds[i + 1], - (half_width / 2)); | 1603 MouseClick(cursor_bounds[i + 1], - (half_width / 2)); |
1633 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); | 1604 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); |
1634 | 1605 |
1635 NonClientMouseClick(); | 1606 NonClientMouseClick(); |
1636 } | 1607 } |
1637 } | 1608 } |
1638 | 1609 |
1639 TEST_F(NativeTextfieldViewsTest, HitOutsideTextAreaTest) { | 1610 TEST_F(TextfieldTest, HitOutsideTextAreaTest) { |
1640 InitTextfield(Textfield::STYLE_DEFAULT); | 1611 InitTextfield(Textfield::STYLE_DEFAULT); |
1641 | 1612 |
1642 // LTR-RTL string in LTR context. | 1613 // LTR-RTL string in LTR context. |
1643 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1614 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
1644 | 1615 |
1645 SendKeyEvent(ui::VKEY_HOME); | 1616 SendKeyEvent(ui::VKEY_HOME); |
1646 gfx::Rect bound = GetCursorBounds(); | 1617 gfx::Rect bound = GetCursorBounds(); |
1647 MouseClick(bound, -10); | 1618 MouseClick(bound, -10); |
1648 EXPECT_EQ(bound, GetCursorBounds()); | 1619 EXPECT_EQ(bound, GetCursorBounds()); |
1649 | 1620 |
(...skipping 11 matching lines...) Expand all Loading... |
1661 bound = GetCursorBounds(); | 1632 bound = GetCursorBounds(); |
1662 MouseClick(bound, 10); | 1633 MouseClick(bound, 10); |
1663 EXPECT_EQ(bound, GetCursorBounds()); | 1634 EXPECT_EQ(bound, GetCursorBounds()); |
1664 | 1635 |
1665 SendKeyEvent(ui::VKEY_END); | 1636 SendKeyEvent(ui::VKEY_END); |
1666 bound = GetCursorBounds(); | 1637 bound = GetCursorBounds(); |
1667 MouseClick(bound, -10); | 1638 MouseClick(bound, -10); |
1668 EXPECT_EQ(bound, GetCursorBounds()); | 1639 EXPECT_EQ(bound, GetCursorBounds()); |
1669 } | 1640 } |
1670 | 1641 |
1671 TEST_F(NativeTextfieldViewsTest, HitOutsideTextAreaInRTLTest) { | 1642 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) { |
1672 std::string locale = l10n_util::GetApplicationLocale(""); | 1643 std::string locale = l10n_util::GetApplicationLocale(""); |
1673 base::i18n::SetICUDefaultLocale("he"); | 1644 base::i18n::SetICUDefaultLocale("he"); |
1674 | 1645 |
1675 InitTextfield(Textfield::STYLE_DEFAULT); | 1646 InitTextfield(Textfield::STYLE_DEFAULT); |
1676 | 1647 |
1677 // RTL-LTR string in RTL context. | 1648 // RTL-LTR string in RTL context. |
1678 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); | 1649 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); |
1679 SendKeyEvent(ui::VKEY_HOME); | 1650 SendKeyEvent(ui::VKEY_HOME); |
1680 gfx::Rect bound = GetCursorBounds(); | 1651 gfx::Rect bound = GetCursorBounds(); |
1681 MouseClick(bound, 10); | 1652 MouseClick(bound, 10); |
(...skipping 15 matching lines...) Expand all Loading... |
1697 | 1668 |
1698 SendKeyEvent(ui::VKEY_END); | 1669 SendKeyEvent(ui::VKEY_END); |
1699 bound = GetCursorBounds(); | 1670 bound = GetCursorBounds(); |
1700 MouseClick(bound, 10); | 1671 MouseClick(bound, 10); |
1701 EXPECT_EQ(bound, GetCursorBounds()); | 1672 EXPECT_EQ(bound, GetCursorBounds()); |
1702 | 1673 |
1703 // Reset locale. | 1674 // Reset locale. |
1704 base::i18n::SetICUDefaultLocale(locale); | 1675 base::i18n::SetICUDefaultLocale(locale); |
1705 } | 1676 } |
1706 | 1677 |
1707 TEST_F(NativeTextfieldViewsTest, OverflowTest) { | 1678 TEST_F(TextfieldTest, OverflowTest) { |
1708 InitTextfield(Textfield::STYLE_DEFAULT); | 1679 InitTextfield(Textfield::STYLE_DEFAULT); |
1709 | 1680 |
1710 base::string16 str; | 1681 base::string16 str; |
1711 for (int i = 0; i < 500; ++i) | 1682 for (int i = 0; i < 500; ++i) |
1712 SendKeyEvent('a'); | 1683 SendKeyEvent('a'); |
1713 SendKeyEvent(kHebrewLetterSamekh); | 1684 SendKeyEvent(kHebrewLetterSamekh); |
1714 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1685 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
1715 | 1686 |
1716 // Test mouse pointing. | 1687 // Test mouse pointing. |
1717 MouseClick(GetCursorBounds(), -1); | 1688 MouseClick(GetCursorBounds(), -1); |
1718 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1689 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
1719 | 1690 |
1720 // Clear text. | 1691 // Clear text. |
1721 SendKeyEvent(ui::VKEY_A, false, true); | 1692 SendKeyEvent(ui::VKEY_A, false, true); |
1722 SendKeyEvent('\n'); | 1693 SendKeyEvent('\n'); |
1723 | 1694 |
1724 for (int i = 0; i < 500; ++i) | 1695 for (int i = 0; i < 500; ++i) |
1725 SendKeyEvent(kHebrewLetterSamekh); | 1696 SendKeyEvent(kHebrewLetterSamekh); |
1726 SendKeyEvent('a'); | 1697 SendKeyEvent('a'); |
1727 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1698 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
1728 | 1699 |
1729 MouseClick(GetCursorBounds(), -1); | 1700 MouseClick(GetCursorBounds(), -1); |
1730 EXPECT_EQ(501U, textfield_->GetCursorPosition()); | 1701 EXPECT_EQ(501U, textfield_->GetCursorPosition()); |
1731 } | 1702 } |
1732 | 1703 |
1733 TEST_F(NativeTextfieldViewsTest, OverflowInRTLTest) { | 1704 TEST_F(TextfieldTest, OverflowInRTLTest) { |
1734 std::string locale = l10n_util::GetApplicationLocale(""); | 1705 std::string locale = l10n_util::GetApplicationLocale(""); |
1735 base::i18n::SetICUDefaultLocale("he"); | 1706 base::i18n::SetICUDefaultLocale("he"); |
1736 | 1707 |
1737 InitTextfield(Textfield::STYLE_DEFAULT); | 1708 InitTextfield(Textfield::STYLE_DEFAULT); |
1738 | 1709 |
1739 base::string16 str; | 1710 base::string16 str; |
1740 for (int i = 0; i < 500; ++i) | 1711 for (int i = 0; i < 500; ++i) |
1741 SendKeyEvent('a'); | 1712 SendKeyEvent('a'); |
1742 SendKeyEvent(kHebrewLetterSamekh); | 1713 SendKeyEvent(kHebrewLetterSamekh); |
1743 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1714 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
(...skipping 10 matching lines...) Expand all Loading... |
1754 SendKeyEvent('a'); | 1725 SendKeyEvent('a'); |
1755 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1726 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
1756 | 1727 |
1757 MouseClick(GetCursorBounds(), 1); | 1728 MouseClick(GetCursorBounds(), 1); |
1758 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1729 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
1759 | 1730 |
1760 // Reset locale. | 1731 // Reset locale. |
1761 base::i18n::SetICUDefaultLocale(locale); | 1732 base::i18n::SetICUDefaultLocale(locale); |
1762 } | 1733 } |
1763 | 1734 |
1764 TEST_F(NativeTextfieldViewsTest, GetCompositionCharacterBoundsTest) { | 1735 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) { |
1765 InitTextfield(Textfield::STYLE_DEFAULT); | 1736 InitTextfield(Textfield::STYLE_DEFAULT); |
1766 | 1737 |
1767 base::string16 str; | 1738 base::string16 str; |
1768 const uint32 char_count = 10UL; | 1739 const uint32 char_count = 10UL; |
1769 ui::CompositionText composition; | 1740 ui::CompositionText composition; |
1770 composition.text = UTF8ToUTF16("0123456789"); | 1741 composition.text = UTF8ToUTF16("0123456789"); |
1771 ui::TextInputClient* client = textfield_->GetTextInputClient(); | 1742 ui::TextInputClient* client = textfield_->GetTextInputClient(); |
1772 | 1743 |
1773 // Return false if there is no composition text. | 1744 // Return false if there is no composition text. |
1774 gfx::Rect rect; | 1745 gfx::Rect rect; |
1775 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect)); | 1746 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect)); |
1776 | 1747 |
1777 // Get each character boundary by cursor. | 1748 // Get each character boundary by cursor. |
1778 gfx::Rect char_rect_in_screen_coord[char_count]; | 1749 gfx::Rect char_rect_in_screen_coord[char_count]; |
1779 gfx::Rect prev_cursor = GetCursorBounds(); | 1750 gfx::Rect prev_cursor = GetCursorBounds(); |
1780 for (uint32 i = 0; i < char_count; ++i) { | 1751 for (uint32 i = 0; i < char_count; ++i) { |
1781 composition.selection = gfx::Range(0, i+1); | 1752 composition.selection = gfx::Range(0, i+1); |
1782 client->SetCompositionText(composition); | 1753 client->SetCompositionText(composition); |
1783 EXPECT_TRUE(client->HasCompositionText()) << " i=" << i; | 1754 EXPECT_TRUE(client->HasCompositionText()) << " i=" << i; |
1784 gfx::Rect cursor_bounds = GetCursorBounds(); | 1755 gfx::Rect cursor_bounds = GetCursorBounds(); |
1785 gfx::Point top_left(prev_cursor.x(), prev_cursor.y()); | 1756 gfx::Point top_left(prev_cursor.x(), prev_cursor.y()); |
1786 gfx::Point bottom_right(cursor_bounds.x(), prev_cursor.bottom()); | 1757 gfx::Point bottom_right(cursor_bounds.x(), prev_cursor.bottom()); |
1787 views::View::ConvertPointToScreen(textfield_view_, &top_left); | 1758 views::View::ConvertPointToScreen(textfield_, &top_left); |
1788 views::View::ConvertPointToScreen(textfield_view_, &bottom_right); | 1759 views::View::ConvertPointToScreen(textfield_, &bottom_right); |
1789 char_rect_in_screen_coord[i].set_origin(top_left); | 1760 char_rect_in_screen_coord[i].set_origin(top_left); |
1790 char_rect_in_screen_coord[i].set_width(bottom_right.x() - top_left.x()); | 1761 char_rect_in_screen_coord[i].set_width(bottom_right.x() - top_left.x()); |
1791 char_rect_in_screen_coord[i].set_height(bottom_right.y() - top_left.y()); | 1762 char_rect_in_screen_coord[i].set_height(bottom_right.y() - top_left.y()); |
1792 prev_cursor = cursor_bounds; | 1763 prev_cursor = cursor_bounds; |
1793 } | 1764 } |
1794 | 1765 |
1795 for (uint32 i = 0; i < char_count; ++i) { | 1766 for (uint32 i = 0; i < char_count; ++i) { |
1796 gfx::Rect actual_rect; | 1767 gfx::Rect actual_rect; |
1797 EXPECT_TRUE(client->GetCompositionCharacterBounds(i, &actual_rect)) | 1768 EXPECT_TRUE(client->GetCompositionCharacterBounds(i, &actual_rect)) |
1798 << " i=" << i; | 1769 << " i=" << i; |
1799 EXPECT_EQ(char_rect_in_screen_coord[i], actual_rect) << " i=" << i; | 1770 EXPECT_EQ(char_rect_in_screen_coord[i], actual_rect) << " i=" << i; |
1800 } | 1771 } |
1801 | 1772 |
1802 // Return false if the index is out of range. | 1773 // Return false if the index is out of range. |
1803 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); | 1774 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); |
1804 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); | 1775 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); |
1805 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); | 1776 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); |
1806 } | 1777 } |
1807 | 1778 |
1808 TEST_F(NativeTextfieldViewsTest, GetCompositionCharacterBounds_ComplexText) { | 1779 TEST_F(TextfieldTest, GetCompositionCharacterBounds_ComplexText) { |
1809 InitTextfield(Textfield::STYLE_DEFAULT); | 1780 InitTextfield(Textfield::STYLE_DEFAULT); |
1810 | 1781 |
1811 const base::char16 kUtf16Chars[] = { | 1782 const base::char16 kUtf16Chars[] = { |
1812 // U+0020 SPACE | 1783 // U+0020 SPACE |
1813 0x0020, | 1784 0x0020, |
1814 // U+1F408 (CAT) as surrogate pair | 1785 // U+1F408 (CAT) as surrogate pair |
1815 0xd83d, 0xdc08, | 1786 0xd83d, 0xdc08, |
1816 // U+5642 as Ideographic Variation Sequences | 1787 // U+5642 as Ideographic Variation Sequences |
1817 0x5642, 0xDB40, 0xDD00, | 1788 0x5642, 0xDB40, 0xDD00, |
1818 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences | 1789 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences |
(...skipping 16 matching lines...) Expand all Loading... |
1835 | 1806 |
1836 // Here we might expect the following results but it actually depends on how | 1807 // Here we might expect the following results but it actually depends on how |
1837 // Uniscribe or HarfBuzz treats them with given font. | 1808 // Uniscribe or HarfBuzz treats them with given font. |
1838 // - rects[1] == rects[2] | 1809 // - rects[1] == rects[2] |
1839 // - rects[3] == rects[4] == rects[5] | 1810 // - rects[3] == rects[4] == rects[5] |
1840 // - rects[6] == rects[7] | 1811 // - rects[6] == rects[7] |
1841 } | 1812 } |
1842 | 1813 |
1843 // The word we select by double clicking should remain selected regardless of | 1814 // The word we select by double clicking should remain selected regardless of |
1844 // where we drag the mouse afterwards without releasing the left button. | 1815 // where we drag the mouse afterwards without releasing the left button. |
1845 TEST_F(NativeTextfieldViewsTest, KeepInitiallySelectedWord) { | 1816 TEST_F(TextfieldTest, KeepInitiallySelectedWord) { |
1846 InitTextfield(Textfield::STYLE_DEFAULT); | 1817 InitTextfield(Textfield::STYLE_DEFAULT); |
1847 | 1818 |
1848 textfield_->SetText(ASCIIToUTF16("abc def ghi")); | 1819 textfield_->SetText(ASCIIToUTF16("abc def ghi")); |
1849 | 1820 |
1850 textfield_->SelectRange(gfx::Range(5, 5)); | 1821 textfield_->SelectRange(gfx::Range(5, 5)); |
1851 const gfx::Rect middle_cursor = GetCursorBounds(); | 1822 const gfx::Rect middle_cursor = GetCursorBounds(); |
1852 textfield_->SelectRange(gfx::Range(0, 0)); | 1823 textfield_->SelectRange(gfx::Range(0, 0)); |
1853 const gfx::Point beginning = GetCursorBounds().origin(); | 1824 const gfx::Point beginning = GetCursorBounds().origin(); |
1854 | 1825 |
1855 // Double click, but do not release the left button. | 1826 // Double click, but do not release the left button. |
1856 MouseClick(middle_cursor, 0); | 1827 MouseClick(middle_cursor, 0); |
1857 const gfx::Point middle(middle_cursor.x(), | 1828 const gfx::Point middle(middle_cursor.x(), |
1858 middle_cursor.y() + middle_cursor.height() / 2); | 1829 middle_cursor.y() + middle_cursor.height() / 2); |
1859 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, | 1830 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, |
1860 ui::EF_LEFT_MOUSE_BUTTON, | 1831 ui::EF_LEFT_MOUSE_BUTTON, |
1861 ui::EF_LEFT_MOUSE_BUTTON); | 1832 ui::EF_LEFT_MOUSE_BUTTON); |
1862 textfield_view_->OnMousePressed(press_event); | 1833 textfield_->OnMousePressed(press_event); |
1863 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); | 1834 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); |
1864 | 1835 |
1865 // Drag the mouse to the beginning of the textfield. | 1836 // Drag the mouse to the beginning of the textfield. |
1866 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, | 1837 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, |
1867 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1838 ui::EF_LEFT_MOUSE_BUTTON, 0); |
1868 textfield_view_->OnMouseDragged(drag_event); | 1839 textfield_->OnMouseDragged(drag_event); |
1869 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); | 1840 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); |
1870 } | 1841 } |
1871 | 1842 |
1872 // Touch selection and draggin currently only works for chromeos. | 1843 // Touch selection and dragging currently only works for chromeos. |
1873 #if defined(OS_CHROMEOS) | 1844 #if defined(OS_CHROMEOS) |
1874 TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) { | 1845 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { |
1875 InitTextfield(Textfield::STYLE_DEFAULT); | 1846 InitTextfield(Textfield::STYLE_DEFAULT); |
1876 textfield_->SetText(ASCIIToUTF16("hello world")); | 1847 textfield_->SetText(ASCIIToUTF16("hello world")); |
1877 EXPECT_FALSE(GetTouchSelectionController()); | 1848 EXPECT_FALSE(GetTouchSelectionController()); |
1878 const int eventX = GetCursorPositionX(2); | 1849 const int x = GetCursorPositionX(2); |
1879 const int eventY = 0; | 1850 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); |
| 1851 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, x, 0, 0.0f, 0.0f); |
| 1852 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); |
1880 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); | 1853 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
1881 | 1854 |
1882 // Tapping on the textfield should turn on the TouchSelectionController. | 1855 // Tapping on the textfield should turn on the TouchSelectionController. |
1883 GestureEventForTest tap(ui::ET_GESTURE_TAP, eventX, eventY, 1.0f, 0.0f); | 1856 textfield_->OnGestureEvent(&tap); |
1884 textfield_view_->OnGestureEvent(&tap); | |
1885 EXPECT_TRUE(GetTouchSelectionController()); | 1857 EXPECT_TRUE(GetTouchSelectionController()); |
1886 | 1858 |
1887 // Un-focusing the textfield should reset the TouchSelectionController | 1859 // Un-focusing the textfield should reset the TouchSelectionController |
1888 textfield_view_->GetFocusManager()->ClearFocus(); | 1860 textfield_->GetFocusManager()->ClearFocus(); |
1889 EXPECT_FALSE(GetTouchSelectionController()); | 1861 EXPECT_FALSE(GetTouchSelectionController()); |
1890 | 1862 |
1891 // With touch editing enabled, long press should not show context menu. | 1863 // With touch editing enabled, long press should not show context menu. |
1892 // Instead, select word and invoke TouchSelectionController. | 1864 // Instead, select word and invoke TouchSelectionController. |
1893 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, eventX, eventY, 0.0f, | 1865 textfield_->OnGestureEvent(&tap_down); |
1894 0.0f); | 1866 textfield_->OnGestureEvent(&long_press); |
1895 textfield_view_->OnGestureEvent(&tap_down); | |
1896 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, | |
1897 0.0f, 0.0f); | |
1898 textfield_view_->OnGestureEvent(&long_press); | |
1899 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1867 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
1900 EXPECT_TRUE(GetTouchSelectionController()); | 1868 EXPECT_TRUE(GetTouchSelectionController()); |
1901 | 1869 |
1902 // Long pressing again in the selecting region should not do anything since | 1870 // With touch drag drop enabled, long pressing in the selected region should |
1903 // touch drag drop is not yet enabled. | 1871 // start a drag and remove TouchSelectionController. |
1904 textfield_view_->OnGestureEvent(&tap_down); | 1872 ASSERT_TRUE(switches::IsTouchDragDropEnabled()); |
1905 textfield_view_->OnGestureEvent(&long_press); | 1873 textfield_->OnGestureEvent(&tap_down); |
| 1874 textfield_->OnGestureEvent(&long_press); |
| 1875 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 1876 EXPECT_FALSE(GetTouchSelectionController()); |
| 1877 |
| 1878 // After disabling touch drag drop, long pressing again in the selection |
| 1879 // region should not do anything. |
| 1880 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1881 switches::kDisableTouchDragDrop); |
| 1882 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); |
| 1883 textfield_->OnGestureEvent(&tap_down); |
| 1884 textfield_->OnGestureEvent(&long_press); |
1906 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1885 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
1907 EXPECT_TRUE(GetTouchSelectionController()); | 1886 EXPECT_TRUE(GetTouchSelectionController()); |
1908 EXPECT_TRUE(long_press.handled()); | 1887 EXPECT_TRUE(long_press.handled()); |
1909 | |
1910 // After enabling touch drag drop, long pressing in the selected region should | |
1911 // start a drag and remove TouchSelectionController. | |
1912 CommandLine::ForCurrentProcess()->AppendSwitch( | |
1913 switches::kEnableTouchDragDrop); | |
1914 textfield_view_->OnGestureEvent(&tap_down); | |
1915 | |
1916 // Create a new long press event since the previous one is not marked handled. | |
1917 GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, | |
1918 0.0f, 0.0f); | |
1919 textfield_view_->OnGestureEvent(&long_press2); | |
1920 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | |
1921 EXPECT_FALSE(GetTouchSelectionController()); | |
1922 } | 1888 } |
1923 | 1889 |
1924 TEST_F(NativeTextfieldViewsTest, TouchScrubbingSelection) { | 1890 TEST_F(TextfieldTest, TouchScrubbingSelection) { |
1925 InitTextfield(Textfield::STYLE_DEFAULT); | 1891 InitTextfield(Textfield::STYLE_DEFAULT); |
1926 textfield_->SetText(ASCIIToUTF16("hello world")); | 1892 textfield_->SetText(ASCIIToUTF16("hello world")); |
1927 EXPECT_FALSE(GetTouchSelectionController()); | 1893 EXPECT_FALSE(GetTouchSelectionController()); |
1928 | 1894 |
1929 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); | 1895 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
1930 | 1896 |
1931 // Simulate touch-scrubbing. | 1897 // Simulate touch-scrubbing. |
1932 int scrubbing_start = GetCursorPositionX(1); | 1898 int scrubbing_start = GetCursorPositionX(1); |
1933 int scrubbing_end = GetCursorPositionX(6); | 1899 int scrubbing_end = GetCursorPositionX(6); |
1934 | 1900 |
1935 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0, | 1901 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0, |
1936 0.0f, 0.0f); | 1902 0.0f, 0.0f); |
1937 textfield_view_->OnGestureEvent(&tap_down); | 1903 textfield_->OnGestureEvent(&tap_down); |
1938 | 1904 |
1939 GestureEventForTest tap_cancel(ui::ET_GESTURE_TAP_CANCEL, scrubbing_start, 0, | 1905 GestureEventForTest tap_cancel(ui::ET_GESTURE_TAP_CANCEL, scrubbing_start, 0, |
1940 0.0f, 0.0f); | 1906 0.0f, 0.0f); |
1941 textfield_view_->OnGestureEvent(&tap_cancel); | 1907 textfield_->OnGestureEvent(&tap_cancel); |
1942 | 1908 |
1943 GestureEventForTest scroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, scrubbing_start, | 1909 GestureEventForTest scroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, scrubbing_start, |
1944 0, 0.0f, 0.0f); | 1910 0, 0.0f, 0.0f); |
1945 textfield_view_->OnGestureEvent(&scroll_begin); | 1911 textfield_->OnGestureEvent(&scroll_begin); |
1946 | 1912 |
1947 GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, scrubbing_end, | 1913 GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, scrubbing_end, |
1948 0, scrubbing_end - scrubbing_start, 0.0f); | 1914 0, scrubbing_end - scrubbing_start, 0.0f); |
1949 textfield_view_->OnGestureEvent(&scroll_update); | 1915 textfield_->OnGestureEvent(&scroll_update); |
1950 | 1916 |
1951 GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, scrubbing_end, 0, | 1917 GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, scrubbing_end, 0, |
1952 0.0f, 0.0f); | 1918 0.0f, 0.0f); |
1953 textfield_view_->OnGestureEvent(&scroll_end); | 1919 textfield_->OnGestureEvent(&scroll_end); |
1954 | 1920 |
1955 GestureEventForTest end(ui::ET_GESTURE_END, scrubbing_end, 0, 0.0f, 0.0f); | 1921 GestureEventForTest end(ui::ET_GESTURE_END, scrubbing_end, 0, 0.0f, 0.0f); |
1956 textfield_view_->OnGestureEvent(&end); | 1922 textfield_->OnGestureEvent(&end); |
1957 | 1923 |
1958 // In the end, part of text should have been selected and handles should have | 1924 // In the end, part of text should have been selected and handles should have |
1959 // appeared. | 1925 // appeared. |
1960 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); | 1926 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); |
1961 EXPECT_TRUE(GetTouchSelectionController()); | 1927 EXPECT_TRUE(GetTouchSelectionController()); |
1962 } | 1928 } |
1963 #endif | 1929 #endif |
1964 | 1930 |
1965 // Long_Press gesture in NativeTextfieldViews can initiate a drag and drop now. | 1931 // Long_Press gesture in Textfield can initiate a drag and drop now. |
1966 TEST_F(NativeTextfieldViewsTest, TestLongPressInitiatesDragDrop) { | 1932 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { |
1967 InitTextfield(Textfield::STYLE_DEFAULT); | 1933 InitTextfield(Textfield::STYLE_DEFAULT); |
1968 textfield_->SetText(ASCIIToUTF16("Hello string world")); | 1934 textfield_->SetText(ASCIIToUTF16("Hello string world")); |
1969 | 1935 |
1970 // Ensure the textfield will provide selected text for drag data. | 1936 // Ensure the textfield will provide selected text for drag data. |
1971 textfield_->SelectRange(gfx::Range(6, 12)); | 1937 textfield_->SelectRange(gfx::Range(6, 12)); |
1972 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 1938 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
1973 | 1939 |
1974 // Enable touch-drag-drop to make long press effective. | 1940 // Enable touch-drag-drop to make long press effective. |
1975 CommandLine::ForCurrentProcess()->AppendSwitch( | 1941 CommandLine::ForCurrentProcess()->AppendSwitch( |
1976 switches::kEnableTouchDragDrop); | 1942 switches::kEnableTouchDragDrop); |
1977 | 1943 |
1978 // Create a long press event in the selected region should start a drag. | 1944 // Create a long press event in the selected region should start a drag. |
1979 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), | 1945 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), |
1980 kStringPoint.y(), 0.0f, 0.0f); | 1946 kStringPoint.y(), 0.0f, 0.0f); |
1981 textfield_view_->OnGestureEvent(&long_press); | 1947 textfield_->OnGestureEvent(&long_press); |
1982 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, | 1948 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, |
1983 kStringPoint, kStringPoint)); | 1949 kStringPoint)); |
1984 } | 1950 } |
1985 | 1951 |
1986 TEST_F(NativeTextfieldViewsTest, GetTextfieldBaseline_FontFallbackTest) { | 1952 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) { |
1987 InitTextfield(Textfield::STYLE_DEFAULT); | 1953 InitTextfield(Textfield::STYLE_DEFAULT); |
1988 textfield_->SetText(UTF8ToUTF16("abc")); | 1954 textfield_->SetText(UTF8ToUTF16("abc")); |
1989 const int old_baseline = textfield_->GetBaseline(); | 1955 const int old_baseline = textfield_->GetBaseline(); |
1990 | 1956 |
1991 // Set text which may fall back to a font which has taller baseline than | 1957 // Set text which may fall back to a font which has taller baseline than |
1992 // the default font. | 1958 // the default font. |
1993 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); | 1959 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); |
1994 const int new_baseline = textfield_->GetBaseline(); | 1960 const int new_baseline = textfield_->GetBaseline(); |
1995 | 1961 |
1996 // Regardless of the text, the baseline must be the same. | 1962 // Regardless of the text, the baseline must be the same. |
1997 EXPECT_EQ(new_baseline, old_baseline); | 1963 EXPECT_EQ(new_baseline, old_baseline); |
1998 } | 1964 } |
1999 | 1965 |
2000 } // namespace views | 1966 } // namespace views |
OLD | NEW |