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

Side by Side Diff: ui/views/controls/textfield/textfield_unittest.cc

Issue 138363004: Views Textfield fixes and cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and rebase. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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
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
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
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
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
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
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
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
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
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
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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 bad_data.SetPickledData(fmt, Pickle()); 814 bad_data.SetPickledData(fmt, Pickle());
907 bad_data.SetFileContents(base::FilePath(L"x"), "x"); 815 bad_data.SetFileContents(base::FilePath(L"x"), "x");
908 bad_data.SetHtml(base::string16(ASCIIToUTF16("x")), GURL("x.org")); 816 bad_data.SetHtml(base::string16(ASCIIToUTF16("x")), GURL("x.org"));
909 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL); 817 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL);
910 bad_data.SetDownloadFileInfo(download); 818 bad_data.SetDownloadFileInfo(download);
911 EXPECT_FALSE(textfield_->CanDrop(bad_data)); 819 EXPECT_FALSE(textfield_->CanDrop(bad_data));
912 } 820 }
913 #endif 821 #endif
914 822
915 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { 823 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) {
916 InitTextfield(Textfield::STYLE_DEFAULT); 824 InitTextfield();
917 textfield_->SetText(ASCIIToUTF16("hello string world")); 825 textfield_->SetText(ASCIIToUTF16("hello string world"));
918 826
919 // Ensure the textfield will provide selected text for drag data. 827 // Ensure the textfield will provide selected text for drag data.
920 base::string16 string; 828 base::string16 string;
921 ui::OSExchangeData data; 829 ui::OSExchangeData data;
922 const gfx::Range kStringRange(6, 12); 830 const gfx::Range kStringRange(6, 12);
923 textfield_->SelectRange(kStringRange); 831 textfield_->SelectRange(kStringRange);
924 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 832 const gfx::Point kStringPoint(GetCursorPositionX(9), 0);
925 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); 833 textfield_->WriteDragDataForView(NULL, kStringPoint, &data);
926 EXPECT_TRUE(data.GetString(&string)); 834 EXPECT_TRUE(data.GetString(&string));
927 EXPECT_EQ(textfield_->GetSelectedText(), string); 835 EXPECT_EQ(textfield_->GetSelectedText(), string);
928 836
929 // Ensure that disabled textfields do not support drag operations. 837 // Ensure that disabled textfields do not support drag operations.
930 textfield_->SetEnabled(false); 838 textfield_->SetEnabled(false);
931 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 839 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
932 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 840 textfield_->GetDragOperationsForView(NULL, kStringPoint));
933 textfield_->SetEnabled(true); 841 textfield_->SetEnabled(true);
934 // Ensure that textfields without selections do not support drag operations. 842 // Ensure that textfields without selections do not support drag operations.
935 textfield_->ClearSelection(); 843 textfield_->ClearSelection();
936 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 844 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
937 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 845 textfield_->GetDragOperationsForView(NULL, kStringPoint));
938 textfield_->SelectRange(kStringRange); 846 textfield_->SelectRange(kStringRange);
939 // Ensure that password textfields do not support drag operations. 847 // Ensure that password textfields do not support drag operations.
940 textfield_->SetObscured(true); 848 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
941 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 849 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
942 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 850 textfield_->GetDragOperationsForView(NULL, kStringPoint));
943 textfield_->SetObscured(false); 851 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT);
944 // Ensure that textfields only initiate drag operations inside the selection. 852 // Ensure that textfields only initiate drag operations inside the selection.
945 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, 853 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint,
946 ui::EF_LEFT_MOUSE_BUTTON, 854 ui::EF_LEFT_MOUSE_BUTTON,
947 ui::EF_LEFT_MOUSE_BUTTON); 855 ui::EF_LEFT_MOUSE_BUTTON);
948 textfield_->OnMousePressed(press_event); 856 textfield_->OnMousePressed(press_event);
949 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 857 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
950 textfield_->GetDragOperationsForView(NULL, gfx::Point())); 858 textfield_->GetDragOperationsForView(NULL, gfx::Point()));
951 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(), 859 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(),
952 gfx::Point())); 860 gfx::Point()));
953 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, 861 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY,
954 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 862 textfield_->GetDragOperationsForView(NULL, kStringPoint));
955 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, 863 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint,
956 gfx::Point())); 864 gfx::Point()));
957 // Ensure that textfields support local moves. 865 // Ensure that textfields support local moves.
958 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 866 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
959 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); 867 textfield_->GetDragOperationsForView(textfield_, kStringPoint));
960 } 868 }
961 869
962 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { 870 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) {
963 InitTextfield(Textfield::STYLE_DEFAULT); 871 InitTextfield();
964 textfield_->SetText(ASCIIToUTF16("hello world")); 872 textfield_->SetText(ASCIIToUTF16("hello world"));
965 873
966 base::string16 string; 874 base::string16 string;
967 ui::OSExchangeData data; 875 ui::OSExchangeData data;
968 int formats = 0; 876 int formats = 0;
969 int operations = 0; 877 int operations = 0;
970 std::set<OSExchangeData::CustomFormat> custom_formats; 878 std::set<OSExchangeData::CustomFormat> custom_formats;
971 879
972 // Start dragging "ello". 880 // Start dragging "ello".
973 textfield_->SelectRange(gfx::Range(1, 5)); 881 textfield_->SelectRange(gfx::Range(1, 5));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 EXPECT_STR_EQ("", textfield_->text()); 914 EXPECT_STR_EQ("", textfield_->text());
1007 SendKeyEvent(ui::VKEY_Y, false, true); 915 SendKeyEvent(ui::VKEY_Y, false, true);
1008 EXPECT_STR_EQ("hello world", textfield_->text()); 916 EXPECT_STR_EQ("hello world", textfield_->text());
1009 SendKeyEvent(ui::VKEY_Y, false, true); 917 SendKeyEvent(ui::VKEY_Y, false, true);
1010 EXPECT_STR_EQ("h welloorld", textfield_->text()); 918 EXPECT_STR_EQ("h welloorld", 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 } 921 }
1014 922
1015 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { 923 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) {
1016 InitTextfield(Textfield::STYLE_DEFAULT); 924 InitTextfield();
1017 textfield_->SetText(ASCIIToUTF16("hello world")); 925 textfield_->SetText(ASCIIToUTF16("hello world"));
1018 926
1019 base::string16 string; 927 base::string16 string;
1020 ui::OSExchangeData data; 928 ui::OSExchangeData data;
1021 int formats = 0; 929 int formats = 0;
1022 int operations = 0; 930 int operations = 0;
1023 std::set<OSExchangeData::CustomFormat> custom_formats; 931 std::set<OSExchangeData::CustomFormat> custom_formats;
1024 932
1025 // Start dragging " worl". 933 // Start dragging " worl".
1026 textfield_->SelectRange(gfx::Range(5, 10)); 934 textfield_->SelectRange(gfx::Range(5, 10));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 EXPECT_STR_EQ("", textfield_->text()); 967 EXPECT_STR_EQ("", textfield_->text());
1060 SendKeyEvent(ui::VKEY_Y, false, true); 968 SendKeyEvent(ui::VKEY_Y, false, true);
1061 EXPECT_STR_EQ("hello world", textfield_->text()); 969 EXPECT_STR_EQ("hello world", textfield_->text());
1062 SendKeyEvent(ui::VKEY_Y, false, true); 970 SendKeyEvent(ui::VKEY_Y, false, true);
1063 EXPECT_STR_EQ("h worlellod", textfield_->text()); 971 EXPECT_STR_EQ("h worlellod", 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 } 974 }
1067 975
1068 TEST_F(TextfieldTest, DragAndDrop_Canceled) { 976 TEST_F(TextfieldTest, DragAndDrop_Canceled) {
1069 InitTextfield(Textfield::STYLE_DEFAULT); 977 InitTextfield();
1070 textfield_->SetText(ASCIIToUTF16("hello world")); 978 textfield_->SetText(ASCIIToUTF16("hello world"));
1071 979
1072 // Start dragging "worl". 980 // Start dragging "worl".
1073 textfield_->SelectRange(gfx::Range(6, 10)); 981 textfield_->SelectRange(gfx::Range(6, 10));
1074 gfx::Point point(GetCursorPositionX(8), 0); 982 gfx::Point point(GetCursorPositionX(8), 0);
1075 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, 983 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point,
1076 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 984 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
1077 textfield_->OnMousePressed(click); 985 textfield_->OnMousePressed(click);
1078 ui::OSExchangeData data; 986 ui::OSExchangeData data;
1079 textfield_->WriteDragDataForView(NULL, click.location(), &data); 987 textfield_->WriteDragDataForView(NULL, click.location(), &data);
1080 EXPECT_TRUE(textfield_->CanDrop(data)); 988 EXPECT_TRUE(textfield_->CanDrop(data));
1081 // Drag the text over somewhere valid, outside the current selection. 989 // Drag the text over somewhere valid, outside the current selection.
1082 gfx::Point drop_point(GetCursorPositionX(2), 0); 990 gfx::Point drop_point(GetCursorPositionX(2), 0);
1083 ui::DropTargetEvent drop(data, drop_point, drop_point, 991 ui::DropTargetEvent drop(data, drop_point, drop_point,
1084 ui::DragDropTypes::DRAG_MOVE); 992 ui::DragDropTypes::DRAG_MOVE);
1085 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); 993 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop));
1086 // "Cancel" the drag, via move and release over the selection, and OnDragDone. 994 // "Cancel" the drag, via move and release over the selection, and OnDragDone.
1087 gfx::Point drag_point(GetCursorPositionX(9), 0); 995 gfx::Point drag_point(GetCursorPositionX(9), 0);
1088 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, 996 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point,
1089 ui::EF_LEFT_MOUSE_BUTTON, 0); 997 ui::EF_LEFT_MOUSE_BUTTON, 0);
1090 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, 998 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point,
1091 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 999 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
1092 textfield_->OnMouseDragged(drag); 1000 textfield_->OnMouseDragged(drag);
1093 textfield_->OnMouseReleased(release); 1001 textfield_->OnMouseReleased(release);
1094 textfield_->OnDragDone(); 1002 textfield_->OnDragDone();
1095 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); 1003 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text());
1096 } 1004 }
1097 1005
1098 TEST_F(TextfieldTest, ReadOnlyTest) { 1006 TEST_F(TextfieldTest, ReadOnlyTest) {
1099 InitTextfield(Textfield::STYLE_DEFAULT); 1007 InitTextfield();
1100 textfield_->SetText(ASCIIToUTF16("read only")); 1008 textfield_->SetText(ASCIIToUTF16("read only"));
1101 textfield_->SetReadOnly(true); 1009 textfield_->SetReadOnly(true);
1102 EXPECT_TRUE(textfield_->enabled()); 1010 EXPECT_TRUE(textfield_->enabled());
1103 EXPECT_TRUE(textfield_->focusable()); 1011 EXPECT_TRUE(textfield_->IsFocusable());
1104 1012
1105 SendKeyEvent(ui::VKEY_HOME); 1013 SendKeyEvent(ui::VKEY_HOME);
1106 EXPECT_EQ(0U, textfield_->GetCursorPosition()); 1014 EXPECT_EQ(0U, textfield_->GetCursorPosition());
1107 SendKeyEvent(ui::VKEY_END); 1015 SendKeyEvent(ui::VKEY_END);
1108 EXPECT_EQ(9U, textfield_->GetCursorPosition()); 1016 EXPECT_EQ(9U, textfield_->GetCursorPosition());
1109 1017
1110 SendKeyEvent(ui::VKEY_LEFT, false, false); 1018 SendKeyEvent(ui::VKEY_LEFT, false, false);
1111 EXPECT_EQ(8U, textfield_->GetCursorPosition()); 1019 EXPECT_EQ(8U, textfield_->GetCursorPosition());
1112 SendKeyEvent(ui::VKEY_LEFT, false, true); 1020 SendKeyEvent(ui::VKEY_LEFT, false, true);
1113 EXPECT_EQ(5U, textfield_->GetCursorPosition()); 1021 EXPECT_EQ(5U, textfield_->GetCursorPosition());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 // Text field is unmodifiable and selection shouldn't change. 1063 // Text field is unmodifiable and selection shouldn't change.
1156 SendKeyEvent(ui::VKEY_DELETE); 1064 SendKeyEvent(ui::VKEY_DELETE);
1157 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1065 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1158 SendKeyEvent(ui::VKEY_BACK); 1066 SendKeyEvent(ui::VKEY_BACK);
1159 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1067 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1160 SendKeyEvent(ui::VKEY_T); 1068 SendKeyEvent(ui::VKEY_T);
1161 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1069 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1162 } 1070 }
1163 1071
1164 TEST_F(TextfieldTest, TextInputClientTest) { 1072 TEST_F(TextfieldTest, TextInputClientTest) {
1165 InitTextfield(Textfield::STYLE_DEFAULT); 1073 InitTextfield();
1166 ui::TextInputClient* client = textfield_->GetTextInputClient(); 1074 ui::TextInputClient* client = textfield_->GetTextInputClient();
1167 EXPECT_TRUE(client); 1075 EXPECT_TRUE(client);
1168 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); 1076 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType());
1169 1077
1170 textfield_->SetText(ASCIIToUTF16("0123456789")); 1078 textfield_->SetText(ASCIIToUTF16("0123456789"));
1171 gfx::Range range; 1079 gfx::Range range;
1172 EXPECT_TRUE(client->GetTextRange(&range)); 1080 EXPECT_TRUE(client->GetTextRange(&range));
1173 EXPECT_EQ(0U, range.start()); 1081 EXPECT_EQ(0U, range.start());
1174 EXPECT_EQ(10U, range.end()); 1082 EXPECT_EQ(10U, range.end());
1175 1083
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 EXPECT_EQ(0, on_before_user_action_); 1162 EXPECT_EQ(0, on_before_user_action_);
1255 EXPECT_EQ(0, on_after_user_action_); 1163 EXPECT_EQ(0, on_after_user_action_);
1256 1164
1257 input_method_->Clear(); 1165 input_method_->Clear();
1258 textfield_->SetReadOnly(true); 1166 textfield_->SetReadOnly(true);
1259 EXPECT_TRUE(input_method_->text_input_type_changed()); 1167 EXPECT_TRUE(input_method_->text_input_type_changed());
1260 EXPECT_FALSE(textfield_->GetTextInputClient()); 1168 EXPECT_FALSE(textfield_->GetTextInputClient());
1261 1169
1262 textfield_->SetReadOnly(false); 1170 textfield_->SetReadOnly(false);
1263 input_method_->Clear(); 1171 input_method_->Clear();
1264 textfield_->SetObscured(true); 1172 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
1265 EXPECT_TRUE(input_method_->text_input_type_changed()); 1173 EXPECT_TRUE(input_method_->text_input_type_changed());
1266 EXPECT_TRUE(textfield_->GetTextInputClient()); 1174 EXPECT_TRUE(textfield_->GetTextInputClient());
1267 } 1175 }
1268 1176
1269 TEST_F(TextfieldTest, UndoRedoTest) { 1177 TEST_F(TextfieldTest, UndoRedoTest) {
1270 InitTextfield(Textfield::STYLE_DEFAULT); 1178 InitTextfield();
1271 SendKeyEvent(ui::VKEY_A); 1179 SendKeyEvent(ui::VKEY_A);
1272 EXPECT_STR_EQ("a", textfield_->text()); 1180 EXPECT_STR_EQ("a", textfield_->text());
1273 SendKeyEvent(ui::VKEY_Z, false, true); 1181 SendKeyEvent(ui::VKEY_Z, false, true);
1274 EXPECT_STR_EQ("", textfield_->text()); 1182 EXPECT_STR_EQ("", 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_Y, false, true); 1185 SendKeyEvent(ui::VKEY_Y, false, true);
1278 EXPECT_STR_EQ("a", textfield_->text()); 1186 EXPECT_STR_EQ("a", 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());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 EXPECT_STR_EQ("ab", textfield_->text()); 1262 EXPECT_STR_EQ("ab", textfield_->text());
1355 SendKeyEvent(ui::VKEY_Y, false, true); 1263 SendKeyEvent(ui::VKEY_Y, false, true);
1356 EXPECT_STR_EQ("b", textfield_->text()); 1264 EXPECT_STR_EQ("b", textfield_->text());
1357 SendKeyEvent(ui::VKEY_Y, false, true); 1265 SendKeyEvent(ui::VKEY_Y, false, true);
1358 EXPECT_STR_EQ("", textfield_->text()); 1266 EXPECT_STR_EQ("", 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 } 1269 }
1362 1270
1363 TEST_F(TextfieldTest, CutCopyPaste) { 1271 TEST_F(TextfieldTest, CutCopyPaste) {
1364 InitTextfield(Textfield::STYLE_DEFAULT); 1272 InitTextfield();
1365 1273
1366 // Ensure IDS_APP_CUT cuts. 1274 // Ensure IDS_APP_CUT cuts.
1367 textfield_->SetText(ASCIIToUTF16("123")); 1275 textfield_->SetText(ASCIIToUTF16("123"));
1368 textfield_->SelectAll(false); 1276 textfield_->SelectAll(false);
1369 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); 1277 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT));
1370 textfield_->ExecuteCommand(IDS_APP_CUT, 0); 1278 textfield_->ExecuteCommand(IDS_APP_CUT, 0);
1371 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); 1279 EXPECT_STR_EQ("123", base::string16(GetClipboardText()));
1372 EXPECT_STR_EQ("", textfield_->text()); 1280 EXPECT_STR_EQ("", textfield_->text());
1373 1281
1374 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. 1282 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 EXPECT_STR_EQ("abcabcabc", textfield_->text()); 1333 EXPECT_STR_EQ("abcabcabc", textfield_->text());
1426 1334
1427 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. 1335 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op.
1428 textfield_->SelectAll(false); 1336 textfield_->SelectAll(false);
1429 SendKeyEvent(ui::VKEY_INSERT, true, true); 1337 SendKeyEvent(ui::VKEY_INSERT, true, true);
1430 EXPECT_STR_EQ("abc", base::string16(GetClipboardText())); 1338 EXPECT_STR_EQ("abc", base::string16(GetClipboardText()));
1431 EXPECT_STR_EQ("abcabcabc", textfield_->text()); 1339 EXPECT_STR_EQ("abcabcabc", textfield_->text());
1432 } 1340 }
1433 1341
1434 TEST_F(TextfieldTest, OvertypeMode) { 1342 TEST_F(TextfieldTest, OvertypeMode) {
1435 InitTextfield(Textfield::STYLE_DEFAULT); 1343 InitTextfield();
1436 // Overtype mode should be disabled (no-op [Insert]). 1344 // Overtype mode should be disabled (no-op [Insert]).
1437 textfield_->SetText(ASCIIToUTF16("2")); 1345 textfield_->SetText(ASCIIToUTF16("2"));
1438 SendKeyEvent(ui::VKEY_HOME); 1346 SendKeyEvent(ui::VKEY_HOME);
1439 SendKeyEvent(ui::VKEY_INSERT); 1347 SendKeyEvent(ui::VKEY_INSERT);
1440 SendKeyEvent(ui::VKEY_1, false, false); 1348 SendKeyEvent(ui::VKEY_1, false, false);
1441 EXPECT_STR_EQ("12", textfield_->text()); 1349 EXPECT_STR_EQ("12", textfield_->text());
1442 } 1350 }
1443 1351
1444 TEST_F(TextfieldTest, TextCursorDisplayTest) { 1352 TEST_F(TextfieldTest, TextCursorDisplayTest) {
1445 InitTextfield(Textfield::STYLE_DEFAULT); 1353 InitTextfield();
1446 // LTR-RTL string in LTR context. 1354 // LTR-RTL string in LTR context.
1447 SendKeyEvent('a'); 1355 SendKeyEvent('a');
1448 EXPECT_STR_EQ("a", textfield_->text()); 1356 EXPECT_STR_EQ("a", textfield_->text());
1449 int x = GetCursorBounds().x(); 1357 int x = GetCursorBounds().x();
1450 int prev_x = x; 1358 int prev_x = x;
1451 1359
1452 SendKeyEvent('b'); 1360 SendKeyEvent('b');
1453 EXPECT_STR_EQ("ab", textfield_->text()); 1361 EXPECT_STR_EQ("ab", textfield_->text());
1454 x = GetCursorBounds().x(); 1362 x = GetCursorBounds().x();
1455 EXPECT_LT(prev_x, x); 1363 EXPECT_LT(prev_x, x);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 SendKeyEvent('b'); 1398 SendKeyEvent('b');
1491 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); 1399 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text());
1492 x = GetCursorBounds().x(); 1400 x = GetCursorBounds().x();
1493 EXPECT_LT(prev_x, x); 1401 EXPECT_LT(prev_x, x);
1494 } 1402 }
1495 1403
1496 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) { 1404 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) {
1497 std::string locale = l10n_util::GetApplicationLocale(""); 1405 std::string locale = l10n_util::GetApplicationLocale("");
1498 base::i18n::SetICUDefaultLocale("he"); 1406 base::i18n::SetICUDefaultLocale("he");
1499 1407
1500 InitTextfield(Textfield::STYLE_DEFAULT); 1408 InitTextfield();
1501 // LTR-RTL string in RTL context. 1409 // LTR-RTL string in RTL context.
1502 SendKeyEvent('a'); 1410 SendKeyEvent('a');
1503 EXPECT_STR_EQ("a", textfield_->text()); 1411 EXPECT_STR_EQ("a", textfield_->text());
1504 int x = GetCursorBounds().x(); 1412 int x = GetCursorBounds().x();
1505 EXPECT_EQ(GetDisplayRect().right() - 1, x); 1413 EXPECT_EQ(GetDisplayRect().right() - 1, x);
1506 int prev_x = x; 1414 int prev_x = x;
1507 1415
1508 SendKeyEvent('b'); 1416 SendKeyEvent('b');
1509 EXPECT_STR_EQ("ab", textfield_->text()); 1417 EXPECT_STR_EQ("ab", textfield_->text());
1510 x = GetCursorBounds().x(); 1418 x = GetCursorBounds().x();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 SendKeyEvent('b'); 1453 SendKeyEvent('b');
1546 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); 1454 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text());
1547 x = GetCursorBounds().x(); 1455 x = GetCursorBounds().x();
1548 EXPECT_EQ(prev_x, x); 1456 EXPECT_EQ(prev_x, x);
1549 1457
1550 // Reset locale. 1458 // Reset locale.
1551 base::i18n::SetICUDefaultLocale(locale); 1459 base::i18n::SetICUDefaultLocale(locale);
1552 } 1460 }
1553 1461
1554 TEST_F(TextfieldTest, HitInsideTextAreaTest) { 1462 TEST_F(TextfieldTest, HitInsideTextAreaTest) {
1555 InitTextfield(Textfield::STYLE_DEFAULT); 1463 InitTextfield();
1556 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); 1464 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2"));
1557 std::vector<gfx::Rect> cursor_bounds; 1465 std::vector<gfx::Rect> cursor_bounds;
1558 1466
1559 // Save each cursor bound. 1467 // Save each cursor bound.
1560 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD); 1468 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD);
1561 cursor_bounds.push_back(GetCursorBounds(sel)); 1469 cursor_bounds.push_back(GetCursorBounds(sel));
1562 1470
1563 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD); 1471 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD);
1564 gfx::Rect bound = GetCursorBounds(sel); 1472 gfx::Rect bound = GetCursorBounds(sel);
1565 sel = gfx::SelectionModel(1, gfx::CURSOR_FORWARD); 1473 sel = gfx::SelectionModel(1, gfx::CURSOR_FORWARD);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 NonClientMouseClick(); 1508 NonClientMouseClick();
1601 1509
1602 MouseClick(cursor_bounds[i + 1], - (half_width / 2)); 1510 MouseClick(cursor_bounds[i + 1], - (half_width / 2));
1603 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); 1511 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition());
1604 1512
1605 NonClientMouseClick(); 1513 NonClientMouseClick();
1606 } 1514 }
1607 } 1515 }
1608 1516
1609 TEST_F(TextfieldTest, HitOutsideTextAreaTest) { 1517 TEST_F(TextfieldTest, HitOutsideTextAreaTest) {
1610 InitTextfield(Textfield::STYLE_DEFAULT); 1518 InitTextfield();
1611 1519
1612 // LTR-RTL string in LTR context. 1520 // LTR-RTL string in LTR context.
1613 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); 1521 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2"));
1614 1522
1615 SendKeyEvent(ui::VKEY_HOME); 1523 SendKeyEvent(ui::VKEY_HOME);
1616 gfx::Rect bound = GetCursorBounds(); 1524 gfx::Rect bound = GetCursorBounds();
1617 MouseClick(bound, -10); 1525 MouseClick(bound, -10);
1618 EXPECT_EQ(bound, GetCursorBounds()); 1526 EXPECT_EQ(bound, GetCursorBounds());
1619 1527
1620 SendKeyEvent(ui::VKEY_END); 1528 SendKeyEvent(ui::VKEY_END);
(...skipping 14 matching lines...) Expand all
1635 SendKeyEvent(ui::VKEY_END); 1543 SendKeyEvent(ui::VKEY_END);
1636 bound = GetCursorBounds(); 1544 bound = GetCursorBounds();
1637 MouseClick(bound, -10); 1545 MouseClick(bound, -10);
1638 EXPECT_EQ(bound, GetCursorBounds()); 1546 EXPECT_EQ(bound, GetCursorBounds());
1639 } 1547 }
1640 1548
1641 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) { 1549 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) {
1642 std::string locale = l10n_util::GetApplicationLocale(""); 1550 std::string locale = l10n_util::GetApplicationLocale("");
1643 base::i18n::SetICUDefaultLocale("he"); 1551 base::i18n::SetICUDefaultLocale("he");
1644 1552
1645 InitTextfield(Textfield::STYLE_DEFAULT); 1553 InitTextfield();
1646 1554
1647 // RTL-LTR string in RTL context. 1555 // RTL-LTR string in RTL context.
1648 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); 1556 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab"));
1649 SendKeyEvent(ui::VKEY_HOME); 1557 SendKeyEvent(ui::VKEY_HOME);
1650 gfx::Rect bound = GetCursorBounds(); 1558 gfx::Rect bound = GetCursorBounds();
1651 MouseClick(bound, 10); 1559 MouseClick(bound, 10);
1652 EXPECT_EQ(bound, GetCursorBounds()); 1560 EXPECT_EQ(bound, GetCursorBounds());
1653 1561
1654 SendKeyEvent(ui::VKEY_END); 1562 SendKeyEvent(ui::VKEY_END);
1655 bound = GetCursorBounds(); 1563 bound = GetCursorBounds();
(...skipping 12 matching lines...) Expand all
1668 SendKeyEvent(ui::VKEY_END); 1576 SendKeyEvent(ui::VKEY_END);
1669 bound = GetCursorBounds(); 1577 bound = GetCursorBounds();
1670 MouseClick(bound, 10); 1578 MouseClick(bound, 10);
1671 EXPECT_EQ(bound, GetCursorBounds()); 1579 EXPECT_EQ(bound, GetCursorBounds());
1672 1580
1673 // Reset locale. 1581 // Reset locale.
1674 base::i18n::SetICUDefaultLocale(locale); 1582 base::i18n::SetICUDefaultLocale(locale);
1675 } 1583 }
1676 1584
1677 TEST_F(TextfieldTest, OverflowTest) { 1585 TEST_F(TextfieldTest, OverflowTest) {
1678 InitTextfield(Textfield::STYLE_DEFAULT); 1586 InitTextfield();
1679 1587
1680 base::string16 str; 1588 base::string16 str;
1681 for (int i = 0; i < 500; ++i) 1589 for (int i = 0; i < 500; ++i)
1682 SendKeyEvent('a'); 1590 SendKeyEvent('a');
1683 SendKeyEvent(kHebrewLetterSamekh); 1591 SendKeyEvent(kHebrewLetterSamekh);
1684 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1592 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1685 1593
1686 // Test mouse pointing. 1594 // Test mouse pointing.
1687 MouseClick(GetCursorBounds(), -1); 1595 MouseClick(GetCursorBounds(), -1);
1688 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1596 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1689 1597
1690 // Clear text. 1598 // Clear text.
1691 SendKeyEvent(ui::VKEY_A, false, true); 1599 SendKeyEvent(ui::VKEY_A, false, true);
1692 SendKeyEvent('\n'); 1600 SendKeyEvent('\n');
1693 1601
1694 for (int i = 0; i < 500; ++i) 1602 for (int i = 0; i < 500; ++i)
1695 SendKeyEvent(kHebrewLetterSamekh); 1603 SendKeyEvent(kHebrewLetterSamekh);
1696 SendKeyEvent('a'); 1604 SendKeyEvent('a');
1697 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1605 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1698 1606
1699 MouseClick(GetCursorBounds(), -1); 1607 MouseClick(GetCursorBounds(), -1);
1700 EXPECT_EQ(501U, textfield_->GetCursorPosition()); 1608 EXPECT_EQ(501U, textfield_->GetCursorPosition());
1701 } 1609 }
1702 1610
1703 TEST_F(TextfieldTest, OverflowInRTLTest) { 1611 TEST_F(TextfieldTest, OverflowInRTLTest) {
1704 std::string locale = l10n_util::GetApplicationLocale(""); 1612 std::string locale = l10n_util::GetApplicationLocale("");
1705 base::i18n::SetICUDefaultLocale("he"); 1613 base::i18n::SetICUDefaultLocale("he");
1706 1614
1707 InitTextfield(Textfield::STYLE_DEFAULT); 1615 InitTextfield();
1708 1616
1709 base::string16 str; 1617 base::string16 str;
1710 for (int i = 0; i < 500; ++i) 1618 for (int i = 0; i < 500; ++i)
1711 SendKeyEvent('a'); 1619 SendKeyEvent('a');
1712 SendKeyEvent(kHebrewLetterSamekh); 1620 SendKeyEvent(kHebrewLetterSamekh);
1713 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1621 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1714 1622
1715 MouseClick(GetCursorBounds(), 1); 1623 MouseClick(GetCursorBounds(), 1);
1716 EXPECT_EQ(501U, textfield_->GetCursorPosition()); 1624 EXPECT_EQ(501U, textfield_->GetCursorPosition());
1717 1625
1718 // Clear text. 1626 // Clear text.
1719 SendKeyEvent(ui::VKEY_A, false, true); 1627 SendKeyEvent(ui::VKEY_A, false, true);
1720 SendKeyEvent('\n'); 1628 SendKeyEvent('\n');
1721 1629
1722 for (int i = 0; i < 500; ++i) 1630 for (int i = 0; i < 500; ++i)
1723 SendKeyEvent(kHebrewLetterSamekh); 1631 SendKeyEvent(kHebrewLetterSamekh);
1724 SendKeyEvent('a'); 1632 SendKeyEvent('a');
1725 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1633 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1726 1634
1727 MouseClick(GetCursorBounds(), 1); 1635 MouseClick(GetCursorBounds(), 1);
1728 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1636 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1729 1637
1730 // Reset locale. 1638 // Reset locale.
1731 base::i18n::SetICUDefaultLocale(locale); 1639 base::i18n::SetICUDefaultLocale(locale);
1732 } 1640 }
1733 1641
1734 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) { 1642 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) {
1735 InitTextfield(Textfield::STYLE_DEFAULT); 1643 InitTextfield();
1736 1644
1737 base::string16 str; 1645 base::string16 str;
1738 const uint32 char_count = 10UL; 1646 const uint32 char_count = 10UL;
1739 ui::CompositionText composition; 1647 ui::CompositionText composition;
1740 composition.text = UTF8ToUTF16("0123456789"); 1648 composition.text = UTF8ToUTF16("0123456789");
1741 ui::TextInputClient* client = textfield_->GetTextInputClient(); 1649 ui::TextInputClient* client = textfield_->GetTextInputClient();
1742 1650
1743 // Return false if there is no composition text. 1651 // Return false if there is no composition text.
1744 gfx::Rect rect; 1652 gfx::Rect rect;
1745 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect)); 1653 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect));
(...skipping 23 matching lines...) Expand all
1769 EXPECT_EQ(char_rect_in_screen_coord[i], actual_rect) << " i=" << i; 1677 EXPECT_EQ(char_rect_in_screen_coord[i], actual_rect) << " i=" << i;
1770 } 1678 }
1771 1679
1772 // Return false if the index is out of range. 1680 // Return false if the index is out of range.
1773 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); 1681 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect));
1774 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); 1682 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect));
1775 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); 1683 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect));
1776 } 1684 }
1777 1685
1778 TEST_F(TextfieldTest, GetCompositionCharacterBounds_ComplexText) { 1686 TEST_F(TextfieldTest, GetCompositionCharacterBounds_ComplexText) {
1779 InitTextfield(Textfield::STYLE_DEFAULT); 1687 InitTextfield();
1780 1688
1781 const base::char16 kUtf16Chars[] = { 1689 const base::char16 kUtf16Chars[] = {
1782 // U+0020 SPACE 1690 // U+0020 SPACE
1783 0x0020, 1691 0x0020,
1784 // U+1F408 (CAT) as surrogate pair 1692 // U+1F408 (CAT) as surrogate pair
1785 0xd83d, 0xdc08, 1693 0xd83d, 0xdc08,
1786 // U+5642 as Ideographic Variation Sequences 1694 // U+5642 as Ideographic Variation Sequences
1787 0x5642, 0xDB40, 0xDD00, 1695 0x5642, 0xDB40, 0xDD00,
1788 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences 1696 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences
1789 0x260E, 0xFE0F, 1697 0x260E, 0xFE0F,
(...skipping 16 matching lines...) Expand all
1806 // Here we might expect the following results but it actually depends on how 1714 // Here we might expect the following results but it actually depends on how
1807 // Uniscribe or HarfBuzz treats them with given font. 1715 // Uniscribe or HarfBuzz treats them with given font.
1808 // - rects[1] == rects[2] 1716 // - rects[1] == rects[2]
1809 // - rects[3] == rects[4] == rects[5] 1717 // - rects[3] == rects[4] == rects[5]
1810 // - rects[6] == rects[7] 1718 // - rects[6] == rects[7]
1811 } 1719 }
1812 1720
1813 // The word we select by double clicking should remain selected regardless of 1721 // The word we select by double clicking should remain selected regardless of
1814 // where we drag the mouse afterwards without releasing the left button. 1722 // where we drag the mouse afterwards without releasing the left button.
1815 TEST_F(TextfieldTest, KeepInitiallySelectedWord) { 1723 TEST_F(TextfieldTest, KeepInitiallySelectedWord) {
1816 InitTextfield(Textfield::STYLE_DEFAULT); 1724 InitTextfield();
1817 1725
1818 textfield_->SetText(ASCIIToUTF16("abc def ghi")); 1726 textfield_->SetText(ASCIIToUTF16("abc def ghi"));
1819 1727
1820 textfield_->SelectRange(gfx::Range(5, 5)); 1728 textfield_->SelectRange(gfx::Range(5, 5));
1821 const gfx::Rect middle_cursor = GetCursorBounds(); 1729 const gfx::Rect middle_cursor = GetCursorBounds();
1822 textfield_->SelectRange(gfx::Range(0, 0)); 1730 textfield_->SelectRange(gfx::Range(0, 0));
1823 const gfx::Point beginning = GetCursorBounds().origin(); 1731 const gfx::Point beginning = GetCursorBounds().origin();
1824 1732
1825 // Double click, but do not release the left button. 1733 // Double click, but do not release the left button.
1826 MouseClick(middle_cursor, 0); 1734 MouseClick(middle_cursor, 0);
1827 const gfx::Point middle(middle_cursor.x(), 1735 const gfx::Point middle(middle_cursor.x(),
1828 middle_cursor.y() + middle_cursor.height() / 2); 1736 middle_cursor.y() + middle_cursor.height() / 2);
1829 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, 1737 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle,
1830 ui::EF_LEFT_MOUSE_BUTTON, 1738 ui::EF_LEFT_MOUSE_BUTTON,
1831 ui::EF_LEFT_MOUSE_BUTTON); 1739 ui::EF_LEFT_MOUSE_BUTTON);
1832 textfield_->OnMousePressed(press_event); 1740 textfield_->OnMousePressed(press_event);
1833 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); 1741 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange());
1834 1742
1835 // Drag the mouse to the beginning of the textfield. 1743 // Drag the mouse to the beginning of the textfield.
1836 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, 1744 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning,
1837 ui::EF_LEFT_MOUSE_BUTTON, 0); 1745 ui::EF_LEFT_MOUSE_BUTTON, 0);
1838 textfield_->OnMouseDragged(drag_event); 1746 textfield_->OnMouseDragged(drag_event);
1839 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); 1747 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange());
1840 } 1748 }
1841 1749
1842 // Touch selection and dragging currently only works for chromeos. 1750 // Touch selection and dragging currently only works for chromeos.
1843 #if defined(OS_CHROMEOS) 1751 #if defined(OS_CHROMEOS)
1844 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { 1752 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) {
1845 InitTextfield(Textfield::STYLE_DEFAULT); 1753 InitTextfield();
1846 textfield_->SetText(ASCIIToUTF16("hello world")); 1754 textfield_->SetText(ASCIIToUTF16("hello world"));
1847 EXPECT_FALSE(GetTouchSelectionController()); 1755 EXPECT_FALSE(GetTouchSelectionController());
1848 const int x = GetCursorPositionX(2); 1756 const int x = GetCursorPositionX(2);
1849 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); 1757 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f);
1850 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, x, 0, 0.0f, 0.0f); 1758 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, x, 0, 0.0f, 0.0f);
1851 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); 1759 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f);
1852 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); 1760 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing);
1853 1761
1854 // Tapping on the textfield should turn on the TouchSelectionController. 1762 // Tapping on the textfield should turn on the TouchSelectionController.
1855 textfield_->OnGestureEvent(&tap); 1763 textfield_->OnGestureEvent(&tap);
(...skipping 24 matching lines...) Expand all
1880 switches::kDisableTouchDragDrop); 1788 switches::kDisableTouchDragDrop);
1881 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); 1789 ASSERT_FALSE(switches::IsTouchDragDropEnabled());
1882 textfield_->OnGestureEvent(&tap_down); 1790 textfield_->OnGestureEvent(&tap_down);
1883 textfield_->OnGestureEvent(&long_press); 1791 textfield_->OnGestureEvent(&long_press);
1884 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1792 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1885 EXPECT_TRUE(GetTouchSelectionController()); 1793 EXPECT_TRUE(GetTouchSelectionController());
1886 EXPECT_TRUE(long_press.handled()); 1794 EXPECT_TRUE(long_press.handled());
1887 } 1795 }
1888 1796
1889 TEST_F(TextfieldTest, TouchScrubbingSelection) { 1797 TEST_F(TextfieldTest, TouchScrubbingSelection) {
1890 InitTextfield(Textfield::STYLE_DEFAULT); 1798 InitTextfield();
1891 textfield_->SetText(ASCIIToUTF16("hello world")); 1799 textfield_->SetText(ASCIIToUTF16("hello world"));
1892 EXPECT_FALSE(GetTouchSelectionController()); 1800 EXPECT_FALSE(GetTouchSelectionController());
1893 1801
1894 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); 1802 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing);
1895 1803
1896 // Simulate touch-scrubbing. 1804 // Simulate touch-scrubbing.
1897 int scrubbing_start = GetCursorPositionX(1); 1805 int scrubbing_start = GetCursorPositionX(1);
1898 int scrubbing_end = GetCursorPositionX(6); 1806 int scrubbing_end = GetCursorPositionX(6);
1899 1807
1900 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0, 1808 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0,
(...skipping 21 matching lines...) Expand all
1922 1830
1923 // In the end, part of text should have been selected and handles should have 1831 // In the end, part of text should have been selected and handles should have
1924 // appeared. 1832 // appeared.
1925 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); 1833 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText());
1926 EXPECT_TRUE(GetTouchSelectionController()); 1834 EXPECT_TRUE(GetTouchSelectionController());
1927 } 1835 }
1928 #endif 1836 #endif
1929 1837
1930 // Long_Press gesture in Textfield can initiate a drag and drop now. 1838 // Long_Press gesture in Textfield can initiate a drag and drop now.
1931 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { 1839 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) {
1932 InitTextfield(Textfield::STYLE_DEFAULT); 1840 InitTextfield();
1933 textfield_->SetText(ASCIIToUTF16("Hello string world")); 1841 textfield_->SetText(ASCIIToUTF16("Hello string world"));
1934 1842
1935 // Ensure the textfield will provide selected text for drag data. 1843 // Ensure the textfield will provide selected text for drag data.
1936 textfield_->SelectRange(gfx::Range(6, 12)); 1844 textfield_->SelectRange(gfx::Range(6, 12));
1937 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 1845 const gfx::Point kStringPoint(GetCursorPositionX(9), 0);
1938 1846
1939 // Enable touch-drag-drop to make long press effective. 1847 // Enable touch-drag-drop to make long press effective.
1940 CommandLine::ForCurrentProcess()->AppendSwitch( 1848 CommandLine::ForCurrentProcess()->AppendSwitch(
1941 switches::kEnableTouchDragDrop); 1849 switches::kEnableTouchDragDrop);
1942 1850
1943 // Create a long press event in the selected region should start a drag. 1851 // Create a long press event in the selected region should start a drag.
1944 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), 1852 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(),
1945 kStringPoint.y(), 0.0f, 0.0f); 1853 kStringPoint.y(), 0.0f, 0.0f);
1946 textfield_->OnGestureEvent(&long_press); 1854 textfield_->OnGestureEvent(&long_press);
1947 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, 1855 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint,
1948 kStringPoint)); 1856 kStringPoint));
1949 } 1857 }
1950 1858
1951 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) { 1859 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) {
1952 InitTextfield(Textfield::STYLE_DEFAULT); 1860 InitTextfield();
1953 textfield_->SetText(UTF8ToUTF16("abc")); 1861 textfield_->SetText(UTF8ToUTF16("abc"));
1954 const int old_baseline = textfield_->GetBaseline(); 1862 const int old_baseline = textfield_->GetBaseline();
1955 1863
1956 // Set text which may fall back to a font which has taller baseline than 1864 // Set text which may fall back to a font which has taller baseline than
1957 // the default font. 1865 // the default font.
1958 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); 1866 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91"));
1959 const int new_baseline = textfield_->GetBaseline(); 1867 const int new_baseline = textfield_->GetBaseline();
1960 1868
1961 // Regardless of the text, the baseline must be the same. 1869 // Regardless of the text, the baseline must be the same.
1962 EXPECT_EQ(new_baseline, old_baseline); 1870 EXPECT_EQ(new_baseline, old_baseline);
1963 } 1871 }
1964 1872
1965 } // namespace views 1873 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield_model_unittest.cc ('k') | ui/views/controls/tree/tree_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698