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

Side by Side Diff: ui/events/gesture_detection/gesture_provider_unittest.cc

Issue 2849603003: Use ScopedTaskEnvironment instead of MessageLoopForUI in ui tests. (Closed)
Patch Set: CR-add-newline-after-include Created 3 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/events/gesture_detection/gesture_provider.h" 5 #include "ui/events/gesture_detection/gesture_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/test/scoped_task_environment.h"
16 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/events/event_constants.h" 20 #include "ui/events/event_constants.h"
20 #include "ui/events/gesture_detection/gesture_event_data.h" 21 #include "ui/events/gesture_detection/gesture_event_data.h"
21 #include "ui/events/gesture_detection/motion_event.h" 22 #include "ui/events/gesture_detection/motion_event.h"
22 #include "ui/events/test/motion_event_test_utils.h" 23 #include "ui/events/test/motion_event_test_utils.h"
23 #include "ui/gfx/geometry/point_f.h" 24 #include "ui/gfx/geometry/point_f.h"
24 25
25 using base::TimeDelta; 26 using base::TimeDelta;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 58
58 gfx::RectF BoundsForSingleMockTouchAtLocation(float x, float y) { 59 gfx::RectF BoundsForSingleMockTouchAtLocation(float x, float y) {
59 float diameter = MockMotionEvent::TOUCH_MAJOR; 60 float diameter = MockMotionEvent::TOUCH_MAJOR;
60 return gfx::RectF(x - diameter / 2, y - diameter / 2, diameter, diameter); 61 return gfx::RectF(x - diameter / 2, y - diameter / 2, diameter, diameter);
61 } 62 }
62 63
63 } // namespace 64 } // namespace
64 65
65 class GestureProviderTest : public testing::Test, public GestureProviderClient { 66 class GestureProviderTest : public testing::Test, public GestureProviderClient {
66 public: 67 public:
67 GestureProviderTest() {} 68 GestureProviderTest()
69 : scoped_task_environment_(
70 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
68 ~GestureProviderTest() override {} 71 ~GestureProviderTest() override {}
69 72
70 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time, 73 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
71 MotionEvent::Action action, 74 MotionEvent::Action action,
72 float x, 75 float x,
73 float y) { 76 float y) {
74 return MockMotionEvent(action, event_time, x, y); 77 return MockMotionEvent(action, event_time, x, y);
75 } 78 }
76 79
77 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time, 80 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 421
419 static void RunTasksAndWait(base::TimeDelta delay) { 422 static void RunTasksAndWait(base::TimeDelta delay) {
420 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 423 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
421 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), delay); 424 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), delay);
422 base::RunLoop().Run(); 425 base::RunLoop().Run();
423 } 426 }
424 427
425 std::vector<GestureEventData> gestures_; 428 std::vector<GestureEventData> gestures_;
426 std::unique_ptr<GestureProvider> gesture_provider_; 429 std::unique_ptr<GestureProvider> gesture_provider_;
427 std::unique_ptr<GestureEventData> active_scroll_begin_event_; 430 std::unique_ptr<GestureEventData> active_scroll_begin_event_;
428 base::MessageLoopForUI message_loop_; 431 base::test::ScopedTaskEnvironment scoped_task_environment_;
429 }; 432 };
430 433
431 // Verify that a DOWN followed shortly by an UP will trigger a single tap. 434 // Verify that a DOWN followed shortly by an UP will trigger a single tap.
432 TEST_F(GestureProviderTest, GestureTap) { 435 TEST_F(GestureProviderTest, GestureTap) {
433 base::TimeTicks event_time = base::TimeTicks::Now(); 436 base::TimeTicks event_time = base::TimeTicks::Now();
434 int motion_event_id = 6; 437 int motion_event_id = 6;
435 int motion_event_flags = EF_CONTROL_DOWN | EF_ALT_DOWN; 438 int motion_event_flags = EF_CONTROL_DOWN | EF_ALT_DOWN;
436 439
437 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 440 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
438 441
(...skipping 2386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2825 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, 2828 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX,
2826 kFakeCoordY + GetTouchSlop() / 2); 2829 kFakeCoordY + GetTouchSlop() / 2);
2827 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2830 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2828 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); 2831 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2829 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2832 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2830 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 2833 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2831 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 2834 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2832 } 2835 }
2833 2836
2834 } // namespace ui 2837 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698