| 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/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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 ~QueueTouchEventDelegate() override { | 342 ~QueueTouchEventDelegate() override { |
| 343 while(!queue_.empty()) { | 343 while(!queue_.empty()) { |
| 344 delete queue_.front(); | 344 delete queue_.front(); |
| 345 queue_.pop(); | 345 queue_.pop(); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 | 348 |
| 349 void OnTouchEvent(ui::TouchEvent* event) override { | 349 void OnTouchEvent(ui::TouchEvent* event) override { |
| 350 if (queue_events_) { | 350 if (queue_events_) { |
| 351 queue_.push(new ui::TouchEvent(*event, window_, window_)); | 351 queue_.push(new ui::TouchEvent(*event, window_, window_)); |
| 352 event->StopPropagation(); | 352 event->DisableSynchronousHandling(); |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 void ReceivedAck() { | 356 void ReceivedAck() { |
| 357 ReceivedAckImpl(false); | 357 ReceivedAckImpl(false); |
| 358 } | 358 } |
| 359 | 359 |
| 360 void ReceivedAckPreventDefaulted() { | 360 void ReceivedAckPreventDefaulted() { |
| 361 ReceivedAckImpl(true); | 361 ReceivedAckImpl(true); |
| 362 } | 362 } |
| (...skipping 3877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4240 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(65, 202), | 4240 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(65, 202), |
| 4241 kTouchId1, tes.Now()); | 4241 kTouchId1, tes.Now()); |
| 4242 DispatchEventUsingWindowDispatcher(&move2); | 4242 DispatchEventUsingWindowDispatcher(&move2); |
| 4243 EXPECT_2_EVENTS(delegate->events(), | 4243 EXPECT_2_EVENTS(delegate->events(), |
| 4244 ui::ET_GESTURE_SCROLL_UPDATE, | 4244 ui::ET_GESTURE_SCROLL_UPDATE, |
| 4245 ui::ET_GESTURE_PINCH_UPDATE); | 4245 ui::ET_GESTURE_PINCH_UPDATE); |
| 4246 } | 4246 } |
| 4247 | 4247 |
| 4248 // Tests that delaying the ack of a touch release doesn't trigger a long press | 4248 // Tests that delaying the ack of a touch release doesn't trigger a long press |
| 4249 // gesture. | 4249 // gesture. |
| 4250 TEST_F(GestureRecognizerTest, DISABLED_EagerGestureDetection) { | 4250 TEST_F(GestureRecognizerTest, EagerGestureDetection) { |
| 4251 scoped_ptr<QueueTouchEventDelegate> delegate( | 4251 scoped_ptr<QueueTouchEventDelegate> delegate( |
| 4252 new QueueTouchEventDelegate(host()->dispatcher())); | 4252 new QueueTouchEventDelegate(host()->dispatcher())); |
| 4253 TimedEvents tes; | 4253 TimedEvents tes; |
| 4254 const int kTouchId = 2; | 4254 const int kTouchId = 2; |
| 4255 gfx::Rect bounds(100, 200, 100, 100); | 4255 gfx::Rect bounds(100, 200, 100, 100); |
| 4256 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 4256 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 4257 delegate.get(), -1234, bounds, root_window())); | 4257 delegate.get(), -1234, bounds, root_window())); |
| 4258 delegate->set_window(window.get()); | 4258 delegate->set_window(window.get()); |
| 4259 | 4259 |
| 4260 delegate->Reset(); | 4260 delegate->Reset(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4273 delegate->Reset(); | 4273 delegate->Reset(); |
| 4274 // Wait until the long press event would fire (if we weren't eager). | 4274 // Wait until the long press event would fire (if we weren't eager). |
| 4275 DelayByLongPressTimeout(); | 4275 DelayByLongPressTimeout(); |
| 4276 | 4276 |
| 4277 // Ack the touch release. | 4277 // Ack the touch release. |
| 4278 delegate->ReceivedAck(); | 4278 delegate->ReceivedAck(); |
| 4279 EXPECT_TRUE(delegate->tap()); | 4279 EXPECT_TRUE(delegate->tap()); |
| 4280 EXPECT_FALSE(delegate->long_press()); | 4280 EXPECT_FALSE(delegate->long_press()); |
| 4281 } | 4281 } |
| 4282 | 4282 |
| 4283 // This tests crbug.com/405519, in which events which the gesture detector | 4283 // This tests crbug.com/405519, in which touch events which the gesture detector |
| 4284 // ignores cause future events to also be thrown away. | 4284 // ignores interfere with gesture recognition. |
| 4285 TEST_F(GestureRecognizerTest, IgnoredEventsDontPreventFutureEvents) { | 4285 TEST_F(GestureRecognizerTest, IgnoredEventsDontBreakGestureRecognition) { |
| 4286 scoped_ptr<QueueTouchEventDelegate> delegate( | 4286 scoped_ptr<QueueTouchEventDelegate> delegate( |
| 4287 new QueueTouchEventDelegate(host()->dispatcher())); | 4287 new QueueTouchEventDelegate(host()->dispatcher())); |
| 4288 TimedEvents tes; | 4288 TimedEvents tes; |
| 4289 const int kWindowWidth = 300; | 4289 const int kWindowWidth = 300; |
| 4290 const int kWindowHeight = 400; | 4290 const int kWindowHeight = 400; |
| 4291 const int kTouchId1 = 3; | 4291 const int kTouchId1 = 3; |
| 4292 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); | 4292 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); |
| 4293 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 4293 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 4294 delegate.get(), -1234, bounds, root_window())); | 4294 delegate.get(), -1234, bounds, root_window())); |
| 4295 delegate->set_window(window.get()); | 4295 delegate->set_window(window.get()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4308 ui::ET_TOUCH_MOVED, gfx::Point(65, 201), kTouchId1, tes.Now()); | 4308 ui::ET_TOUCH_MOVED, gfx::Point(65, 201), kTouchId1, tes.Now()); |
| 4309 DispatchEventUsingWindowDispatcher(&move1); | 4309 DispatchEventUsingWindowDispatcher(&move1); |
| 4310 delegate->ReceivedAck(); | 4310 delegate->ReceivedAck(); |
| 4311 | 4311 |
| 4312 EXPECT_3_EVENTS(delegate->events(), | 4312 EXPECT_3_EVENTS(delegate->events(), |
| 4313 ui::ET_GESTURE_TAP_CANCEL, | 4313 ui::ET_GESTURE_TAP_CANCEL, |
| 4314 ui::ET_GESTURE_SCROLL_BEGIN, | 4314 ui::ET_GESTURE_SCROLL_BEGIN, |
| 4315 ui::ET_GESTURE_SCROLL_UPDATE); | 4315 ui::ET_GESTURE_SCROLL_UPDATE); |
| 4316 | 4316 |
| 4317 delegate->Reset(); | 4317 delegate->Reset(); |
| 4318 |
| 4319 // Send a valid event, but don't ack it. |
| 4318 ui::TouchEvent move2( | 4320 ui::TouchEvent move2( |
| 4319 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); | 4321 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); |
| 4320 DispatchEventUsingWindowDispatcher(&move2); | 4322 DispatchEventUsingWindowDispatcher(&move2); |
| 4323 EXPECT_0_EVENTS(delegate->events()); |
| 4321 | 4324 |
| 4322 // Send a touchmove event at the same location as the previous touchmove | 4325 // Send a touchmove event at the same location as the previous touchmove |
| 4323 // event. This shouldn't do anything. | 4326 // event. This shouldn't do anything. |
| 4324 ui::TouchEvent move3( | 4327 ui::TouchEvent move3( |
| 4325 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); | 4328 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); |
| 4326 DispatchEventUsingWindowDispatcher(&move3); | 4329 DispatchEventUsingWindowDispatcher(&move3); |
| 4327 | 4330 |
| 4331 // Ack the previous valid event. The intermediary invalid event shouldn't |
| 4332 // interfere. |
| 4328 delegate->ReceivedAck(); | 4333 delegate->ReceivedAck(); |
| 4329 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); | 4334 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); |
| 4330 } | 4335 } |
| 4331 | 4336 |
| 4332 } // namespace test | 4337 } // namespace test |
| 4333 } // namespace aura | 4338 } // namespace aura |
| OLD | NEW |