| 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/location.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) { | 991 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) { |
| 992 // Start with a short timeout. | 992 // Start with a short timeout. |
| 993 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 993 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 994 | 994 |
| 995 // Immediately try to add a long 30 second timeout. | 995 // Immediately try to add a long 30 second timeout. |
| 996 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 996 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 997 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30)); | 997 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30)); |
| 998 | 998 |
| 999 // Wait long enough for first timeout and see if it fired. | 999 // Wait long enough for first timeout and see if it fired. |
| 1000 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1000 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1001 FROM_HERE, base::MessageLoop::QuitClosure(), | 1001 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1002 TimeDelta::FromMilliseconds(10)); | 1002 TimeDelta::FromMilliseconds(10)); |
| 1003 base::MessageLoop::current()->Run(); | 1003 base::MessageLoop::current()->Run(); |
| 1004 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1004 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 // Test that the hang monitor timer expires properly if it is started, stopped, | 1007 // Test that the hang monitor timer expires properly if it is started, stopped, |
| 1008 // and then started again. | 1008 // and then started again. |
| 1009 TEST_F(RenderWidgetHostTest, StopAndStartHangMonitorTimeout) { | 1009 TEST_F(RenderWidgetHostTest, StopAndStartHangMonitorTimeout) { |
| 1010 // Start with a short timeout, then stop it. | 1010 // Start with a short timeout, then stop it. |
| 1011 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 1011 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 1012 host_->StopHangMonitorTimeout(); | 1012 host_->StopHangMonitorTimeout(); |
| 1013 | 1013 |
| 1014 // Start it again to ensure it still works. | 1014 // Start it again to ensure it still works. |
| 1015 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1015 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 1016 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 1016 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
| 1017 | 1017 |
| 1018 // Wait long enough for first timeout and see if it fired. | 1018 // Wait long enough for first timeout and see if it fired. |
| 1019 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1019 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1020 FROM_HERE, base::MessageLoop::QuitClosure(), | 1020 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1021 TimeDelta::FromMilliseconds(40)); | 1021 TimeDelta::FromMilliseconds(40)); |
| 1022 base::MessageLoop::current()->Run(); | 1022 base::MessageLoop::current()->Run(); |
| 1023 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1023 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 // Test that the hang monitor timer expires properly if it is started, then | 1026 // Test that the hang monitor timer expires properly if it is started, then |
| 1027 // updated to a shorter duration. | 1027 // updated to a shorter duration. |
| 1028 TEST_F(RenderWidgetHostTest, ShorterDelayHangMonitorTimeout) { | 1028 TEST_F(RenderWidgetHostTest, ShorterDelayHangMonitorTimeout) { |
| 1029 // Start with a timeout. | 1029 // Start with a timeout. |
| 1030 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(100)); | 1030 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(100)); |
| 1031 | 1031 |
| 1032 // Start it again with shorter delay. | 1032 // Start it again with shorter delay. |
| 1033 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1033 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 1034 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(20)); | 1034 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(20)); |
| 1035 | 1035 |
| 1036 // Wait long enough for the second timeout and see if it fired. | 1036 // Wait long enough for the second timeout and see if it fired. |
| 1037 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1037 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1038 FROM_HERE, base::MessageLoop::QuitClosure(), | 1038 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1039 TimeDelta::FromMilliseconds(25)); | 1039 TimeDelta::FromMilliseconds(25)); |
| 1040 base::MessageLoop::current()->Run(); | 1040 base::MessageLoop::current()->Run(); |
| 1041 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1041 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1042 } | 1042 } |
| 1043 | 1043 |
| 1044 // Test that the hang monitor timer is effectively disabled when the widget is | 1044 // Test that the hang monitor timer is effectively disabled when the widget is |
| 1045 // hidden. | 1045 // hidden. |
| 1046 TEST_F(RenderWidgetHostTest, HangMonitorTimeoutDisabledForInputWhenHidden) { | 1046 TEST_F(RenderWidgetHostTest, HangMonitorTimeoutDisabledForInputWhenHidden) { |
| 1047 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(1)); | 1047 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(1)); |
| 1048 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); | 1048 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); |
| 1049 | 1049 |
| 1050 // Hiding the widget should deactivate the timeout. | 1050 // Hiding the widget should deactivate the timeout. |
| 1051 host_->WasHidden(); | 1051 host_->WasHidden(); |
| 1052 | 1052 |
| 1053 // The timeout should not fire. | 1053 // The timeout should not fire. |
| 1054 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1054 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 1055 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1055 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1056 FROM_HERE, base::MessageLoop::QuitClosure(), | 1056 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1057 TimeDelta::FromMicroseconds(2)); | 1057 TimeDelta::FromMicroseconds(2)); |
| 1058 base::MessageLoop::current()->Run(); | 1058 base::MessageLoop::current()->Run(); |
| 1059 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1059 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 1060 | 1060 |
| 1061 // The timeout should never reactivate while hidden. | 1061 // The timeout should never reactivate while hidden. |
| 1062 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); | 1062 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); |
| 1063 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1063 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1064 FROM_HERE, base::MessageLoop::QuitClosure(), | 1064 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1065 TimeDelta::FromMicroseconds(2)); | 1065 TimeDelta::FromMicroseconds(2)); |
| 1066 base::MessageLoop::current()->Run(); | 1066 base::MessageLoop::current()->Run(); |
| 1067 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 1067 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
| 1068 | 1068 |
| 1069 // Showing the widget should restore the timeout, as the events have | 1069 // Showing the widget should restore the timeout, as the events have |
| 1070 // not yet been ack'ed. | 1070 // not yet been ack'ed. |
| 1071 host_->WasShown(ui::LatencyInfo()); | 1071 host_->WasShown(ui::LatencyInfo()); |
| 1072 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1072 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1073 FROM_HERE, base::MessageLoop::QuitClosure(), | 1073 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1074 TimeDelta::FromMicroseconds(2)); | 1074 TimeDelta::FromMicroseconds(2)); |
| 1075 base::MessageLoop::current()->Run(); | 1075 base::MessageLoop::current()->Run(); |
| 1076 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1076 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1077 } | 1077 } |
| 1078 | 1078 |
| 1079 // Test that the hang monitor catches two input events but only one ack. | 1079 // Test that the hang monitor catches two input events but only one ack. |
| 1080 // This can happen if the second input event causes the renderer to hang. | 1080 // This can happen if the second input event causes the renderer to hang. |
| 1081 // This test will catch a regression of crbug.com/111185. | 1081 // This test will catch a regression of crbug.com/111185. |
| 1082 TEST_F(RenderWidgetHostTest, MultipleInputEvents) { | 1082 TEST_F(RenderWidgetHostTest, MultipleInputEvents) { |
| 1083 // Configure the host to wait 10ms before considering | 1083 // Configure the host to wait 10ms before considering |
| 1084 // the renderer hung. | 1084 // the renderer hung. |
| 1085 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(10)); | 1085 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(10)); |
| 1086 | 1086 |
| 1087 // Send two events but only one ack. | 1087 // Send two events but only one ack. |
| 1088 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1088 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 1089 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1089 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 1090 SendInputEventACK(WebInputEvent::RawKeyDown, | 1090 SendInputEventACK(WebInputEvent::RawKeyDown, |
| 1091 INPUT_EVENT_ACK_STATE_CONSUMED); | 1091 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1092 | 1092 |
| 1093 // Wait long enough for first timeout and see if it fired. | 1093 // Wait long enough for first timeout and see if it fired. |
| 1094 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1094 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1095 FROM_HERE, base::MessageLoop::QuitClosure(), | 1095 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1096 TimeDelta::FromMicroseconds(20)); | 1096 TimeDelta::FromMicroseconds(20)); |
| 1097 base::MessageLoop::current()->Run(); | 1097 base::MessageLoop::current()->Run(); |
| 1098 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1098 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1099 } | 1099 } |
| 1100 | 1100 |
| 1101 // Test that the rendering timeout for newly loaded content fires | 1101 // Test that the rendering timeout for newly loaded content fires |
| 1102 // when enough time passes without receiving a new compositor frame. | 1102 // when enough time passes without receiving a new compositor frame. |
| 1103 TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { | 1103 TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { |
| 1104 host_->set_new_content_rendering_delay_for_testing( | 1104 host_->set_new_content_rendering_delay_for_testing( |
| 1105 base::TimeDelta::FromMicroseconds(10)); | 1105 base::TimeDelta::FromMicroseconds(10)); |
| 1106 | 1106 |
| 1107 // Test immediate start and stop, ensuring that the timeout doesn't fire. | 1107 // Test immediate start and stop, ensuring that the timeout doesn't fire. |
| 1108 host_->StartNewContentRenderingTimeout(); | 1108 host_->StartNewContentRenderingTimeout(); |
| 1109 host_->OnFirstPaintAfterLoad(); | 1109 host_->OnFirstPaintAfterLoad(); |
| 1110 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1110 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1111 FROM_HERE, base::MessageLoop::QuitClosure(), | 1111 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1112 TimeDelta::FromMicroseconds(20)); | 1112 TimeDelta::FromMicroseconds(20)); |
| 1113 base::MessageLoop::current()->Run(); | 1113 base::MessageLoop::current()->Run(); |
| 1114 | 1114 |
| 1115 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); | 1115 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); |
| 1116 | 1116 |
| 1117 // Test that the timer doesn't fire if it receives a stop before | 1117 // Test that the timer doesn't fire if it receives a stop before |
| 1118 // a start. | 1118 // a start. |
| 1119 host_->OnFirstPaintAfterLoad(); | 1119 host_->OnFirstPaintAfterLoad(); |
| 1120 host_->StartNewContentRenderingTimeout(); | 1120 host_->StartNewContentRenderingTimeout(); |
| 1121 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1121 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1122 FROM_HERE, base::MessageLoop::QuitClosure(), | 1122 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1123 TimeDelta::FromMicroseconds(20)); | 1123 TimeDelta::FromMicroseconds(20)); |
| 1124 base::MessageLoop::current()->Run(); | 1124 base::MessageLoop::current()->Run(); |
| 1125 | 1125 |
| 1126 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); | 1126 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); |
| 1127 | 1127 |
| 1128 // Test with a long delay to ensure that it does fire this time. | 1128 // Test with a long delay to ensure that it does fire this time. |
| 1129 host_->StartNewContentRenderingTimeout(); | 1129 host_->StartNewContentRenderingTimeout(); |
| 1130 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1130 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1131 FROM_HERE, base::MessageLoop::QuitClosure(), | 1131 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1132 TimeDelta::FromMicroseconds(20)); | 1132 TimeDelta::FromMicroseconds(20)); |
| 1133 base::MessageLoop::current()->Run(); | 1133 base::MessageLoop::current()->Run(); |
| 1134 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); | 1134 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) { | 1137 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) { |
| 1138 std::string result; | 1138 std::string result; |
| 1139 for (size_t i = 0; i < process->sink().message_count(); ++i) { | 1139 for (size_t i = 0; i < process->sink().message_count(); ++i) { |
| 1140 const IPC::Message *message = process->sink().GetMessageAt(i); | 1140 const IPC::Message *message = process->sink().GetMessageAt(i); |
| 1141 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); | 1141 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 // Having an initial size set means that the size information had been sent | 1590 // Having an initial size set means that the size information had been sent |
| 1591 // with the reqiest to new up the RenderView and so subsequent WasResized | 1591 // with the reqiest to new up the RenderView and so subsequent WasResized |
| 1592 // calls should not result in new IPC (unless the size has actually changed). | 1592 // calls should not result in new IPC (unless the size has actually changed). |
| 1593 host_->WasResized(); | 1593 host_->WasResized(); |
| 1594 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 1594 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 1595 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); | 1595 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); |
| 1596 EXPECT_TRUE(host_->resize_ack_pending_); | 1596 EXPECT_TRUE(host_->resize_ack_pending_); |
| 1597 } | 1597 } |
| 1598 | 1598 |
| 1599 } // namespace content | 1599 } // namespace content |
| OLD | NEW |