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

Side by Side Diff: athena/home/home_card_gesture_manager_unittest.cc

Issue 502583002: Exports gesture manager to a separate file and adds its unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « athena/home/home_card_gesture_manager.cc ('k') | athena/home/home_card_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "athena/home/home_card_gesture_manager.h"
6
7 #include "athena/home/home_card_constants.h"
8 #include "athena/home/public/home_card.h"
9 #include "athena/test/athena_test_base.h"
10 #include "base/time/time.h"
11 #include "ui/events/event.h"
12 #include "ui/events/event_constants.h"
13
14 namespace athena {
15
16 class HomeCardGestureManagerTest : public test::AthenaTestBase,
17 public HomeCardGestureManager::Delegate {
18 public:
19 HomeCardGestureManagerTest()
20 : final_state_(HomeCard::HIDDEN),
21 last_from_state_(HomeCard::HIDDEN),
22 last_to_state_(HomeCard::HIDDEN),
23 last_progress_(0.0f),
24 last_y_(0),
25 progress_count_(0),
26 end_count_(0) {}
27 virtual ~HomeCardGestureManagerTest() {}
28
29 // testing::Test:
30 virtual void SetUp() OVERRIDE {
31 test::AthenaTestBase::SetUp();
32 gesture_manager_.reset(new HomeCardGestureManager(this, screen_bounds()));
33 }
34
35 protected:
36 int GetEndCountAndReset() {
37 int result = end_count_;
38 end_count_ = 0;
39 return result;
40 }
41 int GetProgressCountAndReset() {
42 int result = progress_count_;
43 progress_count_ = 0;
44 return result;
45 }
46
47 // Process a gesture event for our use case.
48 bool ProcessGestureEvent(ui::EventType type, int y) {
49 ui::GestureEvent event(0, y, ui::EF_NONE, base::TimeDelta(),
50 ui::GestureEventDetails(type, 0, (y - last_y_)));
51 // Assumes the initial location is based on minimized height.
52 if (type == ui::ET_GESTURE_SCROLL_BEGIN) {
53 gfx::Point location = event.location();
54 location.set_y(
55 location.y() - (screen_bounds().bottom() - kHomeCardMinimizedHeight));
56 event.set_location(location);
57 }
58 gesture_manager_->ProcessGestureEvent(&event);
59 last_y_ = y;
60 return event.handled();
61 }
62 void ProcessFlingGesture(float velocity) {
63 ui::GestureEvent event(0, last_y_, ui::EF_NONE, base::TimeDelta(),
64 ui::GestureEventDetails(
65 ui::ET_SCROLL_FLING_START, 0, velocity));
66 gesture_manager_->ProcessGestureEvent(&event);
67 }
68
69 HomeCard::State final_state_;
70 HomeCard::State last_from_state_;
71 HomeCard::State last_to_state_;
72 float last_progress_;
73
74 private:
75 gfx::Rect screen_bounds() const {
76 return gfx::Rect(0, 0, 1280, 1024);
77 }
78
79 // HomeCardGestureManager::Delegate:
80 virtual void OnGestureEnded(HomeCard::State final_state) OVERRIDE {
81 final_state_ = final_state;
82 ++end_count_;
83 }
84
85 virtual void OnGestureProgressed(HomeCard::State from_state,
86 HomeCard::State to_state,
87 float progress) OVERRIDE {
88 last_from_state_ = from_state;
89 last_to_state_ = to_state;
90 last_progress_ = progress;
91 ++progress_count_;
92 }
93
94 int last_y_;
95 int progress_count_;
96 int end_count_;
97 scoped_ptr<HomeCardGestureManager> gesture_manager_;
98
99 DISALLOW_COPY_AND_ASSIGN(HomeCardGestureManagerTest);
100 };
101
102 TEST_F(HomeCardGestureManagerTest, Basic) {
103 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 1020));
104 EXPECT_EQ(0, GetEndCountAndReset());
105 EXPECT_EQ(0, GetProgressCountAndReset());
106
107 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1019);
108 EXPECT_EQ(1, GetProgressCountAndReset());
109 EXPECT_EQ(HomeCard::VISIBLE_MINIMIZED, last_from_state_);
110 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, last_to_state_);
111 EXPECT_GT(1.0f, last_progress_);
112
113 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1010);
114 float progress_1010 = last_progress_;
115 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1008);
116 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1000);
117 EXPECT_EQ(3, GetProgressCountAndReset());
118 EXPECT_EQ(HomeCard::VISIBLE_MINIMIZED, last_from_state_);
119 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, last_to_state_);
120 EXPECT_LT(progress_1010, last_progress_);
121
122 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 900);
123 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 800);
124 EXPECT_EQ(2, GetProgressCountAndReset());
125 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, last_from_state_);
126 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, last_to_state_);
127 float progress_800 = last_progress_;
128 EXPECT_GT(1.0f, last_progress_);
129 EXPECT_LT(0.0f, last_progress_);
130
131 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 790);
132 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, last_from_state_);
133 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, last_to_state_);
134 EXPECT_LT(progress_800, last_progress_);
135
136 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 810);
137 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, last_from_state_);
138 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, last_to_state_);
139 EXPECT_GT(progress_800, (1.0f - last_progress_));
140
141 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_END, 810));
142 EXPECT_EQ(1, GetEndCountAndReset());
143 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_);
144 }
145
146 TEST_F(HomeCardGestureManagerTest, FlingUpAtEnd) {
147 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 1020));
148 EXPECT_EQ(0, GetEndCountAndReset());
149 EXPECT_EQ(0, GetProgressCountAndReset());
150
151 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1010);
152 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 800);
153 ProcessFlingGesture(-150.0f);
154 EXPECT_EQ(1, GetEndCountAndReset());
155 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, final_state_);
156 }
157
158 TEST_F(HomeCardGestureManagerTest, FlingDownAtEnd) {
159 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 1020));
160 EXPECT_EQ(0, GetEndCountAndReset());
161 EXPECT_EQ(0, GetProgressCountAndReset());
162
163 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1010);
164 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 800);
165 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 200);
166 ProcessFlingGesture(150.0f);
167 EXPECT_EQ(1, GetEndCountAndReset());
168 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_);
169 }
170
171 } // namespace athena
OLDNEW
« no previous file with comments | « athena/home/home_card_gesture_manager.cc ('k') | athena/home/home_card_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698