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