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

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: Addressed more comments 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
« no previous file with comments | « ui/chromeos/touch_exploration_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 "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 TouchExplorationModeAtLocation(gfx::Point tap_location, int id){
aboxhall 2014/06/13 20:52:50 Nit: space between ) and { Also, this might be be
evy 2014/06/13 22:03:47 I made it like that just in case we want to try te
aboxhall 2014/06/13 22:09:00 Yep, that sounds like a good idea. You could even
128 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, id, 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);
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);
702 } 708 }
703 709
710 // Tapping and releasing with a second finger when in touch exploration mode
711 // should send a touch press and released to the location of the last
712 // successful touch exploration and return to touch explore.
713 TEST_F(TouchExplorationTest, SplitTap) {
714 SwitchTouchExplorationMode(true);
715 gfx::Point initial_touch_location(11, 12);
716
717 // Tap and hold at one location, and get a mouse move event in touch explore.
718 TouchExplorationModeAtLocation(initial_touch_location, 0);
719 std::vector<ui::LocatedEvent*> events =
720 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
721 ASSERT_EQ(1U, events.size());
722
723 EXPECT_EQ(initial_touch_location, events[0]->location());
724 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
725 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
726 ClearCapturedEvents();
727
728 // Now tap and release at a different location. This should result in a
729 // single touch and release at the location of the first (held) tap,
730 // not at the location of the second tap and release.
731 // After the release, there is still a finger in touch explore mode.
732 ui::TouchEvent touch1_press(
733 ui::ET_TOUCH_PRESSED, gfx::Point(33, 34), 1, Now());
734 generator_->Dispatch(&touch1_press);
735 ui::TouchEvent touch1_release(
736 ui::ET_TOUCH_RELEASED, gfx::Point(33, 34), 1, Now());
737 generator_->Dispatch(&touch1_release);
738 EXPECT_FALSE(IsInNoFingersDownState());
739
740 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
741 ASSERT_EQ(2U, captured_events.size());
742 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
743 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
744 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
745 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
746 }
747
748 // If split tap is started but the touch explore finger is released first,
749 // there should still be a touch press and release sent to the location of
750 // the last successful touch exploration.
751 // All fingers should be released after the click goes through.
752 TEST_F(TouchExplorationTest, SplitTapRelease) {
753 SwitchTouchExplorationMode(true);
754
755 gfx::Point initial_touch_location(11, 12);
756
757 // Tap and hold at one location, and get a mouse move event in touch explore.
758 TouchExplorationModeAtLocation(initial_touch_location, 0);
759
760 std::vector<ui::LocatedEvent*> events =
761 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
762 ASSERT_EQ(1U, events.size());
763
764 EXPECT_EQ(initial_touch_location, events[0]->location());
765 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
766 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
767 ClearCapturedEvents();
768
769 // Now tap at a different location. Release at the first location,
770 // then release at the second. This should result in a
771 // single touch and release at the location of the first (held) tap,
772 // not at the location of the second tap and release.
773 ui::TouchEvent touch1_press(
774 ui::ET_TOUCH_PRESSED, gfx::Point(33, 34), 1, Now());
775 generator_->Dispatch(&touch1_press);
776 ui::TouchEvent touch0_release(
777 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now());
778 generator_->Dispatch(&touch0_release);
779 ui::TouchEvent touch1_release(
780 ui::ET_TOUCH_RELEASED, gfx::Point(33, 34), 1, Now());
781 generator_->Dispatch(&touch1_release);
782 EXPECT_TRUE(IsInNoFingersDownState());
783
784 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
785 ASSERT_EQ(2U, captured_events.size());
786 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
787 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
788 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
789 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
790 }
791
792 // When in touch exploration mode, making a long press with a second finger
793 // should send a touch press and released to the location of the last
794 // successful touch exploration. There should be a delay between the
795 // touch and release events (right click).
796 TEST_F(TouchExplorationTest, SplitTapLongPress) {
797 SwitchTouchExplorationMode(true);
798 gfx::Point initial_touch_location(11, 12);
799
800 // Tap and hold at one location, and get a mouse move event in touch explore.
801 TouchExplorationModeAtLocation(initial_touch_location, 0);
802
803 std::vector<ui::LocatedEvent*> events =
804 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
805 ASSERT_EQ(1U, events.size());
806
807 EXPECT_EQ(initial_touch_location, events[0]->location());
808 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
809 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
810 ClearCapturedEvents();
811
812 // Now tap and release at a different location. This should result in a
813 // single touch and release at the location of the first (held) tap,
814 // not at the location of the second tap and release.
815 // After the release, there is still a finger in touch explore mode.
816 ui::TouchEvent touch1_press(
817 ui::ET_TOUCH_PRESSED, gfx::Point(33, 34), 1, Now());
818 generator_->Dispatch(&touch1_press);
819 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
820 ui::TouchEvent touch1_release(
821 ui::ET_TOUCH_RELEASED, gfx::Point(33, 34), 1, Now());
822 generator_->Dispatch(&touch1_release);
823 EXPECT_FALSE(IsInNoFingersDownState());
824
825 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
826 ASSERT_EQ(2U, captured_events.size());
827 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
828 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
829 base::TimeDelta pressed_time = captured_events[0]->time_stamp();
830 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
831 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
832 base::TimeDelta released_time = captured_events[1]->time_stamp();
833 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
834 released_time - pressed_time);
835 }
836
837 // If split tap is started but the touch explore finger is released first,
838 // there should still be a touch press and release sent to the location of
839 // the last successful touch exploration. If the remaining finger is held
840 // as a longpress, there should be a delay between the sent touch and release
841 // events (right click).
842 // All fingers should be released after the click goes through.
843 TEST_F(TouchExplorationTest, SplitTapReleaseLongPress) {
844 SwitchTouchExplorationMode(true);
845 gfx::Point initial_touch_location(11, 12);
846
847 // Tap and hold at one location, and get a mouse move event in touch explore.
848 TouchExplorationModeAtLocation(initial_touch_location, 0);
849
850 std::vector<ui::LocatedEvent*> events =
851 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
852 ASSERT_EQ(1U, events.size());
853
854 EXPECT_EQ(initial_touch_location, events[0]->location());
855 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
856 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
857 ClearCapturedEvents();
858
859 // Now tap at a different location. Release at the first location,
860 // then release at the second. This should result in a
861 // single touch and release at the location of the first (held) tap,
862 // not at the location of the second tap and release.
863 // After the release, TouchToMouseMode should still be on.
864 ui::TouchEvent touch1_press(
865 ui::ET_TOUCH_PRESSED, gfx::Point(33, 34), 1, Now());
866 generator_->Dispatch(&touch1_press);
867 ui::TouchEvent touch0_release(
868 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now());
869 generator_->Dispatch(&touch0_release);
870 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
871 ui::TouchEvent touch1_release(
872 ui::ET_TOUCH_RELEASED, gfx::Point(33, 34), 1, Now());
873 generator_->Dispatch(&touch1_release);
874 EXPECT_TRUE(IsInTouchToMouseMode());
875
876 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
877 ASSERT_EQ(2U, captured_events.size());
878 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
879 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
880 base::TimeDelta pressed_time = captured_events[0]->time_stamp();
881 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
882 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
883 base::TimeDelta released_time = captured_events[1]->time_stamp();
884 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
885 released_time - pressed_time);
886 }
887
888
704 } // namespace ui 889 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/touch_exploration_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698