OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "grit/ui_resources.h" | 7 #include "grit/ui_resources.h" |
8 #include "ui/aura/client/screen_position_client.h" | 8 #include "ui/aura/client/screen_position_client.h" |
9 #include "ui/aura/test/event_generator.h" | |
10 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
11 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/base/touch/touch_editing_controller.h" | 11 #include "ui/base/touch/touch_editing_controller.h" |
13 #include "ui/base/ui_base_switches.h" | 12 #include "ui/base/ui_base_switches.h" |
| 13 #include "ui/events/test/event_generator.h" |
14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/render_text.h" | 17 #include "ui/gfx/render_text.h" |
18 #include "ui/views/controls/textfield/textfield.h" | 18 #include "ui/views/controls/textfield/textfield.h" |
19 #include "ui/views/controls/textfield/textfield_test_api.h" | 19 #include "ui/views/controls/textfield/textfield_test_api.h" |
20 #include "ui/views/test/views_test_base.h" | 20 #include "ui/views/test/views_test_base.h" |
21 #include "ui/views/touchui/touch_selection_controller_impl.h" | 21 #include "ui/views/touchui/touch_selection_controller_impl.h" |
22 #include "ui/views/views_touch_selection_controller_factory.h" | 22 #include "ui/views/views_touch_selection_controller_factory.h" |
23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 EXPECT_NE(visible_handle_position, textfield_->GetSelectedRange().end()); | 536 EXPECT_NE(visible_handle_position, textfield_->GetSelectedRange().end()); |
537 visible_handle_position = textfield_->GetSelectedRange().end(); | 537 visible_handle_position = textfield_->GetSelectedRange().end(); |
538 EXPECT_EQ((size_t) 10, textfield_->GetSelectedRange().start()); | 538 EXPECT_EQ((size_t) 10, textfield_->GetSelectedRange().start()); |
539 } | 539 } |
540 } | 540 } |
541 | 541 |
542 TEST_F(TouchSelectionControllerImplTest, | 542 TEST_F(TouchSelectionControllerImplTest, |
543 DoubleTapInTextfieldWithCursorHandleShouldSelectText) { | 543 DoubleTapInTextfieldWithCursorHandleShouldSelectText) { |
544 CreateTextfield(); | 544 CreateTextfield(); |
545 textfield_->SetText(ASCIIToUTF16("some text")); | 545 textfield_->SetText(ASCIIToUTF16("some text")); |
546 aura::test::EventGenerator generator( | 546 ui::test::EventGenerator generator( |
547 textfield_->GetWidget()->GetNativeView()->GetRootWindow()); | 547 textfield_->GetWidget()->GetNativeView()->GetRootWindow()); |
548 | 548 |
549 // Tap the textfield to invoke touch selection. | 549 // Tap the textfield to invoke touch selection. |
550 generator.GestureTapAt(gfx::Point(10, 10)); | 550 generator.GestureTapAt(gfx::Point(10, 10)); |
551 | 551 |
552 // Cursor handle should be visible. | 552 // Cursor handle should be visible. |
553 EXPECT_FALSE(textfield_->HasSelection()); | 553 EXPECT_FALSE(textfield_->HasSelection()); |
554 VERIFY_HANDLE_POSITIONS(false); | 554 VERIFY_HANDLE_POSITIONS(false); |
555 | 555 |
556 // Double tap on the cursor handle position. We want to check that the cursor | 556 // Double tap on the cursor handle position. We want to check that the cursor |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 // Close the widget, hence quick menus, before quick menu controller goes out | 797 // Close the widget, hence quick menus, before quick menu controller goes out |
798 // of scope. | 798 // of scope. |
799 widget_->CloseNow(); | 799 widget_->CloseNow(); |
800 widget_ = NULL; | 800 widget_ = NULL; |
801 } | 801 } |
802 | 802 |
803 TEST_F(TouchSelectionControllerImplTest, MouseEventDeactivatesTouchSelection) { | 803 TEST_F(TouchSelectionControllerImplTest, MouseEventDeactivatesTouchSelection) { |
804 CreateTextfield(); | 804 CreateTextfield(); |
805 EXPECT_FALSE(GetSelectionController()); | 805 EXPECT_FALSE(GetSelectionController()); |
806 | 806 |
807 aura::test::EventGenerator generator( | 807 ui::test::EventGenerator generator( |
808 textfield_widget_->GetNativeView()->GetRootWindow()); | 808 textfield_widget_->GetNativeView()->GetRootWindow()); |
809 | 809 |
810 generator.set_current_location(gfx::Point(5, 5)); | 810 generator.set_current_location(gfx::Point(5, 5)); |
811 RunPendingMessages(); | 811 RunPendingMessages(); |
812 | 812 |
813 // Start touch editing; then move mouse over the textfield and ensure it | 813 // Start touch editing; then move mouse over the textfield and ensure it |
814 // deactivates touch selection. | 814 // deactivates touch selection. |
815 StartTouchEditing(); | 815 StartTouchEditing(); |
816 EXPECT_TRUE(GetSelectionController()); | 816 EXPECT_TRUE(GetSelectionController()); |
817 generator.MoveMouseTo(gfx::Point(5, 10)); | 817 generator.MoveMouseTo(gfx::Point(5, 10)); |
(...skipping 20 matching lines...) Expand all Loading... |
838 EXPECT_TRUE(GetSelectionController()); | 838 EXPECT_TRUE(GetSelectionController()); |
839 generator.MoveMouseTo(5, 505); | 839 generator.MoveMouseTo(5, 505); |
840 RunPendingMessages(); | 840 RunPendingMessages(); |
841 EXPECT_FALSE(GetSelectionController()); | 841 EXPECT_FALSE(GetSelectionController()); |
842 } | 842 } |
843 | 843 |
844 TEST_F(TouchSelectionControllerImplTest, KeyEventDeactivatesTouchSelection) { | 844 TEST_F(TouchSelectionControllerImplTest, KeyEventDeactivatesTouchSelection) { |
845 CreateTextfield(); | 845 CreateTextfield(); |
846 EXPECT_FALSE(GetSelectionController()); | 846 EXPECT_FALSE(GetSelectionController()); |
847 | 847 |
848 aura::test::EventGenerator generator( | 848 ui::test::EventGenerator generator( |
849 textfield_widget_->GetNativeView()->GetRootWindow()); | 849 textfield_widget_->GetNativeView()->GetRootWindow()); |
850 | 850 |
851 RunPendingMessages(); | 851 RunPendingMessages(); |
852 | 852 |
853 // Start touch editing; then press a key and ensure it deactivates touch | 853 // Start touch editing; then press a key and ensure it deactivates touch |
854 // selection. | 854 // selection. |
855 StartTouchEditing(); | 855 StartTouchEditing(); |
856 EXPECT_TRUE(GetSelectionController()); | 856 EXPECT_TRUE(GetSelectionController()); |
857 generator.PressKey(ui::VKEY_A, 0); | 857 generator.PressKey(ui::VKEY_A, 0); |
858 RunPendingMessages(); | 858 RunPendingMessages(); |
859 EXPECT_FALSE(GetSelectionController()); | 859 EXPECT_FALSE(GetSelectionController()); |
860 } | 860 } |
861 | 861 |
862 } // namespace views | 862 } // namespace views |
OLD | NEW |