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

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

Issue 9318010: Tweak the aura gesture recognizer slightly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 | « ui/aura/gestures/gesture_point.cc ('k') | ui/aura/gestures/gesture_sequence.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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/aura/event.h" 6 #include "ui/aura/event.h"
7 #include "ui/aura/root_window.h" 7 #include "ui/aura/root_window.h"
8 #include "ui/aura/test/aura_test_base.h" 8 #include "ui/aura/test/aura_test_base.h"
9 #include "ui/aura/test/test_window_delegate.h" 9 #include "ui/aura/test/test_window_delegate.h"
10 #include "ui/aura/test/test_windows.h" 10 #include "ui/aura/test/test_windows.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 base::TimeDelta::FromMilliseconds(50)); 284 base::TimeDelta::FromMilliseconds(50));
285 RootWindow::GetInstance()->DispatchTouchEvent(&release); 285 RootWindow::GetInstance()->DispatchTouchEvent(&release);
286 EXPECT_FALSE(delegate->tap()); 286 EXPECT_FALSE(delegate->tap());
287 EXPECT_FALSE(delegate->tap_down()); 287 EXPECT_FALSE(delegate->tap_down());
288 EXPECT_FALSE(delegate->double_tap()); 288 EXPECT_FALSE(delegate->double_tap());
289 EXPECT_FALSE(delegate->scroll_begin()); 289 EXPECT_FALSE(delegate->scroll_begin());
290 EXPECT_FALSE(delegate->scroll_update()); 290 EXPECT_FALSE(delegate->scroll_update());
291 EXPECT_TRUE(delegate->scroll_end()); 291 EXPECT_TRUE(delegate->scroll_end());
292 } 292 }
293 293
294 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
295 // First, tap. Then, do a scroll using the same touch-id.
296 scoped_ptr<GestureEventConsumeDelegate> delegate(
297 new GestureEventConsumeDelegate());
298 const int kWindowWidth = 123;
299 const int kWindowHeight = 45;
300 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
301 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
302 delegate.get(), -1234, bounds, NULL));
303
304 delegate->Reset();
305 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0);
306 RootWindow::GetInstance()->DispatchTouchEvent(&press);
307 EXPECT_FALSE(delegate->tap());
308 EXPECT_TRUE(delegate->tap_down());
309 EXPECT_FALSE(delegate->double_tap());
310 EXPECT_FALSE(delegate->scroll_begin());
311 EXPECT_FALSE(delegate->scroll_update());
312 EXPECT_FALSE(delegate->scroll_end());
313
314 // Make sure there is enough delay before the touch is released so that it is
315 // recognized as a tap.
316 delegate->Reset();
317 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0);
318 Event::TestApi test_release(&release);
319 test_release.set_time_stamp(press.time_stamp() +
320 base::TimeDelta::FromMilliseconds(50));
321 RootWindow::GetInstance()->DispatchTouchEvent(&release);
322 EXPECT_TRUE(delegate->tap());
323 EXPECT_FALSE(delegate->tap_down());
324 EXPECT_FALSE(delegate->double_tap());
325 EXPECT_FALSE(delegate->scroll_begin());
326 EXPECT_FALSE(delegate->scroll_update());
327 EXPECT_FALSE(delegate->scroll_end());
328
329 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger
330 // a double-tap.
331 delegate->Reset();
332 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0);
333 Event::TestApi test_release1(&press1);
334 test_release1.set_time_stamp(release.time_stamp() +
335 base::TimeDelta::FromMilliseconds(1000));
336 RootWindow::GetInstance()->DispatchTouchEvent(&press1);
337 EXPECT_FALSE(delegate->tap());
338 EXPECT_TRUE(delegate->tap_down());
339 EXPECT_FALSE(delegate->double_tap());
340 EXPECT_FALSE(delegate->scroll_begin());
341 EXPECT_FALSE(delegate->scroll_update());
342 EXPECT_FALSE(delegate->scroll_end());
343
344 // Move the touch-point enough so that it is considered as a scroll. This
345 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
346 delegate->Reset();
347 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 201), 0);
348 RootWindow::GetInstance()->DispatchTouchEvent(&move);
349 EXPECT_FALSE(delegate->tap());
350 EXPECT_FALSE(delegate->tap_down());
351 EXPECT_FALSE(delegate->double_tap());
352 EXPECT_TRUE(delegate->scroll_begin());
353 EXPECT_TRUE(delegate->scroll_update());
354 EXPECT_FALSE(delegate->scroll_end());
355 EXPECT_EQ(29, delegate->scroll_x());
356 EXPECT_EQ(0, delegate->scroll_y());
357
358 // Move some more to generate a few more scroll updates.
359 delegate->Reset();
360 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211), 0);
361 RootWindow::GetInstance()->DispatchTouchEvent(&move1);
362 EXPECT_FALSE(delegate->tap());
363 EXPECT_FALSE(delegate->tap_down());
364 EXPECT_FALSE(delegate->double_tap());
365 EXPECT_FALSE(delegate->scroll_begin());
366 EXPECT_TRUE(delegate->scroll_update());
367 EXPECT_FALSE(delegate->scroll_end());
368 EXPECT_EQ(-20, delegate->scroll_x());
369 EXPECT_EQ(10, delegate->scroll_y());
370
371 delegate->Reset();
372 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215), 0);
373 RootWindow::GetInstance()->DispatchTouchEvent(&move2);
374 EXPECT_FALSE(delegate->tap());
375 EXPECT_FALSE(delegate->tap_down());
376 EXPECT_FALSE(delegate->double_tap());
377 EXPECT_FALSE(delegate->scroll_begin());
378 EXPECT_TRUE(delegate->scroll_update());
379 EXPECT_FALSE(delegate->scroll_end());
380 EXPECT_EQ(30, delegate->scroll_x());
381 EXPECT_EQ(4, delegate->scroll_y());
382
383 // Release the touch. This should end the scroll.
384 delegate->Reset();
385 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0);
386 RootWindow::GetInstance()->DispatchTouchEvent(&release1);
387 EXPECT_FALSE(delegate->tap());
388 EXPECT_FALSE(delegate->tap_down());
389 EXPECT_FALSE(delegate->double_tap());
390 EXPECT_FALSE(delegate->scroll_begin());
391 EXPECT_FALSE(delegate->scroll_update());
392 EXPECT_TRUE(delegate->scroll_end());
393 }
394
294 // Check that unprocessed gesture events generate appropriate synthetic mouse 395 // Check that unprocessed gesture events generate appropriate synthetic mouse
295 // events. 396 // events.
296 TEST_F(GestureRecognizerTest, GestureTapSyntheticMouse) { 397 TEST_F(GestureRecognizerTest, GestureTapSyntheticMouse) {
297 scoped_ptr<GestureEventSynthDelegate> delegate( 398 scoped_ptr<GestureEventSynthDelegate> delegate(
298 new GestureEventSynthDelegate()); 399 new GestureEventSynthDelegate());
299 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, 400 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234,
300 gfx::Rect(0, 0, 123, 45), NULL)); 401 gfx::Rect(0, 0, 123, 45), NULL));
301 402
302 delegate->Reset(); 403 delegate->Reset();
303 GestureEvent tap(ui::ET_GESTURE_TAP, 20, 20, 0, base::Time::Now(), 0, 0); 404 GestureEvent tap(ui::ET_GESTURE_TAP, 20, 20, 0, base::Time::Now(), 0, 0);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 EXPECT_TRUE(queued_delegate->tap()); 478 EXPECT_TRUE(queued_delegate->tap());
378 EXPECT_FALSE(queued_delegate->tap_down()); 479 EXPECT_FALSE(queued_delegate->tap_down());
379 EXPECT_FALSE(queued_delegate->double_tap()); 480 EXPECT_FALSE(queued_delegate->double_tap());
380 EXPECT_FALSE(queued_delegate->scroll_begin()); 481 EXPECT_FALSE(queued_delegate->scroll_begin());
381 EXPECT_FALSE(queued_delegate->scroll_update()); 482 EXPECT_FALSE(queued_delegate->scroll_update());
382 EXPECT_FALSE(queued_delegate->scroll_end()); 483 EXPECT_FALSE(queued_delegate->scroll_end());
383 } 484 }
384 485
385 } // namespace test 486 } // namespace test
386 } // namespace aura 487 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/gestures/gesture_point.cc ('k') | ui/aura/gestures/gesture_sequence.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698