| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 using RenderWidgetHostImpl::resize_ack_pending_; | 182 using RenderWidgetHostImpl::resize_ack_pending_; |
| 183 using RenderWidgetHostImpl::input_router_; | 183 using RenderWidgetHostImpl::input_router_; |
| 184 | 184 |
| 185 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, | 185 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, |
| 186 InputEventAckState ack_result) override { | 186 InputEventAckState ack_result) override { |
| 187 // Sniff touch acks. | 187 // Sniff touch acks. |
| 188 acked_touch_event_type_ = event.event.type(); | 188 acked_touch_event_type_ = event.event.type(); |
| 189 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); | 189 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void reset_new_content_rendering_timeout_fired() { |
| 193 new_content_rendering_timeout_fired_ = false; |
| 194 } |
| 195 |
| 192 bool new_content_rendering_timeout_fired() const { | 196 bool new_content_rendering_timeout_fired() const { |
| 193 return new_content_rendering_timeout_fired_; | 197 return new_content_rendering_timeout_fired_; |
| 194 } | 198 } |
| 195 | 199 |
| 196 void DisableGestureDebounce() { | 200 void DisableGestureDebounce() { |
| 197 input_router_.reset(new InputRouterImpl( | 201 input_router_.reset(new InputRouterImpl( |
| 198 process_, this, this, routing_id_, InputRouterImpl::Config())); | 202 process_, this, this, routing_id_, InputRouterImpl::Config())); |
| 199 } | 203 } |
| 200 | 204 |
| 201 WebInputEvent::Type acked_touch_event_type() const { | 205 WebInputEvent::Type acked_touch_event_type() const { |
| (...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1253 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1250 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1254 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1251 TimeDelta::FromMicroseconds(20)); | 1255 TimeDelta::FromMicroseconds(20)); |
| 1252 base::RunLoop().Run(); | 1256 base::RunLoop().Run(); |
| 1253 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); | 1257 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); |
| 1254 } | 1258 } |
| 1255 | 1259 |
| 1256 // Test that the rendering timeout for newly loaded content fires | 1260 // Test that the rendering timeout for newly loaded content fires |
| 1257 // when enough time passes without receiving a new compositor frame. | 1261 // when enough time passes without receiving a new compositor frame. |
| 1258 TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { | 1262 TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { |
| 1263 const gfx::Size frame_size(50, 50); |
| 1264 const cc::LocalSurfaceId local_surface_id(1, |
| 1265 base::UnguessableToken::Create()); |
| 1266 |
| 1259 host_->set_new_content_rendering_delay_for_testing( | 1267 host_->set_new_content_rendering_delay_for_testing( |
| 1260 base::TimeDelta::FromMicroseconds(10)); | 1268 base::TimeDelta::FromMicroseconds(10)); |
| 1261 | 1269 |
| 1262 // Test immediate start and stop, ensuring that the timeout doesn't fire. | 1270 // Start the timer and immediately send a CompositorFrame with the |
| 1263 host_->StartNewContentRenderingTimeout(0); | 1271 // content_source_id of the new page. The timeout shouldn't fire. |
| 1264 host_->OnFirstPaintAfterLoad(); | 1272 host_->StartNewContentRenderingTimeout(5); |
| 1273 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 1274 frame.metadata.content_source_id = 5; |
| 1275 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( |
| 1276 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); |
| 1265 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1277 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1266 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1278 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1267 TimeDelta::FromMicroseconds(20)); | 1279 TimeDelta::FromMicroseconds(20)); |
| 1268 base::RunLoop().Run(); | 1280 base::RunLoop().Run(); |
| 1269 | 1281 |
| 1270 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); | 1282 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); |
| 1283 host_->reset_new_content_rendering_timeout_fired(); |
| 1271 | 1284 |
| 1272 // Test that the timer doesn't fire if it receives a stop before | 1285 // Start the timer but receive frames only from the old page. The timer |
| 1273 // a start. | 1286 // should fire. |
| 1274 host_->OnFirstPaintAfterLoad(); | 1287 host_->StartNewContentRenderingTimeout(10); |
| 1275 host_->StartNewContentRenderingTimeout(0); | 1288 frame = MakeCompositorFrame(1.f, frame_size); |
| 1289 frame.metadata.content_source_id = 9; |
| 1290 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( |
| 1291 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); |
| 1292 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1293 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1294 TimeDelta::FromMicroseconds(20)); |
| 1295 base::RunLoop().Run(); |
| 1296 |
| 1297 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); |
| 1298 host_->reset_new_content_rendering_timeout_fired(); |
| 1299 |
| 1300 // Send a CompositorFrame with content_source_id of the new page before we |
| 1301 // attempt to start the timer. The timer shouldn't fire. |
| 1302 frame = MakeCompositorFrame(1.f, frame_size); |
| 1303 frame.metadata.content_source_id = 7; |
| 1304 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( |
| 1305 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); |
| 1306 host_->StartNewContentRenderingTimeout(7); |
| 1276 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1307 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1277 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1308 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1278 TimeDelta::FromMicroseconds(20)); | 1309 TimeDelta::FromMicroseconds(20)); |
| 1279 base::RunLoop().Run(); | 1310 base::RunLoop().Run(); |
| 1280 | 1311 |
| 1281 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); | 1312 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); |
| 1313 host_->reset_new_content_rendering_timeout_fired(); |
| 1282 | 1314 |
| 1283 // Test with a long delay to ensure that it does fire this time. | 1315 // Don't send any frames after the timer starts. The timer should fire. |
| 1284 host_->StartNewContentRenderingTimeout(0); | 1316 host_->StartNewContentRenderingTimeout(20); |
| 1285 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1317 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1286 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1318 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 1287 TimeDelta::FromMicroseconds(20)); | 1319 TimeDelta::FromMicroseconds(20)); |
| 1288 base::RunLoop().Run(); | 1320 base::RunLoop().Run(); |
| 1289 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); | 1321 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); |
| 1322 host_->reset_new_content_rendering_timeout_fired(); |
| 1290 } | 1323 } |
| 1291 | 1324 |
| 1292 // This tests that a compositor frame received with a stale content source ID | 1325 // This tests that a compositor frame received with a stale content source ID |
| 1293 // in its metadata is properly discarded. | 1326 // in its metadata is properly discarded. |
| 1294 TEST_F(RenderWidgetHostTest, SwapCompositorFrameWithBadSourceId) { | 1327 TEST_F(RenderWidgetHostTest, SwapCompositorFrameWithBadSourceId) { |
| 1295 const gfx::Size frame_size(50, 50); | 1328 const gfx::Size frame_size(50, 50); |
| 1296 const cc::LocalSurfaceId local_surface_id(1, | 1329 const cc::LocalSurfaceId local_surface_id(1, |
| 1297 base::UnguessableToken::Create()); | 1330 base::UnguessableToken::Create()); |
| 1298 | 1331 |
| 1299 host_->StartNewContentRenderingTimeout(100); | 1332 host_->StartNewContentRenderingTimeout(100); |
| 1300 host_->OnFirstPaintAfterLoad(); | 1333 host_->set_new_content_rendering_delay_for_testing( |
| 1334 base::TimeDelta::FromMicroseconds(9999)); |
| 1301 | 1335 |
| 1302 { | 1336 { |
| 1303 // First swap a frame with an invalid ID. | 1337 // First swap a frame with an invalid ID. |
| 1304 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); | 1338 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 1305 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, 0, true); | 1339 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, 0, true); |
| 1306 frame.metadata.content_source_id = 99; | 1340 frame.metadata.content_source_id = 99; |
| 1307 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( | 1341 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( |
| 1308 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); | 1342 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); |
| 1309 EXPECT_FALSE( | 1343 EXPECT_FALSE( |
| 1310 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); | 1344 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1827 ui::LatencyInfo()); | 1861 ui::LatencyInfo()); |
| 1828 | 1862 |
| 1829 | 1863 |
| 1830 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). | 1864 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). |
| 1831 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); | 1865 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); |
| 1832 | 1866 |
| 1833 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); | 1867 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); |
| 1834 } | 1868 } |
| 1835 | 1869 |
| 1836 } // namespace content | 1870 } // namespace content |
| OLD | NEW |