OLD | NEW |
---|---|
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" |
11 #include "ui/aura/test/event_generator.h" | 11 #include "ui/aura/test/event_generator.h" |
12 #include "ui/aura/test/test_cursor_client.h" | 12 #include "ui/aura/test/test_cursor_client.h" |
13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
15 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
16 #include "ui/events/test/events_test_utils.h" | |
16 #include "ui/gfx/geometry/point.h" | 17 #include "ui/gfx/geometry/point.h" |
17 #include "ui/gl/gl_implementation.h" | 18 #include "ui/gl/gl_implementation.h" |
18 #include "ui/gl/gl_surface.h" | 19 #include "ui/gl/gl_surface.h" |
19 | 20 |
20 namespace ui { | 21 namespace ui { |
21 | 22 |
22 namespace { | 23 namespace { |
23 // Records all mouse and touch events. | 24 // Records all mouse and touch events. |
24 class EventCapturer : public ui::EventHandler { | 25 class EventCapturer : public ui::EventHandler { |
25 public: | 26 public: |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
941 EXPECT_EQ(first_touch_location, captured_events[0]->location()); | 942 EXPECT_EQ(first_touch_location, captured_events[0]->location()); |
942 ClearCapturedEvents(); | 943 ClearCapturedEvents(); |
943 | 944 |
944 ui::TouchEvent first_touch_release( | 945 ui::TouchEvent first_touch_release( |
945 ui::ET_TOUCH_RELEASED, first_touch_location, 0, Now()); | 946 ui::ET_TOUCH_RELEASED, first_touch_location, 0, Now()); |
946 generator_->Dispatch(&first_touch_release); | 947 generator_->Dispatch(&first_touch_release); |
947 ASSERT_EQ(captured_events.size(), 1u); | 948 ASSERT_EQ(captured_events.size(), 1u); |
948 EXPECT_TRUE(IsInNoFingersDownState()); | 949 EXPECT_TRUE(IsInNoFingersDownState()); |
949 } | 950 } |
950 | 951 |
952 int Factorial(int n) { | |
dmazzoni
2014/06/26 18:16:43
Put this inside the "namespace {" at the top, so t
evy
2014/06/26 22:31:05
Done.
| |
953 if (n <= 0) | |
954 return 0; | |
955 if (n == 1) | |
956 return 1; | |
957 if (n == 2) | |
958 return 2; | |
959 return n * Factorial(n - 1); | |
960 } | |
961 | |
962 TEST_F(TouchExplorationTest, AllFingerPermutations) { | |
963 SwitchTouchExplorationMode(true); | |
964 | |
965 // We will test all permutations of events from three different fingers | |
966 // to ensure that we return to NO_FINGERS_DOWN when fingers have been | |
967 // released. | |
968 ScopedVector<ui::TouchEvent> all_events; | |
969 all_events.push_back( | |
970 new TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(11, 12), 0, Now())); | |
971 all_events.push_back( | |
972 new TouchEvent(ui::ET_TOUCH_MOVED, gfx::Point(13, 14), 0, Now())); | |
973 all_events.push_back( | |
974 new TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(15, 16), 0, Now())); | |
975 all_events.push_back( | |
976 new TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(21, 22), 1, Now())); | |
977 all_events.push_back( | |
978 new TouchEvent(ui::ET_TOUCH_MOVED, gfx::Point(23, 24), 1, Now())); | |
979 all_events.push_back( | |
980 new TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(25, 26), 1, Now())); | |
981 all_events.push_back( | |
982 new TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(31, 32), 2, Now())); | |
983 all_events.push_back( | |
984 new TouchEvent(ui::ET_TOUCH_MOVED, gfx::Point(33, 34), 2, Now())); | |
985 all_events.push_back( | |
986 new TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(35, 36), 2, Now())); | |
987 | |
988 const int num_events = all_events.size(); | |
989 const int num_permutations = Factorial(num_events); | |
990 std::vector<ui::TouchEvent*> queued_events; | |
991 ui::TouchEvent* next_dispatch; | |
992 int index; | |
dmazzoni
2014/06/26 18:16:43
Declare all of these variables inside the block sc
evy
2014/06/26 22:31:05
Done.
| |
993 std::vector<bool> fingers_pressed(3, false); | |
994 | |
995 for (int i = 0; i < num_permutations; i++) { | |
996 queued_events = all_events.get(); | |
997 for (int j = num_events - 1; j >= 0; j--) { | |
998 if (j == num_events - 1) { | |
999 index = (i / Factorial(num_events - 1)); | |
dmazzoni
2014/06/26 18:16:43
This logic looks correct but inefficient. Calling
evy
2014/06/26 22:31:05
I'm not quite sure what you meant, but I did somet
| |
1000 } else if (j == 0){ | |
1001 index = 0; | |
1002 } else { | |
1003 index = ((i % Factorial(j + 1)) / Factorial(j)); | |
1004 } | |
1005 next_dispatch = queued_events[index]; | |
1006 ASSERT_TRUE(next_dispatch != NULL); | |
1007 EventTestApi test_dispatch(next_dispatch); | |
1008 test_dispatch.set_time_stamp(Now()); | |
1009 generator_->Dispatch(next_dispatch); | |
1010 queued_events.erase(queued_events.begin() + index); | |
1011 // Note: it is possible to send a touched move event in the state | |
1012 // SINGLE_TAP_RELEASED or TOUCH_EXPLORE_RELEASED | |
1013 // because the events are not always generated in a sensical | |
1014 // order. If there is a NOTREACHED() for touch moved hit in | |
dmazzoni
2014/06/26 18:16:43
We should probably change the NOTREACHED to a LOG(
evy
2014/06/26 22:31:05
The thing is, this should never happen when the us
dmazzoni
2014/06/27 07:25:16
What about if the user already has fingers down wh
evy
2014/06/27 16:33:37
Okay, a touch moved is now properly handled.
| |
1015 // InSingleTapOrTouchExploreReleased, that is fine here. | |
1016 | |
1017 // Keep track of what fingers have been pressed, to release | |
1018 // only those fingers at the end, so the check for being in | |
1019 // no fingers down can be accurate. | |
1020 if (next_dispatch->type() == ET_TOUCH_PRESSED) { | |
1021 fingers_pressed[next_dispatch->touch_id()] = true; | |
1022 } else if (next_dispatch->type() == ET_TOUCH_RELEASED) { | |
1023 fingers_pressed[next_dispatch->touch_id()] = false; | |
1024 } | |
1025 } | |
1026 ASSERT_EQ(queued_events.size(), 0u); | |
1027 | |
1028 // Release fingers recorded as pressed. | |
1029 for(int j = 0; j < int(fingers_pressed.size()); j++){ | |
1030 if (fingers_pressed[j] == true) { | |
1031 generator_->ReleaseTouchId(j); | |
1032 fingers_pressed[j] = false; | |
1033 } | |
1034 } | |
1035 AdvanceSimulatedTimePastTapDelay(); | |
1036 EXPECT_TRUE(IsInNoFingersDownState()); | |
1037 ClearCapturedEvents(); | |
1038 } | |
1039 } | |
1040 | |
951 } // namespace ui | 1041 } // namespace ui |
OLD | NEW |