OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/textfield/textfield.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 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 #define EXPECT_STR_EQ(ascii, utf16) EXPECT_EQ(ASCIIToUTF16(ascii), utf16) | 50 #define EXPECT_STR_EQ(ascii, utf16) EXPECT_EQ(ASCIIToUTF16(ascii), utf16) |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 const base::char16 kHebrewLetterSamekh = 0x05E1; | 54 const base::char16 kHebrewLetterSamekh = 0x05E1; |
55 | 55 |
56 // A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults. | 56 // A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults. |
57 class TestTextfield : public views::Textfield { | 57 class TestTextfield : public views::Textfield { |
58 public: | 58 public: |
59 explicit TestTextfield(StyleFlags style) | 59 TestTextfield() : Textfield(), key_handled_(false), key_received_(false) {} |
60 : Textfield(style), | |
61 key_handled_(false), | |
62 key_received_(false) { | |
63 } | |
64 | 60 |
65 virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE { | 61 virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE { |
66 key_received_ = true; | 62 key_received_ = true; |
67 key_handled_ = views::Textfield::OnKeyPressed(e); | 63 key_handled_ = views::Textfield::OnKeyPressed(e); |
68 return key_handled_; | 64 return key_handled_; |
69 } | 65 } |
70 | 66 |
71 virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE { | 67 virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE { |
72 key_received_ = true; | 68 key_received_ = true; |
73 key_handled_ = views::Textfield::OnKeyReleased(e); | 69 key_handled_ = views::Textfield::OnKeyReleased(e); |
74 return key_handled_; | 70 return key_handled_; |
75 } | 71 } |
76 | 72 |
77 bool key_handled() const { return key_handled_; } | 73 bool key_handled() const { return key_handled_; } |
78 bool key_received() const { return key_received_; } | 74 bool key_received() const { return key_received_; } |
79 | 75 |
80 void clear() { key_received_ = key_handled_ = false; } | 76 void clear() { key_received_ = key_handled_ = false; } |
81 | 77 |
82 bool focusable() const { return View::focusable(); } | |
83 | |
84 private: | 78 private: |
85 bool key_handled_; | 79 bool key_handled_; |
86 bool key_received_; | 80 bool key_received_; |
87 | 81 |
88 DISALLOW_COPY_AND_ASSIGN(TestTextfield); | 82 DISALLOW_COPY_AND_ASSIGN(TestTextfield); |
89 }; | 83 }; |
90 | 84 |
91 // A helper class for use with ui::TextInputClient::GetTextFromRange(). | 85 // A helper class for use with ui::TextInputClient::GetTextFromRange(). |
92 class GetTextHelper { | 86 class GetTextHelper { |
93 public: | 87 public: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 151 } |
158 | 152 |
159 virtual void OnBeforeUserAction(Textfield* sender) OVERRIDE { | 153 virtual void OnBeforeUserAction(Textfield* sender) OVERRIDE { |
160 ++on_before_user_action_; | 154 ++on_before_user_action_; |
161 } | 155 } |
162 | 156 |
163 virtual void OnAfterUserAction(Textfield* sender) OVERRIDE { | 157 virtual void OnAfterUserAction(Textfield* sender) OVERRIDE { |
164 ++on_after_user_action_; | 158 ++on_after_user_action_; |
165 } | 159 } |
166 | 160 |
167 void InitTextfield(Textfield::StyleFlags style) { | 161 void InitTextfield() { |
168 InitTextfields(style, 1); | 162 InitTextfields(1); |
169 } | 163 } |
170 | 164 |
171 void InitTextfields(Textfield::StyleFlags style, int count) { | 165 void InitTextfields(int count) { |
172 ASSERT_FALSE(textfield_); | 166 ASSERT_FALSE(textfield_); |
173 textfield_ = new TestTextfield(style); | 167 textfield_ = new TestTextfield(); |
174 textfield_->SetController(this); | 168 textfield_->set_controller(this); |
175 widget_ = new Widget(); | 169 widget_ = new Widget(); |
176 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 170 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
177 params.bounds = gfx::Rect(100, 100, 100, 100); | 171 params.bounds = gfx::Rect(100, 100, 100, 100); |
178 widget_->Init(params); | 172 widget_->Init(params); |
179 View* container = new View(); | 173 View* container = new View(); |
180 widget_->SetContentsView(container); | 174 widget_->SetContentsView(container); |
181 container->AddChildView(textfield_); | 175 container->AddChildView(textfield_); |
182 textfield_->SetBoundsRect(params.bounds); | 176 textfield_->SetBoundsRect(params.bounds); |
183 textfield_->set_id(1); | 177 textfield_->set_id(1); |
184 | 178 |
185 for (int i = 1; i < count; i++) { | 179 for (int i = 1; i < count; i++) { |
186 Textfield* textfield = new Textfield(style); | 180 Textfield* textfield = new Textfield(); |
187 container->AddChildView(textfield); | 181 container->AddChildView(textfield); |
188 textfield->set_id(i + 1); | 182 textfield->set_id(i + 1); |
189 } | 183 } |
190 | 184 |
191 model_ = textfield_->model_.get(); | 185 model_ = textfield_->model_.get(); |
192 model_->ClearEditHistory(); | 186 model_->ClearEditHistory(); |
193 | 187 |
194 input_method_ = new MockInputMethod(); | 188 input_method_ = new MockInputMethod(); |
195 widget_->ReplaceInputMethod(input_method_); | 189 widget_->ReplaceInputMethod(input_method_); |
196 | 190 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 int on_before_user_action_; | 332 int on_before_user_action_; |
339 | 333 |
340 // Indicates how many times OnAfterUserAction() is called. | 334 // Indicates how many times OnAfterUserAction() is called. |
341 int on_after_user_action_; | 335 int on_after_user_action_; |
342 | 336 |
343 private: | 337 private: |
344 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); | 338 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); |
345 }; | 339 }; |
346 | 340 |
347 TEST_F(TextfieldTest, ModelChangesTest) { | 341 TEST_F(TextfieldTest, ModelChangesTest) { |
348 InitTextfield(Textfield::STYLE_DEFAULT); | 342 InitTextfield(); |
349 | 343 |
350 // TextfieldController::ContentsChanged() shouldn't be called when changing | 344 // TextfieldController::ContentsChanged() shouldn't be called when changing |
351 // text programmatically. | 345 // text programmatically. |
352 last_contents_.clear(); | 346 last_contents_.clear(); |
353 textfield_->SetText(ASCIIToUTF16("this is")); | 347 textfield_->SetText(ASCIIToUTF16("this is")); |
354 | 348 |
355 EXPECT_STR_EQ("this is", model_->text()); | 349 EXPECT_STR_EQ("this is", model_->text()); |
356 EXPECT_STR_EQ("this is", textfield_->text()); | 350 EXPECT_STR_EQ("this is", textfield_->text()); |
357 EXPECT_TRUE(last_contents_.empty()); | 351 EXPECT_TRUE(last_contents_.empty()); |
358 | 352 |
359 textfield_->AppendText(ASCIIToUTF16(" a test")); | 353 textfield_->AppendText(ASCIIToUTF16(" a test")); |
360 EXPECT_STR_EQ("this is a test", model_->text()); | 354 EXPECT_STR_EQ("this is a test", model_->text()); |
361 EXPECT_STR_EQ("this is a test", textfield_->text()); | 355 EXPECT_STR_EQ("this is a test", textfield_->text()); |
362 EXPECT_TRUE(last_contents_.empty()); | 356 EXPECT_TRUE(last_contents_.empty()); |
363 | 357 |
364 EXPECT_EQ(base::string16(), textfield_->GetSelectedText()); | 358 EXPECT_EQ(base::string16(), textfield_->GetSelectedText()); |
365 textfield_->SelectAll(false); | 359 textfield_->SelectAll(false); |
366 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); | 360 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); |
367 EXPECT_TRUE(last_contents_.empty()); | 361 EXPECT_TRUE(last_contents_.empty()); |
368 } | 362 } |
369 | 363 |
370 TEST_F(TextfieldTest, ModelChangesTestLowerCase) { | |
371 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE. | |
372 InitTextfield(Textfield::STYLE_LOWERCASE); | |
373 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | |
374 | |
375 last_contents_.clear(); | |
376 textfield_->SetText(ASCIIToUTF16("THIS IS")); | |
377 EXPECT_EQ(7U, textfield_->GetCursorPosition()); | |
378 | |
379 EXPECT_STR_EQ("this is", textfield_->text()); | |
380 EXPECT_TRUE(last_contents_.empty()); | |
381 | |
382 textfield_->AppendText(ASCIIToUTF16(" A TEST")); | |
383 EXPECT_EQ(7U, textfield_->GetCursorPosition()); | |
384 EXPECT_STR_EQ("this is a test", textfield_->text()); | |
385 | |
386 EXPECT_TRUE(last_contents_.empty()); | |
387 } | |
388 | |
389 TEST_F(TextfieldTest, ModelChangesTestLowerCaseI18n) { | |
390 // Check if lower case conversion works for non-ASCII characters. | |
391 InitTextfield(Textfield::STYLE_LOWERCASE); | |
392 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | |
393 | |
394 last_contents_.clear(); | |
395 // Zenkaku Japanese "ABCabc" | |
396 textfield_->SetText(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43")); | |
397 EXPECT_EQ(6U, textfield_->GetCursorPosition()); | |
398 // Zenkaku Japanese "abcabc" | |
399 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"), | |
400 textfield_->text()); | |
401 EXPECT_TRUE(last_contents_.empty()); | |
402 | |
403 // Zenkaku Japanese "XYZxyz" | |
404 textfield_->AppendText(WideToUTF16(L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A")); | |
405 EXPECT_EQ(6U, textfield_->GetCursorPosition()); | |
406 // Zenkaku Japanese "abcabcxyzxyz" | |
407 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43" | |
408 L"\xFF58\xFF59\xFF5A\xFF58\xFF59\xFF5A"), | |
409 textfield_->text()); | |
410 EXPECT_TRUE(last_contents_.empty()); | |
411 } | |
412 | |
413 TEST_F(TextfieldTest, ModelChangesTestLowerCaseWithLocale) { | |
414 // Check if lower case conversion honors locale properly. | |
415 std::string locale = l10n_util::GetApplicationLocale(""); | |
416 base::i18n::SetICUDefaultLocale("tr"); | |
417 | |
418 InitTextfield(Textfield::STYLE_LOWERCASE); | |
419 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | |
420 | |
421 last_contents_.clear(); | |
422 // Turkish 'I' should be converted to dotless 'i' (U+0131). | |
423 textfield_->SetText(WideToUTF16(L"I")); | |
424 EXPECT_EQ(1U, textfield_->GetCursorPosition()); | |
425 EXPECT_EQ(WideToUTF16(L"\x0131"), textfield_->text()); | |
426 EXPECT_TRUE(last_contents_.empty()); | |
427 | |
428 base::i18n::SetICUDefaultLocale(locale); | |
429 | |
430 // On default (en) locale, 'I' should be converted to 'i'. | |
431 textfield_->SetText(WideToUTF16(L"I")); | |
432 EXPECT_EQ(1U, textfield_->GetCursorPosition()); | |
433 EXPECT_EQ(WideToUTF16(L"i"), textfield_->text()); | |
434 EXPECT_TRUE(last_contents_.empty()); | |
435 } | |
436 | |
437 TEST_F(TextfieldTest, KeyTest) { | 364 TEST_F(TextfieldTest, KeyTest) { |
438 InitTextfield(Textfield::STYLE_DEFAULT); | 365 InitTextfield(); |
439 // Event flags: key, alt, shift, ctrl, caps-lock. | 366 // Event flags: key, alt, shift, ctrl, caps-lock. |
440 SendKeyEvent(ui::VKEY_T, false, true, false, false); | 367 SendKeyEvent(ui::VKEY_T, false, true, false, false); |
441 SendKeyEvent(ui::VKEY_E, false, false, false, false); | 368 SendKeyEvent(ui::VKEY_E, false, false, false, false); |
442 SendKeyEvent(ui::VKEY_X, false, true, false, true); | 369 SendKeyEvent(ui::VKEY_X, false, true, false, true); |
443 SendKeyEvent(ui::VKEY_T, false, false, false, true); | 370 SendKeyEvent(ui::VKEY_T, false, false, false, true); |
444 SendKeyEvent(ui::VKEY_1, false, true, false, false); | 371 SendKeyEvent(ui::VKEY_1, false, true, false, false); |
445 SendKeyEvent(ui::VKEY_1, false, false, false, false); | 372 SendKeyEvent(ui::VKEY_1, false, false, false, false); |
446 SendKeyEvent(ui::VKEY_1, false, true, false, true); | 373 SendKeyEvent(ui::VKEY_1, false, true, false, true); |
447 SendKeyEvent(ui::VKEY_1, false, false, false, true); | 374 SendKeyEvent(ui::VKEY_1, false, false, false, true); |
448 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); | 375 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); |
449 } | 376 } |
450 | 377 |
451 TEST_F(TextfieldTest, ControlAndSelectTest) { | 378 TEST_F(TextfieldTest, ControlAndSelectTest) { |
452 // Insert a test string in a textfield. | 379 // Insert a test string in a textfield. |
453 InitTextfield(Textfield::STYLE_DEFAULT); | 380 InitTextfield(); |
454 textfield_->SetText(ASCIIToUTF16("one two three")); | 381 textfield_->SetText(ASCIIToUTF16("one two three")); |
455 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); | 382 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); |
456 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 383 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
457 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 384 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
458 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 385 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
459 | 386 |
460 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); | 387 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); |
461 | 388 |
462 // Test word select. | 389 // Test word select. |
463 SendKeyEvent(ui::VKEY_RIGHT, true, true); | 390 SendKeyEvent(ui::VKEY_RIGHT, true, true); |
(...skipping 14 matching lines...) Expand all Loading... |
478 EXPECT_STR_EQ("ZERO two three", textfield_->text()); | 405 EXPECT_STR_EQ("ZERO two three", textfield_->text()); |
479 | 406 |
480 SendKeyEvent(ui::VKEY_END, true, false); | 407 SendKeyEvent(ui::VKEY_END, true, false); |
481 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); | 408 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); |
482 SendKeyEvent(ui::VKEY_HOME, true, false); | 409 SendKeyEvent(ui::VKEY_HOME, true, false); |
483 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); | 410 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); |
484 } | 411 } |
485 | 412 |
486 TEST_F(TextfieldTest, InsertionDeletionTest) { | 413 TEST_F(TextfieldTest, InsertionDeletionTest) { |
487 // Insert a test string in a textfield. | 414 // Insert a test string in a textfield. |
488 InitTextfield(Textfield::STYLE_DEFAULT); | 415 InitTextfield(); |
489 for (size_t i = 0; i < 10; i++) | 416 for (size_t i = 0; i < 10; i++) |
490 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); | 417 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); |
491 EXPECT_STR_EQ("abcdefghij", textfield_->text()); | 418 EXPECT_STR_EQ("abcdefghij", textfield_->text()); |
492 | 419 |
493 // Test the delete and backspace keys. | 420 // Test the delete and backspace keys. |
494 textfield_->SelectRange(gfx::Range(5)); | 421 textfield_->SelectRange(gfx::Range(5)); |
495 for (int i = 0; i < 3; i++) | 422 for (int i = 0; i < 3; i++) |
496 SendKeyEvent(ui::VKEY_BACK); | 423 SendKeyEvent(ui::VKEY_BACK); |
497 EXPECT_STR_EQ("abfghij", textfield_->text()); | 424 EXPECT_STR_EQ("abfghij", textfield_->text()); |
498 for (int i = 0; i < 3; i++) | 425 for (int i = 0; i < 3; i++) |
(...skipping 30 matching lines...) Expand all Loading... |
529 SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); | 456 SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); |
530 SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); | 457 SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); |
531 #if defined(OS_LINUX) | 458 #if defined(OS_LINUX) |
532 EXPECT_STR_EQ(" two", textfield_->text()); | 459 EXPECT_STR_EQ(" two", textfield_->text()); |
533 #else | 460 #else |
534 EXPECT_STR_EQ(" two three four", textfield_->text()); | 461 EXPECT_STR_EQ(" two three four", textfield_->text()); |
535 #endif | 462 #endif |
536 } | 463 } |
537 | 464 |
538 TEST_F(TextfieldTest, PasswordTest) { | 465 TEST_F(TextfieldTest, PasswordTest) { |
539 InitTextfield(Textfield::STYLE_OBSCURED); | 466 InitTextfield(); |
| 467 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
540 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 468 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
541 EXPECT_TRUE(textfield_->enabled()); | 469 EXPECT_TRUE(textfield_->enabled()); |
542 EXPECT_TRUE(textfield_->focusable()); | 470 EXPECT_TRUE(textfield_->IsFocusable()); |
543 | 471 |
544 last_contents_.clear(); | 472 last_contents_.clear(); |
545 textfield_->SetText(ASCIIToUTF16("password")); | 473 textfield_->SetText(ASCIIToUTF16("password")); |
546 // Ensure text() and the callback returns the actual text instead of "*". | 474 // Ensure text() and the callback returns the actual text instead of "*". |
547 EXPECT_STR_EQ("password", textfield_->text()); | 475 EXPECT_STR_EQ("password", textfield_->text()); |
548 EXPECT_TRUE(last_contents_.empty()); | 476 EXPECT_TRUE(last_contents_.empty()); |
549 model_->SelectAll(false); | 477 model_->SelectAll(false); |
550 SetClipboardText("foo"); | 478 SetClipboardText("foo"); |
551 | 479 |
552 // Cut and copy should be disabled. | 480 // Cut and copy should be disabled. |
(...skipping 12 matching lines...) Expand all Loading... |
565 | 493 |
566 // Paste should work normally. | 494 // Paste should work normally. |
567 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); | 495 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
568 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); | 496 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
569 SendKeyEvent(ui::VKEY_V, false, true); | 497 SendKeyEvent(ui::VKEY_V, false, true); |
570 SendKeyEvent(ui::VKEY_INSERT, true, false); | 498 SendKeyEvent(ui::VKEY_INSERT, true, false); |
571 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); | 499 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); |
572 EXPECT_STR_EQ("foofoofoo", textfield_->text()); | 500 EXPECT_STR_EQ("foofoofoo", textfield_->text()); |
573 } | 501 } |
574 | 502 |
575 TEST_F(TextfieldTest, InputTypeSetsObscured) { | 503 TEST_F(TextfieldTest, TextInputType) { |
576 InitTextfield(Textfield::STYLE_DEFAULT); | 504 InitTextfield(); |
577 | 505 |
578 // Defaults to TEXT | 506 // Defaults to TEXT |
579 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 507 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
580 | |
581 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. | |
582 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | |
583 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | |
584 EXPECT_TRUE(textfield_->IsObscured()); | |
585 } | |
586 | |
587 TEST_F(TextfieldTest, ObscuredSetsInputType) { | |
588 InitTextfield(Textfield::STYLE_DEFAULT); | |
589 | |
590 // Defaults to TEXT | |
591 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
592 | |
593 textfield_->SetObscured(true); | |
594 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | |
595 | |
596 textfield_->SetObscured(false); | |
597 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
598 } | |
599 | |
600 TEST_F(TextfieldTest, TextInputType) { | |
601 InitTextfield(Textfield::STYLE_DEFAULT); | |
602 | |
603 // Defaults to TEXT | |
604 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | |
605 | 508 |
606 // And can be set. | 509 // And can be set. |
607 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 510 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
608 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); | 511 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); |
| 512 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 513 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
609 | 514 |
610 // Readonly textfields have type NONE | 515 // Readonly textfields have type NONE |
611 textfield_->SetReadOnly(true); | 516 textfield_->SetReadOnly(true); |
612 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 517 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); |
613 | 518 |
614 textfield_->SetReadOnly(false); | 519 textfield_->SetReadOnly(false); |
615 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); | 520 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
616 | 521 |
617 // As do disabled textfields | 522 // As do disabled textfields |
618 textfield_->SetEnabled(false); | 523 textfield_->SetEnabled(false); |
619 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 524 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); |
| 525 |
| 526 textfield_->SetEnabled(true); |
| 527 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
620 } | 528 } |
621 | 529 |
622 TEST_F(TextfieldTest, OnKeyPressReturnValueTest) { | 530 TEST_F(TextfieldTest, OnKeyPressReturnValueTest) { |
623 InitTextfield(Textfield::STYLE_DEFAULT); | 531 InitTextfield(); |
624 | 532 |
625 // Character keys will be handled by input method. | 533 // Character keys will be handled by input method. |
626 SendKeyEvent(ui::VKEY_A); | 534 SendKeyEvent(ui::VKEY_A); |
627 EXPECT_TRUE(textfield_->key_received()); | 535 EXPECT_TRUE(textfield_->key_received()); |
628 EXPECT_FALSE(textfield_->key_handled()); | 536 EXPECT_FALSE(textfield_->key_handled()); |
629 textfield_->clear(); | 537 textfield_->clear(); |
630 | 538 |
631 // Home will be handled. | 539 // Home will be handled. |
632 SendKeyEvent(ui::VKEY_HOME); | 540 SendKeyEvent(ui::VKEY_HOME); |
633 EXPECT_TRUE(textfield_->key_received()); | 541 EXPECT_TRUE(textfield_->key_received()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 textfield_->clear(); | 584 textfield_->clear(); |
677 | 585 |
678 // Now left key should not be handled. | 586 // Now left key should not be handled. |
679 SendKeyEvent(ui::VKEY_LEFT); | 587 SendKeyEvent(ui::VKEY_LEFT); |
680 EXPECT_TRUE(textfield_->key_received()); | 588 EXPECT_TRUE(textfield_->key_received()); |
681 EXPECT_FALSE(textfield_->key_handled()); | 589 EXPECT_FALSE(textfield_->key_handled()); |
682 textfield_->clear(); | 590 textfield_->clear(); |
683 } | 591 } |
684 | 592 |
685 TEST_F(TextfieldTest, CursorMovement) { | 593 TEST_F(TextfieldTest, CursorMovement) { |
686 InitTextfield(Textfield::STYLE_DEFAULT); | 594 InitTextfield(); |
687 | 595 |
688 // Test with trailing whitespace. | 596 // Test with trailing whitespace. |
689 textfield_->SetText(ASCIIToUTF16("one two hre ")); | 597 textfield_->SetText(ASCIIToUTF16("one two hre ")); |
690 | 598 |
691 // Send the cursor at the end. | 599 // Send the cursor at the end. |
692 SendKeyEvent(ui::VKEY_END); | 600 SendKeyEvent(ui::VKEY_END); |
693 | 601 |
694 // Ctrl+Left should move the cursor just before the last word. | 602 // Ctrl+Left should move the cursor just before the last word. |
695 SendKeyEvent(ui::VKEY_LEFT, false, true); | 603 SendKeyEvent(ui::VKEY_LEFT, false, true); |
696 SendKeyEvent(ui::VKEY_T); | 604 SendKeyEvent(ui::VKEY_T); |
(...skipping 29 matching lines...) Expand all Loading... |
726 // Ctrl+Left to move the cursor to the beginning of the first word. | 634 // Ctrl+Left to move the cursor to the beginning of the first word. |
727 SendKeyEvent(ui::VKEY_LEFT, false, true); | 635 SendKeyEvent(ui::VKEY_LEFT, false, true); |
728 // Ctrl+Left again should move the cursor back to the very beginning. | 636 // Ctrl+Left again should move the cursor back to the very beginning. |
729 SendKeyEvent(ui::VKEY_LEFT, false, true); | 637 SendKeyEvent(ui::VKEY_LEFT, false, true); |
730 SendKeyEvent(ui::VKEY_DELETE); | 638 SendKeyEvent(ui::VKEY_DELETE); |
731 EXPECT_STR_EQ("one two", textfield_->text()); | 639 EXPECT_STR_EQ("one two", textfield_->text()); |
732 EXPECT_STR_EQ("one two", last_contents_); | 640 EXPECT_STR_EQ("one two", last_contents_); |
733 } | 641 } |
734 | 642 |
735 TEST_F(TextfieldTest, FocusTraversalTest) { | 643 TEST_F(TextfieldTest, FocusTraversalTest) { |
736 InitTextfields(Textfield::STYLE_DEFAULT, 3); | 644 InitTextfields(3); |
737 textfield_->RequestFocus(); | 645 textfield_->RequestFocus(); |
738 | 646 |
739 EXPECT_EQ(1, GetFocusedView()->id()); | 647 EXPECT_EQ(1, GetFocusedView()->id()); |
740 widget_->GetFocusManager()->AdvanceFocus(false); | 648 widget_->GetFocusManager()->AdvanceFocus(false); |
741 EXPECT_EQ(2, GetFocusedView()->id()); | 649 EXPECT_EQ(2, GetFocusedView()->id()); |
742 widget_->GetFocusManager()->AdvanceFocus(false); | 650 widget_->GetFocusManager()->AdvanceFocus(false); |
743 EXPECT_EQ(3, GetFocusedView()->id()); | 651 EXPECT_EQ(3, GetFocusedView()->id()); |
744 // Cycle back to the first textfield. | 652 // Cycle back to the first textfield. |
745 widget_->GetFocusManager()->AdvanceFocus(false); | 653 widget_->GetFocusManager()->AdvanceFocus(false); |
746 EXPECT_EQ(1, GetFocusedView()->id()); | 654 EXPECT_EQ(1, GetFocusedView()->id()); |
(...skipping 15 matching lines...) Expand all Loading... |
762 // Test if clicking on textfield view sets the focus to textfield_. | 670 // Test if clicking on textfield view sets the focus to textfield_. |
763 widget_->GetFocusManager()->AdvanceFocus(true); | 671 widget_->GetFocusManager()->AdvanceFocus(true); |
764 EXPECT_EQ(3, GetFocusedView()->id()); | 672 EXPECT_EQ(3, GetFocusedView()->id()); |
765 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 673 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
766 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 674 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
767 textfield_->OnMousePressed(click); | 675 textfield_->OnMousePressed(click); |
768 EXPECT_EQ(1, GetFocusedView()->id()); | 676 EXPECT_EQ(1, GetFocusedView()->id()); |
769 } | 677 } |
770 | 678 |
771 TEST_F(TextfieldTest, ContextMenuDisplayTest) { | 679 TEST_F(TextfieldTest, ContextMenuDisplayTest) { |
772 InitTextfield(Textfield::STYLE_DEFAULT); | 680 InitTextfield(); |
773 EXPECT_TRUE(textfield_->context_menu_controller()); | 681 EXPECT_TRUE(textfield_->context_menu_controller()); |
774 textfield_->SetText(ASCIIToUTF16("hello world")); | 682 textfield_->SetText(ASCIIToUTF16("hello world")); |
775 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); | 683 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); |
776 textfield_->ClearEditHistory(); | 684 textfield_->ClearEditHistory(); |
777 EXPECT_TRUE(GetContextMenuModel()); | 685 EXPECT_TRUE(GetContextMenuModel()); |
778 VerifyTextfieldContextMenuContents(false, false, GetContextMenuModel()); | 686 VerifyTextfieldContextMenuContents(false, false, GetContextMenuModel()); |
779 | 687 |
780 textfield_->SelectAll(false); | 688 textfield_->SelectAll(false); |
781 VerifyTextfieldContextMenuContents(true, false, GetContextMenuModel()); | 689 VerifyTextfieldContextMenuContents(true, false, GetContextMenuModel()); |
782 | 690 |
783 SendKeyEvent(ui::VKEY_T); | 691 SendKeyEvent(ui::VKEY_T); |
784 VerifyTextfieldContextMenuContents(false, true, GetContextMenuModel()); | 692 VerifyTextfieldContextMenuContents(false, true, GetContextMenuModel()); |
785 | 693 |
786 textfield_->SelectAll(false); | 694 textfield_->SelectAll(false); |
787 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); | 695 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); |
788 | 696 |
789 // Exercise the "paste enabled?" check in the verifier. | 697 // Exercise the "paste enabled?" check in the verifier. |
790 SetClipboardText("Test"); | 698 SetClipboardText("Test"); |
791 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); | 699 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); |
792 } | 700 } |
793 | 701 |
794 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { | 702 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { |
795 InitTextfield(Textfield::STYLE_DEFAULT); | 703 InitTextfield(); |
796 textfield_->SetText(ASCIIToUTF16("hello world")); | 704 textfield_->SetText(ASCIIToUTF16("hello world")); |
797 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 705 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
798 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 706 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
799 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 707 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
800 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 708 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
801 ui::MouseEvent double_click( | 709 ui::MouseEvent double_click( |
802 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 710 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
803 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, | 711 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, |
804 ui::EF_LEFT_MOUSE_BUTTON); | 712 ui::EF_LEFT_MOUSE_BUTTON); |
805 | 713 |
(...skipping 10 matching lines...) Expand all Loading... |
816 textfield_->OnMouseReleased(release); | 724 textfield_->OnMouseReleased(release); |
817 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); | 725 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); |
818 | 726 |
819 // Another click should reset back to double click. | 727 // Another click should reset back to double click. |
820 textfield_->OnMousePressed(click); | 728 textfield_->OnMousePressed(click); |
821 textfield_->OnMouseReleased(release); | 729 textfield_->OnMouseReleased(release); |
822 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 730 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
823 } | 731 } |
824 | 732 |
825 TEST_F(TextfieldTest, DragToSelect) { | 733 TEST_F(TextfieldTest, DragToSelect) { |
826 InitTextfield(Textfield::STYLE_DEFAULT); | 734 InitTextfield(); |
827 textfield_->SetText(ASCIIToUTF16("hello world")); | 735 textfield_->SetText(ASCIIToUTF16("hello world")); |
828 const int kStart = GetCursorPositionX(5); | 736 const int kStart = GetCursorPositionX(5); |
829 const int kEnd = 500; | 737 const int kEnd = 500; |
830 gfx::Point start_point(kStart, 0); | 738 gfx::Point start_point(kStart, 0); |
831 gfx::Point end_point(kEnd, 0); | 739 gfx::Point end_point(kEnd, 0); |
832 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, | 740 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, |
833 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 741 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
834 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, | 742 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, |
835 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 743 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
836 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), | 744 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), |
(...skipping 17 matching lines...) Expand all Loading... |
854 EXPECT_EQ(text_right, textfield_->GetSelectedText()); | 762 EXPECT_EQ(text_right, textfield_->GetSelectedText()); |
855 // Check that dragging from beyond the text length works too. | 763 // Check that dragging from beyond the text length works too. |
856 textfield_->OnMousePressed(click_b); | 764 textfield_->OnMousePressed(click_b); |
857 textfield_->OnMouseDragged(drag_left); | 765 textfield_->OnMouseDragged(drag_left); |
858 textfield_->OnMouseReleased(release); | 766 textfield_->OnMouseReleased(release); |
859 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); | 767 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); |
860 } | 768 } |
861 | 769 |
862 #if defined(OS_WIN) | 770 #if defined(OS_WIN) |
863 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { | 771 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { |
864 InitTextfield(Textfield::STYLE_DEFAULT); | 772 InitTextfield(); |
865 textfield_->SetText(ASCIIToUTF16("hello world")); | 773 textfield_->SetText(ASCIIToUTF16("hello world")); |
866 | 774 |
867 ui::OSExchangeData data; | 775 ui::OSExchangeData data; |
868 base::string16 string(ASCIIToUTF16("string ")); | 776 base::string16 string(ASCIIToUTF16("string ")); |
869 data.SetString(string); | 777 data.SetString(string); |
870 int formats = 0; | 778 int formats = 0; |
871 std::set<OSExchangeData::CustomFormat> custom_formats; | 779 std::set<OSExchangeData::CustomFormat> custom_formats; |
872 | 780 |
873 // Ensure that disabled textfields do not accept drops. | 781 // Ensure that disabled textfields do not accept drops. |
874 textfield_->SetEnabled(false); | 782 textfield_->SetEnabled(false); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 bad_data.SetFileContents(base::FilePath(L"x"), "x"); | 816 bad_data.SetFileContents(base::FilePath(L"x"), "x"); |
909 bad_data.SetHtml(base::string16(ASCIIToUTF16("x")), GURL("x.org")); | 817 bad_data.SetHtml(base::string16(ASCIIToUTF16("x")), GURL("x.org")); |
910 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL); | 818 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL); |
911 bad_data.SetDownloadFileInfo(download); | 819 bad_data.SetDownloadFileInfo(download); |
912 #endif | 820 #endif |
913 EXPECT_FALSE(textfield_->CanDrop(bad_data)); | 821 EXPECT_FALSE(textfield_->CanDrop(bad_data)); |
914 } | 822 } |
915 #endif | 823 #endif |
916 | 824 |
917 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { | 825 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { |
918 InitTextfield(Textfield::STYLE_DEFAULT); | 826 InitTextfield(); |
919 textfield_->SetText(ASCIIToUTF16("hello string world")); | 827 textfield_->SetText(ASCIIToUTF16("hello string world")); |
920 | 828 |
921 // Ensure the textfield will provide selected text for drag data. | 829 // Ensure the textfield will provide selected text for drag data. |
922 base::string16 string; | 830 base::string16 string; |
923 ui::OSExchangeData data; | 831 ui::OSExchangeData data; |
924 const gfx::Range kStringRange(6, 12); | 832 const gfx::Range kStringRange(6, 12); |
925 textfield_->SelectRange(kStringRange); | 833 textfield_->SelectRange(kStringRange); |
926 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 834 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
927 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); | 835 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); |
928 EXPECT_TRUE(data.GetString(&string)); | 836 EXPECT_TRUE(data.GetString(&string)); |
929 EXPECT_EQ(textfield_->GetSelectedText(), string); | 837 EXPECT_EQ(textfield_->GetSelectedText(), string); |
930 | 838 |
931 // Ensure that disabled textfields do not support drag operations. | 839 // Ensure that disabled textfields do not support drag operations. |
932 textfield_->SetEnabled(false); | 840 textfield_->SetEnabled(false); |
933 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 841 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
934 textfield_->GetDragOperationsForView(NULL, kStringPoint)); | 842 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
935 textfield_->SetEnabled(true); | 843 textfield_->SetEnabled(true); |
936 // Ensure that textfields without selections do not support drag operations. | 844 // Ensure that textfields without selections do not support drag operations. |
937 textfield_->ClearSelection(); | 845 textfield_->ClearSelection(); |
938 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 846 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
939 textfield_->GetDragOperationsForView(NULL, kStringPoint)); | 847 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
940 textfield_->SelectRange(kStringRange); | 848 textfield_->SelectRange(kStringRange); |
941 // Ensure that password textfields do not support drag operations. | 849 // Ensure that password textfields do not support drag operations. |
942 textfield_->SetObscured(true); | 850 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
943 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 851 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
944 textfield_->GetDragOperationsForView(NULL, kStringPoint)); | 852 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
945 textfield_->SetObscured(false); | 853 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); |
946 // Ensure that textfields only initiate drag operations inside the selection. | 854 // Ensure that textfields only initiate drag operations inside the selection. |
947 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, | 855 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, |
948 ui::EF_LEFT_MOUSE_BUTTON, | 856 ui::EF_LEFT_MOUSE_BUTTON, |
949 ui::EF_LEFT_MOUSE_BUTTON); | 857 ui::EF_LEFT_MOUSE_BUTTON); |
950 textfield_->OnMousePressed(press_event); | 858 textfield_->OnMousePressed(press_event); |
951 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 859 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
952 textfield_->GetDragOperationsForView(NULL, gfx::Point())); | 860 textfield_->GetDragOperationsForView(NULL, gfx::Point())); |
953 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(), | 861 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(), |
954 gfx::Point())); | 862 gfx::Point())); |
955 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, | 863 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, |
956 textfield_->GetDragOperationsForView(NULL, kStringPoint)); | 864 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
957 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, | 865 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, |
958 gfx::Point())); | 866 gfx::Point())); |
959 // Ensure that textfields support local moves. | 867 // Ensure that textfields support local moves. |
960 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 868 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
961 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); | 869 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); |
962 } | 870 } |
963 | 871 |
964 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { | 872 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { |
965 InitTextfield(Textfield::STYLE_DEFAULT); | 873 InitTextfield(); |
966 textfield_->SetText(ASCIIToUTF16("hello world")); | 874 textfield_->SetText(ASCIIToUTF16("hello world")); |
967 | 875 |
968 base::string16 string; | 876 base::string16 string; |
969 ui::OSExchangeData data; | 877 ui::OSExchangeData data; |
970 int formats = 0; | 878 int formats = 0; |
971 int operations = 0; | 879 int operations = 0; |
972 std::set<OSExchangeData::CustomFormat> custom_formats; | 880 std::set<OSExchangeData::CustomFormat> custom_formats; |
973 | 881 |
974 // Start dragging "ello". | 882 // Start dragging "ello". |
975 textfield_->SelectRange(gfx::Range(1, 5)); | 883 textfield_->SelectRange(gfx::Range(1, 5)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 EXPECT_STR_EQ("", textfield_->text()); | 916 EXPECT_STR_EQ("", textfield_->text()); |
1009 SendKeyEvent(ui::VKEY_Y, false, true); | 917 SendKeyEvent(ui::VKEY_Y, false, true); |
1010 EXPECT_STR_EQ("hello world", textfield_->text()); | 918 EXPECT_STR_EQ("hello world", textfield_->text()); |
1011 SendKeyEvent(ui::VKEY_Y, false, true); | 919 SendKeyEvent(ui::VKEY_Y, false, true); |
1012 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 920 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
1013 SendKeyEvent(ui::VKEY_Y, false, true); | 921 SendKeyEvent(ui::VKEY_Y, false, true); |
1014 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 922 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
1015 } | 923 } |
1016 | 924 |
1017 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { | 925 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { |
1018 InitTextfield(Textfield::STYLE_DEFAULT); | 926 InitTextfield(); |
1019 textfield_->SetText(ASCIIToUTF16("hello world")); | 927 textfield_->SetText(ASCIIToUTF16("hello world")); |
1020 | 928 |
1021 base::string16 string; | 929 base::string16 string; |
1022 ui::OSExchangeData data; | 930 ui::OSExchangeData data; |
1023 int formats = 0; | 931 int formats = 0; |
1024 int operations = 0; | 932 int operations = 0; |
1025 std::set<OSExchangeData::CustomFormat> custom_formats; | 933 std::set<OSExchangeData::CustomFormat> custom_formats; |
1026 | 934 |
1027 // Start dragging " worl". | 935 // Start dragging " worl". |
1028 textfield_->SelectRange(gfx::Range(5, 10)); | 936 textfield_->SelectRange(gfx::Range(5, 10)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 EXPECT_STR_EQ("", textfield_->text()); | 969 EXPECT_STR_EQ("", textfield_->text()); |
1062 SendKeyEvent(ui::VKEY_Y, false, true); | 970 SendKeyEvent(ui::VKEY_Y, false, true); |
1063 EXPECT_STR_EQ("hello world", textfield_->text()); | 971 EXPECT_STR_EQ("hello world", textfield_->text()); |
1064 SendKeyEvent(ui::VKEY_Y, false, true); | 972 SendKeyEvent(ui::VKEY_Y, false, true); |
1065 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 973 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
1066 SendKeyEvent(ui::VKEY_Y, false, true); | 974 SendKeyEvent(ui::VKEY_Y, false, true); |
1067 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 975 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
1068 } | 976 } |
1069 | 977 |
1070 TEST_F(TextfieldTest, DragAndDrop_Canceled) { | 978 TEST_F(TextfieldTest, DragAndDrop_Canceled) { |
1071 InitTextfield(Textfield::STYLE_DEFAULT); | 979 InitTextfield(); |
1072 textfield_->SetText(ASCIIToUTF16("hello world")); | 980 textfield_->SetText(ASCIIToUTF16("hello world")); |
1073 | 981 |
1074 // Start dragging "worl". | 982 // Start dragging "worl". |
1075 textfield_->SelectRange(gfx::Range(6, 10)); | 983 textfield_->SelectRange(gfx::Range(6, 10)); |
1076 gfx::Point point(GetCursorPositionX(8), 0); | 984 gfx::Point point(GetCursorPositionX(8), 0); |
1077 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 985 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, |
1078 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 986 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
1079 textfield_->OnMousePressed(click); | 987 textfield_->OnMousePressed(click); |
1080 ui::OSExchangeData data; | 988 ui::OSExchangeData data; |
1081 textfield_->WriteDragDataForView(NULL, click.location(), &data); | 989 textfield_->WriteDragDataForView(NULL, click.location(), &data); |
1082 EXPECT_TRUE(textfield_->CanDrop(data)); | 990 EXPECT_TRUE(textfield_->CanDrop(data)); |
1083 // Drag the text over somewhere valid, outside the current selection. | 991 // Drag the text over somewhere valid, outside the current selection. |
1084 gfx::Point drop_point(GetCursorPositionX(2), 0); | 992 gfx::Point drop_point(GetCursorPositionX(2), 0); |
1085 ui::DropTargetEvent drop(data, drop_point, drop_point, | 993 ui::DropTargetEvent drop(data, drop_point, drop_point, |
1086 ui::DragDropTypes::DRAG_MOVE); | 994 ui::DragDropTypes::DRAG_MOVE); |
1087 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); | 995 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); |
1088 // "Cancel" the drag, via move and release over the selection, and OnDragDone. | 996 // "Cancel" the drag, via move and release over the selection, and OnDragDone. |
1089 gfx::Point drag_point(GetCursorPositionX(9), 0); | 997 gfx::Point drag_point(GetCursorPositionX(9), 0); |
1090 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, | 998 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, |
1091 ui::EF_LEFT_MOUSE_BUTTON, 0); | 999 ui::EF_LEFT_MOUSE_BUTTON, 0); |
1092 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, | 1000 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, |
1093 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1001 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
1094 textfield_->OnMouseDragged(drag); | 1002 textfield_->OnMouseDragged(drag); |
1095 textfield_->OnMouseReleased(release); | 1003 textfield_->OnMouseReleased(release); |
1096 textfield_->OnDragDone(); | 1004 textfield_->OnDragDone(); |
1097 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); | 1005 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); |
1098 } | 1006 } |
1099 | 1007 |
1100 TEST_F(TextfieldTest, ReadOnlyTest) { | 1008 TEST_F(TextfieldTest, ReadOnlyTest) { |
1101 InitTextfield(Textfield::STYLE_DEFAULT); | 1009 InitTextfield(); |
1102 textfield_->SetText(ASCIIToUTF16("read only")); | 1010 textfield_->SetText(ASCIIToUTF16("read only")); |
1103 textfield_->SetReadOnly(true); | 1011 textfield_->SetReadOnly(true); |
1104 EXPECT_TRUE(textfield_->enabled()); | 1012 EXPECT_TRUE(textfield_->enabled()); |
1105 EXPECT_TRUE(textfield_->focusable()); | 1013 EXPECT_TRUE(textfield_->IsFocusable()); |
1106 | 1014 |
1107 SendKeyEvent(ui::VKEY_HOME); | 1015 SendKeyEvent(ui::VKEY_HOME); |
1108 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1016 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
1109 SendKeyEvent(ui::VKEY_END); | 1017 SendKeyEvent(ui::VKEY_END); |
1110 EXPECT_EQ(9U, textfield_->GetCursorPosition()); | 1018 EXPECT_EQ(9U, textfield_->GetCursorPosition()); |
1111 | 1019 |
1112 SendKeyEvent(ui::VKEY_LEFT, false, false); | 1020 SendKeyEvent(ui::VKEY_LEFT, false, false); |
1113 EXPECT_EQ(8U, textfield_->GetCursorPosition()); | 1021 EXPECT_EQ(8U, textfield_->GetCursorPosition()); |
1114 SendKeyEvent(ui::VKEY_LEFT, false, true); | 1022 SendKeyEvent(ui::VKEY_LEFT, false, true); |
1115 EXPECT_EQ(5U, textfield_->GetCursorPosition()); | 1023 EXPECT_EQ(5U, textfield_->GetCursorPosition()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 // Text field is unmodifiable and selection shouldn't change. | 1065 // Text field is unmodifiable and selection shouldn't change. |
1158 SendKeyEvent(ui::VKEY_DELETE); | 1066 SendKeyEvent(ui::VKEY_DELETE); |
1159 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1067 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1160 SendKeyEvent(ui::VKEY_BACK); | 1068 SendKeyEvent(ui::VKEY_BACK); |
1161 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1069 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1162 SendKeyEvent(ui::VKEY_T); | 1070 SendKeyEvent(ui::VKEY_T); |
1163 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1071 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1164 } | 1072 } |
1165 | 1073 |
1166 TEST_F(TextfieldTest, TextInputClientTest) { | 1074 TEST_F(TextfieldTest, TextInputClientTest) { |
1167 InitTextfield(Textfield::STYLE_DEFAULT); | 1075 InitTextfield(); |
1168 ui::TextInputClient* client = textfield_->GetTextInputClient(); | 1076 ui::TextInputClient* client = textfield_->GetTextInputClient(); |
1169 EXPECT_TRUE(client); | 1077 EXPECT_TRUE(client); |
1170 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); | 1078 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); |
1171 | 1079 |
1172 textfield_->SetText(ASCIIToUTF16("0123456789")); | 1080 textfield_->SetText(ASCIIToUTF16("0123456789")); |
1173 gfx::Range range; | 1081 gfx::Range range; |
1174 EXPECT_TRUE(client->GetTextRange(&range)); | 1082 EXPECT_TRUE(client->GetTextRange(&range)); |
1175 EXPECT_EQ(0U, range.start()); | 1083 EXPECT_EQ(0U, range.start()); |
1176 EXPECT_EQ(10U, range.end()); | 1084 EXPECT_EQ(10U, range.end()); |
1177 | 1085 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 EXPECT_EQ(0, on_before_user_action_); | 1164 EXPECT_EQ(0, on_before_user_action_); |
1257 EXPECT_EQ(0, on_after_user_action_); | 1165 EXPECT_EQ(0, on_after_user_action_); |
1258 | 1166 |
1259 input_method_->Clear(); | 1167 input_method_->Clear(); |
1260 textfield_->SetReadOnly(true); | 1168 textfield_->SetReadOnly(true); |
1261 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1169 EXPECT_TRUE(input_method_->text_input_type_changed()); |
1262 EXPECT_FALSE(textfield_->GetTextInputClient()); | 1170 EXPECT_FALSE(textfield_->GetTextInputClient()); |
1263 | 1171 |
1264 textfield_->SetReadOnly(false); | 1172 textfield_->SetReadOnly(false); |
1265 input_method_->Clear(); | 1173 input_method_->Clear(); |
1266 textfield_->SetObscured(true); | 1174 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
1267 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1175 EXPECT_TRUE(input_method_->text_input_type_changed()); |
1268 EXPECT_TRUE(textfield_->GetTextInputClient()); | 1176 EXPECT_TRUE(textfield_->GetTextInputClient()); |
1269 } | 1177 } |
1270 | 1178 |
1271 TEST_F(TextfieldTest, UndoRedoTest) { | 1179 TEST_F(TextfieldTest, UndoRedoTest) { |
1272 InitTextfield(Textfield::STYLE_DEFAULT); | 1180 InitTextfield(); |
1273 SendKeyEvent(ui::VKEY_A); | 1181 SendKeyEvent(ui::VKEY_A); |
1274 EXPECT_STR_EQ("a", textfield_->text()); | 1182 EXPECT_STR_EQ("a", textfield_->text()); |
1275 SendKeyEvent(ui::VKEY_Z, false, true); | 1183 SendKeyEvent(ui::VKEY_Z, false, true); |
1276 EXPECT_STR_EQ("", textfield_->text()); | 1184 EXPECT_STR_EQ("", textfield_->text()); |
1277 SendKeyEvent(ui::VKEY_Z, false, true); | 1185 SendKeyEvent(ui::VKEY_Z, false, true); |
1278 EXPECT_STR_EQ("", textfield_->text()); | 1186 EXPECT_STR_EQ("", textfield_->text()); |
1279 SendKeyEvent(ui::VKEY_Y, false, true); | 1187 SendKeyEvent(ui::VKEY_Y, false, true); |
1280 EXPECT_STR_EQ("a", textfield_->text()); | 1188 EXPECT_STR_EQ("a", textfield_->text()); |
1281 SendKeyEvent(ui::VKEY_Y, false, true); | 1189 SendKeyEvent(ui::VKEY_Y, false, true); |
1282 EXPECT_STR_EQ("a", textfield_->text()); | 1190 EXPECT_STR_EQ("a", textfield_->text()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 EXPECT_STR_EQ("ab", textfield_->text()); | 1264 EXPECT_STR_EQ("ab", textfield_->text()); |
1357 SendKeyEvent(ui::VKEY_Y, false, true); | 1265 SendKeyEvent(ui::VKEY_Y, false, true); |
1358 EXPECT_STR_EQ("b", textfield_->text()); | 1266 EXPECT_STR_EQ("b", textfield_->text()); |
1359 SendKeyEvent(ui::VKEY_Y, false, true); | 1267 SendKeyEvent(ui::VKEY_Y, false, true); |
1360 EXPECT_STR_EQ("", textfield_->text()); | 1268 EXPECT_STR_EQ("", textfield_->text()); |
1361 SendKeyEvent(ui::VKEY_Y, false, true); | 1269 SendKeyEvent(ui::VKEY_Y, false, true); |
1362 EXPECT_STR_EQ("", textfield_->text()); | 1270 EXPECT_STR_EQ("", textfield_->text()); |
1363 } | 1271 } |
1364 | 1272 |
1365 TEST_F(TextfieldTest, CutCopyPaste) { | 1273 TEST_F(TextfieldTest, CutCopyPaste) { |
1366 InitTextfield(Textfield::STYLE_DEFAULT); | 1274 InitTextfield(); |
1367 | 1275 |
1368 // Ensure IDS_APP_CUT cuts. | 1276 // Ensure IDS_APP_CUT cuts. |
1369 textfield_->SetText(ASCIIToUTF16("123")); | 1277 textfield_->SetText(ASCIIToUTF16("123")); |
1370 textfield_->SelectAll(false); | 1278 textfield_->SelectAll(false); |
1371 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); | 1279 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
1372 textfield_->ExecuteCommand(IDS_APP_CUT, 0); | 1280 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
1373 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1281 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); |
1374 EXPECT_STR_EQ("", textfield_->text()); | 1282 EXPECT_STR_EQ("", textfield_->text()); |
1375 | 1283 |
1376 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. | 1284 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1335 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
1428 | 1336 |
1429 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. | 1337 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. |
1430 textfield_->SelectAll(false); | 1338 textfield_->SelectAll(false); |
1431 SendKeyEvent(ui::VKEY_INSERT, true, true); | 1339 SendKeyEvent(ui::VKEY_INSERT, true, true); |
1432 EXPECT_STR_EQ("abc", base::string16(GetClipboardText())); | 1340 EXPECT_STR_EQ("abc", base::string16(GetClipboardText())); |
1433 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1341 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
1434 } | 1342 } |
1435 | 1343 |
1436 TEST_F(TextfieldTest, OvertypeMode) { | 1344 TEST_F(TextfieldTest, OvertypeMode) { |
1437 InitTextfield(Textfield::STYLE_DEFAULT); | 1345 InitTextfield(); |
1438 // Overtype mode should be disabled (no-op [Insert]). | 1346 // Overtype mode should be disabled (no-op [Insert]). |
1439 textfield_->SetText(ASCIIToUTF16("2")); | 1347 textfield_->SetText(ASCIIToUTF16("2")); |
1440 SendKeyEvent(ui::VKEY_HOME); | 1348 SendKeyEvent(ui::VKEY_HOME); |
1441 SendKeyEvent(ui::VKEY_INSERT); | 1349 SendKeyEvent(ui::VKEY_INSERT); |
1442 SendKeyEvent(ui::VKEY_1, false, false); | 1350 SendKeyEvent(ui::VKEY_1, false, false); |
1443 EXPECT_STR_EQ("12", textfield_->text()); | 1351 EXPECT_STR_EQ("12", textfield_->text()); |
1444 } | 1352 } |
1445 | 1353 |
1446 TEST_F(TextfieldTest, TextCursorDisplayTest) { | 1354 TEST_F(TextfieldTest, TextCursorDisplayTest) { |
1447 InitTextfield(Textfield::STYLE_DEFAULT); | 1355 InitTextfield(); |
1448 // LTR-RTL string in LTR context. | 1356 // LTR-RTL string in LTR context. |
1449 SendKeyEvent('a'); | 1357 SendKeyEvent('a'); |
1450 EXPECT_STR_EQ("a", textfield_->text()); | 1358 EXPECT_STR_EQ("a", textfield_->text()); |
1451 int x = GetCursorBounds().x(); | 1359 int x = GetCursorBounds().x(); |
1452 int prev_x = x; | 1360 int prev_x = x; |
1453 | 1361 |
1454 SendKeyEvent('b'); | 1362 SendKeyEvent('b'); |
1455 EXPECT_STR_EQ("ab", textfield_->text()); | 1363 EXPECT_STR_EQ("ab", textfield_->text()); |
1456 x = GetCursorBounds().x(); | 1364 x = GetCursorBounds().x(); |
1457 EXPECT_LT(prev_x, x); | 1365 EXPECT_LT(prev_x, x); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 SendKeyEvent('b'); | 1400 SendKeyEvent('b'); |
1493 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); | 1401 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); |
1494 x = GetCursorBounds().x(); | 1402 x = GetCursorBounds().x(); |
1495 EXPECT_LT(prev_x, x); | 1403 EXPECT_LT(prev_x, x); |
1496 } | 1404 } |
1497 | 1405 |
1498 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) { | 1406 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) { |
1499 std::string locale = l10n_util::GetApplicationLocale(""); | 1407 std::string locale = l10n_util::GetApplicationLocale(""); |
1500 base::i18n::SetICUDefaultLocale("he"); | 1408 base::i18n::SetICUDefaultLocale("he"); |
1501 | 1409 |
1502 InitTextfield(Textfield::STYLE_DEFAULT); | 1410 InitTextfield(); |
1503 // LTR-RTL string in RTL context. | 1411 // LTR-RTL string in RTL context. |
1504 SendKeyEvent('a'); | 1412 SendKeyEvent('a'); |
1505 EXPECT_STR_EQ("a", textfield_->text()); | 1413 EXPECT_STR_EQ("a", textfield_->text()); |
1506 int x = GetCursorBounds().x(); | 1414 int x = GetCursorBounds().x(); |
1507 EXPECT_EQ(GetDisplayRect().right() - 1, x); | 1415 EXPECT_EQ(GetDisplayRect().right() - 1, x); |
1508 int prev_x = x; | 1416 int prev_x = x; |
1509 | 1417 |
1510 SendKeyEvent('b'); | 1418 SendKeyEvent('b'); |
1511 EXPECT_STR_EQ("ab", textfield_->text()); | 1419 EXPECT_STR_EQ("ab", textfield_->text()); |
1512 x = GetCursorBounds().x(); | 1420 x = GetCursorBounds().x(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 SendKeyEvent('b'); | 1455 SendKeyEvent('b'); |
1548 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); | 1456 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); |
1549 x = GetCursorBounds().x(); | 1457 x = GetCursorBounds().x(); |
1550 EXPECT_EQ(prev_x, x); | 1458 EXPECT_EQ(prev_x, x); |
1551 | 1459 |
1552 // Reset locale. | 1460 // Reset locale. |
1553 base::i18n::SetICUDefaultLocale(locale); | 1461 base::i18n::SetICUDefaultLocale(locale); |
1554 } | 1462 } |
1555 | 1463 |
1556 TEST_F(TextfieldTest, HitInsideTextAreaTest) { | 1464 TEST_F(TextfieldTest, HitInsideTextAreaTest) { |
1557 InitTextfield(Textfield::STYLE_DEFAULT); | 1465 InitTextfield(); |
1558 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1466 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
1559 std::vector<gfx::Rect> cursor_bounds; | 1467 std::vector<gfx::Rect> cursor_bounds; |
1560 | 1468 |
1561 // Save each cursor bound. | 1469 // Save each cursor bound. |
1562 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD); | 1470 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD); |
1563 cursor_bounds.push_back(GetCursorBounds(sel)); | 1471 cursor_bounds.push_back(GetCursorBounds(sel)); |
1564 | 1472 |
1565 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD); | 1473 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD); |
1566 gfx::Rect bound = GetCursorBounds(sel); | 1474 gfx::Rect bound = GetCursorBounds(sel); |
1567 sel = gfx::SelectionModel(1, gfx::CURSOR_FORWARD); | 1475 sel = gfx::SelectionModel(1, gfx::CURSOR_FORWARD); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 NonClientMouseClick(); | 1510 NonClientMouseClick(); |
1603 | 1511 |
1604 MouseClick(cursor_bounds[i + 1], - (half_width / 2)); | 1512 MouseClick(cursor_bounds[i + 1], - (half_width / 2)); |
1605 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); | 1513 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); |
1606 | 1514 |
1607 NonClientMouseClick(); | 1515 NonClientMouseClick(); |
1608 } | 1516 } |
1609 } | 1517 } |
1610 | 1518 |
1611 TEST_F(TextfieldTest, HitOutsideTextAreaTest) { | 1519 TEST_F(TextfieldTest, HitOutsideTextAreaTest) { |
1612 InitTextfield(Textfield::STYLE_DEFAULT); | 1520 InitTextfield(); |
1613 | 1521 |
1614 // LTR-RTL string in LTR context. | 1522 // LTR-RTL string in LTR context. |
1615 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1523 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
1616 | 1524 |
1617 SendKeyEvent(ui::VKEY_HOME); | 1525 SendKeyEvent(ui::VKEY_HOME); |
1618 gfx::Rect bound = GetCursorBounds(); | 1526 gfx::Rect bound = GetCursorBounds(); |
1619 MouseClick(bound, -10); | 1527 MouseClick(bound, -10); |
1620 EXPECT_EQ(bound, GetCursorBounds()); | 1528 EXPECT_EQ(bound, GetCursorBounds()); |
1621 | 1529 |
1622 SendKeyEvent(ui::VKEY_END); | 1530 SendKeyEvent(ui::VKEY_END); |
(...skipping 14 matching lines...) Expand all Loading... |
1637 SendKeyEvent(ui::VKEY_END); | 1545 SendKeyEvent(ui::VKEY_END); |
1638 bound = GetCursorBounds(); | 1546 bound = GetCursorBounds(); |
1639 MouseClick(bound, -10); | 1547 MouseClick(bound, -10); |
1640 EXPECT_EQ(bound, GetCursorBounds()); | 1548 EXPECT_EQ(bound, GetCursorBounds()); |
1641 } | 1549 } |
1642 | 1550 |
1643 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) { | 1551 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) { |
1644 std::string locale = l10n_util::GetApplicationLocale(""); | 1552 std::string locale = l10n_util::GetApplicationLocale(""); |
1645 base::i18n::SetICUDefaultLocale("he"); | 1553 base::i18n::SetICUDefaultLocale("he"); |
1646 | 1554 |
1647 InitTextfield(Textfield::STYLE_DEFAULT); | 1555 InitTextfield(); |
1648 | 1556 |
1649 // RTL-LTR string in RTL context. | 1557 // RTL-LTR string in RTL context. |
1650 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); | 1558 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); |
1651 SendKeyEvent(ui::VKEY_HOME); | 1559 SendKeyEvent(ui::VKEY_HOME); |
1652 gfx::Rect bound = GetCursorBounds(); | 1560 gfx::Rect bound = GetCursorBounds(); |
1653 MouseClick(bound, 10); | 1561 MouseClick(bound, 10); |
1654 EXPECT_EQ(bound, GetCursorBounds()); | 1562 EXPECT_EQ(bound, GetCursorBounds()); |
1655 | 1563 |
1656 SendKeyEvent(ui::VKEY_END); | 1564 SendKeyEvent(ui::VKEY_END); |
1657 bound = GetCursorBounds(); | 1565 bound = GetCursorBounds(); |
(...skipping 12 matching lines...) Expand all Loading... |
1670 SendKeyEvent(ui::VKEY_END); | 1578 SendKeyEvent(ui::VKEY_END); |
1671 bound = GetCursorBounds(); | 1579 bound = GetCursorBounds(); |
1672 MouseClick(bound, 10); | 1580 MouseClick(bound, 10); |
1673 EXPECT_EQ(bound, GetCursorBounds()); | 1581 EXPECT_EQ(bound, GetCursorBounds()); |
1674 | 1582 |
1675 // Reset locale. | 1583 // Reset locale. |
1676 base::i18n::SetICUDefaultLocale(locale); | 1584 base::i18n::SetICUDefaultLocale(locale); |
1677 } | 1585 } |
1678 | 1586 |
1679 TEST_F(TextfieldTest, OverflowTest) { | 1587 TEST_F(TextfieldTest, OverflowTest) { |
1680 InitTextfield(Textfield::STYLE_DEFAULT); | 1588 InitTextfield(); |
1681 | 1589 |
1682 base::string16 str; | 1590 base::string16 str; |
1683 for (int i = 0; i < 500; ++i) | 1591 for (int i = 0; i < 500; ++i) |
1684 SendKeyEvent('a'); | 1592 SendKeyEvent('a'); |
1685 SendKeyEvent(kHebrewLetterSamekh); | 1593 SendKeyEvent(kHebrewLetterSamekh); |
1686 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1594 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
1687 | 1595 |
1688 // Test mouse pointing. | 1596 // Test mouse pointing. |
1689 MouseClick(GetCursorBounds(), -1); | 1597 MouseClick(GetCursorBounds(), -1); |
1690 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1598 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
1691 | 1599 |
1692 // Clear text. | 1600 // Clear text. |
1693 SendKeyEvent(ui::VKEY_A, false, true); | 1601 SendKeyEvent(ui::VKEY_A, false, true); |
1694 SendKeyEvent('\n'); | 1602 SendKeyEvent('\n'); |
1695 | 1603 |
1696 for (int i = 0; i < 500; ++i) | 1604 for (int i = 0; i < 500; ++i) |
1697 SendKeyEvent(kHebrewLetterSamekh); | 1605 SendKeyEvent(kHebrewLetterSamekh); |
1698 SendKeyEvent('a'); | 1606 SendKeyEvent('a'); |
1699 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1607 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
1700 | 1608 |
1701 MouseClick(GetCursorBounds(), -1); | 1609 MouseClick(GetCursorBounds(), -1); |
1702 EXPECT_EQ(501U, textfield_->GetCursorPosition()); | 1610 EXPECT_EQ(501U, textfield_->GetCursorPosition()); |
1703 } | 1611 } |
1704 | 1612 |
1705 TEST_F(TextfieldTest, OverflowInRTLTest) { | 1613 TEST_F(TextfieldTest, OverflowInRTLTest) { |
1706 std::string locale = l10n_util::GetApplicationLocale(""); | 1614 std::string locale = l10n_util::GetApplicationLocale(""); |
1707 base::i18n::SetICUDefaultLocale("he"); | 1615 base::i18n::SetICUDefaultLocale("he"); |
1708 | 1616 |
1709 InitTextfield(Textfield::STYLE_DEFAULT); | 1617 InitTextfield(); |
1710 | 1618 |
1711 base::string16 str; | 1619 base::string16 str; |
1712 for (int i = 0; i < 500; ++i) | 1620 for (int i = 0; i < 500; ++i) |
1713 SendKeyEvent('a'); | 1621 SendKeyEvent('a'); |
1714 SendKeyEvent(kHebrewLetterSamekh); | 1622 SendKeyEvent(kHebrewLetterSamekh); |
1715 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1623 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
1716 | 1624 |
1717 MouseClick(GetCursorBounds(), 1); | 1625 MouseClick(GetCursorBounds(), 1); |
1718 EXPECT_EQ(501U, textfield_->GetCursorPosition()); | 1626 EXPECT_EQ(501U, textfield_->GetCursorPosition()); |
1719 | 1627 |
1720 // Clear text. | 1628 // Clear text. |
1721 SendKeyEvent(ui::VKEY_A, false, true); | 1629 SendKeyEvent(ui::VKEY_A, false, true); |
1722 SendKeyEvent('\n'); | 1630 SendKeyEvent('\n'); |
1723 | 1631 |
1724 for (int i = 0; i < 500; ++i) | 1632 for (int i = 0; i < 500; ++i) |
1725 SendKeyEvent(kHebrewLetterSamekh); | 1633 SendKeyEvent(kHebrewLetterSamekh); |
1726 SendKeyEvent('a'); | 1634 SendKeyEvent('a'); |
1727 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1635 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
1728 | 1636 |
1729 MouseClick(GetCursorBounds(), 1); | 1637 MouseClick(GetCursorBounds(), 1); |
1730 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1638 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
1731 | 1639 |
1732 // Reset locale. | 1640 // Reset locale. |
1733 base::i18n::SetICUDefaultLocale(locale); | 1641 base::i18n::SetICUDefaultLocale(locale); |
1734 } | 1642 } |
1735 | 1643 |
1736 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) { | 1644 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) { |
1737 InitTextfield(Textfield::STYLE_DEFAULT); | 1645 InitTextfield(); |
1738 | 1646 |
1739 base::string16 str; | 1647 base::string16 str; |
1740 const uint32 char_count = 10UL; | 1648 const uint32 char_count = 10UL; |
1741 ui::CompositionText composition; | 1649 ui::CompositionText composition; |
1742 composition.text = UTF8ToUTF16("0123456789"); | 1650 composition.text = UTF8ToUTF16("0123456789"); |
1743 ui::TextInputClient* client = textfield_->GetTextInputClient(); | 1651 ui::TextInputClient* client = textfield_->GetTextInputClient(); |
1744 | 1652 |
1745 // Return false if there is no composition text. | 1653 // Return false if there is no composition text. |
1746 gfx::Rect rect; | 1654 gfx::Rect rect; |
1747 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect)); | 1655 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect)); |
(...skipping 23 matching lines...) Expand all Loading... |
1771 EXPECT_EQ(char_rect_in_screen_coord[i], actual_rect) << " i=" << i; | 1679 EXPECT_EQ(char_rect_in_screen_coord[i], actual_rect) << " i=" << i; |
1772 } | 1680 } |
1773 | 1681 |
1774 // Return false if the index is out of range. | 1682 // Return false if the index is out of range. |
1775 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); | 1683 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); |
1776 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); | 1684 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); |
1777 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); | 1685 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); |
1778 } | 1686 } |
1779 | 1687 |
1780 TEST_F(TextfieldTest, GetCompositionCharacterBounds_ComplexText) { | 1688 TEST_F(TextfieldTest, GetCompositionCharacterBounds_ComplexText) { |
1781 InitTextfield(Textfield::STYLE_DEFAULT); | 1689 InitTextfield(); |
1782 | 1690 |
1783 const base::char16 kUtf16Chars[] = { | 1691 const base::char16 kUtf16Chars[] = { |
1784 // U+0020 SPACE | 1692 // U+0020 SPACE |
1785 0x0020, | 1693 0x0020, |
1786 // U+1F408 (CAT) as surrogate pair | 1694 // U+1F408 (CAT) as surrogate pair |
1787 0xd83d, 0xdc08, | 1695 0xd83d, 0xdc08, |
1788 // U+5642 as Ideographic Variation Sequences | 1696 // U+5642 as Ideographic Variation Sequences |
1789 0x5642, 0xDB40, 0xDD00, | 1697 0x5642, 0xDB40, 0xDD00, |
1790 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences | 1698 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences |
1791 0x260E, 0xFE0F, | 1699 0x260E, 0xFE0F, |
(...skipping 16 matching lines...) Expand all Loading... |
1808 // Here we might expect the following results but it actually depends on how | 1716 // Here we might expect the following results but it actually depends on how |
1809 // Uniscribe or HarfBuzz treats them with given font. | 1717 // Uniscribe or HarfBuzz treats them with given font. |
1810 // - rects[1] == rects[2] | 1718 // - rects[1] == rects[2] |
1811 // - rects[3] == rects[4] == rects[5] | 1719 // - rects[3] == rects[4] == rects[5] |
1812 // - rects[6] == rects[7] | 1720 // - rects[6] == rects[7] |
1813 } | 1721 } |
1814 | 1722 |
1815 // The word we select by double clicking should remain selected regardless of | 1723 // The word we select by double clicking should remain selected regardless of |
1816 // where we drag the mouse afterwards without releasing the left button. | 1724 // where we drag the mouse afterwards without releasing the left button. |
1817 TEST_F(TextfieldTest, KeepInitiallySelectedWord) { | 1725 TEST_F(TextfieldTest, KeepInitiallySelectedWord) { |
1818 InitTextfield(Textfield::STYLE_DEFAULT); | 1726 InitTextfield(); |
1819 | 1727 |
1820 textfield_->SetText(ASCIIToUTF16("abc def ghi")); | 1728 textfield_->SetText(ASCIIToUTF16("abc def ghi")); |
1821 | 1729 |
1822 textfield_->SelectRange(gfx::Range(5, 5)); | 1730 textfield_->SelectRange(gfx::Range(5, 5)); |
1823 const gfx::Rect middle_cursor = GetCursorBounds(); | 1731 const gfx::Rect middle_cursor = GetCursorBounds(); |
1824 textfield_->SelectRange(gfx::Range(0, 0)); | 1732 textfield_->SelectRange(gfx::Range(0, 0)); |
1825 const gfx::Point beginning = GetCursorBounds().origin(); | 1733 const gfx::Point beginning = GetCursorBounds().origin(); |
1826 | 1734 |
1827 // Double click, but do not release the left button. | 1735 // Double click, but do not release the left button. |
1828 MouseClick(middle_cursor, 0); | 1736 MouseClick(middle_cursor, 0); |
1829 const gfx::Point middle(middle_cursor.x(), | 1737 const gfx::Point middle(middle_cursor.x(), |
1830 middle_cursor.y() + middle_cursor.height() / 2); | 1738 middle_cursor.y() + middle_cursor.height() / 2); |
1831 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, | 1739 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, |
1832 ui::EF_LEFT_MOUSE_BUTTON, | 1740 ui::EF_LEFT_MOUSE_BUTTON, |
1833 ui::EF_LEFT_MOUSE_BUTTON); | 1741 ui::EF_LEFT_MOUSE_BUTTON); |
1834 textfield_->OnMousePressed(press_event); | 1742 textfield_->OnMousePressed(press_event); |
1835 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); | 1743 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); |
1836 | 1744 |
1837 // Drag the mouse to the beginning of the textfield. | 1745 // Drag the mouse to the beginning of the textfield. |
1838 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, | 1746 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, |
1839 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1747 ui::EF_LEFT_MOUSE_BUTTON, 0); |
1840 textfield_->OnMouseDragged(drag_event); | 1748 textfield_->OnMouseDragged(drag_event); |
1841 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); | 1749 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); |
1842 } | 1750 } |
1843 | 1751 |
1844 // Touch selection and dragging currently only works for chromeos. | 1752 // Touch selection and dragging currently only works for chromeos. |
1845 #if defined(OS_CHROMEOS) | 1753 #if defined(OS_CHROMEOS) |
1846 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { | 1754 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { |
1847 InitTextfield(Textfield::STYLE_DEFAULT); | 1755 InitTextfield(); |
1848 textfield_->SetText(ASCIIToUTF16("hello world")); | 1756 textfield_->SetText(ASCIIToUTF16("hello world")); |
1849 EXPECT_FALSE(GetTouchSelectionController()); | 1757 EXPECT_FALSE(GetTouchSelectionController()); |
1850 const int x = GetCursorPositionX(2); | 1758 const int x = GetCursorPositionX(2); |
1851 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); | 1759 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); |
1852 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, x, 0, 0.0f, 0.0f); | 1760 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, x, 0, 0.0f, 0.0f); |
1853 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); | 1761 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); |
1854 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); | 1762 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
1855 | 1763 |
1856 // Tapping on the textfield should turn on the TouchSelectionController. | 1764 // Tapping on the textfield should turn on the TouchSelectionController. |
1857 textfield_->OnGestureEvent(&tap); | 1765 textfield_->OnGestureEvent(&tap); |
(...skipping 24 matching lines...) Expand all Loading... |
1882 switches::kDisableTouchDragDrop); | 1790 switches::kDisableTouchDragDrop); |
1883 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); | 1791 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); |
1884 textfield_->OnGestureEvent(&tap_down); | 1792 textfield_->OnGestureEvent(&tap_down); |
1885 textfield_->OnGestureEvent(&long_press); | 1793 textfield_->OnGestureEvent(&long_press); |
1886 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1794 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
1887 EXPECT_TRUE(GetTouchSelectionController()); | 1795 EXPECT_TRUE(GetTouchSelectionController()); |
1888 EXPECT_TRUE(long_press.handled()); | 1796 EXPECT_TRUE(long_press.handled()); |
1889 } | 1797 } |
1890 | 1798 |
1891 TEST_F(TextfieldTest, TouchScrubbingSelection) { | 1799 TEST_F(TextfieldTest, TouchScrubbingSelection) { |
1892 InitTextfield(Textfield::STYLE_DEFAULT); | 1800 InitTextfield(); |
1893 textfield_->SetText(ASCIIToUTF16("hello world")); | 1801 textfield_->SetText(ASCIIToUTF16("hello world")); |
1894 EXPECT_FALSE(GetTouchSelectionController()); | 1802 EXPECT_FALSE(GetTouchSelectionController()); |
1895 | 1803 |
1896 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); | 1804 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
1897 | 1805 |
1898 // Simulate touch-scrubbing. | 1806 // Simulate touch-scrubbing. |
1899 int scrubbing_start = GetCursorPositionX(1); | 1807 int scrubbing_start = GetCursorPositionX(1); |
1900 int scrubbing_end = GetCursorPositionX(6); | 1808 int scrubbing_end = GetCursorPositionX(6); |
1901 | 1809 |
1902 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0, | 1810 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0, |
(...skipping 21 matching lines...) Expand all Loading... |
1924 | 1832 |
1925 // In the end, part of text should have been selected and handles should have | 1833 // In the end, part of text should have been selected and handles should have |
1926 // appeared. | 1834 // appeared. |
1927 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); | 1835 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); |
1928 EXPECT_TRUE(GetTouchSelectionController()); | 1836 EXPECT_TRUE(GetTouchSelectionController()); |
1929 } | 1837 } |
1930 #endif | 1838 #endif |
1931 | 1839 |
1932 // Long_Press gesture in Textfield can initiate a drag and drop now. | 1840 // Long_Press gesture in Textfield can initiate a drag and drop now. |
1933 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { | 1841 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { |
1934 InitTextfield(Textfield::STYLE_DEFAULT); | 1842 InitTextfield(); |
1935 textfield_->SetText(ASCIIToUTF16("Hello string world")); | 1843 textfield_->SetText(ASCIIToUTF16("Hello string world")); |
1936 | 1844 |
1937 // Ensure the textfield will provide selected text for drag data. | 1845 // Ensure the textfield will provide selected text for drag data. |
1938 textfield_->SelectRange(gfx::Range(6, 12)); | 1846 textfield_->SelectRange(gfx::Range(6, 12)); |
1939 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 1847 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
1940 | 1848 |
1941 // Enable touch-drag-drop to make long press effective. | 1849 // Enable touch-drag-drop to make long press effective. |
1942 CommandLine::ForCurrentProcess()->AppendSwitch( | 1850 CommandLine::ForCurrentProcess()->AppendSwitch( |
1943 switches::kEnableTouchDragDrop); | 1851 switches::kEnableTouchDragDrop); |
1944 | 1852 |
1945 // Create a long press event in the selected region should start a drag. | 1853 // Create a long press event in the selected region should start a drag. |
1946 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), | 1854 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), |
1947 kStringPoint.y(), 0.0f, 0.0f); | 1855 kStringPoint.y(), 0.0f, 0.0f); |
1948 textfield_->OnGestureEvent(&long_press); | 1856 textfield_->OnGestureEvent(&long_press); |
1949 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, | 1857 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, |
1950 kStringPoint)); | 1858 kStringPoint)); |
1951 } | 1859 } |
1952 | 1860 |
1953 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) { | 1861 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) { |
1954 InitTextfield(Textfield::STYLE_DEFAULT); | 1862 InitTextfield(); |
1955 textfield_->SetText(UTF8ToUTF16("abc")); | 1863 textfield_->SetText(UTF8ToUTF16("abc")); |
1956 const int old_baseline = textfield_->GetBaseline(); | 1864 const int old_baseline = textfield_->GetBaseline(); |
1957 | 1865 |
1958 // Set text which may fall back to a font which has taller baseline than | 1866 // Set text which may fall back to a font which has taller baseline than |
1959 // the default font. | 1867 // the default font. |
1960 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); | 1868 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); |
1961 const int new_baseline = textfield_->GetBaseline(); | 1869 const int new_baseline = textfield_->GetBaseline(); |
1962 | 1870 |
1963 // Regardless of the text, the baseline must be the same. | 1871 // Regardless of the text, the baseline must be the same. |
1964 EXPECT_EQ(new_baseline, old_baseline); | 1872 EXPECT_EQ(new_baseline, old_baseline); |
1965 } | 1873 } |
1966 | 1874 |
1967 } // namespace views | 1875 } // namespace views |
OLD | NEW |