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

Side by Side Diff: content/browser/renderer_host/input/touch_selection_controller_client_aura_browsertest.cc

Issue 2124913002: Fix long press touch selection on empty text fields (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: EmptyTextfield -> ClearTextfield Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h" 5 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 bool GetPointInsideTextfield(gfx::PointF* point) { 145 bool GetPointInsideTextfield(gfx::PointF* point) {
146 std::string str; 146 std::string str;
147 if (ExecuteScriptAndExtractString(shell(), "get_point_inside_textfield()", 147 if (ExecuteScriptAndExtractString(shell(), "get_point_inside_textfield()",
148 &str)) { 148 &str)) {
149 return JSONToPoint(str, point); 149 return JSONToPoint(str, point);
150 } 150 }
151 return false; 151 return false;
152 } 152 }
153 153
154 bool EmptyTextfield() { return ExecuteScript(shell(), "empty_textfield()"); } 154 bool ClearTextfield() { return ExecuteScript(shell(), "clear_textfield()"); }
155 155
156 RenderWidgetHostViewAura* GetRenderWidgetHostViewAura() { 156 RenderWidgetHostViewAura* GetRenderWidgetHostViewAura() {
157 return static_cast<RenderWidgetHostViewAura*>( 157 return static_cast<RenderWidgetHostViewAura*>(
158 shell()->web_contents()->GetRenderWidgetHostView()); 158 shell()->web_contents()->GetRenderWidgetHostView());
159 } 159 }
160 160
161 TestTouchSelectionControllerClientAura* selection_controller_client() { 161 TestTouchSelectionControllerClientAura* selection_controller_client() {
162 return selection_controller_client_; 162 return selection_controller_client_;
163 } 163 }
164 164
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // handle. 275 // handle.
276 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, 276 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
277 EmptyTextfieldInsertionOnTap) { 277 EmptyTextfieldInsertionOnTap) {
278 // Set the test page up. 278 // Set the test page up.
279 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); 279 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
280 InitSelectionController(); 280 InitSelectionController();
281 281
282 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura(); 282 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
283 283
284 // Clear textfield contents. 284 // Clear textfield contents.
285 ASSERT_TRUE(EmptyTextfield()); 285 ASSERT_TRUE(ClearTextfield());
286 286
287 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 287 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
288 rwhva->selection_controller()->active_status()); 288 rwhva->selection_controller()->active_status());
289 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 289 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
290 290
291 // Tap inside the textfield and wait for the insertion cursor. 291 // Tap inside the textfield and wait for the insertion cursor.
292 selection_controller_client()->InitWaitForSelectionEvent( 292 selection_controller_client()->InitWaitForSelectionEvent(
293 ui::SELECTION_ESTABLISHED); 293 ui::SELECTION_ESTABLISHED);
294 294
295 gfx::PointF point; 295 gfx::PointF point;
296 ASSERT_TRUE(GetPointInsideTextfield(&point)); 296 ASSERT_TRUE(GetPointInsideTextfield(&point));
297 ui::GestureEventDetails tap_details(ui::ET_GESTURE_TAP); 297 ui::GestureEventDetails tap_details(ui::ET_GESTURE_TAP);
298 tap_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN); 298 tap_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
299 tap_details.set_tap_count(1); 299 tap_details.set_tap_count(1);
300 ui::GestureEvent tap(point.x(), point.y(), 0, ui::EventTimeForNow(), 300 ui::GestureEvent tap(point.x(), point.y(), 0, ui::EventTimeForNow(),
301 tap_details); 301 tap_details);
302 rwhva->OnGestureEvent(&tap); 302 rwhva->OnGestureEvent(&tap);
303 303
304 selection_controller_client()->Wait(); 304 selection_controller_client()->Wait();
305 305
306 // Check that insertion is not active and the quick menu is not showing. 306 // Check that insertion is not active and the quick menu is not showing.
307 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 307 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
308 rwhva->selection_controller()->active_status()); 308 rwhva->selection_controller()->active_status());
309 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning()); 309 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
310 } 310 }
311 311
312 // Tests that long-pressing on an empty textfield brings up the insertion handle
313 // and the quick menu.
314 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
315 EmptyTextfieldInsertionOnLongPress) {
316 // Set the test page up.
317 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
318 InitSelectionController();
319
320 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
321
322 // Clear textfield contents.
323 ASSERT_TRUE(ClearTextfield());
324
325 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
326 rwhva->selection_controller()->active_status());
327 EXPECT_FALSE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
328
329 // Long-press inside the textfield and wait for the insertion handle.
330 selection_controller_client()->InitWaitForSelectionEvent(
331 ui::INSERTION_HANDLE_SHOWN);
332
333 gfx::PointF point;
334 ASSERT_TRUE(GetPointInsideTextfield(&point));
335 ui::GestureEventDetails long_press_details(ui::ET_GESTURE_LONG_PRESS);
336 long_press_details.set_device_type(ui::GestureDeviceType::DEVICE_TOUCHSCREEN);
337 ui::GestureEvent long_press(point.x(), point.y(), 0, ui::EventTimeForNow(),
338 long_press_details);
339 rwhva->OnGestureEvent(&long_press);
340
341 selection_controller_client()->Wait();
342
343 // Check that insertion is active and the quick menu is showing.
344 EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE,
345 rwhva->selection_controller()->active_status());
346 EXPECT_TRUE(ui::TouchSelectionMenuRunner::GetInstance()->IsRunning());
347 }
348
312 // Tests that the quick menu is hidden whenever a touch point is active. 349 // Tests that the quick menu is hidden whenever a touch point is active.
313 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest, 350 IN_PROC_BROWSER_TEST_F(TouchSelectionControllerClientAuraTest,
314 QuickMenuHiddenOnTouch) { 351 QuickMenuHiddenOnTouch) {
315 // Set the test page up. 352 // Set the test page up.
316 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html")); 353 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/touch_selection.html"));
317 InitSelectionController(); 354 InitSelectionController();
318 355
319 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura(); 356 RenderWidgetHostViewAura* rwhva = GetRenderWidgetHostViewAura();
320 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, 357 EXPECT_EQ(ui::TouchSelectionController::INACTIVE,
321 rwhva->selection_controller()->active_status()); 358 rwhva->selection_controller()->active_status());
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 711
675 // The handle should have moved to right. 712 // The handle should have moved to right.
676 EXPECT_EQ(initial_handle_rect.y(), moved_handle_rect.y()); 713 EXPECT_EQ(initial_handle_rect.y(), moved_handle_rect.y());
677 EXPECT_LT(initial_handle_rect.x(), moved_handle_rect.x()); 714 EXPECT_LT(initial_handle_rect.x(), moved_handle_rect.x());
678 715
679 EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE, 716 EXPECT_EQ(ui::TouchSelectionController::INSERTION_ACTIVE,
680 rwhva->selection_controller()->active_status()); 717 rwhva->selection_controller()->active_status());
681 } 718 }
682 719
683 } // namespace content 720 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/touch_selection_controller_client_aura.cc ('k') | content/test/data/touch_selection.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698