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

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

Issue 2943133002: Async Wheel Event with only the first one cancellable behind a flag. (Closed)
Patch Set: 'k' removed from constant string Created 3 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/mouse_wheel_event_queue.h" 5 #include "content/browser/renderer_host/input/mouse_wheel_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/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_feature_list.h"
16 #include "base/test/scoped_task_environment.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"
21 #include "content/public/common/content_features.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/WebKit/public/platform/WebInputEvent.h" 23 #include "third_party/WebKit/public/platform/WebInputEvent.h"
22 #include "ui/events/base_event_utils.h" 24 #include "ui/events/base_event_utils.h"
23 25
24 using blink::WebGestureEvent; 26 using blink::WebGestureEvent;
25 using blink::WebInputEvent; 27 using blink::WebInputEvent;
26 using blink::WebMouseWheelEvent; 28 using blink::WebMouseWheelEvent;
27 29
28 namespace content { 30 namespace content {
29 namespace { 31 namespace {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 130
129 #define EXPECT_SYNTHETIC_INERTIAL_GESTURE_SCROLL_END(event) \ 131 #define EXPECT_SYNTHETIC_INERTIAL_GESTURE_SCROLL_END(event) \
130 EXPECT_GESTURE_SCROLL_END_IMPL(event); \ 132 EXPECT_GESTURE_SCROLL_END_IMPL(event); \
131 EXPECT_TRUE(event->data.scroll_end.synthetic); \ 133 EXPECT_TRUE(event->data.scroll_end.synthetic); \
132 EXPECT_EQ(WebGestureEvent::kMomentumPhase, \ 134 EXPECT_EQ(WebGestureEvent::kMomentumPhase, \
133 event->data.scroll_end.inertial_phase); 135 event->data.scroll_end.inertial_phase);
134 136
135 #define EXPECT_MOUSE_WHEEL(event) \ 137 #define EXPECT_MOUSE_WHEEL(event) \
136 EXPECT_EQ(WebInputEvent::kMouseWheel, event->GetType()); 138 EXPECT_EQ(WebInputEvent::kMouseWheel, event->GetType());
137 139
140 enum WheelScrollingMode {
141 kWheelScrollingModeNone,
142 kWheelScrollLatching,
143 kAsyncWheelEvents,
144 };
145
138 } // namespace 146 } // namespace
139 147
140 class MouseWheelEventQueueTest : public testing::TestWithParam<bool>, 148 class MouseWheelEventQueueTest
141 public MouseWheelEventQueueClient { 149 : public testing::TestWithParam<WheelScrollingMode>,
150 public MouseWheelEventQueueClient {
142 public: 151 public:
143 MouseWheelEventQueueTest() 152 MouseWheelEventQueueTest()
144 : scoped_task_environment_( 153 : scoped_task_environment_(
145 base::test::ScopedTaskEnvironment::MainThreadType::UI), 154 base::test::ScopedTaskEnvironment::MainThreadType::UI),
146 acked_event_count_(0), 155 acked_event_count_(0),
147 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) { 156 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {
148 scroll_latching_enabled_ = GetParam(); 157 scroll_latching_enabled_ = GetParam() != kWheelScrollingModeNone;
158 switch (GetParam()) {
159 case kWheelScrollingModeNone:
160 feature_list_.InitWithFeatures(
161 {}, {features::kTouchpadAndWheelScrollLatching,
162 features::kAsyncWheelEvents});
163 break;
164 case kWheelScrollLatching:
165 feature_list_.InitWithFeatures(
166 {features::kTouchpadAndWheelScrollLatching},
167 {features::kAsyncWheelEvents});
168 break;
169 case kAsyncWheelEvents:
170 feature_list_.InitWithFeatures(
171 {features::kTouchpadAndWheelScrollLatching,
172 features::kAsyncWheelEvents},
173 {});
174 }
175
149 queue_.reset(new MouseWheelEventQueue(this, scroll_latching_enabled_)); 176 queue_.reset(new MouseWheelEventQueue(this, scroll_latching_enabled_));
150 scroll_end_timeout_ms_ = scroll_latching_enabled_ ? 100 : 0;
151 } 177 }
152 178
153 ~MouseWheelEventQueueTest() override {} 179 ~MouseWheelEventQueueTest() override {}
154 180
155 // MouseWheelEventQueueClient 181 // MouseWheelEventQueueClient
156 void SendMouseWheelEventImmediately( 182 void SendMouseWheelEventImmediately(
157 const MouseWheelEventWithLatencyInfo& event) override { 183 const MouseWheelEventWithLatencyInfo& event) override {
158 WebMouseWheelEvent* cloned_event = new WebMouseWheelEvent(); 184 WebMouseWheelEvent* cloned_event = new WebMouseWheelEvent();
159 std::unique_ptr<WebInputEvent> cloned_event_holder(cloned_event); 185 std::unique_ptr<WebInputEvent> cloned_event_holder(cloned_event);
160 *cloned_event = event.event; 186 *cloned_event = event.event;
161 sent_events_.push_back(std::move(cloned_event_holder)); 187 sent_events_.push_back(std::move(cloned_event_holder));
162 } 188 }
163 189
164 void ForwardGestureEventWithLatencyInfo( 190 void ForwardGestureEventWithLatencyInfo(
165 const blink::WebGestureEvent& event, 191 const blink::WebGestureEvent& event,
166 const ui::LatencyInfo& latency_info) override { 192 const ui::LatencyInfo& latency_info) override {
167 WebGestureEvent* cloned_event = new WebGestureEvent(); 193 WebGestureEvent* cloned_event = new WebGestureEvent();
168 std::unique_ptr<WebInputEvent> cloned_event_holder(cloned_event); 194 std::unique_ptr<WebInputEvent> cloned_event_holder(cloned_event);
169 *cloned_event = event; 195 *cloned_event = event;
170 sent_events_.push_back(std::move(cloned_event_holder)); 196 sent_events_.push_back(std::move(cloned_event_holder));
171 } 197 }
172 198
173 void OnMouseWheelEventAck(const MouseWheelEventWithLatencyInfo& event, 199 void OnMouseWheelEventAck(const MouseWheelEventWithLatencyInfo& event,
174 InputEventAckState ack_result) override { 200 InputEventAckState ack_result) override {
175 ++acked_event_count_; 201 ++acked_event_count_;
176 last_acked_event_ = event.event; 202 last_acked_event_ = event.event;
177 last_acked_event_state_ = ack_result; 203 last_acked_event_state_ = ack_result;
178 } 204 }
179 205
180 base::TimeDelta DefaultScrollEndTimeoutDelay() {
181 return base::TimeDelta::FromMilliseconds(scroll_end_timeout_ms_);
182 }
183
184 bool scroll_latching_enabled() { return scroll_latching_enabled_; } 206 bool scroll_latching_enabled() { return scroll_latching_enabled_; }
185 207
186 protected: 208 protected:
187 size_t queued_event_count() const { return queue_->queued_size(); } 209 size_t queued_event_count() const { return queue_->queued_size(); }
188 210
189 bool event_in_flight() const { return queue_->event_in_flight(); } 211 bool event_in_flight() const { return queue_->event_in_flight(); }
190 212
191 std::vector<std::unique_ptr<WebInputEvent>>& all_sent_events() { 213 std::vector<std::unique_ptr<WebInputEvent>>& all_sent_events() {
192 return sent_events_; 214 return sent_events_;
193 } 215 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 EXPECT_EQ(2U, GetAndResetSentEventCount()); 522 EXPECT_EQ(2U, GetAndResetSentEventCount());
501 } 523 }
502 } 524 }
503 525
504 base::test::ScopedTaskEnvironment scoped_task_environment_; 526 base::test::ScopedTaskEnvironment scoped_task_environment_;
505 std::unique_ptr<MouseWheelEventQueue> queue_; 527 std::unique_ptr<MouseWheelEventQueue> queue_;
506 std::vector<std::unique_ptr<WebInputEvent>> sent_events_; 528 std::vector<std::unique_ptr<WebInputEvent>> sent_events_;
507 size_t acked_event_count_; 529 size_t acked_event_count_;
508 InputEventAckState last_acked_event_state_; 530 InputEventAckState last_acked_event_state_;
509 WebMouseWheelEvent last_acked_event_; 531 WebMouseWheelEvent last_acked_event_;
510 int64_t scroll_end_timeout_ms_;
511 bool scroll_latching_enabled_; 532 bool scroll_latching_enabled_;
533
534 private:
535 base::test::ScopedFeatureList feature_list_;
512 }; 536 };
513 537
514 // Tests that mouse wheel events are queued properly. 538 // Tests that mouse wheel events are queued properly.
515 TEST_P(MouseWheelEventQueueTest, Basic) { 539 TEST_P(MouseWheelEventQueueTest, Basic) {
516 SendMouseWheel(kWheelScrollX, kWheelScrollY, kWheelScrollGlobalX, 540 SendMouseWheelPossiblyIncludingPhase(
517 kWheelScrollGlobalY, 1, 1, 0, false); 541 !scroll_latching_enabled_, kWheelScrollX, kWheelScrollY,
542 kWheelScrollGlobalX, kWheelScrollGlobalY, 1, 1, 0, false,
543 WebMouseWheelEvent::kPhaseBegan, WebMouseWheelEvent::kPhaseNone);
518 EXPECT_EQ(0U, queued_event_count()); 544 EXPECT_EQ(0U, queued_event_count());
519 EXPECT_TRUE(event_in_flight()); 545 EXPECT_TRUE(event_in_flight());
520 EXPECT_EQ(1U, GetAndResetSentEventCount()); 546 EXPECT_EQ(1U, GetAndResetSentEventCount());
521 547
522 // The second mouse wheel should not be sent since one is already in queue. 548 // The second mouse wheel should not be sent since one is already in queue.
523 SendMouseWheel(kWheelScrollX, kWheelScrollY, kWheelScrollGlobalX, 549 SendMouseWheelPossiblyIncludingPhase(
524 kWheelScrollGlobalY, 5, 5, 0, false); 550 !scroll_latching_enabled_, kWheelScrollX, kWheelScrollY,
551 kWheelScrollGlobalX, kWheelScrollGlobalY, 5, 5, 0, false,
552 WebMouseWheelEvent::kPhaseChanged, WebMouseWheelEvent::kPhaseNone);
525 EXPECT_EQ(1U, queued_event_count()); 553 EXPECT_EQ(1U, queued_event_count());
526 EXPECT_TRUE(event_in_flight()); 554 EXPECT_TRUE(event_in_flight());
527 EXPECT_EQ(0U, GetAndResetSentEventCount()); 555 EXPECT_EQ(0U, GetAndResetSentEventCount());
528 556
529 // Receive an ACK for the first mouse wheel event. 557 // Receive an ACK for the first mouse wheel event.
530 SendMouseWheelEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); 558 SendMouseWheelEventAck(INPUT_EVENT_ACK_STATE_CONSUMED);
531 EXPECT_EQ(0U, queued_event_count()); 559 EXPECT_EQ(0U, queued_event_count());
532 EXPECT_TRUE(event_in_flight()); 560 EXPECT_TRUE(event_in_flight());
533 EXPECT_EQ(1U, GetAndResetSentEventCount()); 561 EXPECT_EQ(1U, GetAndResetSentEventCount());
534 EXPECT_EQ(1U, GetAndResetAckedEventCount()); 562 EXPECT_EQ(1U, GetAndResetAckedEventCount());
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 // Scroll latching: no new scroll begin expected. 805 // Scroll latching: no new scroll begin expected.
778 EXPECT_EQ(1U, all_sent_events().size()); 806 EXPECT_EQ(1U, all_sent_events().size());
779 EXPECT_GESTURE_SCROLL_UPDATE_WITH_PHASE(sent_gesture_event(0)); 807 EXPECT_GESTURE_SCROLL_UPDATE_WITH_PHASE(sent_gesture_event(0));
780 EXPECT_EQ(0U, sent_gesture_event(0)->data.scroll_update.delta_x); 808 EXPECT_EQ(0U, sent_gesture_event(0)->data.scroll_update.delta_x);
781 EXPECT_EQ(1U, sent_gesture_event(0)->data.scroll_update.delta_y); 809 EXPECT_EQ(1U, sent_gesture_event(0)->data.scroll_update.delta_y);
782 EXPECT_EQ(1U, GetAndResetSentEventCount()); 810 EXPECT_EQ(1U, GetAndResetSentEventCount());
783 } 811 }
784 812
785 INSTANTIATE_TEST_CASE_P(MouseWheelEventQueueTests, 813 INSTANTIATE_TEST_CASE_P(MouseWheelEventQueueTests,
786 MouseWheelEventQueueTest, 814 MouseWheelEventQueueTest,
787 testing::Bool()); 815 testing::Values(kWheelScrollingModeNone,
816 kWheelScrollLatching,
817 kAsyncWheelEvents));
788 818
789 } // namespace content 819 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698