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

Side by Side Diff: content/browser/renderer_host/input/passthrough_touch_event_queue_unittest.cc

Issue 2846933002: Use ScopedTaskEnvironment instead of MessageLoopForUI in content tests. (Closed)
Patch Set: self-review 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "content/browser/renderer_host/input/passthrough_touch_event_queue.h" 5 #include "content/browser/renderer_host/input/passthrough_touch_event_queue.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/test/scoped_task_environment.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "content/browser/renderer_host/input/timeout_monitor.h" 19 #include "content/browser/renderer_host/input/timeout_monitor.h"
19 #include "content/common/input/synthetic_web_input_event_builders.h" 20 #include "content/common/input/synthetic_web_input_event_builders.h"
20 #include "content/common/input/web_touch_event_traits.h" 21 #include "content/common/input/web_touch_event_traits.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/WebKit/public/platform/WebInputEvent.h" 23 #include "third_party/WebKit/public/platform/WebInputEvent.h"
23 #include "ui/events/base_event_utils.h" 24 #include "ui/events/base_event_utils.h"
24 25
25 using blink::WebGestureEvent; 26 using blink::WebGestureEvent;
26 using blink::WebInputEvent; 27 using blink::WebInputEvent;
27 using blink::WebTouchEvent; 28 using blink::WebTouchEvent;
28 using blink::WebTouchPoint; 29 using blink::WebTouchPoint;
29 30
30 namespace content { 31 namespace content {
31 namespace { 32 namespace {
32 33
33 const double kMinSecondsBetweenThrottledTouchmoves = 0.2; 34 const double kMinSecondsBetweenThrottledTouchmoves = 0.2;
34 const float kSlopLengthDips = 10; 35 const float kSlopLengthDips = 10;
35 const float kHalfSlopLengthDips = kSlopLengthDips / 2; 36 const float kHalfSlopLengthDips = kSlopLengthDips / 2;
36 37
37 base::TimeDelta DefaultTouchTimeoutDelay() { 38 base::TimeDelta DefaultTouchTimeoutDelay() {
38 return base::TimeDelta::FromMilliseconds(1); 39 return base::TimeDelta::FromMilliseconds(1);
39 } 40 }
40 } // namespace 41 } // namespace
41 42
42 class PassthroughTouchEventQueueTest : public testing::Test, 43 class PassthroughTouchEventQueueTest : public testing::Test,
43 public TouchEventQueueClient { 44 public TouchEventQueueClient {
44 public: 45 public:
45 PassthroughTouchEventQueueTest() 46 PassthroughTouchEventQueueTest()
46 : acked_event_count_(0), 47 : scoped_task_environment_(
48 base::test::ScopedTaskEnvironment::MainThreadType::UI),
49 acked_event_count_(0),
47 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), 50 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN),
48 slop_length_dips_(0) {} 51 slop_length_dips_(0) {}
49 52
50 ~PassthroughTouchEventQueueTest() override {} 53 ~PassthroughTouchEventQueueTest() override {}
51 54
52 // testing::Test 55 // testing::Test
53 void SetUp() override { 56 void SetUp() override {
54 ResetQueueWithConfig(TouchEventQueue::Config()); 57 ResetQueueWithConfig(TouchEventQueue::Config());
55 sent_events_ids_.clear(); 58 sent_events_ids_.clear();
56 } 59 }
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 void SendTouchEvent() { 320 void SendTouchEvent() {
318 SendTouchEvent(touch_event_); 321 SendTouchEvent(touch_event_);
319 touch_event_.ResetPoints(); 322 touch_event_.ResetPoints();
320 } 323 }
321 324
322 void ResetQueueWithConfig(const TouchEventQueue::Config& config) { 325 void ResetQueueWithConfig(const TouchEventQueue::Config& config) {
323 queue_.reset(new PassthroughTouchEventQueue(this, config)); 326 queue_.reset(new PassthroughTouchEventQueue(this, config));
324 queue_->OnHasTouchEventHandlers(true); 327 queue_->OnHasTouchEventHandlers(true);
325 } 328 }
326 329
330 base::test::ScopedTaskEnvironment scoped_task_environment_;
327 std::unique_ptr<PassthroughTouchEventQueue> queue_; 331 std::unique_ptr<PassthroughTouchEventQueue> queue_;
328 size_t acked_event_count_; 332 size_t acked_event_count_;
329 WebTouchEvent last_acked_event_; 333 WebTouchEvent last_acked_event_;
330 std::vector<WebTouchEvent> sent_events_; 334 std::vector<WebTouchEvent> sent_events_;
331 InputEventAckState last_acked_event_state_; 335 InputEventAckState last_acked_event_state_;
332 SyntheticWebTouchEvent touch_event_; 336 SyntheticWebTouchEvent touch_event_;
333 std::unique_ptr<WebTouchEvent> followup_touch_event_; 337 std::unique_ptr<WebTouchEvent> followup_touch_event_;
334 std::unique_ptr<WebGestureEvent> followup_gesture_event_; 338 std::unique_ptr<WebGestureEvent> followup_gesture_event_;
335 std::unique_ptr<InputEventAckState> sync_ack_result_; 339 std::unique_ptr<InputEventAckState> sync_ack_result_;
336 double slop_length_dips_; 340 double slop_length_dips_;
337 gfx::PointF anchor_; 341 gfx::PointF anchor_;
338 base::MessageLoopForUI message_loop_;
339 std::deque<int> sent_events_ids_; 342 std::deque<int> sent_events_ids_;
340 }; 343 };
341 344
342 // Tests that touch-events are queued properly. 345 // Tests that touch-events are queued properly.
343 TEST_F(PassthroughTouchEventQueueTest, Basic) { 346 TEST_F(PassthroughTouchEventQueueTest, Basic) {
344 PressTouchPoint(1, 1); 347 PressTouchPoint(1, 1);
345 EXPECT_EQ(1U, queued_event_count()); 348 EXPECT_EQ(1U, queued_event_count());
346 EXPECT_EQ(1U, GetAndResetSentEventCount()); 349 EXPECT_EQ(1U, GetAndResetSentEventCount());
347 350
348 // The second touch should be sent right away even though 351 // The second touch should be sent right away even though
(...skipping 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 EXPECT_EQ(WebInputEvent::kTouchMove, sent_event().GetType()); 1762 EXPECT_EQ(WebInputEvent::kTouchMove, sent_event().GetType());
1760 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); 1763 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move);
1761 1764
1762 ReleaseTouchPoint(0); 1765 ReleaseTouchPoint(0);
1763 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 1766 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
1764 EXPECT_EQ(WebInputEvent::kTouchEnd, sent_event().GetType()); 1767 EXPECT_EQ(WebInputEvent::kTouchEnd, sent_event().GetType());
1765 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move); 1768 EXPECT_FALSE(sent_event().touch_start_or_first_touch_move);
1766 } 1769 }
1767 1770
1768 } // namespace content 1771 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698