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

Side by Side Diff: ui/aura/gestures/gesture_recognizer_unittest.cc

Issue 10446103: GestureScrollEnd event had non-zero velocity causing overscroll on software fling path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed unit tests Created 8 years, 6 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 | « no previous file | ui/base/gestures/gesture_sequence.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/string_number_conversions.h" 6 #include "base/string_number_conversions.h"
7 #include "base/timer.h" 7 #include "base/timer.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/aura/event.h" 9 #include "ui/aura/event.h"
10 #include "ui/aura/root_window.h" 10 #include "ui/aura/root_window.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 case ui::ET_GESTURE_SCROLL_BEGIN: 123 case ui::ET_GESTURE_SCROLL_BEGIN:
124 scroll_begin_ = true; 124 scroll_begin_ = true;
125 scroll_begin_position_ = gesture->location(); 125 scroll_begin_position_ = gesture->location();
126 break; 126 break;
127 case ui::ET_GESTURE_SCROLL_UPDATE: 127 case ui::ET_GESTURE_SCROLL_UPDATE:
128 scroll_update_ = true; 128 scroll_update_ = true;
129 scroll_x_ += gesture->delta_x(); 129 scroll_x_ += gesture->delta_x();
130 scroll_y_ += gesture->delta_y(); 130 scroll_y_ += gesture->delta_y();
131 break; 131 break;
132 case ui::ET_GESTURE_SCROLL_END: 132 case ui::ET_GESTURE_SCROLL_END:
133 velocity_x_ = gesture->delta_x(); 133 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0);
134 velocity_y_ = gesture->delta_y();
135 scroll_end_ = true; 134 scroll_end_ = true;
136 break; 135 break;
137 case ui::ET_GESTURE_PINCH_BEGIN: 136 case ui::ET_GESTURE_PINCH_BEGIN:
138 pinch_begin_ = true; 137 pinch_begin_ = true;
139 break; 138 break;
140 case ui::ET_GESTURE_PINCH_UPDATE: 139 case ui::ET_GESTURE_PINCH_UPDATE:
141 pinch_update_ = true; 140 pinch_update_ = true;
142 break; 141 break;
143 case ui::ET_GESTURE_PINCH_END: 142 case ui::ET_GESTURE_PINCH_END:
144 pinch_end_ = true; 143 pinch_end_ = true;
145 break; 144 break;
146 case ui::ET_GESTURE_LONG_PRESS: 145 case ui::ET_GESTURE_LONG_PRESS:
147 long_press_ = true; 146 long_press_ = true;
148 touch_id_ = gesture->delta_x(); 147 touch_id_ = gesture->delta_x();
149 break; 148 break;
150 case ui::ET_SCROLL_FLING_START: 149 case ui::ET_SCROLL_FLING_START:
150 EXPECT_TRUE(gesture->delta_x() != 0 || gesture->delta_y() != 0);
151 EXPECT_TRUE(scroll_end_); 151 EXPECT_TRUE(scroll_end_);
152 EXPECT_TRUE(velocity_x_ != 0 || velocity_y_ != 0);
153 fling_ = true; 152 fling_ = true;
154 break; 153 break;
155 case ui::ET_GESTURE_TAP_UP: 154 case ui::ET_GESTURE_TAP_UP:
156 break; 155 break;
157 default: 156 default:
158 NOTREACHED(); 157 NOTREACHED();
159 } 158 }
160 return ui::GESTURE_STATUS_CONSUMED; 159 return ui::GESTURE_STATUS_CONSUMED;
161 } 160 }
162 161
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 100, 10, kTouchId, 1, 737 100, 10, kTouchId, 1,
739 ui::GestureConfiguration::points_buffered_for_velocity(), 738 ui::GestureConfiguration::points_buffered_for_velocity(),
740 delegate.get()); 739 delegate.get());
741 740
742 delegate->Reset(); 741 delegate->Reset();
743 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 742 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
744 kTouchId, GetTime()); 743 kTouchId, GetTime());
745 root_window()->DispatchTouchEvent(&release); 744 root_window()->DispatchTouchEvent(&release);
746 745
747 EXPECT_TRUE(delegate->scroll_end()); 746 EXPECT_TRUE(delegate->scroll_end());
748 EXPECT_EQ(100000, delegate->velocity_x()); 747 EXPECT_EQ(0, delegate->velocity_x());
749 EXPECT_EQ(0, delegate->velocity_y()); 748 EXPECT_EQ(0, delegate->velocity_y());
750 } 749 }
751 750
752 // Check Scroll End Events report correct velocities 751 // Check Scroll End Events report correct velocities
753 // if the user was on a vertical rail 752 // if the user was on a vertical rail
754 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { 753 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) {
755 scoped_ptr<GestureEventConsumeDelegate> delegate( 754 scoped_ptr<GestureEventConsumeDelegate> delegate(
756 new GestureEventConsumeDelegate()); 755 new GestureEventConsumeDelegate());
757 const int kTouchId = 7; 756 const int kTouchId = 7;
758 gfx::Rect bounds(0, 0, 1000, 1000); 757 gfx::Rect bounds(0, 0, 1000, 1000);
(...skipping 16 matching lines...) Expand all
775 ui::GestureConfiguration::points_buffered_for_velocity(), 774 ui::GestureConfiguration::points_buffered_for_velocity(),
776 delegate.get()); 775 delegate.get());
777 776
778 delegate->Reset(); 777 delegate->Reset();
779 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 778 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
780 kTouchId, GetTime()); 779 kTouchId, GetTime());
781 root_window()->DispatchTouchEvent(&release); 780 root_window()->DispatchTouchEvent(&release);
782 781
783 EXPECT_TRUE(delegate->scroll_end()); 782 EXPECT_TRUE(delegate->scroll_end());
784 EXPECT_EQ(0, delegate->velocity_x()); 783 EXPECT_EQ(0, delegate->velocity_x());
785 EXPECT_EQ(100000, delegate->velocity_y()); 784 EXPECT_EQ(0, delegate->velocity_y());
786 } 785 }
787 786
788 // Check Scroll End Events report correct velocities 787 // Check Scroll End Events reports zero velocities
789 // if the user is not on a rail 788 // if the user is not on a rail
790 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { 789 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) {
791 scoped_ptr<GestureEventConsumeDelegate> delegate( 790 scoped_ptr<GestureEventConsumeDelegate> delegate(
792 new GestureEventConsumeDelegate()); 791 new GestureEventConsumeDelegate());
793 const int kTouchId = 7; 792 const int kTouchId = 7;
794 gfx::Rect bounds(0, 0, 1000, 1000); 793 gfx::Rect bounds(0, 0, 1000, 1000);
795 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 794 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
796 delegate.get(), -1234, bounds, NULL)); 795 delegate.get(), -1234, bounds, NULL));
797 796
798 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 797 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
799 kTouchId, GetTime()); 798 kTouchId, GetTime());
800 root_window()->DispatchTouchEvent(&press); 799 root_window()->DispatchTouchEvent(&press);
801 800
802 // Move the touch-point such that a non-rail scroll begins 801 // Move the touch-point such that a non-rail scroll begins
803 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get()); 802 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get());
804 EXPECT_EQ(20, delegate->scroll_y()); 803 EXPECT_EQ(20, delegate->scroll_y());
805 EXPECT_EQ(20, delegate->scroll_x()); 804 EXPECT_EQ(20, delegate->scroll_x());
806 805
807 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 806 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
808 10, 100, kTouchId, 1, 807 10, 100, kTouchId, 1,
809 ui::GestureConfiguration::points_buffered_for_velocity(), 808 ui::GestureConfiguration::points_buffered_for_velocity(),
810 delegate.get()); 809 delegate.get());
811 810
812 delegate->Reset(); 811 delegate->Reset();
813 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 812 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
814 kTouchId, GetTime()); 813 kTouchId, GetTime());
815 root_window()->DispatchTouchEvent(&release); 814 root_window()->DispatchTouchEvent(&release);
816 815
817 EXPECT_TRUE(delegate->scroll_end()); 816 EXPECT_TRUE(delegate->scroll_end());
818 EXPECT_EQ(10000, delegate->velocity_x()); 817 EXPECT_EQ(0, delegate->velocity_x());
819 EXPECT_EQ(100000, delegate->velocity_y()); 818 EXPECT_EQ(0, delegate->velocity_y());
820 } 819 }
821 820
822 // Check that appropriate touch events generate long press events 821 // Check that appropriate touch events generate long press events
823 TEST_F(GestureRecognizerTest, GestureEventLongPress) { 822 TEST_F(GestureRecognizerTest, GestureEventLongPress) {
824 scoped_ptr<GestureEventConsumeDelegate> delegate( 823 scoped_ptr<GestureEventConsumeDelegate> delegate(
825 new GestureEventConsumeDelegate()); 824 new GestureEventConsumeDelegate());
826 const int kWindowWidth = 123; 825 const int kWindowWidth = 123;
827 const int kWindowHeight = 45; 826 const int kWindowHeight = 45;
828 const int kTouchId = 2; 827 const int kTouchId = 2;
829 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 828 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 delegate->Reset(); 1701 delegate->Reset();
1703 delegate->ReceivedAck(); 1702 delegate->ReceivedAck();
1704 EXPECT_TRUE(delegate->tap_down()); 1703 EXPECT_TRUE(delegate->tap_down());
1705 delegate->Reset(); 1704 delegate->Reset();
1706 delegate->ReceivedAckPreventDefaulted(); 1705 delegate->ReceivedAckPreventDefaulted();
1707 EXPECT_FALSE(delegate->tap()); 1706 EXPECT_FALSE(delegate->tap());
1708 } 1707 }
1709 1708
1710 } // namespace test 1709 } // namespace test
1711 } // namespace aura 1710 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/base/gestures/gesture_sequence.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698