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" |
11 #include "ui/aura/test/event_generator.h" | 11 #include "ui/aura/test/event_generator.h" |
12 #include "ui/aura/test/test_window_delegate.h" | 12 #include "ui/aura/test/test_window_delegate.h" |
13 #include "ui/aura/test/test_windows.h" | 13 #include "ui/aura/test/test_windows.h" |
14 #include "ui/base/events/event.h" | 14 #include "ui/base/events/event.h" |
15 #include "ui/base/gestures/gesture_configuration.h" | 15 #include "ui/base/gestures/gesture_configuration.h" |
16 #include "ui/base/gestures/gesture_recognizer_impl.h" | 16 #include "ui/base/gestures/gesture_recognizer_impl.h" |
17 #include "ui/base/gestures/gesture_sequence.h" | 17 #include "ui/base/gestures/gesture_sequence.h" |
18 #include "ui/base/gestures/gesture_types.h" | 18 #include "ui/base/gestures/gesture_types.h" |
19 #include "ui/base/hit_test.h" | 19 #include "ui/base/hit_test.h" |
20 #include "ui/gfx/point.h" | 20 #include "ui/gfx/point.h" |
21 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
22 | 22 |
| 23 #include <queue> |
| 24 |
23 namespace aura { | 25 namespace aura { |
24 namespace test { | 26 namespace test { |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 std::string WindowIDAsString(ui::GestureConsumer* consumer) { | 30 std::string WindowIDAsString(ui::GestureConsumer* consumer) { |
29 return consumer && !consumer->ignores_events() ? | 31 return consumer && !consumer->ignores_events() ? |
30 base::IntToString(static_cast<Window*>(consumer)->id()) : "?"; | 32 base::IntToString(static_cast<Window*>(consumer)->id()) : "?"; |
31 } | 33 } |
32 | 34 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { | 283 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { |
282 public: | 284 public: |
283 explicit QueueTouchEventDelegate(RootWindow* root_window) | 285 explicit QueueTouchEventDelegate(RootWindow* root_window) |
284 : window_(NULL), | 286 : window_(NULL), |
285 root_window_(root_window), | 287 root_window_(root_window), |
286 queue_events_(true) { | 288 queue_events_(true) { |
287 } | 289 } |
288 virtual ~QueueTouchEventDelegate() {} | 290 virtual ~QueueTouchEventDelegate() {} |
289 | 291 |
290 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE { | 292 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE { |
291 return queue_events_ ? ui::ER_ASYNC : ui::ER_UNHANDLED; | 293 if (queue_events_) { |
| 294 queue_.push(new ui::TouchEvent(*event, window_, window_)); |
| 295 return ui::ER_CONSUMED; |
| 296 } |
| 297 return ui::ER_UNHANDLED; |
292 } | 298 } |
293 | 299 |
294 void ReceivedAck() { | 300 void ReceivedAck() { |
295 root_window_->AdvanceQueuedTouchEvent(window_, false); | 301 ReceivedAckImpl(false); |
296 } | 302 } |
297 | 303 |
298 void ReceivedAckPreventDefaulted() { | 304 void ReceivedAckPreventDefaulted() { |
299 root_window_->AdvanceQueuedTouchEvent(window_, true); | 305 ReceivedAckImpl(true); |
300 } | 306 } |
301 | 307 |
302 void set_window(Window* w) { window_ = w; } | 308 void set_window(Window* w) { window_ = w; } |
303 void set_queue_events(bool queue) { queue_events_ = queue; } | 309 void set_queue_events(bool queue) { queue_events_ = queue; } |
304 | 310 |
305 private: | 311 private: |
| 312 void ReceivedAckImpl(bool prevent_defaulted) { |
| 313 scoped_ptr<ui::TouchEvent> event(queue_.front()); |
| 314 root_window_->ProcessedTouchEvent(event.get(), window_, |
| 315 prevent_defaulted ? ui::ER_HANDLED : ui::ER_UNHANDLED); |
| 316 queue_.pop(); |
| 317 } |
| 318 |
| 319 std::queue<ui::TouchEvent*> queue_; |
306 Window* window_; | 320 Window* window_; |
307 RootWindow* root_window_; | 321 RootWindow* root_window_; |
308 bool queue_events_; | 322 bool queue_events_; |
309 | 323 |
310 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate); | 324 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate); |
311 }; | 325 }; |
312 | 326 |
313 // A delegate that ignores gesture events but keeps track of [synthetic] mouse | 327 // A delegate that ignores gesture events but keeps track of [synthetic] mouse |
314 // events. | 328 // events. |
315 class GestureEventSynthDelegate : public TestWindowDelegate { | 329 class GestureEventSynthDelegate : public TestWindowDelegate { |
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2066 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, GetTime()); | 2080 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, GetTime()); |
2067 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); | 2081 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
2068 | 2082 |
2069 // This new press should not generate a tap-down. | 2083 // This new press should not generate a tap-down. |
2070 EXPECT_FALSE(delegate->begin()); | 2084 EXPECT_FALSE(delegate->begin()); |
2071 EXPECT_FALSE(delegate->tap_down()); | 2085 EXPECT_FALSE(delegate->tap_down()); |
2072 EXPECT_FALSE(delegate->tap_cancel()); | 2086 EXPECT_FALSE(delegate->tap_cancel()); |
2073 EXPECT_FALSE(delegate->scroll_begin()); | 2087 EXPECT_FALSE(delegate->scroll_begin()); |
2074 } | 2088 } |
2075 | 2089 |
2076 // Tests that if a consumer has touch-events queued, then no touch-event gets | |
2077 // processed synchronously until all the queued evets are processed. | |
2078 TEST_F(GestureRecognizerTest, SyncTouchEventWithQueuedTouchEvents) { | |
2079 scoped_ptr<QueueTouchEventDelegate> queued_delegate( | |
2080 new QueueTouchEventDelegate(root_window())); | |
2081 const int kWindowWidth = 123; | |
2082 const int kWindowHeight = 45; | |
2083 const int kTouchId1 = 6; | |
2084 gfx::Rect bounds(10, 20, kWindowWidth, kWindowHeight); | |
2085 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( | |
2086 queued_delegate.get(), -1234, bounds, NULL)); | |
2087 | |
2088 queued_delegate->set_window(queue.get()); | |
2089 | |
2090 // Send a touch-event to the window so that the event gets queued. No gesture | |
2091 // event should be created. | |
2092 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(20, 30), kTouchId1, | |
2093 GetTime()); | |
2094 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(80, 25), kTouchId1, | |
2095 press1.time_stamp() + base::TimeDelta::FromMilliseconds(100)); | |
2096 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(80, 25), kTouchId1, | |
2097 move1.time_stamp() + base::TimeDelta::FromMilliseconds(100)); | |
2098 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); | |
2099 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); | |
2100 EXPECT_FALSE(queued_delegate->begin()); | |
2101 EXPECT_FALSE(queued_delegate->tap_down()); | |
2102 EXPECT_FALSE(queued_delegate->scroll_begin()); | |
2103 | |
2104 // Stop queueing events. | |
2105 queued_delegate->set_queue_events(false); | |
2106 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); | |
2107 | |
2108 // Process the two queued events. | |
2109 queued_delegate->ReceivedAck(); | |
2110 RunAllPendingInMessageLoop(); | |
2111 EXPECT_TRUE(queued_delegate->begin()); | |
2112 EXPECT_TRUE(queued_delegate->tap_down()); | |
2113 queued_delegate->Reset(); | |
2114 | |
2115 queued_delegate->ReceivedAck(); | |
2116 RunAllPendingInMessageLoop(); | |
2117 EXPECT_TRUE(queued_delegate->tap_cancel()); | |
2118 EXPECT_TRUE(queued_delegate->scroll_begin()); | |
2119 EXPECT_TRUE(queued_delegate->scroll_update()); | |
2120 EXPECT_TRUE(queued_delegate->scroll_end()); | |
2121 EXPECT_TRUE(queued_delegate->end()); | |
2122 } | |
2123 | |
2124 TEST_F(GestureRecognizerTest, TwoFingerTap) { | 2090 TEST_F(GestureRecognizerTest, TwoFingerTap) { |
2125 scoped_ptr<GestureEventConsumeDelegate> delegate( | 2091 scoped_ptr<GestureEventConsumeDelegate> delegate( |
2126 new GestureEventConsumeDelegate()); | 2092 new GestureEventConsumeDelegate()); |
2127 const int kWindowWidth = 123; | 2093 const int kWindowWidth = 123; |
2128 const int kWindowHeight = 45; | 2094 const int kWindowHeight = 45; |
2129 const int kTouchId1 = 2; | 2095 const int kTouchId1 = 2; |
2130 const int kTouchId2 = 3; | 2096 const int kTouchId2 = 3; |
2131 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 2097 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
2132 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2098 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
2133 delegate.get(), -1234, bounds, NULL)); | 2099 delegate.get(), -1234, bounds, NULL)); |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2902 press1.time_stamp() + base::TimeDelta::FromMilliseconds(40)); | 2868 press1.time_stamp() + base::TimeDelta::FromMilliseconds(40)); |
2903 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); | 2869 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); |
2904 EXPECT_TRUE(delegate->scroll_update()); | 2870 EXPECT_TRUE(delegate->scroll_update()); |
2905 EXPECT_EQ(-1, delegate->scroll_y()); | 2871 EXPECT_EQ(-1, delegate->scroll_y()); |
2906 | 2872 |
2907 delegate->Reset(); | 2873 delegate->Reset(); |
2908 } | 2874 } |
2909 | 2875 |
2910 } // namespace test | 2876 } // namespace test |
2911 } // namespace aura | 2877 } // namespace aura |
OLD | NEW |