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

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

Issue 434583002: Prevent repeated taps from resetting insertion handle position (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch Created 6 years, 4 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
« no previous file with comments | « content/browser/renderer_host/input/touch_selection_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/renderer_host/input/touch_selection_controller.h" 5 #include "content/browser/renderer_host/input/touch_selection_controller.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/test/mock_motion_event.h" 8 #include "ui/events/test/mock_motion_event.h"
9 9
10 using ui::test::MockMotionEvent; 10 using ui::test::MockMotionEvent;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType()); 403 ASSERT_EQ(INSERTION_SHOWN, GetLastEventType());
404 404
405 // No tap should be signalled if the touch sequence is cancelled. 405 // No tap should be signalled if the touch sequence is cancelled.
406 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); 406 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
407 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 407 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
408 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0); 408 event = MockMotionEvent(MockMotionEvent::ACTION_CANCEL, event_time, 0, 0);
409 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); 409 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
410 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType()); 410 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType());
411 } 411 }
412 412
413 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) {
414 base::TimeTicks event_time = base::TimeTicks::Now();
415 controller().OnTapEvent();
416 controller().OnSelectionEditable(true);
417 SetDraggingEnabled(true);
418
419 gfx::RectF anchor_rect(10, 0, 0, 10);
420 bool visible = true;
421 ChangeInsertion(anchor_rect, visible);
422 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType());
423 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
424
425 // Tapping again shouldn't reset the active insertion point.
426 controller().OnTapEvent();
427 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
428 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
429 EXPECT_EQ(INSERTION_SHOWN, GetLastEventType());
430 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
431
432 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
433 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
434 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType());
435 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
436
437 anchor_rect.Offset(5, 15);
438 ChangeInsertion(anchor_rect, visible);
439 EXPECT_EQ(INSERTION_MOVED, GetLastEventType());
440 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
441
442 // Pressing shouldn't reset the active insertion point.
443 controller().OnLongPressEvent();
444 controller().OnSelectionEmpty(true);
445 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
446 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
447 EXPECT_EQ(INSERTION_MOVED, GetLastEventType());
448 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
449
450 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
451 EXPECT_TRUE(controller().WillHandleTouchEvent(event));
452 EXPECT_EQ(INSERTION_TAPPED, GetLastEventType());
453 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor());
454 }
455
413 TEST_F(TouchSelectionControllerTest, SelectionBasic) { 456 TEST_F(TouchSelectionControllerTest, SelectionBasic) {
414 gfx::RectF start_rect(5, 5, 0, 10); 457 gfx::RectF start_rect(5, 5, 0, 10);
415 gfx::RectF end_rect(50, 5, 0, 10); 458 gfx::RectF end_rect(50, 5, 0, 10);
416 bool visible = true; 459 bool visible = true;
417 460
418 // Selection events are ignored until automatic showing is enabled. 461 // Selection events are ignored until automatic showing is enabled.
419 ChangeSelection(start_rect, visible, end_rect, visible); 462 ChangeSelection(start_rect, visible, end_rect, visible);
420 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); 463 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor());
421 464
422 controller().OnLongPressEvent(); 465 controller().OnLongPressEvent();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 618
576 visible = true; 619 visible = true;
577 ChangeInsertion(insertion_rect, visible); 620 ChangeInsertion(insertion_rect, visible);
578 EXPECT_FALSE(GetAndResetNeedsAnimate()); 621 EXPECT_FALSE(GetAndResetNeedsAnimate());
579 622
580 controller().SetTemporarilyHidden(false); 623 controller().SetTemporarilyHidden(false);
581 EXPECT_TRUE(GetAndResetNeedsAnimate()); 624 EXPECT_TRUE(GetAndResetNeedsAnimate());
582 } 625 }
583 626
584 } // namespace content 627 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/touch_selection_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698