OLD | NEW |
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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
8 #include "base/timer.h" | 8 #include "base/timer.h" |
9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
10 #include "content/browser/renderer_host/backing_store.h" | 10 #include "content/browser/renderer_host/backing_store.h" |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 | 432 |
433 void SimulateWheelEvent(float dX, float dY, int modifiers) { | 433 void SimulateWheelEvent(float dX, float dY, int modifiers) { |
434 WebMouseWheelEvent wheel_event; | 434 WebMouseWheelEvent wheel_event; |
435 wheel_event.type = WebInputEvent::MouseWheel; | 435 wheel_event.type = WebInputEvent::MouseWheel; |
436 wheel_event.deltaX = dX; | 436 wheel_event.deltaX = dX; |
437 wheel_event.deltaY = dY; | 437 wheel_event.deltaY = dY; |
438 wheel_event.modifiers = modifiers; | 438 wheel_event.modifiers = modifiers; |
439 host_->ForwardWheelEvent(wheel_event); | 439 host_->ForwardWheelEvent(wheel_event); |
440 } | 440 } |
441 | 441 |
| 442 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) { |
| 443 WebMouseWheelEvent wheel_event; |
| 444 wheel_event.type = WebInputEvent::MouseWheel; |
| 445 wheel_event.phase = phase; |
| 446 host_->ForwardWheelEvent(wheel_event); |
| 447 } |
| 448 |
442 // Inject simple synthetic WebGestureEvent instances. | 449 // Inject simple synthetic WebGestureEvent instances. |
443 void SimulateGestureEvent(WebInputEvent::Type type) { | 450 void SimulateGestureEvent(WebInputEvent::Type type) { |
444 WebGestureEvent gesture_event; | 451 WebGestureEvent gesture_event; |
445 gesture_event.type = type; | 452 gesture_event.type = type; |
446 host_->ForwardGestureEvent(gesture_event); | 453 host_->ForwardGestureEvent(gesture_event); |
447 } | 454 } |
448 | 455 |
449 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) { | 456 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) { |
450 WebGestureEvent gesture_event; | 457 WebGestureEvent gesture_event; |
451 gesture_event.type = WebInputEvent::GestureScrollUpdate; | 458 gesture_event.type = WebInputEvent::GestureScrollUpdate; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 touch_event_.touches[index].state = WebKit::WebTouchPoint::StateMoved; | 520 touch_event_.touches[index].state = WebKit::WebTouchPoint::StateMoved; |
514 touch_event_.type = WebInputEvent::TouchMove; | 521 touch_event_.type = WebInputEvent::TouchMove; |
515 } | 522 } |
516 | 523 |
517 void ReleaseTouchPoint(int index) { | 524 void ReleaseTouchPoint(int index) { |
518 CHECK(index >= 0 && index < touch_event_.touchesLengthCap); | 525 CHECK(index >= 0 && index < touch_event_.touchesLengthCap); |
519 touch_event_.touches[index].state = WebKit::WebTouchPoint::StateReleased; | 526 touch_event_.touches[index].state = WebKit::WebTouchPoint::StateReleased; |
520 touch_event_.type = WebInputEvent::TouchEnd; | 527 touch_event_.type = WebInputEvent::TouchEnd; |
521 } | 528 } |
522 | 529 |
| 530 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) { |
| 531 PickleIterator iter(message); |
| 532 const char* data; |
| 533 int data_length; |
| 534 if (!message.ReadData(&iter, &data, &data_length)) |
| 535 return NULL; |
| 536 return reinterpret_cast<const WebInputEvent*>(data); |
| 537 } |
| 538 |
523 MessageLoopForUI message_loop_; | 539 MessageLoopForUI message_loop_; |
524 | 540 |
525 scoped_ptr<TestBrowserContext> browser_context_; | 541 scoped_ptr<TestBrowserContext> browser_context_; |
526 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. | 542 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. |
527 scoped_ptr<MockRenderWidgetHostDelegate> delegate_; | 543 scoped_ptr<MockRenderWidgetHostDelegate> delegate_; |
528 scoped_ptr<MockRenderWidgetHost> host_; | 544 scoped_ptr<MockRenderWidgetHost> host_; |
529 scoped_ptr<TestView> view_; | 545 scoped_ptr<TestView> view_; |
530 scoped_ptr<gfx::Screen> screen_; | 546 scoped_ptr<gfx::Screen> screen_; |
531 | 547 |
532 private: | 548 private: |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 968 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
953 ViewMsg_HandleInputEvent::ID)); | 969 ViewMsg_HandleInputEvent::ID)); |
954 process_->sink().ClearMessages(); | 970 process_->sink().ClearMessages(); |
955 | 971 |
956 // After the final ack, the queue should be empty. | 972 // After the final ack, the queue should be empty. |
957 SendInputEventACK(WebInputEvent::MouseWheel, true); | 973 SendInputEventACK(WebInputEvent::MouseWheel, true); |
958 MessageLoop::current()->RunUntilIdle(); | 974 MessageLoop::current()->RunUntilIdle(); |
959 EXPECT_EQ(0U, process_->sink().message_count()); | 975 EXPECT_EQ(0U, process_->sink().message_count()); |
960 } | 976 } |
961 | 977 |
| 978 TEST_F(RenderWidgetHostTest, CoalescesWheelEventsQueuedPhaseEndIsNotDropped) { |
| 979 process_->sink().ClearMessages(); |
| 980 |
| 981 // Send an initial gesture begin and ACK it. |
| 982 SimulateGestureEvent(WebInputEvent::GestureScrollBegin); |
| 983 EXPECT_EQ(1U, process_->sink().message_count()); |
| 984 SendInputEventACK(WebInputEvent::GestureScrollBegin, true); |
| 985 MessageLoop::current()->RunUntilIdle(); |
| 986 |
| 987 // Send a wheel event, should get sent directly. |
| 988 SimulateWheelEvent(0, -5, 0); |
| 989 EXPECT_EQ(2U, process_->sink().message_count()); |
| 990 |
| 991 // Send a wheel phase end event before an ACK is received for the previous |
| 992 // wheel event, which should get queued. |
| 993 SimulateWheelEventWithPhase(WebMouseWheelEvent::PhaseEnded); |
| 994 EXPECT_EQ(2U, process_->sink().message_count()); |
| 995 |
| 996 // A gesture event should now result in the queued phase ended event being |
| 997 // transmitted before it. |
| 998 SimulateGestureEvent(WebInputEvent::GestureScrollEnd); |
| 999 ASSERT_EQ(4U, process_->sink().message_count()); |
| 1000 |
| 1001 // Verify the events that were sent. |
| 1002 const WebInputEvent* input_event = |
| 1003 GetInputEventFromMessage(*process_->sink().GetMessageAt(2)); |
| 1004 ASSERT_EQ(WebInputEvent::MouseWheel, input_event->type); |
| 1005 const WebMouseWheelEvent* wheel_event = |
| 1006 static_cast<const WebMouseWheelEvent*>(input_event); |
| 1007 ASSERT_EQ(WebMouseWheelEvent::PhaseEnded, wheel_event->phase); |
| 1008 |
| 1009 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(3)); |
| 1010 EXPECT_EQ(WebInputEvent::GestureScrollEnd, input_event->type); |
| 1011 } |
| 1012 |
962 TEST_F(RenderWidgetHostTest, CoalescesGesturesEvents) { | 1013 TEST_F(RenderWidgetHostTest, CoalescesGesturesEvents) { |
963 // Turn off debounce handling for test isolation. | 1014 // Turn off debounce handling for test isolation. |
964 host_->set_debounce_interval_time_ms(0); | 1015 host_->set_debounce_interval_time_ms(0); |
965 process_->sink().ClearMessages(); | 1016 process_->sink().ClearMessages(); |
966 // Only GestureScrollUpdate events can be coalesced. | 1017 // Only GestureScrollUpdate events can be coalesced. |
967 // Simulate gesture events. | 1018 // Simulate gesture events. |
968 | 1019 |
969 // Sent. | 1020 // Sent. |
970 SimulateGestureEvent(WebInputEvent::GestureScrollBegin); | 1021 SimulateGestureEvent(WebInputEvent::GestureScrollBegin); |
971 | 1022 |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1793 process_->InitUpdateRectParams(¶ms); | 1844 process_->InitUpdateRectParams(¶ms); |
1794 params.scale_factor = params.scale_factor * 2; | 1845 params.scale_factor = params.scale_factor * 2; |
1795 | 1846 |
1796 EXPECT_EQ(0, process_->bad_msg_count()); | 1847 EXPECT_EQ(0, process_->bad_msg_count()); |
1797 host_->OnMsgUpdateRect(params); | 1848 host_->OnMsgUpdateRect(params); |
1798 EXPECT_EQ(1, process_->bad_msg_count()); | 1849 EXPECT_EQ(1, process_->bad_msg_count()); |
1799 } | 1850 } |
1800 #endif | 1851 #endif |
1801 | 1852 |
1802 } // namespace content | 1853 } // namespace content |
OLD | NEW |