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

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

Issue 406413004: Cleanups for aura/test/event_generator.h (resolve TODOs) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix gn Created 6 years, 5 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
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"
11 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
12 #include "ui/aura/test/aura_test_base.h" 12 #include "ui/aura/test/aura_test_base.h"
13 #include "ui/aura/test/event_generator.h"
14 #include "ui/aura/test/test_window_delegate.h" 13 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/aura/test/test_windows.h" 14 #include "ui/aura/test/test_windows.h"
16 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h" 16 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/base/hit_test.h" 17 #include "ui/base/hit_test.h"
19 #include "ui/base/ui_base_switches.h" 18 #include "ui/base/ui_base_switches.h"
20 #include "ui/events/event.h" 19 #include "ui/events/event.h"
21 #include "ui/events/event_switches.h" 20 #include "ui/events/event_switches.h"
22 #include "ui/events/event_utils.h" 21 #include "ui/events/event_utils.h"
23 #include "ui/events/gestures/gesture_configuration.h" 22 #include "ui/events/gestures/gesture_configuration.h"
24 #include "ui/events/gestures/gesture_recognizer_impl.h" 23 #include "ui/events/gestures/gesture_recognizer_impl.h"
25 #include "ui/events/gestures/gesture_sequence.h" 24 #include "ui/events/gestures/gesture_sequence.h"
26 #include "ui/events/gestures/gesture_types.h" 25 #include "ui/events/gestures/gesture_types.h"
26 #include "ui/events/test/event_generator.h"
27 #include "ui/events/test/events_test_utils.h" 27 #include "ui/events/test/events_test_utils.h"
28 #include "ui/gfx/point.h" 28 #include "ui/gfx/point.h"
29 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
30 30
31 #include <queue> 31 #include <queue>
32 32
33 namespace aura { 33 namespace aura {
34 namespace test { 34 namespace test {
35 35
36 namespace { 36 namespace {
(...skipping 2428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 delegate->Reset(); 2465 delegate->Reset();
2466 delegate->ReceivedAckPreventDefaulted(); 2466 delegate->ReceivedAckPreventDefaulted();
2467 EXPECT_TRUE(delegate->scroll_end()); 2467 EXPECT_TRUE(delegate->scroll_end());
2468 EXPECT_TRUE(delegate->end()); 2468 EXPECT_TRUE(delegate->end());
2469 } 2469 }
2470 2470
2471 TEST_P(GestureRecognizerTest, GestureEndLocation) { 2471 TEST_P(GestureRecognizerTest, GestureEndLocation) {
2472 GestureEventConsumeDelegate delegate; 2472 GestureEventConsumeDelegate delegate;
2473 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2473 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2474 &delegate, -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2474 &delegate, -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2475 EventGenerator generator(root_window(), window.get()); 2475 ui::test::EventGenerator generator(root_window(), window.get());
2476 const gfx::Point begin(20, 20); 2476 const gfx::Point begin(20, 20);
2477 const gfx::Point end(150, 150); 2477 const gfx::Point end(150, 150);
2478 const gfx::Vector2d window_offset = 2478 const gfx::Vector2d window_offset =
2479 window->bounds().origin().OffsetFromOrigin(); 2479 window->bounds().origin().OffsetFromOrigin();
2480 generator.GestureScrollSequence(begin, end, 2480 generator.GestureScrollSequence(begin, end,
2481 base::TimeDelta::FromMilliseconds(20), 2481 base::TimeDelta::FromMilliseconds(20),
2482 10); 2482 10);
2483 EXPECT_EQ((begin - window_offset).ToString(), 2483 EXPECT_EQ((begin - window_offset).ToString(),
2484 delegate.scroll_begin_position().ToString()); 2484 delegate.scroll_begin_position().ToString());
2485 EXPECT_EQ((end - window_offset).ToString(), 2485 EXPECT_EQ((end - window_offset).ToString(),
2486 delegate.gesture_end_location().ToString()); 2486 delegate.gesture_end_location().ToString());
2487 } 2487 }
2488 2488
2489 TEST_P(GestureRecognizerTest, CaptureSendsGestureEnd) { 2489 TEST_P(GestureRecognizerTest, CaptureSendsGestureEnd) {
2490 scoped_ptr<GestureEventConsumeDelegate> delegate( 2490 scoped_ptr<GestureEventConsumeDelegate> delegate(
2491 new GestureEventConsumeDelegate()); 2491 new GestureEventConsumeDelegate());
2492 TestGestureRecognizer* gesture_recognizer = 2492 TestGestureRecognizer* gesture_recognizer =
2493 new TestGestureRecognizer(); 2493 new TestGestureRecognizer();
2494 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer); 2494 ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
2495 2495
2496 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2496 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2497 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2497 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2498 EventGenerator generator(root_window()); 2498 ui::test::EventGenerator generator(root_window());
2499 2499
2500 generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10)); 2500 generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10));
2501 generator.PressTouch(); 2501 generator.PressTouch();
2502 RunAllPendingInMessageLoop(); 2502 RunAllPendingInMessageLoop();
2503 2503
2504 EXPECT_TRUE(delegate->tap_down()); 2504 EXPECT_TRUE(delegate->tap_down());
2505 2505
2506 scoped_ptr<aura::Window> capture(CreateTestWindowWithBounds( 2506 scoped_ptr<aura::Window> capture(CreateTestWindowWithBounds(
2507 gfx::Rect(10, 10, 200, 200), root_window())); 2507 gfx::Rect(10, 10, 200, 200), root_window()));
2508 capture->SetCapture(); 2508 capture->SetCapture();
(...skipping 10 matching lines...) Expand all
2519 scoped_ptr<GestureEventConsumeDelegate> delegate( 2519 scoped_ptr<GestureEventConsumeDelegate> delegate(
2520 new GestureEventConsumeDelegate()); 2520 new GestureEventConsumeDelegate());
2521 scoped_ptr<TestEventHandler> handler(new TestEventHandler); 2521 scoped_ptr<TestEventHandler> handler(new TestEventHandler);
2522 root_window()->AddPreTargetHandler(handler.get()); 2522 root_window()->AddPreTargetHandler(handler.get());
2523 2523
2524 // Create a window and set it as the capture window. 2524 // Create a window and set it as the capture window.
2525 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(delegate.get(), 2525 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(delegate.get(),
2526 -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2526 -1234, gfx::Rect(10, 10, 300, 300), root_window()));
2527 window1->SetCapture(); 2527 window1->SetCapture();
2528 2528
2529 EventGenerator generator(root_window()); 2529 ui::test::EventGenerator generator(root_window());
2530 TimedEvents tes; 2530 TimedEvents tes;
2531 2531
2532 // Generate two touch-press events on the window. 2532 // Generate two touch-press events on the window.
2533 scoped_ptr<ui::TouchEvent> touch0(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, 2533 scoped_ptr<ui::TouchEvent> touch0(new ui::TouchEvent(ui::ET_TOUCH_PRESSED,
2534 gfx::Point(20, 20), 0, 2534 gfx::Point(20, 20), 0,
2535 tes.Now())); 2535 tes.Now()));
2536 scoped_ptr<ui::TouchEvent> touch1(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, 2536 scoped_ptr<ui::TouchEvent> touch1(new ui::TouchEvent(ui::ET_TOUCH_PRESSED,
2537 gfx::Point(30, 30), 1, 2537 gfx::Point(30, 30), 1,
2538 tes.Now())); 2538 tes.Now()));
2539 generator.Dispatch(touch0.get()); 2539 generator.Dispatch(touch0.get());
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2858 2858
2859 const int kSteps = 15; 2859 const int kSteps = 15;
2860 const int kTouchPoints = 4; 2860 const int kTouchPoints = 4;
2861 gfx::Point points[kTouchPoints] = { 2861 gfx::Point points[kTouchPoints] = {
2862 gfx::Point(10, 30), 2862 gfx::Point(10, 30),
2863 gfx::Point(30, 20), 2863 gfx::Point(30, 20),
2864 gfx::Point(50, 30), 2864 gfx::Point(50, 30),
2865 gfx::Point(80, 50) 2865 gfx::Point(80, 50)
2866 }; 2866 };
2867 2867
2868 aura::test::EventGenerator generator(root_window(), window.get()); 2868 ui::test::EventGenerator generator(root_window(), window.get());
2869 2869
2870 // The unified gesture recognizer assumes a finger has stopped if it hasn't 2870 // The unified gesture recognizer assumes a finger has stopped if it hasn't
2871 // moved for too long. See ui/events/gesture_detection/velocity_tracker.cc's 2871 // moved for too long. See ui/events/gesture_detection/velocity_tracker.cc's
2872 // kAssumePointerStoppedTimeMs. 2872 // kAssumePointerStoppedTimeMs.
2873 for (int count = 2; count <= kTouchPoints; ++count) { 2873 for (int count = 2; count <= kTouchPoints; ++count) {
2874 generator.GestureMultiFingerScroll( 2874 generator.GestureMultiFingerScroll(
2875 count, points, 10, kSteps, 0, -11 * kSteps); 2875 count, points, 10, kSteps, 0, -11 * kSteps);
2876 EXPECT_TRUE(delegate->swipe_up()); 2876 EXPECT_TRUE(delegate->swipe_up());
2877 delegate->Reset(); 2877 delegate->Reset();
2878 2878
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after
4425 delegate.WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 4425 delegate.WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS);
4426 EXPECT_EQ(NULL, window); 4426 EXPECT_EQ(NULL, window);
4427 } 4427 }
4428 4428
4429 INSTANTIATE_TEST_CASE_P(GestureRecognizer, 4429 INSTANTIATE_TEST_CASE_P(GestureRecognizer,
4430 GestureRecognizerTest, 4430 GestureRecognizerTest,
4431 ::testing::Bool()); 4431 ::testing::Bool());
4432 4432
4433 } // namespace test 4433 } // namespace test
4434 } // namespace aura 4434 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698