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

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

Issue 393953012: Eager Gesture Recognition on Aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 4 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 | « content/public/test/browser_test_utils.cc ('k') | ui/aura/window_event_dispatcher.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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 3909 matching lines...) Expand 10 before | Expand all | Expand 10 after
3920 3920
3921 // Test that consuming the first move touch event prevents a scroll. 3921 // Test that consuming the first move touch event prevents a scroll.
3922 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) { 3922 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) {
3923 scoped_ptr<QueueTouchEventDelegate> delegate( 3923 scoped_ptr<QueueTouchEventDelegate> delegate(
3924 new QueueTouchEventDelegate(host()->dispatcher())); 3924 new QueueTouchEventDelegate(host()->dispatcher()));
3925 TimedEvents tes; 3925 TimedEvents tes;
3926 const int kTouchId = 7; 3926 const int kTouchId = 7;
3927 gfx::Rect bounds(0, 0, 1000, 1000); 3927 gfx::Rect bounds(0, 0, 1000, 1000);
3928 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3928 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3929 delegate.get(), -1234, bounds, root_window())); 3929 delegate.get(), -1234, bounds, root_window()));
3930 delegate->set_window(window.get());
3930 3931
3931 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 3932 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
3932 kTouchId, tes.Now()); 3933 kTouchId, tes.Now());
3933 DispatchEventUsingWindowDispatcher(&press); 3934 DispatchEventUsingWindowDispatcher(&press);
3934 delegate->ReceivedAck(); 3935 delegate->ReceivedAck();
3935 3936
3936 // A touch move within the slop region is never consumed in web contents. The 3937 // A touch move within the slop region is never consumed in web contents. The
3937 // unified GR won't prevent scroll if a touch move within the slop region is 3938 // unified GR won't prevent scroll if a touch move within the slop region is
3938 // consumed, so make sure this touch move exceeds the slop region. 3939 // consumed, so make sure this touch move exceeds the slop region.
3939 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10), 3940 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(10, 10),
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
4022 4023
4023 // Test that consuming the first move touch doesn't prevent a tap. 4024 // Test that consuming the first move touch doesn't prevent a tap.
4024 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) { 4025 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) {
4025 scoped_ptr<QueueTouchEventDelegate> delegate( 4026 scoped_ptr<QueueTouchEventDelegate> delegate(
4026 new QueueTouchEventDelegate(host()->dispatcher())); 4027 new QueueTouchEventDelegate(host()->dispatcher()));
4027 TimedEvents tes; 4028 TimedEvents tes;
4028 const int kTouchId = 7; 4029 const int kTouchId = 7;
4029 gfx::Rect bounds(0, 0, 1000, 1000); 4030 gfx::Rect bounds(0, 0, 1000, 1000);
4030 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4031 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4031 delegate.get(), -1234, bounds, root_window())); 4032 delegate.get(), -1234, bounds, root_window()));
4033 delegate->set_window(window.get());
4032 4034
4033 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 4035 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
4034 kTouchId, tes.Now()); 4036 kTouchId, tes.Now());
4035 DispatchEventUsingWindowDispatcher(&press); 4037 DispatchEventUsingWindowDispatcher(&press);
4036 delegate->ReceivedAck(); 4038 delegate->ReceivedAck();
4037 4039
4038 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(2, 2), 4040 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(2, 2),
4039 kTouchId, tes.Now()); 4041 kTouchId, tes.Now());
4040 DispatchEventUsingWindowDispatcher(&move); 4042 DispatchEventUsingWindowDispatcher(&move);
4041 delegate->ReceivedAckPreventDefaulted(); 4043 delegate->ReceivedAckPreventDefaulted();
(...skipping 10 matching lines...) Expand all
4052 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) { 4054 TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) {
4053 scoped_ptr<QueueTouchEventDelegate> delegate( 4055 scoped_ptr<QueueTouchEventDelegate> delegate(
4054 new QueueTouchEventDelegate(host()->dispatcher())); 4056 new QueueTouchEventDelegate(host()->dispatcher()));
4055 TimedEvents tes; 4057 TimedEvents tes;
4056 const int kWindowWidth = 123; 4058 const int kWindowWidth = 123;
4057 const int kWindowHeight = 45; 4059 const int kWindowHeight = 45;
4058 const int kTouchId = 2; 4060 const int kTouchId = 2;
4059 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 4061 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
4060 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4062 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4061 delegate.get(), -1234, bounds, root_window())); 4063 delegate.get(), -1234, bounds, root_window()));
4064 delegate->set_window(window.get());
4062 4065
4063 delegate->Reset(); 4066 delegate->Reset();
4064 4067
4065 TimerTestGestureRecognizer* gesture_recognizer = 4068 TimerTestGestureRecognizer* gesture_recognizer =
4066 new TimerTestGestureRecognizer(); 4069 new TimerTestGestureRecognizer();
4067 4070
4068 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 4071 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
4069 4072
4070 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 4073 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
4071 kTouchId, tes.Now()); 4074 kTouchId, tes.Now());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
4148 TEST_P(GestureRecognizerTest, ScrollAlternatelyConsumedTest) { 4151 TEST_P(GestureRecognizerTest, ScrollAlternatelyConsumedTest) {
4149 scoped_ptr<QueueTouchEventDelegate> delegate( 4152 scoped_ptr<QueueTouchEventDelegate> delegate(
4150 new QueueTouchEventDelegate(host()->dispatcher())); 4153 new QueueTouchEventDelegate(host()->dispatcher()));
4151 TimedEvents tes; 4154 TimedEvents tes;
4152 const int kWindowWidth = 3000; 4155 const int kWindowWidth = 3000;
4153 const int kWindowHeight = 3000; 4156 const int kWindowHeight = 3000;
4154 const int kTouchId = 2; 4157 const int kTouchId = 2;
4155 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 4158 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
4156 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 4159 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4157 delegate.get(), -1234, bounds, root_window())); 4160 delegate.get(), -1234, bounds, root_window()));
4161 delegate->set_window(window.get());
4158 4162
4159 delegate->Reset(); 4163 delegate->Reset();
4160 4164
4161 int x = 0; 4165 int x = 0;
4162 int y = 0; 4166 int y = 0;
4163 4167
4164 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(x, y), 4168 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(x, y),
4165 kTouchId, tes.Now()); 4169 kTouchId, tes.Now());
4166 DispatchEventUsingWindowDispatcher(&press1); 4170 DispatchEventUsingWindowDispatcher(&press1);
4167 delegate->ReceivedAck(); 4171 delegate->ReceivedAck();
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
4505 4509
4506 delegate->Reset(); 4510 delegate->Reset();
4507 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(65, 202), 4511 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(65, 202),
4508 kTouchId1, tes.Now()); 4512 kTouchId1, tes.Now());
4509 DispatchEventUsingWindowDispatcher(&move2); 4513 DispatchEventUsingWindowDispatcher(&move2);
4510 EXPECT_2_EVENTS(delegate->events(), 4514 EXPECT_2_EVENTS(delegate->events(),
4511 ui::ET_GESTURE_SCROLL_UPDATE, 4515 ui::ET_GESTURE_SCROLL_UPDATE,
4512 ui::ET_GESTURE_PINCH_UPDATE); 4516 ui::ET_GESTURE_PINCH_UPDATE);
4513 } 4517 }
4514 4518
4519 // Tests that delaying the ack of a touch release doesn't trigger a long press
4520 // gesture.
4521 TEST_P(GestureRecognizerTest, EagerGestureDetection) {
4522 if (!UsingUnifiedGR())
4523 return;
4524
4525 scoped_ptr<QueueTouchEventDelegate> delegate(
4526 new QueueTouchEventDelegate(host()->dispatcher()));
4527 TimedEvents tes;
4528 const int kTouchId = 2;
4529 gfx::Rect bounds(100, 200, 100, 100);
4530 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
4531 delegate.get(), -1234, bounds, root_window()));
4532 delegate->set_window(window.get());
4533
4534 delegate->Reset();
4535 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
4536 kTouchId, tes.Now());
4537 DispatchEventUsingWindowDispatcher(&press);
4538 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
4539 kTouchId, tes.LeapForward(50));
4540 DispatchEventUsingWindowDispatcher(&release);
4541
4542 delegate->Reset();
4543 // Ack the touch press.
4544 delegate->ReceivedAck();
4545 EXPECT_TRUE(delegate->tap_down());
4546
4547 delegate->Reset();
4548 // Wait until the long press event would fire (if we weren't eager).
4549 base::MessageLoop::current()->PostDelayedTask(
4550 FROM_HERE,
4551 base::MessageLoop::QuitClosure(),
4552 base::TimeDelta::FromSecondsD(
4553 ui::GestureConfiguration::long_press_time_in_seconds() * 1.1));
4554 base::MessageLoop::current()->Run();
4555
4556 // Ack the touch release.
4557 delegate->ReceivedAck();
4558 EXPECT_TRUE(delegate->tap());
4559 EXPECT_FALSE(delegate->long_press());
4560 }
4561
4515 INSTANTIATE_TEST_CASE_P(GestureRecognizer, 4562 INSTANTIATE_TEST_CASE_P(GestureRecognizer,
4516 GestureRecognizerTest, 4563 GestureRecognizerTest,
4517 ::testing::Bool()); 4564 ::testing::Bool());
4518 4565
4519 } // namespace test 4566 } // namespace test
4520 } // namespace aura 4567 } // namespace aura
OLDNEW
« no previous file with comments | « content/public/test/browser_test_utils.cc ('k') | ui/aura/window_event_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698