OLD | NEW |
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 case ui::ET_GESTURE_PINCH_END: | 156 case ui::ET_GESTURE_PINCH_END: |
157 pinch_end_ = true; | 157 pinch_end_ = true; |
158 break; | 158 break; |
159 case ui::ET_GESTURE_LONG_PRESS: | 159 case ui::ET_GESTURE_LONG_PRESS: |
160 long_press_ = true; | 160 long_press_ = true; |
161 touch_id_ = gesture->details().touch_id(); | 161 touch_id_ = gesture->details().touch_id(); |
162 break; | 162 break; |
163 case ui::ET_SCROLL_FLING_START: | 163 case ui::ET_SCROLL_FLING_START: |
164 EXPECT_TRUE(gesture->details().velocity_x() != 0 || | 164 EXPECT_TRUE(gesture->details().velocity_x() != 0 || |
165 gesture->details().velocity_y() != 0); | 165 gesture->details().velocity_y() != 0); |
166 EXPECT_TRUE(scroll_end_); | 166 EXPECT_FALSE(scroll_end_); |
167 fling_ = true; | 167 fling_ = true; |
| 168 velocity_x_ = gesture->details().velocity_x(); |
| 169 velocity_y_ = gesture->details().velocity_y(); |
168 break; | 170 break; |
169 case ui::ET_GESTURE_TWO_FINGER_TAP: | 171 case ui::ET_GESTURE_TWO_FINGER_TAP: |
170 two_finger_tap_ = true; | 172 two_finger_tap_ = true; |
171 break; | 173 break; |
172 default: | 174 default: |
173 NOTREACHED(); | 175 NOTREACHED(); |
174 } | 176 } |
175 return ui::GESTURE_STATUS_CONSUMED; | 177 return ui::GESTURE_STATUS_CONSUMED; |
176 } | 178 } |
177 | 179 |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 851 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
850 100, 10, kTouchId, 1, | 852 100, 10, kTouchId, 1, |
851 ui::GestureConfiguration::points_buffered_for_velocity(), | 853 ui::GestureConfiguration::points_buffered_for_velocity(), |
852 delegate.get()); | 854 delegate.get()); |
853 | 855 |
854 delegate->Reset(); | 856 delegate->Reset(); |
855 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 857 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
856 kTouchId, GetTime()); | 858 kTouchId, GetTime()); |
857 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); | 859 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
858 | 860 |
859 EXPECT_TRUE(delegate->scroll_end()); | 861 EXPECT_TRUE(delegate->fling()); |
860 EXPECT_EQ(0, delegate->velocity_x()); | 862 EXPECT_FALSE(delegate->scroll_end()); |
| 863 EXPECT_GT(delegate->velocity_x(), 0); |
861 EXPECT_EQ(0, delegate->velocity_y()); | 864 EXPECT_EQ(0, delegate->velocity_y()); |
862 } | 865 } |
863 | 866 |
864 // Check Scroll End Events report correct velocities | 867 // Check Scroll End Events report correct velocities |
865 // if the user was on a vertical rail | 868 // if the user was on a vertical rail |
866 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { | 869 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { |
867 scoped_ptr<GestureEventConsumeDelegate> delegate( | 870 scoped_ptr<GestureEventConsumeDelegate> delegate( |
868 new GestureEventConsumeDelegate()); | 871 new GestureEventConsumeDelegate()); |
869 const int kTouchId = 7; | 872 const int kTouchId = 7; |
870 gfx::Rect bounds(0, 0, 1000, 1000); | 873 gfx::Rect bounds(0, 0, 1000, 1000); |
(...skipping 14 matching lines...) Expand all Loading... |
885 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 888 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
886 10, 100, kTouchId, 1, | 889 10, 100, kTouchId, 1, |
887 ui::GestureConfiguration::points_buffered_for_velocity(), | 890 ui::GestureConfiguration::points_buffered_for_velocity(), |
888 delegate.get()); | 891 delegate.get()); |
889 | 892 |
890 delegate->Reset(); | 893 delegate->Reset(); |
891 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 894 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
892 kTouchId, GetTime()); | 895 kTouchId, GetTime()); |
893 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); | 896 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
894 | 897 |
895 EXPECT_TRUE(delegate->scroll_end()); | 898 EXPECT_TRUE(delegate->fling()); |
| 899 EXPECT_FALSE(delegate->scroll_end()); |
896 EXPECT_EQ(0, delegate->velocity_x()); | 900 EXPECT_EQ(0, delegate->velocity_x()); |
897 EXPECT_EQ(0, delegate->velocity_y()); | 901 EXPECT_GT(delegate->velocity_y(), 0); |
898 } | 902 } |
899 | 903 |
900 // Check Scroll End Events reports zero velocities | 904 // Check Scroll End Events reports zero velocities |
901 // if the user is not on a rail | 905 // if the user is not on a rail |
902 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { | 906 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { |
903 scoped_ptr<GestureEventConsumeDelegate> delegate( | 907 scoped_ptr<GestureEventConsumeDelegate> delegate( |
904 new GestureEventConsumeDelegate()); | 908 new GestureEventConsumeDelegate()); |
905 const int kTouchId = 7; | 909 const int kTouchId = 7; |
906 gfx::Rect bounds(0, 0, 1000, 1000); | 910 gfx::Rect bounds(0, 0, 1000, 1000); |
907 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 911 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
(...skipping 11 matching lines...) Expand all Loading... |
919 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 923 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
920 10, 100, kTouchId, 1, | 924 10, 100, kTouchId, 1, |
921 ui::GestureConfiguration::points_buffered_for_velocity(), | 925 ui::GestureConfiguration::points_buffered_for_velocity(), |
922 delegate.get()); | 926 delegate.get()); |
923 | 927 |
924 delegate->Reset(); | 928 delegate->Reset(); |
925 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 929 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
926 kTouchId, GetTime()); | 930 kTouchId, GetTime()); |
927 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); | 931 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
928 | 932 |
929 EXPECT_TRUE(delegate->scroll_end()); | 933 EXPECT_TRUE(delegate->fling()); |
930 EXPECT_EQ(0, delegate->velocity_x()); | 934 EXPECT_FALSE(delegate->scroll_end()); |
931 EXPECT_EQ(0, delegate->velocity_y()); | 935 EXPECT_GT(delegate->velocity_x(), 0); |
| 936 EXPECT_GT(delegate->velocity_y(), 0); |
932 } | 937 } |
933 | 938 |
934 // Check that appropriate touch events generate long press events | 939 // Check that appropriate touch events generate long press events |
935 TEST_F(GestureRecognizerTest, GestureEventLongPress) { | 940 TEST_F(GestureRecognizerTest, GestureEventLongPress) { |
936 scoped_ptr<GestureEventConsumeDelegate> delegate( | 941 scoped_ptr<GestureEventConsumeDelegate> delegate( |
937 new GestureEventConsumeDelegate()); | 942 new GestureEventConsumeDelegate()); |
938 const int kWindowWidth = 123; | 943 const int kWindowWidth = 123; |
939 const int kWindowHeight = 45; | 944 const int kWindowHeight = 45; |
940 const int kTouchId = 2; | 945 const int kTouchId = 2; |
941 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 946 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
(...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2561 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); | 2566 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); |
2562 EXPECT_FALSE(delegate->tap()); | 2567 EXPECT_FALSE(delegate->tap()); |
2563 EXPECT_FALSE(delegate->scroll_update()); | 2568 EXPECT_FALSE(delegate->scroll_update()); |
2564 EXPECT_FALSE(delegate->pinch_update()); | 2569 EXPECT_FALSE(delegate->pinch_update()); |
2565 | 2570 |
2566 delegate->Reset(); | 2571 delegate->Reset(); |
2567 } | 2572 } |
2568 | 2573 |
2569 } // namespace test | 2574 } // namespace test |
2570 } // namespace aura | 2575 } // namespace aura |
OLD | NEW |