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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <tuple> | 9 #include <tuple> |
10 | 10 |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 1073 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
1074 | 1074 |
1075 // Immediately try to add a long 30 second timeout. | 1075 // Immediately try to add a long 30 second timeout. |
1076 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); | 1076 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); |
1077 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30)); | 1077 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30)); |
1078 | 1078 |
1079 // Wait long enough for first timeout and see if it fired. | 1079 // Wait long enough for first timeout and see if it fired. |
1080 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1080 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1081 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1081 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1082 TimeDelta::FromMilliseconds(10)); | 1082 TimeDelta::FromMilliseconds(10)); |
1083 base::MessageLoop::current()->Run(); | 1083 base::RunLoop().Run(); |
1084 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); | 1084 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); |
1085 } | 1085 } |
1086 | 1086 |
1087 // Test that the hang monitor timer expires properly if it is started, stopped, | 1087 // Test that the hang monitor timer expires properly if it is started, stopped, |
1088 // and then started again. | 1088 // and then started again. |
1089 TEST_F(RenderWidgetHostTest, StopAndStartHangMonitorTimeout) { | 1089 TEST_F(RenderWidgetHostTest, StopAndStartHangMonitorTimeout) { |
1090 // Start with a short timeout, then stop it. | 1090 // Start with a short timeout, then stop it. |
1091 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 1091 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
1092 host_->StopHangMonitorTimeout(); | 1092 host_->StopHangMonitorTimeout(); |
1093 | 1093 |
1094 // Start it again to ensure it still works. | 1094 // Start it again to ensure it still works. |
1095 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); | 1095 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); |
1096 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 1096 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
1097 | 1097 |
1098 // Wait long enough for first timeout and see if it fired. | 1098 // Wait long enough for first timeout and see if it fired. |
1099 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1099 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1100 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1100 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1101 TimeDelta::FromMilliseconds(40)); | 1101 TimeDelta::FromMilliseconds(40)); |
1102 base::MessageLoop::current()->Run(); | 1102 base::RunLoop().Run(); |
1103 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); | 1103 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); |
1104 } | 1104 } |
1105 | 1105 |
1106 // Test that the hang monitor timer expires properly if it is started, then | 1106 // Test that the hang monitor timer expires properly if it is started, then |
1107 // updated to a shorter duration. | 1107 // updated to a shorter duration. |
1108 TEST_F(RenderWidgetHostTest, ShorterDelayHangMonitorTimeout) { | 1108 TEST_F(RenderWidgetHostTest, ShorterDelayHangMonitorTimeout) { |
1109 // Start with a timeout. | 1109 // Start with a timeout. |
1110 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(100)); | 1110 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(100)); |
1111 | 1111 |
1112 // Start it again with shorter delay. | 1112 // Start it again with shorter delay. |
1113 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); | 1113 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); |
1114 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(20)); | 1114 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(20)); |
1115 | 1115 |
1116 // Wait long enough for the second timeout and see if it fired. | 1116 // Wait long enough for the second timeout and see if it fired. |
1117 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1117 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1118 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1118 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1119 TimeDelta::FromMilliseconds(25)); | 1119 TimeDelta::FromMilliseconds(25)); |
1120 base::MessageLoop::current()->Run(); | 1120 base::RunLoop().Run(); |
1121 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); | 1121 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); |
1122 } | 1122 } |
1123 | 1123 |
1124 // Test that the hang monitor timer is effectively disabled when the widget is | 1124 // Test that the hang monitor timer is effectively disabled when the widget is |
1125 // hidden. | 1125 // hidden. |
1126 TEST_F(RenderWidgetHostTest, HangMonitorTimeoutDisabledForInputWhenHidden) { | 1126 TEST_F(RenderWidgetHostTest, HangMonitorTimeoutDisabledForInputWhenHidden) { |
1127 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(1)); | 1127 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(1)); |
1128 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); | 1128 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); |
1129 | 1129 |
1130 // Hiding the widget should deactivate the timeout. | 1130 // Hiding the widget should deactivate the timeout. |
1131 host_->WasHidden(); | 1131 host_->WasHidden(); |
1132 | 1132 |
1133 // The timeout should not fire. | 1133 // The timeout should not fire. |
1134 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); | 1134 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); |
1135 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1135 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1136 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1136 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1137 TimeDelta::FromMicroseconds(2)); | 1137 TimeDelta::FromMicroseconds(2)); |
1138 base::MessageLoop::current()->Run(); | 1138 base::RunLoop().Run(); |
1139 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); | 1139 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); |
1140 | 1140 |
1141 // The timeout should never reactivate while hidden. | 1141 // The timeout should never reactivate while hidden. |
1142 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); | 1142 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); |
1143 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1143 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1144 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1144 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1145 TimeDelta::FromMicroseconds(2)); | 1145 TimeDelta::FromMicroseconds(2)); |
1146 base::MessageLoop::current()->Run(); | 1146 base::RunLoop().Run(); |
1147 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); | 1147 EXPECT_FALSE(delegate_->unresponsive_timer_fired()); |
1148 | 1148 |
1149 // Showing the widget should restore the timeout, as the events have | 1149 // Showing the widget should restore the timeout, as the events have |
1150 // not yet been ack'ed. | 1150 // not yet been ack'ed. |
1151 host_->WasShown(ui::LatencyInfo()); | 1151 host_->WasShown(ui::LatencyInfo()); |
1152 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1152 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1153 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1153 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1154 TimeDelta::FromMicroseconds(2)); | 1154 TimeDelta::FromMicroseconds(2)); |
1155 base::MessageLoop::current()->Run(); | 1155 base::RunLoop().Run(); |
1156 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); | 1156 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); |
1157 } | 1157 } |
1158 | 1158 |
1159 // Test that the hang monitor catches two input events but only one ack. | 1159 // Test that the hang monitor catches two input events but only one ack. |
1160 // This can happen if the second input event causes the renderer to hang. | 1160 // This can happen if the second input event causes the renderer to hang. |
1161 // This test will catch a regression of crbug.com/111185. | 1161 // This test will catch a regression of crbug.com/111185. |
1162 TEST_F(RenderWidgetHostTest, MultipleInputEvents) { | 1162 TEST_F(RenderWidgetHostTest, MultipleInputEvents) { |
1163 // Configure the host to wait 10ms before considering | 1163 // Configure the host to wait 10ms before considering |
1164 // the renderer hung. | 1164 // the renderer hung. |
1165 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(10)); | 1165 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(10)); |
1166 | 1166 |
1167 // Send two events but only one ack. | 1167 // Send two events but only one ack. |
1168 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1168 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
1169 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1169 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
1170 SendInputEventACK(WebInputEvent::RawKeyDown, | 1170 SendInputEventACK(WebInputEvent::RawKeyDown, |
1171 INPUT_EVENT_ACK_STATE_CONSUMED); | 1171 INPUT_EVENT_ACK_STATE_CONSUMED); |
1172 | 1172 |
1173 // Wait long enough for first timeout and see if it fired. | 1173 // Wait long enough for first timeout and see if it fired. |
1174 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1174 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1175 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1175 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1176 TimeDelta::FromMicroseconds(20)); | 1176 TimeDelta::FromMicroseconds(20)); |
1177 base::MessageLoop::current()->Run(); | 1177 base::RunLoop().Run(); |
1178 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); | 1178 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); |
1179 } | 1179 } |
1180 | 1180 |
1181 // Test that the rendering timeout for newly loaded content fires | 1181 // Test that the rendering timeout for newly loaded content fires |
1182 // when enough time passes without receiving a new compositor frame. | 1182 // when enough time passes without receiving a new compositor frame. |
1183 TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { | 1183 TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { |
1184 host_->set_new_content_rendering_delay_for_testing( | 1184 host_->set_new_content_rendering_delay_for_testing( |
1185 base::TimeDelta::FromMicroseconds(10)); | 1185 base::TimeDelta::FromMicroseconds(10)); |
1186 | 1186 |
1187 // Test immediate start and stop, ensuring that the timeout doesn't fire. | 1187 // Test immediate start and stop, ensuring that the timeout doesn't fire. |
1188 host_->StartNewContentRenderingTimeout(); | 1188 host_->StartNewContentRenderingTimeout(); |
1189 host_->OnFirstPaintAfterLoad(); | 1189 host_->OnFirstPaintAfterLoad(); |
1190 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1190 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1191 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1191 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1192 TimeDelta::FromMicroseconds(20)); | 1192 TimeDelta::FromMicroseconds(20)); |
1193 base::MessageLoop::current()->Run(); | 1193 base::RunLoop().Run(); |
1194 | 1194 |
1195 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); | 1195 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); |
1196 | 1196 |
1197 // Test that the timer doesn't fire if it receives a stop before | 1197 // Test that the timer doesn't fire if it receives a stop before |
1198 // a start. | 1198 // a start. |
1199 host_->OnFirstPaintAfterLoad(); | 1199 host_->OnFirstPaintAfterLoad(); |
1200 host_->StartNewContentRenderingTimeout(); | 1200 host_->StartNewContentRenderingTimeout(); |
1201 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1201 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1202 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1202 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1203 TimeDelta::FromMicroseconds(20)); | 1203 TimeDelta::FromMicroseconds(20)); |
1204 base::MessageLoop::current()->Run(); | 1204 base::RunLoop().Run(); |
1205 | 1205 |
1206 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); | 1206 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); |
1207 | 1207 |
1208 // Test with a long delay to ensure that it does fire this time. | 1208 // Test with a long delay to ensure that it does fire this time. |
1209 host_->StartNewContentRenderingTimeout(); | 1209 host_->StartNewContentRenderingTimeout(); |
1210 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1210 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1211 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1211 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1212 TimeDelta::FromMicroseconds(20)); | 1212 TimeDelta::FromMicroseconds(20)); |
1213 base::MessageLoop::current()->Run(); | 1213 base::RunLoop().Run(); |
1214 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); | 1214 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); |
1215 } | 1215 } |
1216 | 1216 |
1217 TEST_F(RenderWidgetHostTest, TouchEmulator) { | 1217 TEST_F(RenderWidgetHostTest, TouchEmulator) { |
1218 simulated_event_time_delta_seconds_ = 0.1; | 1218 simulated_event_time_delta_seconds_ = 0.1; |
1219 // Immediately ack all touches instead of sending them to the renderer. | 1219 // Immediately ack all touches instead of sending them to the renderer. |
1220 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); | 1220 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); |
1221 host_->SetTouchEventEmulationEnabled( | 1221 host_->SetTouchEventEmulationEnabled( |
1222 true, ui::GestureProviderConfigType::GENERIC_MOBILE); | 1222 true, ui::GestureProviderConfigType::GENERIC_MOBILE); |
1223 process_->sink().ClearMessages(); | 1223 process_->sink().ClearMessages(); |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 ui::LatencyInfo()); | 1674 ui::LatencyInfo()); |
1675 | 1675 |
1676 | 1676 |
1677 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). | 1677 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). |
1678 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); | 1678 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); |
1679 | 1679 |
1680 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); | 1680 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); |
1681 } | 1681 } |
1682 | 1682 |
1683 } // namespace content | 1683 } // namespace content |
OLD | NEW |