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

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

Issue 581963004: Clean up GestureEventDetails constructors and fix unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 bool key_received_; 96 bool key_received_;
97 97
98 base::WeakPtrFactory<TestTextfield> weak_ptr_factory_; 98 base::WeakPtrFactory<TestTextfield> weak_ptr_factory_;
99 99
100 DISALLOW_COPY_AND_ASSIGN(TestTextfield); 100 DISALLOW_COPY_AND_ASSIGN(TestTextfield);
101 }; 101 };
102 102
103 // Convenience to make constructing a GestureEvent simpler. 103 // Convenience to make constructing a GestureEvent simpler.
104 class GestureEventForTest : public ui::GestureEvent { 104 class GestureEventForTest : public ui::GestureEvent {
105 public: 105 public:
106 GestureEventForTest(ui::EventType type, 106 GestureEventForTest(int x, int y, ui::GestureEventDetails details)
107 int x, 107 : GestureEvent(x, y, 0, base::TimeDelta(), details) {}
108 int y,
109 float delta_x,
110 float delta_y)
111 : GestureEvent(x,
112 y,
113 0,
114 base::TimeDelta(),
115 ui::GestureEventDetails(type, delta_x, delta_y)) {}
116 108
117 private: 109 private:
118 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); 110 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest);
119 }; 111 };
120 112
121 // This controller will happily destroy the target textfield passed on 113 // This controller will happily destroy the target textfield passed on
122 // construction when a key event is triggered. 114 // construction when a key event is triggered.
123 class TextfieldDestroyerController : public views::TextfieldController { 115 class TextfieldDestroyerController : public views::TextfieldController {
124 public: 116 public:
125 explicit TextfieldDestroyerController(views::Textfield* target) 117 explicit TextfieldDestroyerController(views::Textfield* target)
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 textfield_->OnMousePressed(click); 314 textfield_->OnMousePressed(click);
323 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 315 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(),
324 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, 316 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT,
325 ui::EF_LEFT_MOUSE_BUTTON); 317 ui::EF_LEFT_MOUSE_BUTTON);
326 textfield_->OnMouseReleased(release); 318 textfield_->OnMouseReleased(release);
327 } 319 }
328 320
329 // Simulates a complete tap. 321 // Simulates a complete tap.
330 void Tap(const gfx::Point& point) { 322 void Tap(const gfx::Point& point) {
331 GestureEventForTest begin( 323 GestureEventForTest begin(
332 ui::ET_GESTURE_BEGIN, point.x(), point.y(), 0.0f, 0.0f); 324 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN));
333 textfield_->OnGestureEvent(&begin); 325 textfield_->OnGestureEvent(&begin);
334 326
335 GestureEventForTest tap_down( 327 GestureEventForTest tap_down(
336 ui::ET_GESTURE_TAP_DOWN, point.x(), point.y(), 0.0f, 0.0f); 328 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN));
337 textfield_->OnGestureEvent(&tap_down); 329 textfield_->OnGestureEvent(&tap_down);
338 330
339 GestureEventForTest show_press( 331 GestureEventForTest show_press(
340 ui::ET_GESTURE_SHOW_PRESS, point.x(), point.y(), 0.0f, 0.0f); 332 point.x(),
333 point.y(),
334 ui::GestureEventDetails(ui::ET_GESTURE_SHOW_PRESS));
341 textfield_->OnGestureEvent(&show_press); 335 textfield_->OnGestureEvent(&show_press);
342 336
343 GestureEventForTest tap( 337 ui::GestureEventDetails tap_details(ui::ET_GESTURE_TAP);
344 ui::ET_GESTURE_TAP, point.x(), point.y(), 1.0f, 0.0f); 338 tap_details.set_tap_count(1);
339 GestureEventForTest tap(point.x(), point.y(), tap_details);
345 textfield_->OnGestureEvent(&tap); 340 textfield_->OnGestureEvent(&tap);
346 341
347 GestureEventForTest end( 342 GestureEventForTest end(
348 ui::ET_GESTURE_END, point.x(), point.y(), 0.0f, 0.0f); 343 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_END));
349 textfield_->OnGestureEvent(&end); 344 textfield_->OnGestureEvent(&end);
350 } 345 }
351 346
352 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, 347 void VerifyTextfieldContextMenuContents(bool textfield_has_selection,
353 bool can_undo, 348 bool can_undo,
354 ui::MenuModel* menu) { 349 ui::MenuModel* menu) {
355 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); 350 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */));
356 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); 351 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */));
357 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); 352 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */));
358 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); 353 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */));
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 // Touch selection and dragging currently only works for chromeos. 1944 // Touch selection and dragging currently only works for chromeos.
1950 #if defined(OS_CHROMEOS) 1945 #if defined(OS_CHROMEOS)
1951 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { 1946 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) {
1952 InitTextfield(); 1947 InitTextfield();
1953 textfield_->SetText(ASCIIToUTF16("hello world")); 1948 textfield_->SetText(ASCIIToUTF16("hello world"));
1954 EXPECT_FALSE(test_api_->touch_selection_controller()); 1949 EXPECT_FALSE(test_api_->touch_selection_controller());
1955 const int x = GetCursorPositionX(2); 1950 const int x = GetCursorPositionX(2);
1956 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); 1951 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing);
1957 1952
1958 // Tapping on the textfield should turn on the TouchSelectionController. 1953 // Tapping on the textfield should turn on the TouchSelectionController.
1959 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); 1954 ui::GestureEventDetails tap_details(ui::ET_GESTURE_TAP);
1955 tap_details.set_tap_count(1);
1956 GestureEventForTest tap(x, 0, tap_details);
1960 textfield_->OnGestureEvent(&tap); 1957 textfield_->OnGestureEvent(&tap);
1961 EXPECT_TRUE(test_api_->touch_selection_controller()); 1958 EXPECT_TRUE(test_api_->touch_selection_controller());
1962 1959
1963 // Un-focusing the textfield should reset the TouchSelectionController 1960 // Un-focusing the textfield should reset the TouchSelectionController
1964 textfield_->GetFocusManager()->ClearFocus(); 1961 textfield_->GetFocusManager()->ClearFocus();
1965 EXPECT_FALSE(test_api_->touch_selection_controller()); 1962 EXPECT_FALSE(test_api_->touch_selection_controller());
1966 textfield_->RequestFocus(); 1963 textfield_->RequestFocus();
1967 1964
1968 // With touch editing enabled, long press should not show context menu. 1965 // With touch editing enabled, long press should not show context menu.
1969 // Instead, select word and invoke TouchSelectionController. 1966 // Instead, select word and invoke TouchSelectionController.
1970 GestureEventForTest long_press_1(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); 1967 GestureEventForTest long_press_1(
1968 x, 0, ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
1971 textfield_->OnGestureEvent(&long_press_1); 1969 textfield_->OnGestureEvent(&long_press_1);
1972 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1970 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1973 EXPECT_TRUE(test_api_->touch_selection_controller()); 1971 EXPECT_TRUE(test_api_->touch_selection_controller());
1974 EXPECT_TRUE(long_press_1.handled()); 1972 EXPECT_TRUE(long_press_1.handled());
1975 1973
1976 // With touch drag drop enabled, long pressing in the selected region should 1974 // With touch drag drop enabled, long pressing in the selected region should
1977 // start a drag and remove TouchSelectionController. 1975 // start a drag and remove TouchSelectionController.
1978 ASSERT_TRUE(switches::IsTouchDragDropEnabled()); 1976 ASSERT_TRUE(switches::IsTouchDragDropEnabled());
1979 GestureEventForTest long_press_2(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); 1977 GestureEventForTest long_press_2(
1978 x, 0, ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
1980 textfield_->OnGestureEvent(&long_press_2); 1979 textfield_->OnGestureEvent(&long_press_2);
1981 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1980 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1982 EXPECT_FALSE(test_api_->touch_selection_controller()); 1981 EXPECT_FALSE(test_api_->touch_selection_controller());
1983 EXPECT_FALSE(long_press_2.handled()); 1982 EXPECT_FALSE(long_press_2.handled());
1984 1983
1985 // After disabling touch drag drop, long pressing again in the selection 1984 // After disabling touch drag drop, long pressing again in the selection
1986 // region should not do anything. 1985 // region should not do anything.
1987 CommandLine::ForCurrentProcess()->AppendSwitch( 1986 CommandLine::ForCurrentProcess()->AppendSwitch(
1988 switches::kDisableTouchDragDrop); 1987 switches::kDisableTouchDragDrop);
1989 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); 1988 ASSERT_FALSE(switches::IsTouchDragDropEnabled());
1990 GestureEventForTest long_press_3(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); 1989 GestureEventForTest long_press_3(
1990 x, 0, ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
1991 textfield_->OnGestureEvent(&long_press_3); 1991 textfield_->OnGestureEvent(&long_press_3);
1992 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1992 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1993 EXPECT_FALSE(test_api_->touch_selection_controller()); 1993 EXPECT_FALSE(test_api_->touch_selection_controller());
1994 EXPECT_FALSE(long_press_3.handled()); 1994 EXPECT_FALSE(long_press_3.handled());
1995 } 1995 }
1996 #endif 1996 #endif
1997 1997
1998 TEST_F(TextfieldTest, TouchSelectionInUnfocusableTextfield) { 1998 TEST_F(TextfieldTest, TouchSelectionInUnfocusableTextfield) {
1999 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); 1999 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing);
2000 2000
(...skipping 24 matching lines...) Expand all
2025 2025
2026 // Ensure the textfield will provide selected text for drag data. 2026 // Ensure the textfield will provide selected text for drag data.
2027 textfield_->SelectRange(gfx::Range(6, 12)); 2027 textfield_->SelectRange(gfx::Range(6, 12));
2028 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 2028 const gfx::Point kStringPoint(GetCursorPositionX(9), 0);
2029 2029
2030 // Enable touch-drag-drop to make long press effective. 2030 // Enable touch-drag-drop to make long press effective.
2031 CommandLine::ForCurrentProcess()->AppendSwitch( 2031 CommandLine::ForCurrentProcess()->AppendSwitch(
2032 switches::kEnableTouchDragDrop); 2032 switches::kEnableTouchDragDrop);
2033 2033
2034 // Create a long press event in the selected region should start a drag. 2034 // Create a long press event in the selected region should start a drag.
2035 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), 2035 GestureEventForTest long_press(
2036 kStringPoint.y(), 0.0f, 0.0f); 2036 kStringPoint.x(),
2037 kStringPoint.y(),
2038 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
2037 textfield_->OnGestureEvent(&long_press); 2039 textfield_->OnGestureEvent(&long_press);
2038 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, 2040 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint,
2039 kStringPoint)); 2041 kStringPoint));
2040 } 2042 }
2041 2043
2042 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) { 2044 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) {
2043 InitTextfield(); 2045 InitTextfield();
2044 textfield_->SetText(UTF8ToUTF16("abc")); 2046 textfield_->SetText(UTF8ToUTF16("abc"));
2045 const int old_baseline = textfield_->GetBaseline(); 2047 const int old_baseline = textfield_->GetBaseline();
2046 2048
(...skipping 15 matching lines...) Expand all
2062 TextfieldDestroyerController controller(textfield_); 2064 TextfieldDestroyerController controller(textfield_);
2063 EXPECT_TRUE(controller.target()); 2065 EXPECT_TRUE(controller.target());
2064 2066
2065 // Send a key to trigger OnKeyEvent(). 2067 // Send a key to trigger OnKeyEvent().
2066 SendKeyEvent('X'); 2068 SendKeyEvent('X');
2067 2069
2068 EXPECT_FALSE(controller.target()); 2070 EXPECT_FALSE(controller.target());
2069 } 2071 }
2070 2072
2071 } // namespace views 2073 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/table/table_view_unittest.cc ('k') | ui/views/corewm/desktop_capture_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698