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