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

Side by Side Diff: ui/events/gesture_detection/gesture_provider_unittest.cc

Issue 538653002: Changing the bounding box for show press and tap gesture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delete some unused lines 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 250 }
251 251
252 void SetMinMaxGestureBoundsLength(float min_gesture_bound_length, 252 void SetMinMaxGestureBoundsLength(float min_gesture_bound_length,
253 float max_gesture_bound_length) { 253 float max_gesture_bound_length) {
254 GestureProvider::Config config = GetDefaultConfig(); 254 GestureProvider::Config config = GetDefaultConfig();
255 config.min_gesture_bounds_length = min_gesture_bound_length; 255 config.min_gesture_bounds_length = min_gesture_bound_length;
256 config.max_gesture_bounds_length = max_gesture_bound_length; 256 config.max_gesture_bounds_length = max_gesture_bound_length;
257 SetUpWithConfig(config); 257 SetUpWithConfig(config);
258 } 258 }
259 259
260 void SetShowPressAndLongPressTimeout(base::TimeDelta showpress_timeout,
261 base::TimeDelta longpress_timeout) {
262 GestureProvider::Config config = GetDefaultConfig();
263 config.gesture_detector_config.showpress_timeout = showpress_timeout;
264 config.gesture_detector_config.longpress_timeout = longpress_timeout;
265 SetUpWithConfig(config);
266 }
267
260 bool HasDownEvent() const { return gesture_provider_->current_down_event(); } 268 bool HasDownEvent() const { return gesture_provider_->current_down_event(); }
261 269
262 protected: 270 protected:
263 void CheckScrollEventSequenceForEndActionType( 271 void CheckScrollEventSequenceForEndActionType(
264 MotionEvent::Action end_action_type) { 272 MotionEvent::Action end_action_type) {
265 base::TimeTicks event_time = base::TimeTicks::Now(); 273 base::TimeTicks event_time = base::TimeTicks::Now();
266 const float scroll_to_x = kFakeCoordX + 100; 274 const float scroll_to_x = kFakeCoordX + 100;
267 const float scroll_to_y = kFakeCoordY + 100; 275 const float scroll_to_y = kFakeCoordY + 100;
268 int motion_event_id = 0; 276 int motion_event_id = 0;
269 277
(...skipping 2121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 EXPECT_EQ(0.f, GetMostRecentGestureEvent().details.bounding_box_f().height()); 2399 EXPECT_EQ(0.f, GetMostRecentGestureEvent().details.bounding_box_f().height());
2392 2400
2393 event = 2401 event =
2394 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP); 2402 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2395 event.SetTouchMajor(1); 2403 event.SetTouchMajor(1);
2396 event.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); 2404 event.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
2397 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2405 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2398 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 2406 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2399 EXPECT_EQ(MotionEvent::TOOL_TYPE_STYLUS, 2407 EXPECT_EQ(MotionEvent::TOOL_TYPE_STYLUS,
2400 GetMostRecentGestureEvent().primary_tool_type); 2408 GetMostRecentGestureEvent().primary_tool_type);
2401 EXPECT_EQ(1.f, GetMostRecentGestureEvent().details.bounding_box_f().width()); 2409 EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().width());
2402 EXPECT_EQ(1.f, GetMostRecentGestureEvent().details.bounding_box_f().height()); 2410 EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().height());
tdresser 2014/09/04 13:54:01 Why did this change? (We probably need to include
lanwei 2014/09/05 20:40:37 Now we do not care about the radius of ACTION_UP a
2403 2411
2404 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 2412 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2405 event.SetTouchMajor(2.f * kMaxGestureBoundsLength); 2413 event.SetTouchMajor(2.f * kMaxGestureBoundsLength);
2406 event.SetToolType(0, MotionEvent::TOOL_TYPE_MOUSE); 2414 event.SetToolType(0, MotionEvent::TOOL_TYPE_MOUSE);
2407 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2415 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2408 EXPECT_EQ(MotionEvent::TOOL_TYPE_MOUSE, 2416 EXPECT_EQ(MotionEvent::TOOL_TYPE_MOUSE,
2409 GetMostRecentGestureEvent().primary_tool_type); 2417 GetMostRecentGestureEvent().primary_tool_type);
2410 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 2418 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2411 EXPECT_EQ(2.f * kMaxGestureBoundsLength, 2419 EXPECT_EQ(2.f * kMaxGestureBoundsLength,
2412 GetMostRecentGestureEvent().details.bounding_box_f().width()); 2420 GetMostRecentGestureEvent().details.bounding_box_f().width());
2413 EXPECT_EQ(2.f * kMaxGestureBoundsLength, 2421 EXPECT_EQ(2.f * kMaxGestureBoundsLength,
2414 GetMostRecentGestureEvent().details.bounding_box_f().height()); 2422 GetMostRecentGestureEvent().details.bounding_box_f().height());
2415 2423
2416 event = 2424 event =
2417 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP); 2425 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2418 event.SetTouchMajor(2.f * kMaxGestureBoundsLength); 2426 event.SetTouchMajor(2.f * kMaxGestureBoundsLength);
2419 event.SetToolType(0, MotionEvent::TOOL_TYPE_ERASER); 2427 event.SetToolType(0, MotionEvent::TOOL_TYPE_ERASER);
2420 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2428 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2421 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 2429 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2422 EXPECT_EQ(MotionEvent::TOOL_TYPE_ERASER, 2430 EXPECT_EQ(MotionEvent::TOOL_TYPE_ERASER,
2423 GetMostRecentGestureEvent().primary_tool_type); 2431 GetMostRecentGestureEvent().primary_tool_type);
2424 EXPECT_EQ(2.f * kMaxGestureBoundsLength, 2432 EXPECT_EQ(2.f * kMaxGestureBoundsLength,
2425 GetMostRecentGestureEvent().details.bounding_box_f().width()); 2433 GetMostRecentGestureEvent().details.bounding_box_f().width());
2426 EXPECT_EQ(2.f * kMaxGestureBoundsLength, 2434 EXPECT_EQ(2.f * kMaxGestureBoundsLength,
2427 GetMostRecentGestureEvent().details.bounding_box_f().height()); 2435 GetMostRecentGestureEvent().details.bounding_box_f().height());
2428 } 2436 }
2429 2437
2438 // Test the bounding box for show press and tap gestures.
tdresser 2014/09/04 13:54:01 Nice test!
2439 TEST_F(GestureProviderTest, BoundingBoxForShowPressAndTapGesture) {
2440 base::TimeTicks event_time = base::TimeTicks::Now();
2441 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
2442 base::TimeDelta showpress_timeout = kOneMicrosecond;
2443 base::TimeDelta longpress_timeout = kOneSecond;
2444 SetShowPressAndLongPressTimeout(showpress_timeout, longpress_timeout);
2445
2446 MockMotionEvent event =
2447 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 10, 10);
2448 event.SetTouchMajor(10);
2449
2450 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2451 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2452 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2453 EXPECT_EQ(gfx::RectF(5, 5, 10, 10),
2454 GetMostRecentGestureEvent().details.bounding_box());
2455
2456 event = ObtainMotionEvent(
2457 event_time + kOneMicrosecond, MotionEvent::ACTION_MOVE, 11, 9);
2458 event.SetTouchMajor(20);
2459 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2460 event = ObtainMotionEvent(
2461 event_time + kOneMicrosecond, MotionEvent::ACTION_MOVE, 8, 11);
2462 event.SetTouchMajor(10);
2463 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2464 RunTasksAndWait(showpress_timeout * 2 + kOneMicrosecond);
tdresser 2014/09/04 13:54:01 Probably don't need that kOneMicrosecond, as we're
lanwei 2014/09/05 20:40:36 Done.
2465 EXPECT_EQ(ET_GESTURE_SHOW_PRESS, GetMostRecentGestureEventType());
2466 EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
2467 GetMostRecentGestureEvent().details.bounding_box());
2468
2469 event =
2470 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2471 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2472 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2473
2474 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2475 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2476 EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
2477 GetMostRecentGestureEvent().details.bounding_box());
2478 }
2479
2430 } // namespace ui 2480 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698