OLD | NEW |
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> |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 EXPECT_EQ(WebInputEvent::MouseWheel, event->type); | 138 EXPECT_EQ(WebInputEvent::MouseWheel, event->type); |
139 | 139 |
140 } // namespace | 140 } // namespace |
141 | 141 |
142 class MouseWheelEventQueueTest : public testing::Test, | 142 class MouseWheelEventQueueTest : public testing::Test, |
143 public MouseWheelEventQueueClient { | 143 public MouseWheelEventQueueClient { |
144 public: | 144 public: |
145 MouseWheelEventQueueTest() | 145 MouseWheelEventQueueTest() |
146 : acked_event_count_(0), | 146 : acked_event_count_(0), |
147 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) { | 147 last_acked_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) { |
148 SetUpForGestureTesting(false); | 148 queue_.reset(new MouseWheelEventQueue(this, kScrollEndTimeoutMs)); |
149 } | 149 } |
150 | 150 |
151 ~MouseWheelEventQueueTest() override {} | 151 ~MouseWheelEventQueueTest() override {} |
152 | 152 |
153 // MouseWheelEventQueueClient | 153 // MouseWheelEventQueueClient |
154 void SendMouseWheelEventImmediately( | 154 void SendMouseWheelEventImmediately( |
155 const MouseWheelEventWithLatencyInfo& event) override { | 155 const MouseWheelEventWithLatencyInfo& event) override { |
156 WebMouseWheelEvent* cloned_event = new WebMouseWheelEvent(); | 156 WebMouseWheelEvent* cloned_event = new WebMouseWheelEvent(); |
157 std::unique_ptr<WebInputEvent> cloned_event_holder(cloned_event); | 157 std::unique_ptr<WebInputEvent> cloned_event_holder(cloned_event); |
158 *cloned_event = event.event; | 158 *cloned_event = event.event; |
(...skipping 10 matching lines...) Expand all Loading... |
169 } | 169 } |
170 | 170 |
171 void OnMouseWheelEventAck(const MouseWheelEventWithLatencyInfo& event, | 171 void OnMouseWheelEventAck(const MouseWheelEventWithLatencyInfo& event, |
172 InputEventAckState ack_result) override { | 172 InputEventAckState ack_result) override { |
173 ++acked_event_count_; | 173 ++acked_event_count_; |
174 last_acked_event_ = event.event; | 174 last_acked_event_ = event.event; |
175 last_acked_event_state_ = ack_result; | 175 last_acked_event_state_ = ack_result; |
176 } | 176 } |
177 | 177 |
178 protected: | 178 protected: |
179 void SetUpForGestureTesting(bool send_gestures) { | |
180 queue_.reset( | |
181 new MouseWheelEventQueue(this, send_gestures, kScrollEndTimeoutMs)); | |
182 } | |
183 | |
184 size_t queued_event_count() const { return queue_->queued_size(); } | 179 size_t queued_event_count() const { return queue_->queued_size(); } |
185 | 180 |
186 bool event_in_flight() const { return queue_->event_in_flight(); } | 181 bool event_in_flight() const { return queue_->event_in_flight(); } |
187 | 182 |
188 std::vector<std::unique_ptr<WebInputEvent>>& all_sent_events() { | 183 std::vector<std::unique_ptr<WebInputEvent>>& all_sent_events() { |
189 return sent_events_; | 184 return sent_events_; |
190 } | 185 } |
191 | 186 |
192 const std::unique_ptr<WebInputEvent>& sent_input_event(size_t index) { | 187 const std::unique_ptr<WebInputEvent>& sent_input_event(size_t index) { |
193 return sent_events_[index]; | 188 return sent_events_[index]; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 // Receive an ACK for the second mouse wheel event. | 423 // Receive an ACK for the second mouse wheel event. |
429 SendMouseWheelEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); | 424 SendMouseWheelEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
430 EXPECT_EQ(0U, queued_event_count()); | 425 EXPECT_EQ(0U, queued_event_count()); |
431 EXPECT_FALSE(event_in_flight()); | 426 EXPECT_FALSE(event_in_flight()); |
432 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 427 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
433 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 428 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
434 EXPECT_EQ(WebInputEvent::MouseWheel, acked_event().type); | 429 EXPECT_EQ(WebInputEvent::MouseWheel, acked_event().type); |
435 } | 430 } |
436 | 431 |
437 TEST_F(MouseWheelEventQueueTest, GestureSending) { | 432 TEST_F(MouseWheelEventQueueTest, GestureSending) { |
438 SetUpForGestureTesting(true); | |
439 GestureSendingTest(false); | 433 GestureSendingTest(false); |
440 } | 434 } |
441 | 435 |
442 TEST_F(MouseWheelEventQueueTest, GestureSendingPrecisePixels) { | 436 TEST_F(MouseWheelEventQueueTest, GestureSendingPrecisePixels) { |
443 SetUpForGestureTesting(true); | |
444 GestureSendingTest(false); | 437 GestureSendingTest(false); |
445 } | 438 } |
446 | 439 |
447 TEST_F(MouseWheelEventQueueTest, GestureSendingWithPhaseInformation) { | 440 TEST_F(MouseWheelEventQueueTest, GestureSendingWithPhaseInformation) { |
448 SetUpForGestureTesting(true); | |
449 PhaseGestureSendingTest(false); | 441 PhaseGestureSendingTest(false); |
450 } | 442 } |
451 | 443 |
452 TEST_F(MouseWheelEventQueueTest, | 444 TEST_F(MouseWheelEventQueueTest, |
453 GestureSendingWithPhaseInformationPrecisePixels) { | 445 GestureSendingWithPhaseInformationPrecisePixels) { |
454 SetUpForGestureTesting(true); | |
455 PhaseGestureSendingTest(true); | 446 PhaseGestureSendingTest(true); |
456 } | 447 } |
457 | 448 |
458 TEST_F(MouseWheelEventQueueTest, GestureSendingInterrupted) { | 449 TEST_F(MouseWheelEventQueueTest, GestureSendingInterrupted) { |
459 SetUpForGestureTesting(true); | |
460 const WebGestureEvent::ScrollUnits scroll_units = WebGestureEvent::Pixels; | 450 const WebGestureEvent::ScrollUnits scroll_units = WebGestureEvent::Pixels; |
461 | 451 |
462 SendMouseWheel(kWheelScrollX, kWheelScrollY, kWheelScrollGlobalX, | 452 SendMouseWheel(kWheelScrollX, kWheelScrollY, kWheelScrollGlobalX, |
463 kWheelScrollGlobalY, 1, 1, 0, false); | 453 kWheelScrollGlobalY, 1, 1, 0, false); |
464 EXPECT_EQ(0U, queued_event_count()); | 454 EXPECT_EQ(0U, queued_event_count()); |
465 EXPECT_TRUE(event_in_flight()); | 455 EXPECT_TRUE(event_in_flight()); |
466 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 456 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
467 | 457 |
468 // Receive an ACK for the mouse wheel event. | 458 // Receive an ACK for the mouse wheel event. |
469 SendMouseWheelEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 459 SendMouseWheelEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 EXPECT_FALSE(event_in_flight()); | 502 EXPECT_FALSE(event_in_flight()); |
513 EXPECT_EQ(WebInputEvent::MouseWheel, acked_event().type); | 503 EXPECT_EQ(WebInputEvent::MouseWheel, acked_event().type); |
514 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 504 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
515 EXPECT_EQ(2U, all_sent_events().size()); | 505 EXPECT_EQ(2U, all_sent_events().size()); |
516 EXPECT_GESTURE_SCROLL_BEGIN(sent_gesture_event(0)); | 506 EXPECT_GESTURE_SCROLL_BEGIN(sent_gesture_event(0)); |
517 EXPECT_GESTURE_SCROLL_UPDATE(sent_gesture_event(1)); | 507 EXPECT_GESTURE_SCROLL_UPDATE(sent_gesture_event(1)); |
518 EXPECT_EQ(2U, GetAndResetSentEventCount()); | 508 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
519 } | 509 } |
520 | 510 |
521 TEST_F(MouseWheelEventQueueTest, GestureRailScrolling) { | 511 TEST_F(MouseWheelEventQueueTest, GestureRailScrolling) { |
522 SetUpForGestureTesting(true); | |
523 const WebGestureEvent::ScrollUnits scroll_units = WebGestureEvent::Pixels; | 512 const WebGestureEvent::ScrollUnits scroll_units = WebGestureEvent::Pixels; |
524 | 513 |
525 SendMouseWheel(kWheelScrollX, kWheelScrollY, kWheelScrollGlobalX, | 514 SendMouseWheel(kWheelScrollX, kWheelScrollY, kWheelScrollGlobalX, |
526 kWheelScrollGlobalY, 1, 1, 0, false, | 515 kWheelScrollGlobalY, 1, 1, 0, false, |
527 WebInputEvent::RailsModeHorizontal); | 516 WebInputEvent::RailsModeHorizontal); |
528 EXPECT_EQ(0U, queued_event_count()); | 517 EXPECT_EQ(0U, queued_event_count()); |
529 EXPECT_TRUE(event_in_flight()); | 518 EXPECT_TRUE(event_in_flight()); |
530 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 519 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
531 | 520 |
532 // Receive an ACK for the mouse wheel event. | 521 // Receive an ACK for the mouse wheel event. |
(...skipping 29 matching lines...) Expand all Loading... |
562 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 551 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
563 EXPECT_EQ(2U, all_sent_events().size()); | 552 EXPECT_EQ(2U, all_sent_events().size()); |
564 EXPECT_GESTURE_SCROLL_BEGIN(sent_gesture_event(0)); | 553 EXPECT_GESTURE_SCROLL_BEGIN(sent_gesture_event(0)); |
565 EXPECT_GESTURE_SCROLL_UPDATE(sent_gesture_event(1)); | 554 EXPECT_GESTURE_SCROLL_UPDATE(sent_gesture_event(1)); |
566 EXPECT_EQ(0U, sent_gesture_event(1)->data.scrollUpdate.deltaX); | 555 EXPECT_EQ(0U, sent_gesture_event(1)->data.scrollUpdate.deltaX); |
567 EXPECT_EQ(1U, sent_gesture_event(1)->data.scrollUpdate.deltaY); | 556 EXPECT_EQ(1U, sent_gesture_event(1)->data.scrollUpdate.deltaY); |
568 EXPECT_EQ(2U, GetAndResetSentEventCount()); | 557 EXPECT_EQ(2U, GetAndResetSentEventCount()); |
569 } | 558 } |
570 | 559 |
571 } // namespace content | 560 } // namespace content |
OLD | NEW |