| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "views/events/event.h" | 27 #include "views/events/event.h" |
| 28 #include "views/focus/focus_manager.h" | 28 #include "views/focus/focus_manager.h" |
| 29 #include "views/ime/mock_input_method.h" | 29 #include "views/ime/mock_input_method.h" |
| 30 #include "views/ime/text_input_client.h" | 30 #include "views/ime/text_input_client.h" |
| 31 #include "views/test/test_views_delegate.h" | 31 #include "views/test/test_views_delegate.h" |
| 32 #include "views/test/views_test_base.h" | 32 #include "views/test/views_test_base.h" |
| 33 #include "views/views_delegate.h" | 33 #include "views/views_delegate.h" |
| 34 #include "views/widget/native_widget_private.h" | 34 #include "views/widget/native_widget_private.h" |
| 35 #include "views/widget/widget.h" | 35 #include "views/widget/widget.h" |
| 36 | 36 |
| 37 // Bug 99128. | 37 // Drag and drop for aura in linux hasn't been implemented yet. |
| 38 #if defined(USE_AURA) | 38 // Bug http://crbug.com/97845 |
| 39 #define MAYBE_KeyTest FAILS_KeyTest | 39 #if defined(USE_AURA) && defined(OS_LINUX) |
| 40 #define MAYBE_ControlAndSelectTest FAILS_ControlAndSelectTest | 40 #define MAYBE_DragAndDrop_InitiateDrag DISABLED_DragAndDrop_InitiateDrag |
| 41 #define MAYBE_InsertionDeletionTest FAILS_InsertionDeletionTest | 41 #define MAYBE_DragAndDrop_ToTheLeft DISABLED_DragAndDrop_ToTheLeft |
| 42 #define MAYBE_OnKeyPressReturnValueTest FAILS_OnKeyPressReturnValueTest | 42 #define MAYBE_DragAndDrop_ToTheRight DISABLED_DragAndDrop_ToTheRight |
| 43 #define MAYBE_CursorMovement FAILS_CursorMovement | 43 #define MAYBE_DragAndDrop_Canceled DISABLED_DragAndDrop_Canceled |
| 44 #define MAYBE_DragAndDrop_ToTheRight FAILS_DragAndDrop_ToTheRight | |
| 45 #define MAYBE_DragAndDrop_ToTheLeft FAILS_DragAndDrop_ToTheLeft | |
| 46 #define MAYBE_ReadOnlyTest FAILS_ReadOnlyTest | |
| 47 #define MAYBE_TextInputClientTest FAILS_TextInputClientTest | |
| 48 #define MAYBE_UndoRedoTest FAILS_UndoRedoTest | |
| 49 #define MAYBE_TextCursorDisplayTest FAILS_TextCursorDisplayTest | |
| 50 #define MAYBE_TextCursorDisplayInRTLTest FAILS_TextCursorDisplayInRTLTest | |
| 51 #define MAYBE_HitOutsideTextAreaTest FAILS_HitOutsideTextAreaTest | |
| 52 #define MAYBE_HitOutsideTextAreaInRTLTest FAILS_HitOutsideTextAreaInRTLTest | |
| 53 #define MAYBE_OverflowTest FAILS_OverflowTest | |
| 54 #define MAYBE_OverflowInRTLTest FAILS_OverflowInRTLTest | |
| 55 #else | 44 #else |
| 56 #define MAYBE_KeyTest KeyTest | 45 #define MAYBE_DragAndDrop_InitiateDrag DragAndDrop_InitiateDrag |
| 57 #define MAYBE_ControlAndSelectTest ControlAndSelectTest | 46 #define MAYBE_DragAndDrop_ToTheLeft DragAndDrop_ToTheLeft |
| 58 #define MAYBE_InsertionDeletionTest InsertionDeletionTest | |
| 59 #define MAYBE_OnKeyPressReturnValueTest OnKeyPressReturnValueTest | |
| 60 #define MAYBE_CursorMovement CursorMovement | |
| 61 #define MAYBE_DragAndDrop_ToTheRight DragAndDrop_ToTheRight | 47 #define MAYBE_DragAndDrop_ToTheRight DragAndDrop_ToTheRight |
| 62 #define MAYBE_DragAndDrop_ToTheLeft DragAndDrop_ToTheLeft | 48 #define MAYBE_DragAndDrop_Canceled DragAndDrop_Canceled |
| 63 #define MAYBE_ReadOnlyTest ReadOnlyTest | 49 #endif // OS_LINUX && USE_AURA |
| 64 #define MAYBE_TextInputClientTest TextInputClientTest | |
| 65 #define MAYBE_UndoRedoTest UndoRedoTest | |
| 66 #define MAYBE_TextCursorDisplayTest TextCursorDisplayTest | |
| 67 #define MAYBE_TextCursorDisplayInRTLTest TextCursorDisplayInRTLTest | |
| 68 #define MAYBE_HitOutsideTextAreaTest HitOutsideTextAreaTest | |
| 69 #define MAYBE_HitOutsideTextAreaInRTLTest HitOutsideTextAreaInRTLTest | |
| 70 #define MAYBE_OverflowTest OverflowTest | |
| 71 #define MAYBE_OverflowInRTLTest OverflowInRTLTest | |
| 72 #endif | |
| 73 | 50 |
| 74 namespace { | 51 namespace { |
| 75 | 52 |
| 76 // A wrapper of Textfield to intercept the result of OnKeyPressed() and | 53 // A wrapper of Textfield to intercept the result of OnKeyPressed() and |
| 77 // OnKeyReleased() methods. | 54 // OnKeyReleased() methods. |
| 78 class TestTextfield : public views::Textfield { | 55 class TestTextfield : public views::Textfield { |
| 79 public: | 56 public: |
| 80 TestTextfield() | 57 TestTextfield() |
| 81 : key_handled_(false), | 58 : key_handled_(false), |
| 82 key_received_(false) { | 59 key_received_(false) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 EXPECT_STR_EQ("this is a test", model_->GetText()); | 341 EXPECT_STR_EQ("this is a test", model_->GetText()); |
| 365 EXPECT_STR_EQ("this is a test", textfield_->text()); | 342 EXPECT_STR_EQ("this is a test", textfield_->text()); |
| 366 EXPECT_TRUE(last_contents_.empty()); | 343 EXPECT_TRUE(last_contents_.empty()); |
| 367 | 344 |
| 368 EXPECT_EQ(string16(), textfield_->GetSelectedText()); | 345 EXPECT_EQ(string16(), textfield_->GetSelectedText()); |
| 369 textfield_->SelectAll(); | 346 textfield_->SelectAll(); |
| 370 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); | 347 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); |
| 371 EXPECT_TRUE(last_contents_.empty()); | 348 EXPECT_TRUE(last_contents_.empty()); |
| 372 } | 349 } |
| 373 | 350 |
| 374 TEST_F(NativeTextfieldViewsTest, MAYBE_KeyTest) { | 351 TEST_F(NativeTextfieldViewsTest, KeyTest) { |
| 375 InitTextfield(Textfield::STYLE_DEFAULT); | 352 InitTextfield(Textfield::STYLE_DEFAULT); |
| 376 SendKeyEvent(ui::VKEY_C, true, false); | 353 SendKeyEvent(ui::VKEY_C, true, false); |
| 377 EXPECT_STR_EQ("C", textfield_->text()); | 354 EXPECT_STR_EQ("C", textfield_->text()); |
| 378 EXPECT_STR_EQ("C", last_contents_); | 355 EXPECT_STR_EQ("C", last_contents_); |
| 379 last_contents_.clear(); | 356 last_contents_.clear(); |
| 380 | 357 |
| 381 SendKeyEvent(ui::VKEY_R, false, false); | 358 SendKeyEvent(ui::VKEY_R, false, false); |
| 382 EXPECT_STR_EQ("Cr", textfield_->text()); | 359 EXPECT_STR_EQ("Cr", textfield_->text()); |
| 383 EXPECT_STR_EQ("Cr", last_contents_); | 360 EXPECT_STR_EQ("Cr", last_contents_); |
| 384 | 361 |
| 385 textfield_->SetText(ASCIIToUTF16("")); | 362 textfield_->SetText(ASCIIToUTF16("")); |
| 386 SendKeyEvent(ui::VKEY_C, true, false, true); | 363 SendKeyEvent(ui::VKEY_C, true, false, true); |
| 387 SendKeyEvent(ui::VKEY_C, false, false, true); | 364 SendKeyEvent(ui::VKEY_C, false, false, true); |
| 388 SendKeyEvent(ui::VKEY_1, false, false, true); | 365 SendKeyEvent(ui::VKEY_1, false, false, true); |
| 389 SendKeyEvent(ui::VKEY_1, true, false, true); | 366 SendKeyEvent(ui::VKEY_1, true, false, true); |
| 390 SendKeyEvent(ui::VKEY_1, true, false, false); | 367 SendKeyEvent(ui::VKEY_1, true, false, false); |
| 391 EXPECT_STR_EQ("cC1!!", textfield_->text()); | 368 EXPECT_STR_EQ("cC1!!", textfield_->text()); |
| 392 EXPECT_STR_EQ("cC1!!", last_contents_); | 369 EXPECT_STR_EQ("cC1!!", last_contents_); |
| 393 } | 370 } |
| 394 | 371 |
| 395 TEST_F(NativeTextfieldViewsTest, MAYBE_ControlAndSelectTest) { | 372 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { |
| 396 // Insert a test string in a textfield. | 373 // Insert a test string in a textfield. |
| 397 InitTextfield(Textfield::STYLE_DEFAULT); | 374 InitTextfield(Textfield::STYLE_DEFAULT); |
| 398 textfield_->SetText(ASCIIToUTF16("one two three")); | 375 textfield_->SetText(ASCIIToUTF16("one two three")); |
| 399 SendKeyEvent(ui::VKEY_RIGHT, | 376 SendKeyEvent(ui::VKEY_RIGHT, |
| 400 true /* shift */, false /* control */); | 377 true /* shift */, false /* control */); |
| 401 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 378 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 402 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 379 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 403 | 380 |
| 404 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); | 381 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); |
| 405 | 382 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 420 SendKeyEvent(ui::VKEY_O, true, false); | 397 SendKeyEvent(ui::VKEY_O, true, false); |
| 421 SendKeyEvent(ui::VKEY_SPACE, false, false); | 398 SendKeyEvent(ui::VKEY_SPACE, false, false); |
| 422 EXPECT_STR_EQ("ZERO two three", textfield_->text()); | 399 EXPECT_STR_EQ("ZERO two three", textfield_->text()); |
| 423 | 400 |
| 424 SendKeyEvent(ui::VKEY_END, true, false); | 401 SendKeyEvent(ui::VKEY_END, true, false); |
| 425 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); | 402 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); |
| 426 SendKeyEvent(ui::VKEY_HOME, true, false); | 403 SendKeyEvent(ui::VKEY_HOME, true, false); |
| 427 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); | 404 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); |
| 428 } | 405 } |
| 429 | 406 |
| 430 TEST_F(NativeTextfieldViewsTest, MAYBE_InsertionDeletionTest) { | 407 TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) { |
| 431 // Insert a test string in a textfield. | 408 // Insert a test string in a textfield. |
| 432 InitTextfield(Textfield::STYLE_DEFAULT); | 409 InitTextfield(Textfield::STYLE_DEFAULT); |
| 433 char test_str[] = "this is a test"; | 410 char test_str[] = "this is a test"; |
| 434 for (size_t i = 0; i < sizeof(test_str); i++) { | 411 for (size_t i = 0; i < sizeof(test_str); i++) { |
| 435 // This is ugly and should be replaced by a utility standard function. | 412 // This is ugly and should be replaced by a utility standard function. |
| 436 // See comment in NativeTextfieldViews::GetPrintableChar. | 413 // See comment in NativeTextfieldViews::GetPrintableChar. |
| 437 char c = test_str[i]; | 414 char c = test_str[i]; |
| 438 ui::KeyboardCode code = | 415 ui::KeyboardCode code = |
| 439 c == ' ' ? ui::VKEY_SPACE : | 416 c == ' ' ? ui::VKEY_SPACE : |
| 440 static_cast<ui::KeyboardCode>(ui::VKEY_A + c - 'a'); | 417 static_cast<ui::KeyboardCode>(ui::VKEY_A + c - 'a'); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 526 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); |
| 550 | 527 |
| 551 textfield_->SetReadOnly(false); | 528 textfield_->SetReadOnly(false); |
| 552 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); | 529 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); |
| 553 | 530 |
| 554 // As do disabled textfields | 531 // As do disabled textfields |
| 555 textfield_->SetEnabled(false); | 532 textfield_->SetEnabled(false); |
| 556 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 533 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); |
| 557 } | 534 } |
| 558 | 535 |
| 559 TEST_F(NativeTextfieldViewsTest, MAYBE_OnKeyPressReturnValueTest) { | 536 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) { |
| 560 InitTextfield(Textfield::STYLE_DEFAULT); | 537 InitTextfield(Textfield::STYLE_DEFAULT); |
| 561 | 538 |
| 562 // Character keys will be handled by input method. | 539 // Character keys will be handled by input method. |
| 563 SendKeyEvent(ui::VKEY_A); | 540 SendKeyEvent(ui::VKEY_A); |
| 564 EXPECT_TRUE(textfield_->key_received()); | 541 EXPECT_TRUE(textfield_->key_received()); |
| 565 EXPECT_FALSE(textfield_->key_handled()); | 542 EXPECT_FALSE(textfield_->key_handled()); |
| 566 textfield_->clear(); | 543 textfield_->clear(); |
| 567 | 544 |
| 568 // Home will be handled. | 545 // Home will be handled. |
| 569 SendKeyEvent(ui::VKEY_HOME); | 546 SendKeyEvent(ui::VKEY_HOME); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 580 SendKeyEvent(ui::VKEY_UP); | 557 SendKeyEvent(ui::VKEY_UP); |
| 581 EXPECT_TRUE(textfield_->key_received()); | 558 EXPECT_TRUE(textfield_->key_received()); |
| 582 EXPECT_FALSE(textfield_->key_handled()); | 559 EXPECT_FALSE(textfield_->key_handled()); |
| 583 textfield_->clear(); | 560 textfield_->clear(); |
| 584 | 561 |
| 585 SendKeyEvent(ui::VKEY_DOWN); | 562 SendKeyEvent(ui::VKEY_DOWN); |
| 586 EXPECT_TRUE(textfield_->key_received()); | 563 EXPECT_TRUE(textfield_->key_received()); |
| 587 EXPECT_FALSE(textfield_->key_handled()); | 564 EXPECT_FALSE(textfield_->key_handled()); |
| 588 } | 565 } |
| 589 | 566 |
| 590 TEST_F(NativeTextfieldViewsTest, MAYBE_CursorMovement) { | 567 TEST_F(NativeTextfieldViewsTest, CursorMovement) { |
| 591 InitTextfield(Textfield::STYLE_DEFAULT); | 568 InitTextfield(Textfield::STYLE_DEFAULT); |
| 592 | 569 |
| 593 // Test with trailing whitespace. | 570 // Test with trailing whitespace. |
| 594 textfield_->SetText(ASCIIToUTF16("one two hre ")); | 571 textfield_->SetText(ASCIIToUTF16("one two hre ")); |
| 595 | 572 |
| 596 // Send the cursor at the end. | 573 // Send the cursor at the end. |
| 597 SendKeyEvent(ui::VKEY_END); | 574 SendKeyEvent(ui::VKEY_END); |
| 598 | 575 |
| 599 // Ctrl+Left should move the cursor just before the last word. | 576 // Ctrl+Left should move the cursor just before the last word. |
| 600 SendKeyEvent(ui::VKEY_LEFT, false, true); | 577 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 #else | 780 #else |
| 804 // Skip OSExchangeDataProviderWin::SetURL, which also sets CF_TEXT / STRING. | 781 // Skip OSExchangeDataProviderWin::SetURL, which also sets CF_TEXT / STRING. |
| 805 bad_data.SetURL(GURL("x.org"), string16(ASCIIToUTF16("x"))); | 782 bad_data.SetURL(GURL("x.org"), string16(ASCIIToUTF16("x"))); |
| 806 bad_data.SetPickledData(GDK_SELECTION_PRIMARY, Pickle()); | 783 bad_data.SetPickledData(GDK_SELECTION_PRIMARY, Pickle()); |
| 807 #endif | 784 #endif |
| 808 EXPECT_FALSE(textfield_view_->CanDrop(bad_data)); | 785 EXPECT_FALSE(textfield_view_->CanDrop(bad_data)); |
| 809 } | 786 } |
| 810 #endif | 787 #endif |
| 811 | 788 |
| 812 #if !defined(TOUCH_UI) | 789 #if !defined(TOUCH_UI) |
| 813 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) { | 790 TEST_F(NativeTextfieldViewsTest, MAYBE_DragAndDrop_InitiateDrag) { |
| 814 InitTextfield(Textfield::STYLE_DEFAULT); | 791 InitTextfield(Textfield::STYLE_DEFAULT); |
| 815 textfield_->SetText(ASCIIToUTF16("hello string world")); | 792 textfield_->SetText(ASCIIToUTF16("hello string world")); |
| 816 | 793 |
| 817 // Ensure the textfield will provide selected text for drag data. | 794 // Ensure the textfield will provide selected text for drag data. |
| 818 string16 string; | 795 string16 string; |
| 819 ui::OSExchangeData data; | 796 ui::OSExchangeData data; |
| 820 textfield_->SelectSelectionModel(gfx::SelectionModel(6, 12)); | 797 textfield_->SelectSelectionModel(gfx::SelectionModel(6, 12)); |
| 821 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 798 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
| 822 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data); | 799 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data); |
| 823 EXPECT_TRUE(data.GetString(&string)); | 800 EXPECT_TRUE(data.GetString(&string)); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 SendKeyEvent(ui::VKEY_Z, false, true); | 924 SendKeyEvent(ui::VKEY_Z, false, true); |
| 948 EXPECT_STR_EQ("", textfield_->text()); | 925 EXPECT_STR_EQ("", textfield_->text()); |
| 949 SendKeyEvent(ui::VKEY_Y, false, true); | 926 SendKeyEvent(ui::VKEY_Y, false, true); |
| 950 EXPECT_STR_EQ("hello world", textfield_->text()); | 927 EXPECT_STR_EQ("hello world", textfield_->text()); |
| 951 SendKeyEvent(ui::VKEY_Y, false, true); | 928 SendKeyEvent(ui::VKEY_Y, false, true); |
| 952 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 929 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 953 SendKeyEvent(ui::VKEY_Y, false, true); | 930 SendKeyEvent(ui::VKEY_Y, false, true); |
| 954 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 931 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 955 } | 932 } |
| 956 | 933 |
| 957 TEST_F(NativeTextfieldViewsTest, DragAndDrop_Canceled) { | 934 TEST_F(NativeTextfieldViewsTest, MAYBE_DragAndDrop_Canceled) { |
| 958 InitTextfield(Textfield::STYLE_DEFAULT); | 935 InitTextfield(Textfield::STYLE_DEFAULT); |
| 959 textfield_->SetText(ASCIIToUTF16("hello world")); | 936 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 960 | 937 |
| 961 // Start dragging "worl". | 938 // Start dragging "worl". |
| 962 textfield_->SelectSelectionModel(gfx::SelectionModel(6, 10)); | 939 textfield_->SelectSelectionModel(gfx::SelectionModel(6, 10)); |
| 963 MouseEvent click(ui::ET_MOUSE_PRESSED, GetCursorPositionX(8), 0, | 940 MouseEvent click(ui::ET_MOUSE_PRESSED, GetCursorPositionX(8), 0, |
| 964 ui::EF_LEFT_BUTTON_DOWN); | 941 ui::EF_LEFT_BUTTON_DOWN); |
| 965 textfield_view_->OnMousePressed(click); | 942 textfield_view_->OnMousePressed(click); |
| 966 ui::OSExchangeData data; | 943 ui::OSExchangeData data; |
| 967 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); | 944 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); |
| 968 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 945 EXPECT_TRUE(textfield_view_->CanDrop(data)); |
| 969 // Drag the text over somewhere valid, outside the current selection. | 946 // Drag the text over somewhere valid, outside the current selection. |
| 970 DropTargetEvent drop(data, GetCursorPositionX(2), 0, | 947 DropTargetEvent drop(data, GetCursorPositionX(2), 0, |
| 971 ui::DragDropTypes::DRAG_MOVE); | 948 ui::DragDropTypes::DRAG_MOVE); |
| 972 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); | 949 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); |
| 973 // "Cancel" the drag, via move and release over the selection, and OnDragDone. | 950 // "Cancel" the drag, via move and release over the selection, and OnDragDone. |
| 974 MouseEvent drag(ui::ET_MOUSE_DRAGGED, GetCursorPositionX(9), 0, | 951 MouseEvent drag(ui::ET_MOUSE_DRAGGED, GetCursorPositionX(9), 0, |
| 975 ui::EF_LEFT_BUTTON_DOWN); | 952 ui::EF_LEFT_BUTTON_DOWN); |
| 976 MouseEvent release(ui::ET_MOUSE_RELEASED, GetCursorPositionX(9), 0, | 953 MouseEvent release(ui::ET_MOUSE_RELEASED, GetCursorPositionX(9), 0, |
| 977 ui::EF_LEFT_BUTTON_DOWN); | 954 ui::EF_LEFT_BUTTON_DOWN); |
| 978 textfield_view_->OnMouseDragged(drag); | 955 textfield_view_->OnMouseDragged(drag); |
| 979 textfield_view_->OnMouseReleased(release); | 956 textfield_view_->OnMouseReleased(release); |
| 980 textfield_view_->OnDragDone(); | 957 textfield_view_->OnDragDone(); |
| 981 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); | 958 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); |
| 982 } | 959 } |
| 983 #endif | 960 #endif |
| 984 | 961 |
| 985 TEST_F(NativeTextfieldViewsTest, MAYBE_ReadOnlyTest) { | 962 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { |
| 986 InitTextfield(Textfield::STYLE_DEFAULT); | 963 InitTextfield(Textfield::STYLE_DEFAULT); |
| 987 textfield_->SetText(ASCIIToUTF16(" one two three ")); | 964 textfield_->SetText(ASCIIToUTF16(" one two three ")); |
| 988 textfield_->SetReadOnly(true); | 965 textfield_->SetReadOnly(true); |
| 989 SendKeyEvent(ui::VKEY_HOME); | 966 SendKeyEvent(ui::VKEY_HOME); |
| 990 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 967 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 991 | 968 |
| 992 SendKeyEvent(ui::VKEY_END); | 969 SendKeyEvent(ui::VKEY_END); |
| 993 EXPECT_EQ(15U, textfield_->GetCursorPosition()); | 970 EXPECT_EQ(15U, textfield_->GetCursorPosition()); |
| 994 | 971 |
| 995 SendKeyEvent(ui::VKEY_LEFT, false, false); | 972 SendKeyEvent(ui::VKEY_LEFT, false, false); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 | 1009 |
| 1033 // Text field is unmodifiable and selection shouldn't change. | 1010 // Text field is unmodifiable and selection shouldn't change. |
| 1034 SendKeyEvent(ui::VKEY_DELETE); | 1011 SendKeyEvent(ui::VKEY_DELETE); |
| 1035 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1012 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 1036 SendKeyEvent(ui::VKEY_BACK); | 1013 SendKeyEvent(ui::VKEY_BACK); |
| 1037 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1014 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 1038 SendKeyEvent(ui::VKEY_T); | 1015 SendKeyEvent(ui::VKEY_T); |
| 1039 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1016 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 1040 } | 1017 } |
| 1041 | 1018 |
| 1042 TEST_F(NativeTextfieldViewsTest, MAYBE_TextInputClientTest) { | 1019 TEST_F(NativeTextfieldViewsTest, TextInputClientTest) { |
| 1043 InitTextfield(Textfield::STYLE_DEFAULT); | 1020 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1044 TextInputClient* client = textfield_->GetTextInputClient(); | 1021 TextInputClient* client = textfield_->GetTextInputClient(); |
| 1045 EXPECT_TRUE(client); | 1022 EXPECT_TRUE(client); |
| 1046 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); | 1023 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); |
| 1047 | 1024 |
| 1048 textfield_->SetText(ASCIIToUTF16("0123456789")); | 1025 textfield_->SetText(ASCIIToUTF16("0123456789")); |
| 1049 ui::Range range; | 1026 ui::Range range; |
| 1050 EXPECT_TRUE(client->GetTextRange(&range)); | 1027 EXPECT_TRUE(client->GetTextRange(&range)); |
| 1051 EXPECT_EQ(0U, range.start()); | 1028 EXPECT_EQ(0U, range.start()); |
| 1052 EXPECT_EQ(10U, range.end()); | 1029 EXPECT_EQ(10U, range.end()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1099 EXPECT_TRUE(input_method_->text_input_type_changed()); |
| 1123 EXPECT_FALSE(textfield_->GetTextInputClient()); | 1100 EXPECT_FALSE(textfield_->GetTextInputClient()); |
| 1124 | 1101 |
| 1125 textfield_->SetReadOnly(false); | 1102 textfield_->SetReadOnly(false); |
| 1126 input_method_->Clear(); | 1103 input_method_->Clear(); |
| 1127 textfield_->SetPassword(true); | 1104 textfield_->SetPassword(true); |
| 1128 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1105 EXPECT_TRUE(input_method_->text_input_type_changed()); |
| 1129 EXPECT_TRUE(textfield_->GetTextInputClient()); | 1106 EXPECT_TRUE(textfield_->GetTextInputClient()); |
| 1130 } | 1107 } |
| 1131 | 1108 |
| 1132 TEST_F(NativeTextfieldViewsTest, MAYBE_UndoRedoTest) { | 1109 TEST_F(NativeTextfieldViewsTest, UndoRedoTest) { |
| 1133 InitTextfield(Textfield::STYLE_DEFAULT); | 1110 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1134 SendKeyEvent(ui::VKEY_A); | 1111 SendKeyEvent(ui::VKEY_A); |
| 1135 EXPECT_STR_EQ("a", textfield_->text()); | 1112 EXPECT_STR_EQ("a", textfield_->text()); |
| 1136 SendKeyEvent(ui::VKEY_Z, false, true); | 1113 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1137 EXPECT_STR_EQ("", textfield_->text()); | 1114 EXPECT_STR_EQ("", textfield_->text()); |
| 1138 SendKeyEvent(ui::VKEY_Z, false, true); | 1115 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1139 EXPECT_STR_EQ("", textfield_->text()); | 1116 EXPECT_STR_EQ("", textfield_->text()); |
| 1140 SendKeyEvent(ui::VKEY_Y, false, true); | 1117 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1141 EXPECT_STR_EQ("a", textfield_->text()); | 1118 EXPECT_STR_EQ("a", textfield_->text()); |
| 1142 SendKeyEvent(ui::VKEY_Y, false, true); | 1119 SendKeyEvent(ui::VKEY_Y, false, true); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 SendKeyEvent(ui::VKEY_A); | 1207 SendKeyEvent(ui::VKEY_A); |
| 1231 EXPECT_STR_EQ("a23", textfield_->text()); | 1208 EXPECT_STR_EQ("a23", textfield_->text()); |
| 1232 SendKeyEvent(ui::VKEY_B); | 1209 SendKeyEvent(ui::VKEY_B); |
| 1233 EXPECT_STR_EQ("ab3", textfield_->text()); | 1210 EXPECT_STR_EQ("ab3", textfield_->text()); |
| 1234 SendKeyEvent(ui::VKEY_Z, false, true); | 1211 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1235 EXPECT_STR_EQ("123", textfield_->text()); | 1212 EXPECT_STR_EQ("123", textfield_->text()); |
| 1236 SendKeyEvent(ui::VKEY_Y, false, true); | 1213 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1237 EXPECT_STR_EQ("ab3", textfield_->text()); | 1214 EXPECT_STR_EQ("ab3", textfield_->text()); |
| 1238 } | 1215 } |
| 1239 | 1216 |
| 1240 TEST_F(NativeTextfieldViewsTest, MAYBE_TextCursorDisplayTest) { | 1217 TEST_F(NativeTextfieldViewsTest, TextCursorDisplayTest) { |
| 1241 InitTextfield(Textfield::STYLE_DEFAULT); | 1218 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1242 // LTR-RTL string in LTR context. | 1219 // LTR-RTL string in LTR context. |
| 1243 SendKeyEvent('a'); | 1220 SendKeyEvent('a'); |
| 1244 EXPECT_STR_EQ("a", textfield_->text()); | 1221 EXPECT_STR_EQ("a", textfield_->text()); |
| 1245 int x = GetCursorBounds().x(); | 1222 int x = GetCursorBounds().x(); |
| 1246 int prev_x = x; | 1223 int prev_x = x; |
| 1247 | 1224 |
| 1248 SendKeyEvent('b'); | 1225 SendKeyEvent('b'); |
| 1249 EXPECT_STR_EQ("ab", textfield_->text()); | 1226 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1250 x = GetCursorBounds().x(); | 1227 x = GetCursorBounds().x(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 x = GetCursorBounds().x(); | 1259 x = GetCursorBounds().x(); |
| 1283 EXPECT_LT(prev_x, x); | 1260 EXPECT_LT(prev_x, x); |
| 1284 prev_x = x; | 1261 prev_x = x; |
| 1285 | 1262 |
| 1286 SendKeyEvent('b'); | 1263 SendKeyEvent('b'); |
| 1287 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2"L"ab"), textfield_->text()); | 1264 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2"L"ab"), textfield_->text()); |
| 1288 x = GetCursorBounds().x(); | 1265 x = GetCursorBounds().x(); |
| 1289 EXPECT_LT(prev_x, x); | 1266 EXPECT_LT(prev_x, x); |
| 1290 } | 1267 } |
| 1291 | 1268 |
| 1292 TEST_F(NativeTextfieldViewsTest, MAYBE_TextCursorDisplayInRTLTest) { | 1269 TEST_F(NativeTextfieldViewsTest, TextCursorDisplayInRTLTest) { |
| 1293 std::string locale = l10n_util::GetApplicationLocale(""); | 1270 std::string locale = l10n_util::GetApplicationLocale(""); |
| 1294 base::i18n::SetICUDefaultLocale("he"); | 1271 base::i18n::SetICUDefaultLocale("he"); |
| 1295 | 1272 |
| 1296 InitTextfield(Textfield::STYLE_DEFAULT); | 1273 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1297 // LTR-RTL string in RTL context. | 1274 // LTR-RTL string in RTL context. |
| 1298 SendKeyEvent('a'); | 1275 SendKeyEvent('a'); |
| 1299 EXPECT_STR_EQ("a", textfield_->text()); | 1276 EXPECT_STR_EQ("a", textfield_->text()); |
| 1300 int x = GetCursorBounds().x(); | 1277 int x = GetCursorBounds().x(); |
| 1301 EXPECT_EQ(GetDisplayRect().right() - 1, x); | 1278 EXPECT_EQ(GetDisplayRect().right() - 1, x); |
| 1302 int prev_x = x; | 1279 int prev_x = x; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 // for the test to run if using sleep(). | 1377 // for the test to run if using sleep(). |
| 1401 NonClientMouseClick(); | 1378 NonClientMouseClick(); |
| 1402 | 1379 |
| 1403 MouseClick(cursor_bounds[i + 1], - (half_width / 2)); | 1380 MouseClick(cursor_bounds[i + 1], - (half_width / 2)); |
| 1404 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); | 1381 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); |
| 1405 | 1382 |
| 1406 NonClientMouseClick(); | 1383 NonClientMouseClick(); |
| 1407 } | 1384 } |
| 1408 } | 1385 } |
| 1409 | 1386 |
| 1410 TEST_F(NativeTextfieldViewsTest, MAYBE_HitOutsideTextAreaTest) { | 1387 TEST_F(NativeTextfieldViewsTest, HitOutsideTextAreaTest) { |
| 1411 InitTextfield(Textfield::STYLE_DEFAULT); | 1388 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1412 | 1389 |
| 1413 // LTR-RTL string in LTR context. | 1390 // LTR-RTL string in LTR context. |
| 1414 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1391 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
| 1415 | 1392 |
| 1416 SendKeyEvent(ui::VKEY_HOME); | 1393 SendKeyEvent(ui::VKEY_HOME); |
| 1417 gfx::Rect bound = GetCursorBounds(); | 1394 gfx::Rect bound = GetCursorBounds(); |
| 1418 MouseClick(bound, -10); | 1395 MouseClick(bound, -10); |
| 1419 EXPECT_EQ(bound, GetCursorBounds()); | 1396 EXPECT_EQ(bound, GetCursorBounds()); |
| 1420 | 1397 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1440 SendKeyEvent(ui::VKEY_END); | 1417 SendKeyEvent(ui::VKEY_END); |
| 1441 bound = GetCursorBounds(); | 1418 bound = GetCursorBounds(); |
| 1442 #if defined(OS_WIN) | 1419 #if defined(OS_WIN) |
| 1443 MouseClick(bound, 10); | 1420 MouseClick(bound, 10); |
| 1444 #else | 1421 #else |
| 1445 MouseClick(bound, -10); | 1422 MouseClick(bound, -10); |
| 1446 #endif | 1423 #endif |
| 1447 EXPECT_EQ(bound, GetCursorBounds()); | 1424 EXPECT_EQ(bound, GetCursorBounds()); |
| 1448 } | 1425 } |
| 1449 | 1426 |
| 1450 TEST_F(NativeTextfieldViewsTest, MAYBE_HitOutsideTextAreaInRTLTest) { | 1427 TEST_F(NativeTextfieldViewsTest, HitOutsideTextAreaInRTLTest) { |
| 1451 std::string locale = l10n_util::GetApplicationLocale(""); | 1428 std::string locale = l10n_util::GetApplicationLocale(""); |
| 1452 base::i18n::SetICUDefaultLocale("he"); | 1429 base::i18n::SetICUDefaultLocale("he"); |
| 1453 | 1430 |
| 1454 InitTextfield(Textfield::STYLE_DEFAULT); | 1431 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1455 | 1432 |
| 1456 // RTL-LTR string in RTL context. | 1433 // RTL-LTR string in RTL context. |
| 1457 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2"L"ab")); | 1434 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2"L"ab")); |
| 1458 SendKeyEvent(ui::VKEY_HOME); | 1435 SendKeyEvent(ui::VKEY_HOME); |
| 1459 gfx::Rect bound = GetCursorBounds(); | 1436 gfx::Rect bound = GetCursorBounds(); |
| 1460 MouseClick(bound, 10); | 1437 MouseClick(bound, 10); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 // This verifies that |bound| is contained by |display|. |bound|'s right edge | 1471 // This verifies that |bound| is contained by |display|. |bound|'s right edge |
| 1495 // must be less than |diaplay|'s right edge. | 1472 // must be less than |diaplay|'s right edge. |
| 1496 void OverflowCursorBoundTestVerifier(const gfx::Rect& display, | 1473 void OverflowCursorBoundTestVerifier(const gfx::Rect& display, |
| 1497 const gfx::Rect& bound) { | 1474 const gfx::Rect& bound) { |
| 1498 EXPECT_LE(display.x(), bound.x()); | 1475 EXPECT_LE(display.x(), bound.x()); |
| 1499 EXPECT_GT(display.right(), bound.right()); | 1476 EXPECT_GT(display.right(), bound.right()); |
| 1500 EXPECT_LE(display.y(), bound.y()); | 1477 EXPECT_LE(display.y(), bound.y()); |
| 1501 EXPECT_GE(display.bottom(), bound.bottom()); | 1478 EXPECT_GE(display.bottom(), bound.bottom()); |
| 1502 } | 1479 } |
| 1503 | 1480 |
| 1504 TEST_F(NativeTextfieldViewsTest, MAYBE_OverflowTest) { | 1481 TEST_F(NativeTextfieldViewsTest, OverflowTest) { |
| 1505 InitTextfield(Textfield::STYLE_DEFAULT); | 1482 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1506 | 1483 |
| 1507 string16 str; | 1484 string16 str; |
| 1508 for (int i = 0; i < 500; ++i) | 1485 for (int i = 0; i < 500; ++i) |
| 1509 SendKeyEvent('a'); | 1486 SendKeyEvent('a'); |
| 1510 SendKeyEvent(kHebrewLetterSamekh); | 1487 SendKeyEvent(kHebrewLetterSamekh); |
| 1511 gfx::Rect bound = GetCursorBounds(); | 1488 gfx::Rect bound = GetCursorBounds(); |
| 1512 gfx::Rect display = GetDisplayRect(); | 1489 gfx::Rect display = GetDisplayRect(); |
| 1513 OverflowCursorBoundTestVerifier(display, bound); | 1490 OverflowCursorBoundTestVerifier(display, bound); |
| 1514 | 1491 |
| 1515 // Test mouse pointing. | 1492 // Test mouse pointing. |
| 1516 MouseClick(bound, -1); | 1493 MouseClick(bound, -1); |
| 1517 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1494 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1518 | 1495 |
| 1519 // Clear text. | 1496 // Clear text. |
| 1520 SendKeyEvent(ui::VKEY_A, false, true); | 1497 SendKeyEvent(ui::VKEY_A, false, true); |
| 1521 SendKeyEvent('\n'); | 1498 SendKeyEvent('\n'); |
| 1522 | 1499 |
| 1523 for (int i = 0; i < 500; ++i) | 1500 for (int i = 0; i < 500; ++i) |
| 1524 SendKeyEvent(kHebrewLetterSamekh); | 1501 SendKeyEvent(kHebrewLetterSamekh); |
| 1525 SendKeyEvent('a'); | 1502 SendKeyEvent('a'); |
| 1526 bound = GetCursorBounds(); | 1503 bound = GetCursorBounds(); |
| 1527 display = GetDisplayRect(); | 1504 display = GetDisplayRect(); |
| 1528 OverflowCursorBoundTestVerifier(display, bound); | 1505 OverflowCursorBoundTestVerifier(display, bound); |
| 1529 | 1506 |
| 1530 MouseClick(bound, -1); | 1507 MouseClick(bound, -1); |
| 1531 EXPECT_EQ(501U, textfield_->GetCursorPosition()); | 1508 EXPECT_EQ(501U, textfield_->GetCursorPosition()); |
| 1532 } | 1509 } |
| 1533 | 1510 |
| 1534 TEST_F(NativeTextfieldViewsTest, MAYBE_OverflowInRTLTest) { | 1511 TEST_F(NativeTextfieldViewsTest, OverflowInRTLTest) { |
| 1535 std::string locale = l10n_util::GetApplicationLocale(""); | 1512 std::string locale = l10n_util::GetApplicationLocale(""); |
| 1536 base::i18n::SetICUDefaultLocale("he"); | 1513 base::i18n::SetICUDefaultLocale("he"); |
| 1537 | 1514 |
| 1538 InitTextfield(Textfield::STYLE_DEFAULT); | 1515 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1539 | 1516 |
| 1540 string16 str; | 1517 string16 str; |
| 1541 for (int i = 0; i < 500; ++i) | 1518 for (int i = 0; i < 500; ++i) |
| 1542 SendKeyEvent('a'); | 1519 SendKeyEvent('a'); |
| 1543 SendKeyEvent(kHebrewLetterSamekh); | 1520 SendKeyEvent(kHebrewLetterSamekh); |
| 1544 gfx::Rect bound = GetCursorBounds(); | 1521 gfx::Rect bound = GetCursorBounds(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1567 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1544 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 1568 #else | 1545 #else |
| 1569 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1546 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1570 #endif | 1547 #endif |
| 1571 | 1548 |
| 1572 // Reset locale. | 1549 // Reset locale. |
| 1573 base::i18n::SetICUDefaultLocale(locale); | 1550 base::i18n::SetICUDefaultLocale(locale); |
| 1574 } | 1551 } |
| 1575 | 1552 |
| 1576 } // namespace views | 1553 } // namespace views |
| OLD | NEW |