| 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/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/location.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" |
| 10 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 11 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
| 12 #include "content/browser/gpu/compositor_util.h" | 15 #include "content/browser/gpu/compositor_util.h" |
| 13 #include "content/browser/renderer_host/input/input_router_impl.h" | 16 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 14 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 17 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 15 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 18 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 16 #include "content/common/input/synthetic_web_input_event_builders.h" | 19 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 17 #include "content/common/input_messages.h" | 20 #include "content/common/input_messages.h" |
| 18 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
| 19 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| (...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 // while one is in progress (see crbug.com/11007). | 975 // while one is in progress (see crbug.com/11007). |
| 973 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) { | 976 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) { |
| 974 // Start with a short timeout. | 977 // Start with a short timeout. |
| 975 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 978 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 976 | 979 |
| 977 // Immediately try to add a long 30 second timeout. | 980 // Immediately try to add a long 30 second timeout. |
| 978 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 981 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 979 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30)); | 982 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30)); |
| 980 | 983 |
| 981 // Wait long enough for first timeout and see if it fired. | 984 // Wait long enough for first timeout and see if it fired. |
| 982 base::MessageLoop::current()->PostDelayedTask( | 985 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 983 FROM_HERE, | 986 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 984 base::MessageLoop::QuitClosure(), | |
| 985 TimeDelta::FromMilliseconds(10)); | 987 TimeDelta::FromMilliseconds(10)); |
| 986 base::MessageLoop::current()->Run(); | 988 base::MessageLoop::current()->Run(); |
| 987 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 989 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 988 } | 990 } |
| 989 | 991 |
| 990 // Test that the hang monitor timer expires properly if it is started, stopped, | 992 // Test that the hang monitor timer expires properly if it is started, stopped, |
| 991 // and then started again. | 993 // and then started again. |
| 992 TEST_F(RenderWidgetHostTest, StopAndStartHangMonitorTimeout) { | 994 TEST_F(RenderWidgetHostTest, StopAndStartHangMonitorTimeout) { |
| 993 // Start with a short timeout, then stop it. | 995 // Start with a short timeout, then stop it. |
| 994 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 996 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 995 host_->StopHangMonitorTimeout(); | 997 host_->StopHangMonitorTimeout(); |
| 996 | 998 |
| 997 // Start it again to ensure it still works. | 999 // Start it again to ensure it still works. |
| 998 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1000 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 999 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 1001 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 1000 | 1002 |
| 1001 // Wait long enough for first timeout and see if it fired. | 1003 // Wait long enough for first timeout and see if it fired. |
| 1002 base::MessageLoop::current()->PostDelayedTask( | 1004 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1003 FROM_HERE, | 1005 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 1004 base::MessageLoop::QuitClosure(), | |
| 1005 TimeDelta::FromMilliseconds(40)); | 1006 TimeDelta::FromMilliseconds(40)); |
| 1006 base::MessageLoop::current()->Run(); | 1007 base::MessageLoop::current()->Run(); |
| 1007 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1008 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1008 } | 1009 } |
| 1009 | 1010 |
| 1010 // Test that the hang monitor timer expires properly if it is started, then | 1011 // Test that the hang monitor timer expires properly if it is started, then |
| 1011 // updated to a shorter duration. | 1012 // updated to a shorter duration. |
| 1012 TEST_F(RenderWidgetHostTest, ShorterDelayHangMonitorTimeout) { | 1013 TEST_F(RenderWidgetHostTest, ShorterDelayHangMonitorTimeout) { |
| 1013 // Start with a timeout. | 1014 // Start with a timeout. |
| 1014 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(100)); | 1015 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(100)); |
| 1015 | 1016 |
| 1016 // Start it again with shorter delay. | 1017 // Start it again with shorter delay. |
| 1017 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1018 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 1018 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(20)); | 1019 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(20)); |
| 1019 | 1020 |
| 1020 // Wait long enough for the second timeout and see if it fired. | 1021 // Wait long enough for the second timeout and see if it fired. |
| 1021 base::MessageLoop::current()->PostDelayedTask( | 1022 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1022 FROM_HERE, | 1023 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 1023 base::MessageLoop::QuitClosure(), | |
| 1024 TimeDelta::FromMilliseconds(25)); | 1024 TimeDelta::FromMilliseconds(25)); |
| 1025 base::MessageLoop::current()->Run(); | 1025 base::MessageLoop::current()->Run(); |
| 1026 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1026 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 // Test that the hang monitor timer is effectively disabled when the widget is | 1029 // Test that the hang monitor timer is effectively disabled when the widget is |
| 1030 // hidden. | 1030 // hidden. |
| 1031 TEST_F(RenderWidgetHostTest, HangMonitorTimeoutDisabledForInputWhenHidden) { | 1031 TEST_F(RenderWidgetHostTest, HangMonitorTimeoutDisabledForInputWhenHidden) { |
| 1032 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(1)); | 1032 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(1)); |
| 1033 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); | 1033 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); |
| 1034 | 1034 |
| 1035 // Hiding the widget should deactivate the timeout. | 1035 // Hiding the widget should deactivate the timeout. |
| 1036 host_->WasHidden(); | 1036 host_->WasHidden(); |
| 1037 | 1037 |
| 1038 // The timeout should not fire. | 1038 // The timeout should not fire. |
| 1039 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1039 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 1040 base::MessageLoop::current()->PostDelayedTask( | 1040 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1041 FROM_HERE, | 1041 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 1042 base::MessageLoop::QuitClosure(), | |
| 1043 TimeDelta::FromMicroseconds(2)); | 1042 TimeDelta::FromMicroseconds(2)); |
| 1044 base::MessageLoop::current()->Run(); | 1043 base::MessageLoop::current()->Run(); |
| 1045 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1044 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 1046 | 1045 |
| 1047 // The timeout should never reactivate while hidden. | 1046 // The timeout should never reactivate while hidden. |
| 1048 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); | 1047 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); |
| 1049 base::MessageLoop::current()->PostDelayedTask( | 1048 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1050 FROM_HERE, | 1049 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 1051 base::MessageLoop::QuitClosure(), | |
| 1052 TimeDelta::FromMicroseconds(2)); | 1050 TimeDelta::FromMicroseconds(2)); |
| 1053 base::MessageLoop::current()->Run(); | 1051 base::MessageLoop::current()->Run(); |
| 1054 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1052 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 1055 | 1053 |
| 1056 // Showing the widget should restore the timeout, as the events have | 1054 // Showing the widget should restore the timeout, as the events have |
| 1057 // not yet been ack'ed. | 1055 // not yet been ack'ed. |
| 1058 host_->WasShown(ui::LatencyInfo()); | 1056 host_->WasShown(ui::LatencyInfo()); |
| 1059 base::MessageLoop::current()->PostDelayedTask( | 1057 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1060 FROM_HERE, | 1058 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 1061 base::MessageLoop::QuitClosure(), | |
| 1062 TimeDelta::FromMicroseconds(2)); | 1059 TimeDelta::FromMicroseconds(2)); |
| 1063 base::MessageLoop::current()->Run(); | 1060 base::MessageLoop::current()->Run(); |
| 1064 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1061 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1065 } | 1062 } |
| 1066 | 1063 |
| 1067 // Test that the hang monitor catches two input events but only one ack. | 1064 // Test that the hang monitor catches two input events but only one ack. |
| 1068 // This can happen if the second input event causes the renderer to hang. | 1065 // This can happen if the second input event causes the renderer to hang. |
| 1069 // This test will catch a regression of crbug.com/111185. | 1066 // This test will catch a regression of crbug.com/111185. |
| 1070 TEST_F(RenderWidgetHostTest, MultipleInputEvents) { | 1067 TEST_F(RenderWidgetHostTest, MultipleInputEvents) { |
| 1071 // Configure the host to wait 10ms before considering | 1068 // Configure the host to wait 10ms before considering |
| 1072 // the renderer hung. | 1069 // the renderer hung. |
| 1073 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(10)); | 1070 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(10)); |
| 1074 | 1071 |
| 1075 // Send two events but only one ack. | 1072 // Send two events but only one ack. |
| 1076 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1073 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 1077 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1074 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 1078 SendInputEventACK(WebInputEvent::RawKeyDown, | 1075 SendInputEventACK(WebInputEvent::RawKeyDown, |
| 1079 INPUT_EVENT_ACK_STATE_CONSUMED); | 1076 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1080 | 1077 |
| 1081 // Wait long enough for first timeout and see if it fired. | 1078 // Wait long enough for first timeout and see if it fired. |
| 1082 base::MessageLoop::current()->PostDelayedTask( | 1079 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1083 FROM_HERE, | 1080 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 1084 base::MessageLoop::QuitClosure(), | |
| 1085 TimeDelta::FromMicroseconds(20)); | 1081 TimeDelta::FromMicroseconds(20)); |
| 1086 base::MessageLoop::current()->Run(); | 1082 base::MessageLoop::current()->Run(); |
| 1087 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1083 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1088 } | 1084 } |
| 1089 | 1085 |
| 1090 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) { | 1086 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) { |
| 1091 std::string result; | 1087 std::string result; |
| 1092 for (size_t i = 0; i < process->sink().message_count(); ++i) { | 1088 for (size_t i = 0; i < process->sink().message_count(); ++i) { |
| 1093 const IPC::Message *message = process->sink().GetMessageAt(i); | 1089 const IPC::Message *message = process->sink().GetMessageAt(i); |
| 1094 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); | 1090 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 // Having an initial size set means that the size information had been sent | 1539 // Having an initial size set means that the size information had been sent |
| 1544 // with the reqiest to new up the RenderView and so subsequent WasResized | 1540 // with the reqiest to new up the RenderView and so subsequent WasResized |
| 1545 // calls should not result in new IPC (unless the size has actually changed). | 1541 // calls should not result in new IPC (unless the size has actually changed). |
| 1546 host_->WasResized(); | 1542 host_->WasResized(); |
| 1547 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 1543 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 1548 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); | 1544 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); |
| 1549 EXPECT_TRUE(host_->resize_ack_pending_); | 1545 EXPECT_TRUE(host_->resize_ack_pending_); |
| 1550 } | 1546 } |
| 1551 | 1547 |
| 1552 } // namespace content | 1548 } // namespace content |
| OLD | NEW |