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

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: Little nit 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } else if (on && !touch_exploration_controller_.get()) { 117 } else if (on && !touch_exploration_controller_.get()) {
118 touch_exploration_controller_.reset( 118 touch_exploration_controller_.reset(
119 new ui::TouchExplorationController(root_window())); 119 new ui::TouchExplorationController(root_window()));
120 touch_exploration_controller_->SetEventHandlerForTesting( 120 touch_exploration_controller_->SetEventHandlerForTesting(
121 &event_capturer_); 121 &event_capturer_);
122 cursor_client()->ShowCursor(); 122 cursor_client()->ShowCursor();
123 cursor_client()->DisableMouseEvents(); 123 cursor_client()->DisableMouseEvents();
124 } 124 }
125 } 125 }
126 126
127 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) {
128 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now());
129 generator_->Dispatch(&touch_press);
130 AdvanceSimulatedTimePastTapDelay();
131 EXPECT_TRUE(IsInTouchToMouseMode());
132 }
133
127 bool IsInTouchToMouseMode() { 134 bool IsInTouchToMouseMode() {
128 aura::client::CursorClient* cursor_client = 135 aura::client::CursorClient* cursor_client =
129 aura::client::GetCursorClient(root_window()); 136 aura::client::GetCursorClient(root_window());
130 return cursor_client && 137 return cursor_client &&
131 cursor_client->IsMouseEventsEnabled() && 138 cursor_client->IsMouseEventsEnabled() &&
132 !cursor_client->IsCursorVisible(); 139 !cursor_client->IsCursorVisible();
133 } 140 }
134 141
135 bool IsInNoFingersDownState() { 142 bool IsInNoFingersDownState() {
136 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); 143 return touch_exploration_controller_->IsInNoFingersDownStateForTesting();
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 // This should result in a single touch long press and release 685 // 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. 686 // 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. 687 // There should be a time delay between the touch press and release.
681 gfx::Point first_tap_location(33, 34); 688 gfx::Point first_tap_location(33, 34);
682 generator_->set_current_location(first_tap_location); 689 generator_->set_current_location(first_tap_location);
683 generator_->PressTouch(); 690 generator_->PressTouch();
684 generator_->ReleaseTouch(); 691 generator_->ReleaseTouch();
685 gfx::Point second_tap_location(23, 24); 692 gfx::Point second_tap_location(23, 24);
686 generator_->set_current_location(second_tap_location); 693 generator_->set_current_location(second_tap_location);
687 generator_->PressTouch(); 694 generator_->PressTouch();
688 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(8000)); 695 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
James Cook 2014/06/17 17:06:18 Nice that you're not using hardcoded times!
689 generator_->ReleaseTouch(); 696 generator_->ReleaseTouch();
690 697
691 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); 698 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
692 ASSERT_EQ(2U, captured_events.size()); 699 ASSERT_EQ(2U, captured_events.size());
693 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); 700 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
694 EXPECT_EQ(tap_location, captured_events[0]->location()); 701 EXPECT_EQ(tap_location, captured_events[0]->location());
695 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); 702 base::TimeDelta pressed_time = captured_events[0]->time_stamp();
696 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); 703 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
697 EXPECT_EQ(tap_location, captured_events[1]->location()); 704 EXPECT_EQ(tap_location, captured_events[1]->location());
698 base::TimeDelta released_time = captured_events[1]->time_stamp(); 705 base::TimeDelta released_time = captured_events[1]->time_stamp();
699 EXPECT_EQ( 706 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
700 base::TimeDelta::FromMilliseconds(8000), 707 released_time - pressed_time);
701 released_time - pressed_time); 708 }
702 } 709
710 // Double-tapping without coming from touch exploration (no previous touch
711 // exploration event) should not generate any events.
712 TEST_F(TouchExplorationTest, DoubleTapNoTouchExplore) {
713 SwitchTouchExplorationMode(true);
714
715 // Double-tap without any previous touch.
716 // Touch exploration mode has not been entered, so there is no previous
717 // touch exploration event. The double-tap should be discarded, and no events
718 // should be generated at all.
719 gfx::Point double_tap_location(33, 34);
720 generator_->set_current_location(double_tap_location);
721 generator_->PressTouch();
722 generator_->ReleaseTouch();
723 generator_->PressTouch();
724 generator_->ReleaseTouch();
725
726 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
727 ASSERT_EQ(0U, captured_events.size());
728 }
729
730 // Tapping and releasing with a second finger when in touch exploration mode
731 // should send a touch press and released to the location of the last
732 // successful touch exploration and return to touch explore.
733 TEST_F(TouchExplorationTest, SplitTap) {
734 SwitchTouchExplorationMode(true);
735 gfx::Point initial_touch_location(11, 12);
736 gfx::Point second_touch_location(33, 34);
737
738 // Tap and hold at one location, and get a mouse move event in touch explore.
739 EnterTouchExplorationModeAtLocation(initial_touch_location);
740 std::vector<ui::LocatedEvent*> events =
741 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
742 ASSERT_EQ(1U, events.size());
743
744 EXPECT_EQ(initial_touch_location, events[0]->location());
745 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
746 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
747 ClearCapturedEvents();
748
749 // Now tap and release at a different location. This should result in a
750 // single touch and release at the location of the first (held) tap,
751 // not at the location of the second tap and release.
752 // After the release, there is still a finger in touch explore mode.
753 ui::TouchEvent split_tap_press(
754 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now());
755 generator_->Dispatch(&split_tap_press);
756 ui::TouchEvent split_tap_release(
757 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now());
758 generator_->Dispatch(&split_tap_release);
759 EXPECT_FALSE(IsInNoFingersDownState());
760
761 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
762 ASSERT_EQ(2U, captured_events.size());
763 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
764 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
765 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
766 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
767 }
768
769 // If split tap is started but the touch explore finger is released first,
770 // there should still be a touch press and release sent to the location of
771 // the last successful touch exploration.
772 // Both fingers should be released after the click goes through.
773 TEST_F(TouchExplorationTest, SplitTapRelease) {
774 SwitchTouchExplorationMode(true);
775
776 gfx::Point initial_touch_location(11, 12);
777 gfx::Point second_touch_location(33, 34);
778
779 // Tap and hold at one location, and get a mouse move event in touch explore.
780 EnterTouchExplorationModeAtLocation(initial_touch_location);
781
782 std::vector<ui::LocatedEvent*> events =
783 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
784 ASSERT_EQ(1U, events.size());
785
786 EXPECT_EQ(initial_touch_location, events[0]->location());
787 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
788 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
789 ClearCapturedEvents();
James Cook 2014/06/17 17:06:19 optional: It seems like you do this set of asserti
evy 2014/06/17 18:36:22 Good point! Up to this point, the code is the same
790
791 // Now tap at a different location. Release at the first location,
792 // then release at the second. This should result in a
793 // single touch and release at the location of the first (held) tap,
794 // not at the location of the second tap and release.
795 ui::TouchEvent split_tap_press(
796 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now());
797 generator_->Dispatch(&split_tap_press);
798 ui::TouchEvent touch_explore_release(
James Cook 2014/06/17 17:06:18 I like how these variable names are very descripti
evy 2014/06/17 18:36:22 Thanks to Alice's suggestions! :)
799 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now());
800 generator_->Dispatch(&touch_explore_release);
801 ui::TouchEvent split_tap_release(
802 ui::ET_TOUCH_RELEASED, second_touch_location , 1, Now());
803 generator_->Dispatch(&split_tap_release);
804 EXPECT_TRUE(IsInNoFingersDownState());
805
806 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
807 ASSERT_EQ(2U, captured_events.size());
808 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
809 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
810 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
811 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
812 }
813
814 // When in touch exploration mode, making a long press with a second finger
815 // should send a touch press and released to the location of the last
816 // successful touch exploration. There should be a delay between the
817 // touch and release events (right click).
818 TEST_F(TouchExplorationTest, SplitTapLongPress) {
819 SwitchTouchExplorationMode(true);
820 gfx::Point initial_touch_location(11, 12);
821 gfx::Point second_touch_location(33, 34);
822
823 // Tap and hold at one location, and get a mouse move event in touch explore.
824 EnterTouchExplorationModeAtLocation(initial_touch_location);
825
826 std::vector<ui::LocatedEvent*> events =
827 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
828 ASSERT_EQ(1U, events.size());
829
830 EXPECT_EQ(initial_touch_location, events[0]->location());
831 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
832 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
833 ClearCapturedEvents();
James Cook 2014/06/17 17:06:18 optional: as above
evy 2014/06/17 18:36:22 Done.
834
835 // Now tap and release at a different location. This should result in a
836 // single touch and release at the location of the first (held) tap,
837 // not at the location of the second tap and release.
838 // After the release, there is still a finger in touch explore mode.
839 ui::TouchEvent split_tap_press(
840 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now());
841 generator_->Dispatch(&split_tap_press);
842 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
843 ui::TouchEvent split_tap_release(
844 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now());
845 generator_->Dispatch(&split_tap_release);
846 EXPECT_FALSE(IsInNoFingersDownState());
847
848 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
849 ASSERT_EQ(2U, captured_events.size());
850 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
851 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
852 base::TimeDelta pressed_time = captured_events[0]->time_stamp();
853 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
854 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
855 base::TimeDelta released_time = captured_events[1]->time_stamp();
856 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
857 released_time - pressed_time);
858 }
859
860 // If split tap is started but the touch explore finger is released first,
861 // there should still be a touch press and release sent to the location of
862 // the last successful touch exploration. If the remaining finger is held
863 // as a longpress, there should be a delay between the sent touch and release
864 // events (right click).
865 // All fingers should be released after the click goes through.
James Cook 2014/06/17 17:06:18 merge with line above, or blank line above
evy 2014/06/17 18:36:22 Done.
866 TEST_F(TouchExplorationTest, SplitTapReleaseLongPress) {
867 SwitchTouchExplorationMode(true);
868 gfx::Point initial_touch_location(11, 12);
869 gfx::Point second_touch_location(33, 34);
870
871 // Tap and hold at one location, and get a mouse move event in touch explore.
872 EnterTouchExplorationModeAtLocation(initial_touch_location);
873
874 std::vector<ui::LocatedEvent*> events =
875 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
876 ASSERT_EQ(1U, events.size());
877
878 EXPECT_EQ(initial_touch_location, events[0]->location());
879 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
880 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
881 ClearCapturedEvents();
882
883 // Now tap at a different location. Release at the first location,
884 // then release at the second. This should result in a
885 // single touch and release at the location of the first (held) tap,
886 // not at the location of the second tap and release.
887 // After the release, TouchToMouseMode should still be on.
888 ui::TouchEvent split_tap_press(
889 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now());
890 generator_->Dispatch(&split_tap_press);
891 ui::TouchEvent touch_explore_release(
892 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now());
893 generator_->Dispatch(&touch_explore_release);
894 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
895 ui::TouchEvent split_tap_release(
896 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now());
897 generator_->Dispatch(&split_tap_release);
898 EXPECT_TRUE(IsInTouchToMouseMode());
899
900 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
901 ASSERT_EQ(2U, captured_events.size());
902 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
903 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
904 base::TimeDelta pressed_time = captured_events[0]->time_stamp();
905 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
906 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
907 base::TimeDelta released_time = captured_events[1]->time_stamp();
908 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
909 released_time - pressed_time);
910 }
911
703 912
704 } // namespace ui 913 } // 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