Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 2707243005: Discard compositor frames from unloaded web content (Closed)
Patch Set: Comments updated Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 EXPECT_TRUE(delegate_->unresponsive_timer_fired()); 1246 EXPECT_TRUE(delegate_->unresponsive_timer_fired());
1247 } 1247 }
1248 1248
1249 // Test that the rendering timeout for newly loaded content fires 1249 // Test that the rendering timeout for newly loaded content fires
1250 // when enough time passes without receiving a new compositor frame. 1250 // when enough time passes without receiving a new compositor frame.
1251 TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { 1251 TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) {
1252 host_->set_new_content_rendering_delay_for_testing( 1252 host_->set_new_content_rendering_delay_for_testing(
1253 base::TimeDelta::FromMicroseconds(10)); 1253 base::TimeDelta::FromMicroseconds(10));
1254 1254
1255 // Test immediate start and stop, ensuring that the timeout doesn't fire. 1255 // Test immediate start and stop, ensuring that the timeout doesn't fire.
1256 host_->StartNewContentRenderingTimeout(); 1256 host_->StartNewContentRenderingTimeout(0);
1257 host_->OnFirstPaintAfterLoad(); 1257 host_->OnFirstPaintAfterLoad();
1258 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1258 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1259 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 1259 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
1260 TimeDelta::FromMicroseconds(20)); 1260 TimeDelta::FromMicroseconds(20));
1261 base::RunLoop().Run(); 1261 base::RunLoop().Run();
1262 1262
1263 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); 1263 EXPECT_FALSE(host_->new_content_rendering_timeout_fired());
1264 1264
1265 // Test that the timer doesn't fire if it receives a stop before 1265 // Test that the timer doesn't fire if it receives a stop before
1266 // a start. 1266 // a start.
1267 host_->OnFirstPaintAfterLoad(); 1267 host_->OnFirstPaintAfterLoad();
1268 host_->StartNewContentRenderingTimeout(); 1268 host_->StartNewContentRenderingTimeout(0);
1269 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1269 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1270 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 1270 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
1271 TimeDelta::FromMicroseconds(20)); 1271 TimeDelta::FromMicroseconds(20));
1272 base::RunLoop().Run(); 1272 base::RunLoop().Run();
1273 1273
1274 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); 1274 EXPECT_FALSE(host_->new_content_rendering_timeout_fired());
1275 1275
1276 // Test with a long delay to ensure that it does fire this time. 1276 // Test with a long delay to ensure that it does fire this time.
1277 host_->StartNewContentRenderingTimeout(); 1277 host_->StartNewContentRenderingTimeout(0);
1278 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1278 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1279 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 1279 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
1280 TimeDelta::FromMicroseconds(20)); 1280 TimeDelta::FromMicroseconds(20));
1281 base::RunLoop().Run(); 1281 base::RunLoop().Run();
1282 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); 1282 EXPECT_TRUE(host_->new_content_rendering_timeout_fired());
1283 } 1283 }
1284 1284
1285 // This tests that a compositor frame received with a stale content source ID
1286 // in its metadata is properly discarded.
1287 TEST_F(RenderWidgetHostTest, SwapCompositorFrameWithBadSourceId) {
1288 host_->StartNewContentRenderingTimeout(100);
1289 host_->OnFirstPaintAfterLoad();
1290
1291 // First swap a frame with an invalid ID.
1292 cc::CompositorFrame frame;
1293 frame.metadata.content_source_id = 99;
1294 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame(
1295 0, 0, frame, std::vector<IPC::Message>()));
1296 EXPECT_FALSE(
1297 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame());
1298
1299 // Test with a valid content ID as a control.
1300 frame.metadata.content_source_id = 100;
danakj 2017/03/02 18:12:50 The code also accepts source id > 100. I've been w
kenrb 2017/03/02 19:35:57 That's a point, and I've added it to the test. The
danakj 2017/03/02 19:56:34 OK Thanks. A comment on the >= would be appreciate
kenrb 2017/03/02 21:19:51 Done.
1301 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame(
1302 0, 0, frame, std::vector<IPC::Message>()));
1303 EXPECT_TRUE(
1304 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame());
1305 }
1306
1285 TEST_F(RenderWidgetHostTest, TouchEmulator) { 1307 TEST_F(RenderWidgetHostTest, TouchEmulator) {
1286 simulated_event_time_delta_seconds_ = 0.1; 1308 simulated_event_time_delta_seconds_ = 0.1;
1287 // Immediately ack all touches instead of sending them to the renderer. 1309 // Immediately ack all touches instead of sending them to the renderer.
1288 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); 1310 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1289 host_->SetTouchEventEmulationEnabled( 1311 host_->SetTouchEventEmulationEnabled(
1290 true, ui::GestureProviderConfigType::GENERIC_MOBILE); 1312 true, ui::GestureProviderConfigType::GENERIC_MOBILE);
1291 process_->sink().ClearMessages(); 1313 process_->sink().ClearMessages();
1292 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); 1314 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
1293 view_->Show(); 1315 view_->Show();
1294 1316
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 ui::LatencyInfo()); 1765 ui::LatencyInfo());
1744 1766
1745 1767
1746 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). 1768 // Tests RWHI::ForwardWheelEventWithLatencyInfo().
1747 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); 1769 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo());
1748 1770
1749 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1771 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1750 } 1772 }
1751 1773
1752 } // namespace content 1774 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698