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

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

Issue 2728183002: RendererCompositorFrameSink should handle local surface id allocation (Closed)
Patch Set: rebase 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 bool new_content_rendering_timeout_fired_; 217 bool new_content_rendering_timeout_fired_;
218 WebInputEvent::Type acked_touch_event_type_; 218 WebInputEvent::Type acked_touch_event_type_;
219 219
220 private: 220 private:
221 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); 221 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost);
222 }; 222 };
223 223
224 namespace { 224 namespace {
225 225
226 cc::CompositorFrame MakeCompositorFrame(float scale_factor, gfx::Size size) {
227 cc::CompositorFrame frame;
228 frame.metadata.device_scale_factor = scale_factor;
229 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, 0, true);
230
231 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
232 pass->SetNew(1, gfx::Rect(size), gfx::Rect(), gfx::Transform());
233 frame.render_pass_list.push_back(std::move(pass));
234 if (!size.IsEmpty()) {
235 cc::TransferableResource resource;
236 resource.id = 1;
237 frame.resource_list.push_back(std::move(resource));
238 }
239 return frame;
240 }
241
226 // RenderWidgetHostProcess ----------------------------------------------------- 242 // RenderWidgetHostProcess -----------------------------------------------------
227 243
228 class RenderWidgetHostProcess : public MockRenderProcessHost { 244 class RenderWidgetHostProcess : public MockRenderProcessHost {
229 public: 245 public:
230 explicit RenderWidgetHostProcess(BrowserContext* browser_context) 246 explicit RenderWidgetHostProcess(BrowserContext* browser_context)
231 : MockRenderProcessHost(browser_context) { 247 : MockRenderProcessHost(browser_context) {
232 } 248 }
233 ~RenderWidgetHostProcess() override {} 249 ~RenderWidgetHostProcess() override {}
234 250
235 bool HasConnection() const override { return true; } 251 bool HasConnection() const override { return true; }
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1281 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1266 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 1282 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
1267 TimeDelta::FromMicroseconds(20)); 1283 TimeDelta::FromMicroseconds(20));
1268 base::RunLoop().Run(); 1284 base::RunLoop().Run();
1269 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); 1285 EXPECT_TRUE(host_->new_content_rendering_timeout_fired());
1270 } 1286 }
1271 1287
1272 // This tests that a compositor frame received with a stale content source ID 1288 // This tests that a compositor frame received with a stale content source ID
1273 // in its metadata is properly discarded. 1289 // in its metadata is properly discarded.
1274 TEST_F(RenderWidgetHostTest, SwapCompositorFrameWithBadSourceId) { 1290 TEST_F(RenderWidgetHostTest, SwapCompositorFrameWithBadSourceId) {
1291 const gfx::Size frame_size(50, 50);
1292 const cc::LocalSurfaceId local_surface_id(1,
1293 base::UnguessableToken::Create());
1294
1275 host_->StartNewContentRenderingTimeout(100); 1295 host_->StartNewContentRenderingTimeout(100);
1276 host_->OnFirstPaintAfterLoad(); 1296 host_->OnFirstPaintAfterLoad();
1277 1297
1278 // First swap a frame with an invalid ID. 1298 {
1279 cc::CompositorFrame frame; 1299 // First swap a frame with an invalid ID.
1280 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, 0, true); 1300 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
1281 frame.metadata.content_source_id = 99; 1301 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, 0, true);
1282 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( 1302 frame.metadata.content_source_id = 99;
1283 0, 0, frame, std::vector<IPC::Message>())); 1303 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame(
1284 EXPECT_FALSE( 1304 0, 0, local_surface_id, frame, std::vector<IPC::Message>()));
1285 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); 1305 EXPECT_FALSE(
1286 static_cast<TestView*>(host_->GetView())->reset_did_swap_compositor_frame(); 1306 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame());
1307 static_cast<TestView*>(host_->GetView())->reset_did_swap_compositor_frame();
1308 }
1287 1309
1288 // Test with a valid content ID as a control. 1310 {
1289 frame.metadata.content_source_id = 100; 1311 // Test with a valid content ID as a control.
1290 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( 1312 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
1291 0, 0, frame, std::vector<IPC::Message>())); 1313 frame.metadata.content_source_id = 100;
1292 EXPECT_TRUE( 1314 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame(
1293 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); 1315 0, 0, local_surface_id, frame, std::vector<IPC::Message>()));
1294 static_cast<TestView*>(host_->GetView())->reset_did_swap_compositor_frame(); 1316 EXPECT_TRUE(
1317 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame());
1318 static_cast<TestView*>(host_->GetView())->reset_did_swap_compositor_frame();
1319 }
1295 1320
1296 // We also accept frames with higher content IDs, to cover the case where 1321 {
1297 // the browser process receives a compositor frame for a new page before 1322 // We also accept frames with higher content IDs, to cover the case where
1298 // the corresponding DidCommitProvisionalLoad (it's a race). 1323 // the browser process receives a compositor frame for a new page before
1299 frame.metadata.content_source_id = 101; 1324 // the corresponding DidCommitProvisionalLoad (it's a race).
1300 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( 1325 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
1301 0, 0, frame, std::vector<IPC::Message>())); 1326 frame.metadata.content_source_id = 101;
1302 EXPECT_TRUE( 1327 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame(
1303 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); 1328 0, 0, local_surface_id, frame, std::vector<IPC::Message>()));
1329 EXPECT_TRUE(
1330 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame());
1331 }
1304 } 1332 }
1305 1333
1306 TEST_F(RenderWidgetHostTest, TouchEmulator) { 1334 TEST_F(RenderWidgetHostTest, TouchEmulator) {
1307 simulated_event_time_delta_seconds_ = 0.1; 1335 simulated_event_time_delta_seconds_ = 0.1;
1308 // Immediately ack all touches instead of sending them to the renderer. 1336 // Immediately ack all touches instead of sending them to the renderer.
1309 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); 1337 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
1310 host_->SetTouchEventEmulationEnabled( 1338 host_->SetTouchEventEmulationEnabled(
1311 true, ui::GestureProviderConfigType::GENERIC_MOBILE); 1339 true, ui::GestureProviderConfigType::GENERIC_MOBILE);
1312 process_->sink().ClearMessages(); 1340 process_->sink().ClearMessages();
1313 view_->set_bounds(gfx::Rect(0, 0, 400, 200)); 1341 view_->set_bounds(gfx::Rect(0, 0, 400, 200));
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 ui::LatencyInfo()); 1823 ui::LatencyInfo());
1796 1824
1797 1825
1798 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). 1826 // Tests RWHI::ForwardWheelEventWithLatencyInfo().
1799 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); 1827 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo());
1800 1828
1801 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1829 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1802 } 1830 }
1803 1831
1804 } // namespace content 1832 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698