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" |
11 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 11 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 12 #include "content/browser/renderer_host/gesture_event_filter.h" |
12 #include "content/browser/renderer_host/test_render_view_host.h" | 13 #include "content/browser/renderer_host/test_render_view_host.h" |
13 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
14 #include "content/port/browser/render_widget_host_view_port.h" | 15 #include "content/port/browser/render_widget_host_view_port.h" |
15 #include "content/public/browser/notification_details.h" | 16 #include "content/public/browser/notification_details.h" |
16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
19 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
20 #include "content/public/test/mock_render_process_host.h" | 21 #include "content/public/test/mock_render_process_host.h" |
21 #include "content/public/test/test_browser_context.h" | 22 #include "content/public/test/test_browser_context.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "ui/base/keycodes/keyboard_codes.h" | 24 #include "ui/base/keycodes/keyboard_codes.h" |
24 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
25 | 26 |
26 #if defined(USE_AURA) | 27 #if defined(USE_AURA) |
27 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 28 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
28 #include "ui/aura/env.h" | 29 #include "ui/aura/env.h" |
29 #endif | 30 #endif |
30 | 31 |
31 using base::TimeDelta; | 32 using base::TimeDelta; |
32 using content::BackingStore; | 33 using content::BackingStore; |
33 using content::BrowserThread; | 34 using content::BrowserThread; |
34 using content::BrowserThreadImpl; | 35 using content::BrowserThreadImpl; |
| 36 using content::GestureEventFilter; |
35 using content::MockRenderProcessHost; | 37 using content::MockRenderProcessHost; |
36 using content::NativeWebKeyboardEvent; | 38 using content::NativeWebKeyboardEvent; |
37 using content::RenderWidgetHost; | 39 using content::RenderWidgetHost; |
38 using content::RenderWidgetHostImpl; | 40 using content::RenderWidgetHostImpl; |
39 using WebKit::WebGestureEvent; | 41 using WebKit::WebGestureEvent; |
40 using WebKit::WebInputEvent; | 42 using WebKit::WebInputEvent; |
41 using WebKit::WebMouseWheelEvent; | 43 using WebKit::WebMouseWheelEvent; |
42 | 44 |
43 namespace gfx { | 45 namespace gfx { |
44 class Size; | 46 class Size; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 unresponsive_timer_fired_(false) { | 218 unresponsive_timer_fired_(false) { |
217 } | 219 } |
218 | 220 |
219 // Allow poking at a few private members. | 221 // Allow poking at a few private members. |
220 using RenderWidgetHostImpl::OnMsgPaintAtSizeAck; | 222 using RenderWidgetHostImpl::OnMsgPaintAtSizeAck; |
221 using RenderWidgetHostImpl::OnMsgUpdateRect; | 223 using RenderWidgetHostImpl::OnMsgUpdateRect; |
222 using RenderWidgetHostImpl::RendererExited; | 224 using RenderWidgetHostImpl::RendererExited; |
223 using RenderWidgetHostImpl::in_flight_size_; | 225 using RenderWidgetHostImpl::in_flight_size_; |
224 using RenderWidgetHostImpl::is_hidden_; | 226 using RenderWidgetHostImpl::is_hidden_; |
225 using RenderWidgetHostImpl::resize_ack_pending_; | 227 using RenderWidgetHostImpl::resize_ack_pending_; |
226 using RenderWidgetHostImpl::coalesced_gesture_events_; | 228 using RenderWidgetHostImpl::gesture_event_filter_; |
227 using RenderWidgetHostImpl::fling_in_progress_; | |
228 | 229 |
229 bool unresponsive_timer_fired() const { | 230 bool unresponsive_timer_fired() const { |
230 return unresponsive_timer_fired_; | 231 return unresponsive_timer_fired_; |
231 } | 232 } |
232 | 233 |
233 void set_hung_renderer_delay_ms(int delay_ms) { | 234 void set_hung_renderer_delay_ms(int delay_ms) { |
234 hung_renderer_delay_ms_ = delay_ms; | 235 hung_renderer_delay_ms_ = delay_ms; |
235 } | 236 } |
236 | 237 |
| 238 WebGestureEvent GestureEventLastQueueEvent() { |
| 239 return gesture_event_filter_->coalesced_gesture_events_.back(); |
| 240 } |
| 241 |
| 242 unsigned GestureEventLastQueueEventSize() { |
| 243 return gesture_event_filter_->coalesced_gesture_events_.size(); |
| 244 } |
| 245 |
| 246 bool FlingInProgress() { |
| 247 return gesture_event_filter_->fling_in_progress_; |
| 248 } |
| 249 |
237 protected: | 250 protected: |
238 virtual void NotifyRendererUnresponsive() OVERRIDE { | 251 virtual void NotifyRendererUnresponsive() OVERRIDE { |
239 unresponsive_timer_fired_ = true; | 252 unresponsive_timer_fired_ = true; |
240 } | 253 } |
241 | 254 |
242 private: | 255 private: |
243 bool unresponsive_timer_fired_; | 256 bool unresponsive_timer_fired_; |
244 }; | 257 }; |
245 | 258 |
246 // MockPaintingObserver -------------------------------------------------------- | 259 // MockPaintingObserver -------------------------------------------------------- |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 // Only GestureScrollUpdate events can be coalesced. | 801 // Only GestureScrollUpdate events can be coalesced. |
789 // Simulate gesture events. | 802 // Simulate gesture events. |
790 | 803 |
791 // Sent. | 804 // Sent. |
792 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureScrollBegin); | 805 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureScrollBegin); |
793 | 806 |
794 // Enqueued. | 807 // Enqueued. |
795 SimulateGestureEvent(8, -5, 0, WebInputEvent::GestureScrollUpdate); | 808 SimulateGestureEvent(8, -5, 0, WebInputEvent::GestureScrollUpdate); |
796 | 809 |
797 // Make sure that the queue contains what we think it should. | 810 // Make sure that the queue contains what we think it should. |
798 WebGestureEvent merged_event = host_->coalesced_gesture_events_.back(); | 811 WebGestureEvent merged_event = host_->GestureEventLastQueueEvent(); |
799 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type); | 812 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type); |
800 | 813 |
801 // Coalesced. | 814 // Coalesced. |
802 SimulateGestureEvent(8, -6, 0, WebInputEvent::GestureScrollUpdate); | 815 SimulateGestureEvent(8, -6, 0, WebInputEvent::GestureScrollUpdate); |
803 | 816 |
804 // Check that coalescing updated the correct values. | 817 // Check that coalescing updated the correct values. |
805 merged_event = host_->coalesced_gesture_events_.back(); | 818 merged_event = host_->GestureEventLastQueueEvent(); |
806 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type); | 819 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type); |
807 EXPECT_EQ(0, merged_event.modifiers); | 820 EXPECT_EQ(0, merged_event.modifiers); |
808 EXPECT_EQ(16, merged_event.deltaX); | 821 EXPECT_EQ(16, merged_event.deltaX); |
809 EXPECT_EQ(-11, merged_event.deltaY); | 822 EXPECT_EQ(-11, merged_event.deltaY); |
810 | 823 |
811 // Enqueued. | 824 // Enqueued. |
812 SimulateGestureEvent(8, -7, 1, WebInputEvent::GestureScrollUpdate); | 825 SimulateGestureEvent(8, -7, 1, WebInputEvent::GestureScrollUpdate); |
813 | 826 |
814 // Check that we didn't wrongly coalesce. | 827 // Check that we didn't wrongly coalesce. |
815 merged_event = host_->coalesced_gesture_events_.back(); | 828 merged_event = host_->GestureEventLastQueueEvent(); |
816 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type); | 829 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, merged_event.type); |
817 EXPECT_EQ(1, merged_event.modifiers); | 830 EXPECT_EQ(1, merged_event.modifiers); |
818 | 831 |
819 // Different. | 832 // Different. |
820 SimulateGestureEvent(9, -8, 0, WebInputEvent::GestureScrollEnd); | 833 SimulateGestureEvent(9, -8, 0, WebInputEvent::GestureScrollEnd); |
821 | 834 |
822 // Check that only the first event was sent. | 835 // Check that only the first event was sent. |
823 EXPECT_EQ(1U, process_->sink().message_count()); | 836 EXPECT_EQ(1U, process_->sink().message_count()); |
824 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 837 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
825 ViewMsg_HandleInputEvent::ID)); | 838 ViewMsg_HandleInputEvent::ID)); |
(...skipping 27 matching lines...) Expand all Loading... |
853 SendInputEventACK(WebInputEvent::GestureScrollEnd, true); | 866 SendInputEventACK(WebInputEvent::GestureScrollEnd, true); |
854 MessageLoop::current()->RunAllPending(); | 867 MessageLoop::current()->RunAllPending(); |
855 EXPECT_EQ(0U, process_->sink().message_count()); | 868 EXPECT_EQ(0U, process_->sink().message_count()); |
856 } | 869 } |
857 | 870 |
858 TEST_F(RenderWidgetHostTest, GestureFlingCancelsFiltered) { | 871 TEST_F(RenderWidgetHostTest, GestureFlingCancelsFiltered) { |
859 process_->sink().ClearMessages(); | 872 process_->sink().ClearMessages(); |
860 // GFC without previous GFS is dropped. | 873 // GFC without previous GFS is dropped. |
861 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); | 874 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
862 EXPECT_EQ(0U, process_->sink().message_count()); | 875 EXPECT_EQ(0U, process_->sink().message_count()); |
863 EXPECT_EQ(0U, host_->coalesced_gesture_events_.size()); | 876 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); |
864 | 877 |
865 // GFC after previous GFS is dispatched and acked. | 878 // GFC after previous GFS is dispatched and acked. |
866 process_->sink().ClearMessages(); | 879 process_->sink().ClearMessages(); |
867 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); | 880 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); |
868 EXPECT_TRUE(host_->fling_in_progress_); | 881 EXPECT_TRUE(host_->FlingInProgress()); |
869 SendInputEventACK(WebInputEvent::GestureFlingStart, true); | 882 SendInputEventACK(WebInputEvent::GestureFlingStart, true); |
870 MessageLoop::current()->RunAllPending(); | 883 MessageLoop::current()->RunAllPending(); |
871 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); | 884 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
872 EXPECT_FALSE(host_->fling_in_progress_); | 885 EXPECT_FALSE(host_->FlingInProgress()); |
873 EXPECT_EQ(2U, process_->sink().message_count()); | 886 EXPECT_EQ(2U, process_->sink().message_count()); |
874 SendInputEventACK(WebInputEvent::GestureFlingCancel, true); | 887 SendInputEventACK(WebInputEvent::GestureFlingCancel, true); |
875 MessageLoop::current()->RunAllPending(); | 888 MessageLoop::current()->RunAllPending(); |
876 EXPECT_EQ(0U, host_->coalesced_gesture_events_.size()); | 889 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); |
877 | 890 |
878 // GFC before previous GFS is acked. | 891 // GFC before previous GFS is acked. |
879 process_->sink().ClearMessages(); | 892 process_->sink().ClearMessages(); |
880 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); | 893 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); |
881 EXPECT_TRUE(host_->fling_in_progress_); | 894 EXPECT_TRUE(host_->FlingInProgress()); |
882 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); | 895 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
883 EXPECT_FALSE(host_->fling_in_progress_); | 896 EXPECT_FALSE(host_->FlingInProgress()); |
884 EXPECT_EQ(1U, process_->sink().message_count()); | 897 EXPECT_EQ(1U, process_->sink().message_count()); |
885 EXPECT_FALSE(host_->coalesced_gesture_events_.empty()); | 898 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize()); |
886 | 899 |
887 // Advance state realistically. | 900 // Advance state realistically. |
888 SendInputEventACK(WebInputEvent::GestureFlingStart, true); | 901 SendInputEventACK(WebInputEvent::GestureFlingStart, true); |
889 MessageLoop::current()->RunAllPending(); | 902 MessageLoop::current()->RunAllPending(); |
890 SendInputEventACK(WebInputEvent::GestureFlingCancel, true); | 903 SendInputEventACK(WebInputEvent::GestureFlingCancel, true); |
891 MessageLoop::current()->RunAllPending(); | 904 MessageLoop::current()->RunAllPending(); |
892 EXPECT_EQ(0U, host_->coalesced_gesture_events_.size()); | 905 EXPECT_EQ(0U, host_->GestureEventLastQueueEventSize()); |
893 | 906 |
894 // GFS is added to the queue if another event is pending | 907 // GFS is added to the queue if another event is pending |
895 process_->sink().ClearMessages(); | 908 process_->sink().ClearMessages(); |
896 SimulateGestureEvent(8, -7, 0, WebInputEvent::GestureScrollUpdate); | 909 SimulateGestureEvent(8, -7, 0, WebInputEvent::GestureScrollUpdate); |
897 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); | 910 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); |
898 EXPECT_EQ(1U, process_->sink().message_count()); | 911 EXPECT_EQ(1U, process_->sink().message_count()); |
899 WebGestureEvent merged_event = host_->coalesced_gesture_events_.back(); | 912 WebGestureEvent merged_event = host_->GestureEventLastQueueEvent(); |
900 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); | 913 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); |
901 EXPECT_FALSE(host_->fling_in_progress_); | 914 EXPECT_FALSE(host_->FlingInProgress()); |
902 EXPECT_EQ(1U, host_->coalesced_gesture_events_.size()); | 915 EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize()); |
903 | 916 |
904 // GFS in queue means that a GFC is added to the queue | 917 // GFS in queue means that a GFC is added to the queue |
905 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); | 918 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
906 merged_event = host_->coalesced_gesture_events_.back(); | 919 merged_event =host_->GestureEventLastQueueEvent(); |
907 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); | 920 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); |
908 EXPECT_FALSE(host_->fling_in_progress_); | 921 EXPECT_FALSE(host_->FlingInProgress()); |
909 EXPECT_EQ(2U, host_->coalesced_gesture_events_.size()); | 922 EXPECT_EQ(2U, host_->GestureEventLastQueueEventSize()); |
910 | 923 |
911 | 924 |
912 // Adding a second GFC is dropped. | 925 // Adding a second GFC is dropped. |
913 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); | 926 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
914 EXPECT_FALSE(host_->fling_in_progress_); | 927 EXPECT_FALSE(host_->FlingInProgress()); |
915 EXPECT_EQ(2U, host_->coalesced_gesture_events_.size()); | 928 EXPECT_EQ(2U, host_->GestureEventLastQueueEventSize()); |
916 | 929 |
917 // Adding another GFS will add it to the queue. | 930 // Adding another GFS will add it to the queue. |
918 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); | 931 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart); |
919 merged_event = host_->coalesced_gesture_events_.back(); | 932 merged_event = host_->GestureEventLastQueueEvent(); |
920 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); | 933 EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type); |
921 EXPECT_FALSE(host_->fling_in_progress_); | 934 EXPECT_FALSE(host_->FlingInProgress()); |
922 EXPECT_EQ(3U, host_->coalesced_gesture_events_.size()); | 935 EXPECT_EQ(3U, host_->GestureEventLastQueueEventSize()); |
923 | 936 |
924 // GFS in queue means that a GFC is added to the queue | 937 // GFS in queue means that a GFC is added to the queue |
925 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); | 938 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
926 merged_event = host_->coalesced_gesture_events_.back(); | 939 merged_event = host_->GestureEventLastQueueEvent(); |
927 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); | 940 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); |
928 EXPECT_FALSE(host_->fling_in_progress_); | 941 EXPECT_FALSE(host_->FlingInProgress()); |
929 EXPECT_EQ(4U, host_->coalesced_gesture_events_.size()); | 942 EXPECT_EQ(4U, host_->GestureEventLastQueueEventSize()); |
930 | 943 |
931 // Adding another GFC with a GFC already there is dropped. | 944 // Adding another GFC with a GFC already there is dropped. |
932 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); | 945 SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel); |
933 merged_event = host_->coalesced_gesture_events_.back(); | 946 merged_event = host_->GestureEventLastQueueEvent(); |
934 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); | 947 EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type); |
935 EXPECT_FALSE(host_->fling_in_progress_); | 948 EXPECT_FALSE(host_->FlingInProgress()); |
936 EXPECT_EQ(4U, host_->coalesced_gesture_events_.size()); | 949 EXPECT_EQ(4U, host_->GestureEventLastQueueEventSize()); |
937 } | 950 } |
938 | 951 |
939 // Test that the hang monitor timer expires properly if a new timer is started | 952 // Test that the hang monitor timer expires properly if a new timer is started |
940 // while one is in progress (see crbug.com/11007). | 953 // while one is in progress (see crbug.com/11007). |
941 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) { | 954 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) { |
942 // Start with a short timeout. | 955 // Start with a short timeout. |
943 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 956 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
944 | 957 |
945 // Immediately try to add a long 30 second timeout. | 958 // Immediately try to add a long 30 second timeout. |
946 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 959 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1013 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
1001 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1014 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
1002 SendInputEventACK(WebInputEvent::RawKeyDown, true); | 1015 SendInputEventACK(WebInputEvent::RawKeyDown, true); |
1003 | 1016 |
1004 // Wait long enough for first timeout and see if it fired. | 1017 // Wait long enough for first timeout and see if it fired. |
1005 MessageLoop::current()->PostDelayedTask( | 1018 MessageLoop::current()->PostDelayedTask( |
1006 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); | 1019 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); |
1007 MessageLoop::current()->Run(); | 1020 MessageLoop::current()->Run(); |
1008 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1021 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
1009 } | 1022 } |
OLD | NEW |