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

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

Issue 581933004: Update gesture logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix 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
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 "athena/home/home_card_gesture_manager.h" 5 #include "athena/home/home_card_gesture_manager.h"
6 6
7 #include "athena/home/home_card_constants.h" 7 #include "athena/home/home_card_constants.h"
8 #include "athena/home/public/home_card.h" 8 #include "athena/home/public/home_card.h"
9 #include "athena/test/athena_test_base.h" 9 #include "athena/test/athena_test_base.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 home_card_top = screen_bounds().height() - kHomeCardMinimizedHeight; 59 home_card_top = screen_bounds().height() - kHomeCardMinimizedHeight;
60 60
61 gfx::Point location = event.location(); 61 gfx::Point location = event.location();
62 location.set_y(location.y() - home_card_top); 62 location.set_y(location.y() - home_card_top);
63 event.set_location(location); 63 event.set_location(location);
64 } 64 }
65 gesture_manager_->ProcessGestureEvent(&event); 65 gesture_manager_->ProcessGestureEvent(&event);
66 last_y_ = y; 66 last_y_ = y;
67 return event.handled(); 67 return event.handled();
68 } 68 }
69
69 void ProcessFlingGesture(float velocity) { 70 void ProcessFlingGesture(float velocity) {
70 ui::GestureEvent event(0, last_y_, ui::EF_NONE, base::TimeDelta(), 71 ui::GestureEvent event(0, last_y_, ui::EF_NONE, base::TimeDelta(),
71 ui::GestureEventDetails( 72 ui::GestureEventDetails(
72 ui::ET_SCROLL_FLING_START, 0, velocity)); 73 ui::ET_SCROLL_FLING_START, 0, velocity));
73 gesture_manager_->ProcessGestureEvent(&event); 74 gesture_manager_->ProcessGestureEvent(&event);
74 } 75 }
75 76
77 int screen_height() const {
78 return screen_bounds().height();
79 }
80
76 HomeCard::State final_state_; 81 HomeCard::State final_state_;
77 HomeCard::State last_from_state_; 82 HomeCard::State last_from_state_;
78 HomeCard::State last_to_state_; 83 HomeCard::State last_to_state_;
79 float last_progress_; 84 float last_progress_;
80 85
81 private: 86 private:
82 gfx::Rect screen_bounds() const { 87 gfx::Rect screen_bounds() const {
83 return gfx::Rect(0, 0, 1280, 1024); 88 return gfx::Rect(0, 0, 1280, 1024);
84 } 89 }
85 90
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 EXPECT_EQ(1.0f, last_progress_); 178 EXPECT_EQ(1.0f, last_progress_);
174 179
175 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 900); 180 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 900);
176 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 910); 181 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 910);
177 EXPECT_EQ(2, GetProgressCountAndReset()); 182 EXPECT_EQ(2, GetProgressCountAndReset());
178 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, last_from_state_); 183 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, last_from_state_);
179 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, last_to_state_); 184 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, last_to_state_);
180 EXPECT_GT(1.0f, last_progress_); 185 EXPECT_GT(1.0f, last_progress_);
181 EXPECT_LT(0.0f, last_progress_); 186 EXPECT_LT(0.0f, last_progress_);
182 187
188 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 960);
189 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_END, 960));
190 EXPECT_EQ(1, GetEndCountAndReset());
191 EXPECT_EQ(HomeCard::VISIBLE_MINIMIZED, final_state_);
192 }
193
194 // Test gesture progress when the gesture is initiated when the home card is in
195 // the centered state.
196 TEST_F(HomeCardGestureManagerTest, StartBottom) {
197 HomeCard::Get()->SetState(HomeCard::VISIBLE_BOTTOM);
198
199 // No changes for slight moves.
200 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 950));
201 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 960);
202 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_END, 960));
203 EXPECT_EQ(1, GetEndCountAndReset());
204 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_);
205
206 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 950));
207 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_END, 800));
208 EXPECT_EQ(1, GetEndCountAndReset());
209 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_);
210
211 // State change for the bigger moves.
212 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 950));
213 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1000);
183 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_END, 1000)); 214 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_END, 1000));
184 EXPECT_EQ(1, GetEndCountAndReset()); 215 EXPECT_EQ(1, GetEndCountAndReset());
185 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_); 216 EXPECT_EQ(HomeCard::VISIBLE_MINIMIZED, final_state_);
217
218 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 950));
219 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 300);
220 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_END, 300));
221 EXPECT_EQ(1, GetEndCountAndReset());
222 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, final_state_);
186 } 223 }
187 224
188 TEST_F(HomeCardGestureManagerTest, FlingUpAtEnd) { 225 TEST_F(HomeCardGestureManagerTest, FlingUpAtEnd) {
189 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState()); 226 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
190 227
191 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 1020)); 228 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 1020));
192 EXPECT_EQ(0, GetEndCountAndReset()); 229 EXPECT_EQ(0, GetEndCountAndReset());
193 EXPECT_EQ(0, GetProgressCountAndReset()); 230 EXPECT_EQ(0, GetProgressCountAndReset());
194 231
195 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1010); 232 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1010);
196 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 800);
197 ProcessFlingGesture(-150.0f); 233 ProcessFlingGesture(-150.0f);
198 EXPECT_EQ(1, GetEndCountAndReset()); 234 EXPECT_EQ(1, GetEndCountAndReset());
199 EXPECT_EQ(HomeCard::VISIBLE_CENTERED, final_state_); 235 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_);
200 } 236 }
201 237
202 TEST_F(HomeCardGestureManagerTest, FlingDownAtEnd) { 238 TEST_F(HomeCardGestureManagerTest, FlingDownAtEnd) {
203 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState()); 239 HomeCard::Get()->SetState(HomeCard::VISIBLE_CENTERED);
204 240
205 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 1020)); 241 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 20));
206 EXPECT_EQ(0, GetEndCountAndReset()); 242 EXPECT_EQ(0, GetEndCountAndReset());
207 EXPECT_EQ(0, GetProgressCountAndReset()); 243 EXPECT_EQ(0, GetProgressCountAndReset());
208 244
209 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1010); 245 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 30);
210 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 800); 246 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 100);
211 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 200);
212 ProcessFlingGesture(150.0f); 247 ProcessFlingGesture(150.0f);
213 EXPECT_EQ(1, GetEndCountAndReset()); 248 EXPECT_EQ(1, GetEndCountAndReset());
214 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_); 249 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_);
215 } 250 }
216 251
217 TEST_F(HomeCardGestureManagerTest, WeakFling) { 252 TEST_F(HomeCardGestureManagerTest, WeakFling) {
218 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState()); 253 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
219 254
220 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 1020)); 255 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 1020));
221 EXPECT_EQ(0, GetEndCountAndReset()); 256 EXPECT_EQ(0, GetEndCountAndReset());
222 EXPECT_EQ(0, GetProgressCountAndReset()); 257 EXPECT_EQ(0, GetProgressCountAndReset());
223 258
224 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1010); 259 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1010);
225 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 800);
226 ProcessFlingGesture(-30.0f); 260 ProcessFlingGesture(-30.0f);
227 EXPECT_EQ(1, GetEndCountAndReset()); 261 EXPECT_EQ(1, GetEndCountAndReset());
262 EXPECT_EQ(HomeCard::VISIBLE_MINIMIZED, final_state_);
263 }
264
pkotwicz 2014/09/18 22:15:32 I now understand what the test tests. Thank you fo
Jun Mukai 2014/09/18 22:33:33 Done.
265 // This test case adresses the situation where the user intends a single fling
266 // but the finger touches the screen long enough, so that the home card becomes
267 // bigger than the height of VISIBLE_BOTTOM state due to the scroll events.
268 // In this case the fling event should not change the final state from
269 // VISIBLE_BOTTOM to VISIBLE_CENTERED because the user's intention was a single
270 // fling. See http://crbug.com/415211
271 TEST_F(HomeCardGestureManagerTest, FastFling) {
272 ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
273
274 EXPECT_TRUE(ProcessGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, 1020));
275 EXPECT_EQ(0, GetEndCountAndReset());
276 EXPECT_EQ(0, GetProgressCountAndReset());
277
278 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, 1010);
279 ProcessGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE,
280 screen_height() - kHomeCardHeight);
281 ProcessFlingGesture(-150.0f);
282 EXPECT_EQ(1, GetEndCountAndReset());
228 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_); 283 EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, final_state_);
229 } 284 }
230 285
231 } // namespace athena 286 } // namespace athena
OLDNEW
« athena/home/home_card_gesture_manager.cc ('K') | « athena/home/home_card_gesture_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698