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

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

Issue 10825323: gesture: Make sure a combination of sync/async touch-events work correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 8 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 | « no previous file | ui/aura/root_window.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/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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 gfx::Rect bounding_box_; 205 gfx::Rect bounding_box_;
206 int tap_count_; 206 int tap_count_;
207 207
208 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); 208 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate);
209 }; 209 };
210 210
211 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 211 class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
212 public: 212 public:
213 explicit QueueTouchEventDelegate(RootWindow* root_window) 213 explicit QueueTouchEventDelegate(RootWindow* root_window)
214 : window_(NULL), 214 : window_(NULL),
215 root_window_(root_window) { 215 root_window_(root_window),
216 queue_events_(true) {
216 } 217 }
217 virtual ~QueueTouchEventDelegate() {} 218 virtual ~QueueTouchEventDelegate() {}
218 219
219 virtual ui::TouchStatus OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 220 virtual ui::TouchStatus OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
221 if (!queue_events_)
222 return ui::TOUCH_STATUS_UNKNOWN;
220 return event->type() == ui::ET_TOUCH_RELEASED ? 223 return event->type() == ui::ET_TOUCH_RELEASED ?
221 ui::TOUCH_STATUS_QUEUED_END : ui::TOUCH_STATUS_QUEUED; 224 ui::TOUCH_STATUS_QUEUED_END : ui::TOUCH_STATUS_QUEUED;
222 } 225 }
223 226
224 void ReceivedAck() { 227 void ReceivedAck() {
225 root_window_->AdvanceQueuedTouchEvent(window_, false); 228 root_window_->AdvanceQueuedTouchEvent(window_, false);
226 } 229 }
227 230
228 void ReceivedAckPreventDefaulted() { 231 void ReceivedAckPreventDefaulted() {
229 root_window_->AdvanceQueuedTouchEvent(window_, true); 232 root_window_->AdvanceQueuedTouchEvent(window_, true);
230 } 233 }
231 234
232 void set_window(Window* w) { window_ = w; } 235 void set_window(Window* w) { window_ = w; }
236 void set_queue_events(bool queue) { queue_events_ = queue; }
233 237
234 private: 238 private:
235 Window* window_; 239 Window* window_;
236 RootWindow* root_window_; 240 RootWindow* root_window_;
241 bool queue_events_;
237 242
238 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate); 243 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate);
239 }; 244 };
240 245
241 // A delegate that ignores gesture events but keeps track of [synthetic] mouse 246 // A delegate that ignores gesture events but keeps track of [synthetic] mouse
242 // events. 247 // events.
243 class GestureEventSynthDelegate : public TestWindowDelegate { 248 class GestureEventSynthDelegate : public TestWindowDelegate {
244 public: 249 public:
245 GestureEventSynthDelegate() 250 GestureEventSynthDelegate()
246 : mouse_enter_(false), 251 : mouse_enter_(false),
(...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 1928
1924 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, GetTime()); 1929 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, GetTime());
1925 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1930 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1926 1931
1927 // This new press should not generate a tap-down. 1932 // This new press should not generate a tap-down.
1928 EXPECT_FALSE(delegate->begin()); 1933 EXPECT_FALSE(delegate->begin());
1929 EXPECT_FALSE(delegate->tap_down()); 1934 EXPECT_FALSE(delegate->tap_down());
1930 EXPECT_FALSE(delegate->scroll_begin()); 1935 EXPECT_FALSE(delegate->scroll_begin());
1931 } 1936 }
1932 1937
1938 // Tests that if a consumer has touch-events queued, then no touch-event gets
1939 // processed synchronously until all the queued evets are processed.
1940 TEST_F(GestureRecognizerTest, SyncTouchEventWithQueuedTouchEvents) {
1941 scoped_ptr<QueueTouchEventDelegate> queued_delegate(
1942 new QueueTouchEventDelegate(root_window()));
1943 const int kWindowWidth = 123;
1944 const int kWindowHeight = 45;
1945 const int kTouchId1 = 6;
1946 gfx::Rect bounds(10, 20, kWindowWidth, kWindowHeight);
1947 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate(
1948 queued_delegate.get(), -1234, bounds, NULL));
1949
1950 queued_delegate->set_window(queue.get());
1951
1952 // Send a touch-event to the window so that the event gets queued. No gesture
1953 // event should be created.
1954 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(20, 30), kTouchId1,
1955 GetTime());
1956 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(80, 25), kTouchId1,
1957 press1.time_stamp() + base::TimeDelta::FromMilliseconds(100));
1958 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(80, 25), kTouchId1,
1959 move1.time_stamp() + base::TimeDelta::FromMilliseconds(100));
1960 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
1961 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
1962 EXPECT_FALSE(queued_delegate->begin());
1963 EXPECT_FALSE(queued_delegate->tap_down());
1964 EXPECT_FALSE(queued_delegate->scroll_begin());
1965
1966 // Stop queueing events.
1967 queued_delegate->set_queue_events(false);
1968 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1969
1970 // Process the two queued events.
1971 queued_delegate->ReceivedAck();
1972 RunAllPendingInMessageLoop();
1973 EXPECT_TRUE(queued_delegate->begin());
1974 EXPECT_TRUE(queued_delegate->tap_down());
1975 queued_delegate->Reset();
1976
1977 queued_delegate->ReceivedAck();
1978 RunAllPendingInMessageLoop();
1979 EXPECT_TRUE(queued_delegate->scroll_begin());
1980 EXPECT_TRUE(queued_delegate->scroll_update());
1981 EXPECT_TRUE(queued_delegate->scroll_end());
1982 EXPECT_TRUE(queued_delegate->end());
1983 }
1984
1933 TEST_F(GestureRecognizerTest, TwoFingerTap) { 1985 TEST_F(GestureRecognizerTest, TwoFingerTap) {
1934 scoped_ptr<GestureEventConsumeDelegate> delegate( 1986 scoped_ptr<GestureEventConsumeDelegate> delegate(
1935 new GestureEventConsumeDelegate()); 1987 new GestureEventConsumeDelegate());
1936 const int kWindowWidth = 123; 1988 const int kWindowWidth = 123;
1937 const int kWindowHeight = 45; 1989 const int kWindowHeight = 45;
1938 const int kTouchId1 = 2; 1990 const int kTouchId1 = 2;
1939 const int kTouchId2 = 3; 1991 const int kTouchId2 = 3;
1940 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1992 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1941 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1993 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1942 delegate.get(), -1234, bounds, NULL)); 1994 delegate.get(), -1234, bounds, NULL));
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
2597 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 2649 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
2598 EXPECT_FALSE(delegate->tap()); 2650 EXPECT_FALSE(delegate->tap());
2599 EXPECT_FALSE(delegate->scroll_update()); 2651 EXPECT_FALSE(delegate->scroll_update());
2600 EXPECT_FALSE(delegate->pinch_update()); 2652 EXPECT_FALSE(delegate->pinch_update());
2601 2653
2602 delegate->Reset(); 2654 delegate->Reset();
2603 } 2655 }
2604 2656
2605 } // namespace test 2657 } // namespace test
2606 } // namespace aura 2658 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/aura/root_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698