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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 217 } |
218 | 218 |
219 // Allow poking at a few private members. | 219 // Allow poking at a few private members. |
220 using RenderWidgetHostImpl::OnMsgPaintAtSizeAck; | 220 using RenderWidgetHostImpl::OnMsgPaintAtSizeAck; |
221 using RenderWidgetHostImpl::OnMsgUpdateRect; | 221 using RenderWidgetHostImpl::OnMsgUpdateRect; |
222 using RenderWidgetHostImpl::RendererExited; | 222 using RenderWidgetHostImpl::RendererExited; |
223 using RenderWidgetHostImpl::in_flight_size_; | 223 using RenderWidgetHostImpl::in_flight_size_; |
224 using RenderWidgetHostImpl::is_hidden_; | 224 using RenderWidgetHostImpl::is_hidden_; |
225 using RenderWidgetHostImpl::resize_ack_pending_; | 225 using RenderWidgetHostImpl::resize_ack_pending_; |
226 using RenderWidgetHostImpl::coalesced_gesture_events_; | 226 using RenderWidgetHostImpl::coalesced_gesture_events_; |
| 227 using RenderWidgetHostImpl::fling_in_progress_; |
227 | 228 |
228 bool unresponsive_timer_fired() const { | 229 bool unresponsive_timer_fired() const { |
229 return unresponsive_timer_fired_; | 230 return unresponsive_timer_fired_; |
230 } | 231 } |
231 | 232 |
232 void set_hung_renderer_delay_ms(int delay_ms) { | 233 void set_hung_renderer_delay_ms(int delay_ms) { |
233 hung_renderer_delay_ms_ = delay_ms; | 234 hung_renderer_delay_ms_ = delay_ms; |
234 } | 235 } |
235 | 236 |
236 protected: | 237 protected: |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 848 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
848 ViewMsg_HandleInputEvent::ID)); | 849 ViewMsg_HandleInputEvent::ID)); |
849 process_->sink().ClearMessages(); | 850 process_->sink().ClearMessages(); |
850 | 851 |
851 // After the final ack, the queue should be empty. | 852 // After the final ack, the queue should be empty. |
852 SendInputEventACK(WebInputEvent::GestureScrollEnd, true); | 853 SendInputEventACK(WebInputEvent::GestureScrollEnd, true); |
853 MessageLoop::current()->RunAllPending(); | 854 MessageLoop::current()->RunAllPending(); |
854 EXPECT_EQ(0U, process_->sink().message_count()); | 855 EXPECT_EQ(0U, process_->sink().message_count()); |
855 } | 856 } |
856 | 857 |
| 858 TEST_F(RenderWidgetHostTest, GestureFlingCancelsFiltered) { |
| 859 process_->sink().ClearMessages(); |
| 860 // GFC without previous GFS is dropped. |
| 861 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
| 862 EXPECT_EQ(0U, process_->sink().message_count()); |
| 863 EXPECT_EQ(0U, host_->coalesced_gesture_events_.size()); |
| 864 |
| 865 // GFC after previous GFS is dispatched and acked. |
| 866 process_->sink().ClearMessages(); |
| 867 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); |
| 868 EXPECT_TRUE(host_->fling_in_progress_); |
| 869 SendInputEventACK(WebInputEvent::GestureFlingStart, true); |
| 870 MessageLoop::current()->RunAllPending(); |
| 871 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
| 872 EXPECT_FALSE(host_->fling_in_progress_); |
| 873 EXPECT_EQ(2U, process_->sink().message_count()); |
| 874 SendInputEventACK(WebInputEvent::GestureFlingCancel, true); |
| 875 MessageLoop::current()->RunAllPending(); |
| 876 EXPECT_EQ(0U, host_->coalesced_gesture_events_.size()); |
| 877 |
| 878 // GFC before previous GFS is acked. |
| 879 process_->sink().ClearMessages(); |
| 880 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); |
| 881 EXPECT_TRUE(host_->fling_in_progress_); |
| 882 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
| 883 EXPECT_FALSE(host_->fling_in_progress_); |
| 884 EXPECT_EQ(1U, process_->sink().message_count()); |
| 885 EXPECT_FALSE(host_->coalesced_gesture_events_.empty()); |
| 886 |
| 887 // Advance state realistically. |
| 888 SendInputEventACK(WebInputEvent::GestureFlingStart, true); |
| 889 MessageLoop::current()->RunAllPending(); |
| 890 SendInputEventACK(WebInputEvent::GestureFlingCancel, true); |
| 891 MessageLoop::current()->RunAllPending(); |
| 892 EXPECT_EQ(0U, host_->coalesced_gesture_events_.size()); |
| 893 |
| 894 // GFS is added to the queue if another event is pending |
| 895 process_->sink().ClearMessages(); |
| 896 SimulateGestureEvent(8, -7, 0, WebInputEvent::GestureScrollUpdate); |
| 897 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); |
| 898 EXPECT_EQ(1U, process_->sink().message_count()); |
| 899 WebGestureEvent merged_event = host_->coalesced_gesture_events_.back(); |
| 900 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); |
| 901 EXPECT_FALSE(host_->fling_in_progress_); |
| 902 EXPECT_EQ(1U, host_->coalesced_gesture_events_.size()); |
| 903 |
| 904 // GFS in queue means that a GFC is added to the queue |
| 905 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
| 906 merged_event = host_->coalesced_gesture_events_.back(); |
| 907 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); |
| 908 EXPECT_FALSE(host_->fling_in_progress_); |
| 909 EXPECT_EQ(2U, host_->coalesced_gesture_events_.size()); |
| 910 |
| 911 |
| 912 // Adding a second GFC is dropped. |
| 913 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
| 914 EXPECT_FALSE(host_->fling_in_progress_); |
| 915 EXPECT_EQ(2U, host_->coalesced_gesture_events_.size()); |
| 916 |
| 917 // Adding another GFS will add it to the queue. |
| 918 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); |
| 919 merged_event = host_->coalesced_gesture_events_.back(); |
| 920 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); |
| 921 EXPECT_FALSE(host_->fling_in_progress_); |
| 922 EXPECT_EQ(3U, host_->coalesced_gesture_events_.size()); |
| 923 |
| 924 // GFS in queue means that a GFC is added to the queue |
| 925 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
| 926 merged_event = host_->coalesced_gesture_events_.back(); |
| 927 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); |
| 928 EXPECT_FALSE(host_->fling_in_progress_); |
| 929 EXPECT_EQ(4U, host_->coalesced_gesture_events_.size()); |
| 930 |
| 931 // Adding another GFC with a GFC already there is dropped. |
| 932 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
| 933 merged_event = host_->coalesced_gesture_events_.back(); |
| 934 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); |
| 935 EXPECT_FALSE(host_->fling_in_progress_); |
| 936 EXPECT_EQ(4U, host_->coalesced_gesture_events_.size()); |
| 937 } |
| 938 |
857 // Test that the hang monitor timer expires properly if a new timer is started | 939 // Test that the hang monitor timer expires properly if a new timer is started |
858 // while one is in progress (see crbug.com/11007). | 940 // while one is in progress (see crbug.com/11007). |
859 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) { | 941 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) { |
860 // Start with a short timeout. | 942 // Start with a short timeout. |
861 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 943 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
862 | 944 |
863 // Immediately try to add a long 30 second timeout. | 945 // Immediately try to add a long 30 second timeout. |
864 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 946 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
865 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30)); | 947 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30)); |
866 | 948 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1000 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
919 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1001 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
920 SendInputEventACK(WebInputEvent::RawKeyDown, true); | 1002 SendInputEventACK(WebInputEvent::RawKeyDown, true); |
921 | 1003 |
922 // Wait long enough for first timeout and see if it fired. | 1004 // Wait long enough for first timeout and see if it fired. |
923 MessageLoop::current()->PostDelayedTask( | 1005 MessageLoop::current()->PostDelayedTask( |
924 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); | 1006 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); |
925 MessageLoop::current()->Run(); | 1007 MessageLoop::current()->Run(); |
926 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1008 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
927 } | 1009 } |
OLD | NEW |