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

Side by Side Diff: ui/chromeos/touch_exploration_controller_unittest.cc

Issue 333623003: Added split tap to TouchExplorationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@VLOG
Patch Set: Alice's changes Created 6 years, 6 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/chromeos/touch_exploration_controller.h" 5 #include "ui/chromeos/touch_exploration_controller.h"
6 6
7 #include "base/test/simple_test_tick_clock.h" 7 #include "base/test/simple_test_tick_clock.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "ui/aura/client/cursor_client.h" 9 #include "ui/aura/client/cursor_client.h"
10 #include "ui/aura/test/aura_test_base.h" 10 #include "ui/aura/test/aura_test_base.h"
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 // This should result in a single touch long press and release 678 // This should result in a single touch long press and release
679 // at the location of the tap, not at the location of the double-tap. 679 // at the location of the tap, not at the location of the double-tap.
680 // There should be a time delay between the touch press and release. 680 // There should be a time delay between the touch press and release.
681 gfx::Point first_tap_location(33, 34); 681 gfx::Point first_tap_location(33, 34);
682 generator_->set_current_location(first_tap_location); 682 generator_->set_current_location(first_tap_location);
683 generator_->PressTouch(); 683 generator_->PressTouch();
684 generator_->ReleaseTouch(); 684 generator_->ReleaseTouch();
685 gfx::Point second_tap_location(23, 24); 685 gfx::Point second_tap_location(23, 24);
686 generator_->set_current_location(second_tap_location); 686 generator_->set_current_location(second_tap_location);
687 generator_->PressTouch(); 687 generator_->PressTouch();
688 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(8000)); 688 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
689 generator_->ReleaseTouch(); 689 generator_->ReleaseTouch();
690 690
691 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); 691 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
692 ASSERT_EQ(2U, captured_events.size()); 692 ASSERT_EQ(2U, captured_events.size());
693 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); 693 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
694 EXPECT_EQ(tap_location, captured_events[0]->location()); 694 EXPECT_EQ(tap_location, captured_events[0]->location());
695 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); 695 base::TimeDelta pressed_time = captured_events[0]->time_stamp();
696 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); 696 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
697 EXPECT_EQ(tap_location, captured_events[1]->location()); 697 EXPECT_EQ(tap_location, captured_events[1]->location());
698 base::TimeDelta released_time = captured_events[1]->time_stamp(); 698 base::TimeDelta released_time = captured_events[1]->time_stamp();
699 EXPECT_EQ( 699 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
700 base::TimeDelta::FromMilliseconds(8000), 700 released_time - pressed_time);
701 released_time - pressed_time); 701 }
702 } 702
703 // Tapping and releasing with a second finger when in touch exploration mode
704 // should send a touch press and released to the location of the last
705 // successful touch exploration and return to touch explore.
706 TEST_F(TouchExplorationTest, SplitTap) {
707 SwitchTouchExplorationMode(true);
708 gfx::Point tap_location(11, 12);
aboxhall 2014/06/13 18:20:01 Suggestion: initial_touch_location
evy 2014/06/13 20:27:39 Done.
709
710 // Confirm events from other fingers go through as is.
aboxhall 2014/06/13 18:20:01 This comment is a bit confusing as you're not actu
evy 2014/06/13 20:27:39 Whoops that was a comment from the passthrough cod
711 ui::TouchEvent touch0_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now());
712 ui::TouchEvent touch1_press(
aboxhall 2014/06/13 18:20:01 Consider constructing these just before they're us
evy 2014/06/13 20:27:39 Done. This is what Dominic later suggested below,
aboxhall 2014/06/13 20:52:49 Basically, yeah.
713 ui::ET_TOUCH_PRESSED, gfx::Point(33, 34), 1, Now());
aboxhall 2014/06/13 18:20:00 Suggest using a variable for this location too, e.
evy 2014/06/13 20:27:39 For the tapping finger, or the touch explore finge
aboxhall 2014/06/13 20:52:49 I meant for the actual location (i.e. the gfx::Poi
evy 2014/06/13 22:03:47 Done.
714 ui::TouchEvent touch1_release(
715 ui::ET_TOUCH_RELEASED, gfx::Point(33, 34), 1, Now());
716
717 // Tap and hold at one location, and get a mouse move event in touch explore.
718 generator_->Dispatch(&touch0_press);
719 AdvanceSimulatedTimePastTapDelay();
720 EXPECT_TRUE(IsInTouchToMouseMode());
721
722 std::vector<ui::LocatedEvent*> events =
723 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
724 ASSERT_EQ(1U, events.size());
725
726 EXPECT_EQ(tap_location, events[0]->location());
727 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
728 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
729 ClearCapturedEvents();
730
731 // Now tap and release at a different location. This should result in a
732 // single touch and release at the location of the first (held) tap,
733 // not at the location of the second tap and release.
734 // After the release, there is still a finger in touch explore mode.
735 generator_->Dispatch(&touch1_press);
736 generator_->Dispatch(&touch1_release);
737 EXPECT_FALSE(IsInNoFingersDownState());
738
739 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
740 ASSERT_EQ(2U, captured_events.size());
741 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
742 EXPECT_EQ(tap_location, captured_events[0]->location());
743 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
744 EXPECT_EQ(tap_location, captured_events[1]->location());
745 }
746
747 // If split tap is started but the touch explore finger is released first,
748 // there should still be a touch press and release sent to the location of
749 // the last successful touch exploration.
750 // All fingers should be released after the click goes through.
751 TEST_F(TouchExplorationTest, SplitTapRelease) {
752 SwitchTouchExplorationMode(true);
753
754 gfx::Point tap_location(11, 12);
755
756 // Confirm events from other fingers go through as is.
757 ui::TouchEvent touch0_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now());
758 ui::TouchEvent touch1_press(
759 ui::ET_TOUCH_PRESSED, gfx::Point(33, 34), 1, Now());
760 ui::TouchEvent touch0_release(ui::ET_TOUCH_RELEASED, tap_location, 0, Now());
761 ui::TouchEvent touch1_release(
762 ui::ET_TOUCH_RELEASED, gfx::Point(33, 34), 1, Now());
763
764 // Tap and hold at one location, and get a mouse move event in touch explore.
765 generator_->Dispatch(&touch0_press);
aboxhall 2014/06/13 18:20:00 It might be worthwhile pulling the assertions for
evy 2014/06/13 20:27:39 Done. Great idea!
766 AdvanceSimulatedTimePastTapDelay();
767 EXPECT_TRUE(IsInTouchToMouseMode());
768
769 std::vector<ui::LocatedEvent*> events =
770 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
771 ASSERT_EQ(1U, events.size());
772
773 EXPECT_EQ(tap_location, events[0]->location());
774 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
775 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
776 ClearCapturedEvents();
777
778 // Now tap at a different location. Release at the first location,
779 // then release at the second. This should result in a
780 // single touch and release at the location of the first (held) tap,
781 // not at the location of the second tap and release.
782 generator_->Dispatch(&touch1_press);
783 generator_->Dispatch(&touch0_release);
784 generator_->Dispatch(&touch1_release);
785 EXPECT_TRUE(IsInNoFingersDownState());
786
787 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
788 ASSERT_EQ(2U, captured_events.size());
789 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
790 EXPECT_EQ(tap_location, captured_events[0]->location());
791 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
792 EXPECT_EQ(tap_location, captured_events[1]->location());
793 }
794
795 // When in touch exploration mode, making a long press with a second finger
796 // should send a touch press and released to the location of the last
797 // successful touch exploration. There should be a delay between the
798 // touch and release events (right click).
799 TEST_F(TouchExplorationTest, SplitTapLongPress) {
800 SwitchTouchExplorationMode(true);
801 gfx::Point tap_location(11, 12);
802
803 // Confirm events from other fingers go through as is.
804 ui::TouchEvent touch0_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now());
805 ui::TouchEvent touch1_press(
806 ui::ET_TOUCH_PRESSED, gfx::Point(33, 34), 1, Now());
807 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
aboxhall 2014/06/13 18:20:01 This confuses me. Could you also just do Now() + g
dmazzoni 2014/06/13 18:36:13 I think that'd be a lot more bookkeeping - you'd h
aboxhall 2014/06/13 18:40:29 No more events are created after this one, so the
dmazzoni 2014/06/13 18:46:06 Oh! I see what you mean. I think it'd be more cle
aboxhall 2014/06/13 18:47:22 Yeah, that would work well.
evy 2014/06/13 20:27:39 Done. Events dispatched as they're created
aboxhall 2014/06/13 20:52:49 Thanks, this is much easier to follow now.
808 ui::TouchEvent touch1_release(
809 ui::ET_TOUCH_RELEASED, gfx::Point(33, 34), 1, Now());
810
811 // Tap and hold at one location, and get a mouse move event in touch explore.
812 generator_->Dispatch(&touch0_press);
813 AdvanceSimulatedTimePastTapDelay();
814 EXPECT_TRUE(IsInTouchToMouseMode());
815
816 std::vector<ui::LocatedEvent*> events =
817 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
818 ASSERT_EQ(1U, events.size());
819
820 EXPECT_EQ(tap_location, events[0]->location());
821 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
822 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
823 ClearCapturedEvents();
824
825 // Now tap and release at a different location. This should result in a
826 // single touch and release at the location of the first (held) tap,
827 // not at the location of the second tap and release.
828 // After the release, there is still a finger in touch explore mode.
829 generator_->Dispatch(&touch1_press);
830 generator_->Dispatch(&touch1_release);
831 EXPECT_FALSE(IsInNoFingersDownState());
832
833 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
834 ASSERT_EQ(2U, captured_events.size());
835 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
836 EXPECT_EQ(tap_location, captured_events[0]->location());
837 base::TimeDelta pressed_time = captured_events[0]->time_stamp();
838 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
839 EXPECT_EQ(tap_location, captured_events[1]->location());
840 base::TimeDelta released_time = captured_events[1]->time_stamp();
841 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
842 released_time - pressed_time);
843 }
844
845 // If split tap is started but the touch explore finger is released first,
846 // there should still be a touch press and release sent to the location of
847 // the last successful touch exploration. If the remaining finger is held
848 // as a longpress, there should be a delay between the sent touch and release
849 // events (right click).
850 // All fingers should be released after the click goes through.
851 TEST_F(TouchExplorationTest, SplitTapReleaseLongPress) {
852 SwitchTouchExplorationMode(true);
853 gfx::Point tap_location(11, 12);
854
855 // Confirm events from other fingers go through as is.
856 ui::TouchEvent touch0_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now());
857 ui::TouchEvent touch1_press(
858 ui::ET_TOUCH_PRESSED, gfx::Point(33, 34), 1, Now());
859 ui::TouchEvent touch0_release(ui::ET_TOUCH_RELEASED, tap_location, 0, Now());
860 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
861 ui::TouchEvent touch1_release(
862 ui::ET_TOUCH_RELEASED, gfx::Point(33, 34), 1, Now());
863
864 // Tap and hold at one location, and get a mouse move event in touch explore.
865 generator_->Dispatch(&touch0_press);
866 AdvanceSimulatedTimePastTapDelay();
867 EXPECT_TRUE(IsInTouchToMouseMode());
868
869 std::vector<ui::LocatedEvent*> events =
870 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
871 ASSERT_EQ(1U, events.size());
872
873 EXPECT_EQ(tap_location, events[0]->location());
874 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
875 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
876 ClearCapturedEvents();
877
878 // Now tap at a different location. Release at the first location,
879 // then release at the second. This should result in a
880 // single touch and release at the location of the first (held) tap,
881 // not at the location of the second tap and release.
882 // After the release, TouchToMouseMode should still be on.
883 generator_->Dispatch(&touch1_press);
884 generator_->Dispatch(&touch0_release);
885 generator_->Dispatch(&touch1_release);
886 EXPECT_TRUE(IsInTouchToMouseMode());
887
888 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
889 ASSERT_EQ(2U, captured_events.size());
890 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
891 EXPECT_EQ(tap_location, captured_events[0]->location());
892 base::TimeDelta pressed_time = captured_events[0]->time_stamp();
893 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
894 EXPECT_EQ(tap_location, captured_events[1]->location());
895 base::TimeDelta released_time = captured_events[1]->time_stamp();
896 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
897 released_time - pressed_time);
898 }
899
703 900
704 } // namespace ui 901 } // namespace ui
OLDNEW
« ui/chromeos/touch_exploration_controller.cc ('K') | « ui/chromeos/touch_exploration_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698