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

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

Issue 358693004: Added touch event permutations test to touch_exploration_controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new_passthrough
Patch Set: updated NOTREACHED() logging and prevented the test from reaching the NOTREACHED() Created 6 years, 5 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"
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 24 matching lines...) Expand all
50 const ScopedVector<ui::LocatedEvent>& captured_events() const { 51 const ScopedVector<ui::LocatedEvent>& captured_events() const {
51 return events_; 52 return events_;
52 } 53 }
53 54
54 private: 55 private:
55 ScopedVector<ui::LocatedEvent> events_; 56 ScopedVector<ui::LocatedEvent> events_;
56 57
57 DISALLOW_COPY_AND_ASSIGN(EventCapturer); 58 DISALLOW_COPY_AND_ASSIGN(EventCapturer);
58 }; 59 };
59 60
61 int Factorial(int n) {
62 if (n <= 0)
63 return 0;
64 if (n == 1)
65 return 1;
66 if (n == 2)
67 return 2;
68 return n * Factorial(n - 1);
69 }
70
60 } // namespace 71 } // namespace
61 72
62 class TouchExplorationTest : public aura::test::AuraTestBase { 73 class TouchExplorationTest : public aura::test::AuraTestBase {
63 public: 74 public:
64 TouchExplorationTest() 75 TouchExplorationTest()
65 : simulated_clock_(new base::SimpleTestTickClock()) {} 76 : simulated_clock_(new base::SimpleTestTickClock()) {}
66 virtual ~TouchExplorationTest() {} 77 virtual ~TouchExplorationTest() {}
67 78
68 virtual void SetUp() OVERRIDE { 79 virtual void SetUp() OVERRIDE {
69 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) 80 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone)
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 EXPECT_EQ(first_touch_location, captured_events[0]->location()); 952 EXPECT_EQ(first_touch_location, captured_events[0]->location());
942 ClearCapturedEvents(); 953 ClearCapturedEvents();
943 954
944 ui::TouchEvent first_touch_release( 955 ui::TouchEvent first_touch_release(
945 ui::ET_TOUCH_RELEASED, first_touch_location, 0, Now()); 956 ui::ET_TOUCH_RELEASED, first_touch_location, 0, Now());
946 generator_->Dispatch(&first_touch_release); 957 generator_->Dispatch(&first_touch_release);
947 ASSERT_EQ(captured_events.size(), 1u); 958 ASSERT_EQ(captured_events.size(), 1u);
948 EXPECT_TRUE(IsInNoFingersDownState()); 959 EXPECT_TRUE(IsInNoFingersDownState());
949 } 960 }
950 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(
aboxhall 2014/06/27 18:08:02 This could be a for-loop over touch_id - it'd also
evy 2014/06/27 21:00:03 Done. Great idea.
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
991 for (int i = 0; i < num_permutations; i++) {
aboxhall 2014/06/27 18:08:02 Since this is not used as a simple index on the ne
evy 2014/06/27 21:00:03 Done.
992 std::vector<ui::TouchEvent*> queued_events = all_events.get();
993 std::vector<bool> fingers_pressed(3, false);
aboxhall 2014/06/27 18:08:01 My favourite vector constructor!
evy 2014/06/27 21:00:03 :D
994 // current_factorial starts at factorial(num_events - 1)
995 // and decreases each iteration
996 int current_factorial = num_permutations/num_events;
997 for (int j = num_events - 1; j >= 0; j--) {
aboxhall 2014/06/27 18:08:02 I can't fully understand this code (just the bit a
evy 2014/06/27 21:00:03 I renamed some variables and added tons of comment
998 int index;
999 if (j == num_events - 1) {
aboxhall 2014/06/27 18:08:02 This could be a switch statement (and you could pu
evy 2014/06/27 21:00:03 I'm not sure if this comment applies - can you rea
1000 index = i / current_factorial;
1001 current_factorial /= j;
1002 } else if (j == 0) {
1003 index = 0;
1004 } else {
1005 index = (i % (current_factorial * (j + 1)) / current_factorial);
1006 current_factorial /= j;
1007 }
1008 ui::TouchEvent* next_dispatch = queued_events[index];
1009 ASSERT_TRUE(next_dispatch != NULL);
1010 EventTestApi test_dispatch(next_dispatch);
1011 test_dispatch.set_time_stamp(Now());
1012 generator_->Dispatch(next_dispatch);
1013 queued_events.erase(queued_events.begin() + index);
1014 // Note: it is possible to send a touched move event in the state
1015 // SINGLE_TAP_RELEASED or TOUCH_EXPLORE_RELEASED
1016 // because the events are not always generated in a sensical
1017 // order. If there is a NOTREACHED() for touch moved hit in
aboxhall 2014/06/27 18:08:01 Will NOTREACHED() cause the test to crash in debug
evy 2014/06/27 21:00:03 Yup - I just fixed that problem, but forgot to cha
1018 // InSingleTapOrTouchExploreReleased, that is fine here.
1019
1020 // Keep track of what fingers have been pressed, to release
1021 // only those fingers at the end, so the check for being in
1022 // no fingers down can be accurate.
1023 if (next_dispatch->type() == ET_TOUCH_PRESSED) {
1024 fingers_pressed[next_dispatch->touch_id()] = true;
1025 } else if (next_dispatch->type() == ET_TOUCH_RELEASED) {
1026 fingers_pressed[next_dispatch->touch_id()] = false;
1027 }
1028 }
1029 ASSERT_EQ(queued_events.size(), 0u);
1030
1031 // Release fingers recorded as pressed.
1032 for(int j = 0; j < int(fingers_pressed.size()); j++){
1033 if (fingers_pressed[j] == true) {
1034 generator_->ReleaseTouchId(j);
1035 fingers_pressed[j] = false;
1036 }
1037 }
1038 AdvanceSimulatedTimePastTapDelay();
1039 EXPECT_TRUE(IsInNoFingersDownState());
1040 ClearCapturedEvents();
1041 }
1042 }
1043
951 } // namespace ui 1044 } // 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