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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 // testing::Test | 488 // testing::Test |
489 void SetUp() override { | 489 void SetUp() override { |
490 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 490 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
491 command_line->AppendSwitch(switches::kValidateInputEventStream); | 491 command_line->AppendSwitch(switches::kValidateInputEventStream); |
492 feature_list_.InitFromCommandLine( | 492 feature_list_.InitFromCommandLine( |
493 features::kRafAlignedTouchInputEvents.name, ""); | 493 features::kRafAlignedTouchInputEvents.name, ""); |
494 | 494 |
495 browser_context_.reset(new TestBrowserContext()); | 495 browser_context_.reset(new TestBrowserContext()); |
496 delegate_.reset(new MockRenderWidgetHostDelegate()); | 496 delegate_.reset(new MockRenderWidgetHostDelegate()); |
497 process_ = new RenderWidgetHostProcess(browser_context_.get()); | 497 process_ = new RenderWidgetHostProcess(browser_context_.get()); |
| 498 sink_ = &process_->sink(); |
498 #if defined(USE_AURA) || defined(OS_MACOSX) | 499 #if defined(USE_AURA) || defined(OS_MACOSX) |
499 ImageTransportFactory::InitializeForUnitTests( | 500 ImageTransportFactory::InitializeForUnitTests( |
500 std::unique_ptr<ImageTransportFactory>( | 501 std::unique_ptr<ImageTransportFactory>( |
501 new NoTransportImageTransportFactory)); | 502 new NoTransportImageTransportFactory)); |
502 #endif | 503 #endif |
503 #if defined(OS_ANDROID) | 504 #if defined(OS_ANDROID) |
504 ui::SetScreenAndroid(); // calls display::Screen::SetScreenInstance(). | 505 ui::SetScreenAndroid(); // calls display::Screen::SetScreenInstance(). |
505 #endif | 506 #endif |
506 #if defined(USE_AURA) | 507 #if defined(USE_AURA) |
507 screen_.reset(aura::TestScreen::Create(gfx::Size())); | 508 screen_.reset(aura::TestScreen::Create(gfx::Size())); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 std::unique_ptr<TestBrowserContext> browser_context_; | 676 std::unique_ptr<TestBrowserContext> browser_context_; |
676 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. | 677 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. |
677 std::unique_ptr<MockRenderWidgetHostDelegate> delegate_; | 678 std::unique_ptr<MockRenderWidgetHostDelegate> delegate_; |
678 std::unique_ptr<MockRenderWidgetHost> host_; | 679 std::unique_ptr<MockRenderWidgetHost> host_; |
679 std::unique_ptr<TestView> view_; | 680 std::unique_ptr<TestView> view_; |
680 std::unique_ptr<display::Screen> screen_; | 681 std::unique_ptr<display::Screen> screen_; |
681 bool handle_key_press_event_; | 682 bool handle_key_press_event_; |
682 bool handle_mouse_event_; | 683 bool handle_mouse_event_; |
683 double last_simulated_event_time_seconds_; | 684 double last_simulated_event_time_seconds_; |
684 double simulated_event_time_delta_seconds_; | 685 double simulated_event_time_delta_seconds_; |
| 686 IPC::TestSink* sink_; |
685 | 687 |
686 private: | 688 private: |
687 SyntheticWebTouchEvent touch_event_; | 689 SyntheticWebTouchEvent touch_event_; |
688 | 690 |
689 TestBrowserThreadBundle thread_bundle_; | 691 TestBrowserThreadBundle thread_bundle_; |
690 base::test::ScopedFeatureList feature_list_; | 692 base::test::ScopedFeatureList feature_list_; |
691 | 693 |
692 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); | 694 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); |
693 }; | 695 }; |
694 | 696 |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 base::UnguessableToken::Create()); | 1267 base::UnguessableToken::Create()); |
1266 | 1268 |
1267 host_->set_new_content_rendering_delay_for_testing( | 1269 host_->set_new_content_rendering_delay_for_testing( |
1268 base::TimeDelta::FromMicroseconds(10)); | 1270 base::TimeDelta::FromMicroseconds(10)); |
1269 | 1271 |
1270 // Start the timer and immediately send a CompositorFrame with the | 1272 // Start the timer and immediately send a CompositorFrame with the |
1271 // content_source_id of the new page. The timeout shouldn't fire. | 1273 // content_source_id of the new page. The timeout shouldn't fire. |
1272 host_->StartNewContentRenderingTimeout(5); | 1274 host_->StartNewContentRenderingTimeout(5); |
1273 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); | 1275 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
1274 frame.metadata.content_source_id = 5; | 1276 frame.metadata.content_source_id = 5; |
1275 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( | 1277 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
1276 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); | |
1277 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1278 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1278 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1279 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1279 TimeDelta::FromMicroseconds(20)); | 1280 TimeDelta::FromMicroseconds(20)); |
1280 base::RunLoop().Run(); | 1281 base::RunLoop().Run(); |
1281 | 1282 |
1282 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); | 1283 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); |
1283 host_->reset_new_content_rendering_timeout_fired(); | 1284 host_->reset_new_content_rendering_timeout_fired(); |
1284 | 1285 |
1285 // Start the timer but receive frames only from the old page. The timer | 1286 // Start the timer but receive frames only from the old page. The timer |
1286 // should fire. | 1287 // should fire. |
1287 host_->StartNewContentRenderingTimeout(10); | 1288 host_->StartNewContentRenderingTimeout(10); |
1288 frame = MakeCompositorFrame(1.f, frame_size); | 1289 frame = MakeCompositorFrame(1.f, frame_size); |
1289 frame.metadata.content_source_id = 9; | 1290 frame.metadata.content_source_id = 9; |
1290 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( | 1291 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
1291 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); | |
1292 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1292 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1293 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1293 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1294 TimeDelta::FromMicroseconds(20)); | 1294 TimeDelta::FromMicroseconds(20)); |
1295 base::RunLoop().Run(); | 1295 base::RunLoop().Run(); |
1296 | 1296 |
1297 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); | 1297 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); |
1298 host_->reset_new_content_rendering_timeout_fired(); | 1298 host_->reset_new_content_rendering_timeout_fired(); |
1299 | 1299 |
1300 // Send a CompositorFrame with content_source_id of the new page before we | 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. | 1301 // attempt to start the timer. The timer shouldn't fire. |
1302 frame = MakeCompositorFrame(1.f, frame_size); | 1302 frame = MakeCompositorFrame(1.f, frame_size); |
1303 frame.metadata.content_source_id = 7; | 1303 frame.metadata.content_source_id = 7; |
1304 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( | 1304 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
1305 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); | |
1306 host_->StartNewContentRenderingTimeout(7); | 1305 host_->StartNewContentRenderingTimeout(7); |
1307 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1306 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
1308 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 1307 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
1309 TimeDelta::FromMicroseconds(20)); | 1308 TimeDelta::FromMicroseconds(20)); |
1310 base::RunLoop().Run(); | 1309 base::RunLoop().Run(); |
1311 | 1310 |
1312 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); | 1311 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); |
1313 host_->reset_new_content_rendering_timeout_fired(); | 1312 host_->reset_new_content_rendering_timeout_fired(); |
1314 | 1313 |
1315 // Don't send any frames after the timer starts. The timer should fire. | 1314 // Don't send any frames after the timer starts. The timer should fire. |
(...skipping 15 matching lines...) Expand all Loading... |
1331 | 1330 |
1332 host_->StartNewContentRenderingTimeout(100); | 1331 host_->StartNewContentRenderingTimeout(100); |
1333 host_->set_new_content_rendering_delay_for_testing( | 1332 host_->set_new_content_rendering_delay_for_testing( |
1334 base::TimeDelta::FromMicroseconds(9999)); | 1333 base::TimeDelta::FromMicroseconds(9999)); |
1335 | 1334 |
1336 { | 1335 { |
1337 // First swap a frame with an invalid ID. | 1336 // First swap a frame with an invalid ID. |
1338 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); | 1337 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
1339 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, true); | 1338 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, true); |
1340 frame.metadata.content_source_id = 99; | 1339 frame.metadata.content_source_id = 99; |
1341 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( | 1340 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
1342 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); | |
1343 EXPECT_FALSE( | 1341 EXPECT_FALSE( |
1344 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); | 1342 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); |
1345 static_cast<TestView*>(host_->GetView())->reset_did_swap_compositor_frame(); | 1343 static_cast<TestView*>(host_->GetView())->reset_did_swap_compositor_frame(); |
1346 } | 1344 } |
1347 | 1345 |
1348 { | 1346 { |
1349 // Test with a valid content ID as a control. | 1347 // Test with a valid content ID as a control. |
1350 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); | 1348 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
1351 frame.metadata.content_source_id = 100; | 1349 frame.metadata.content_source_id = 100; |
1352 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( | 1350 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
1353 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); | |
1354 EXPECT_TRUE( | 1351 EXPECT_TRUE( |
1355 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); | 1352 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); |
1356 static_cast<TestView*>(host_->GetView())->reset_did_swap_compositor_frame(); | 1353 static_cast<TestView*>(host_->GetView())->reset_did_swap_compositor_frame(); |
1357 } | 1354 } |
1358 | 1355 |
1359 { | 1356 { |
1360 // We also accept frames with higher content IDs, to cover the case where | 1357 // We also accept frames with higher content IDs, to cover the case where |
1361 // the browser process receives a compositor frame for a new page before | 1358 // the browser process receives a compositor frame for a new page before |
1362 // the corresponding DidCommitProvisionalLoad (it's a race). | 1359 // the corresponding DidCommitProvisionalLoad (it's a race). |
1363 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); | 1360 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
1364 frame.metadata.content_source_id = 101; | 1361 frame.metadata.content_source_id = 101; |
1365 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( | 1362 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
1366 0, 0, local_surface_id, frame, std::vector<IPC::Message>())); | |
1367 EXPECT_TRUE( | 1363 EXPECT_TRUE( |
1368 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); | 1364 static_cast<TestView*>(host_->GetView())->did_swap_compositor_frame()); |
1369 } | 1365 } |
1370 } | 1366 } |
1371 | 1367 |
1372 TEST_F(RenderWidgetHostTest, TouchEmulator) { | 1368 TEST_F(RenderWidgetHostTest, TouchEmulator) { |
1373 simulated_event_time_delta_seconds_ = 0.1; | 1369 simulated_event_time_delta_seconds_ = 0.1; |
1374 // Immediately ack all touches instead of sending them to the renderer. | 1370 // Immediately ack all touches instead of sending them to the renderer. |
1375 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); | 1371 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); |
1376 host_->SetTouchEventEmulationEnabled( | 1372 host_->SetTouchEventEmulationEnabled( |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 blink::WebGestureDeviceTouchscreen, | 1856 blink::WebGestureDeviceTouchscreen, |
1861 ui::LatencyInfo()); | 1857 ui::LatencyInfo()); |
1862 | 1858 |
1863 | 1859 |
1864 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). | 1860 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). |
1865 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); | 1861 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); |
1866 | 1862 |
1867 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); | 1863 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); |
1868 } | 1864 } |
1869 | 1865 |
| 1866 // Checks whether RWHI properly keeps track of the last compositor_frame_sink_id |
| 1867 // and notifies the view_ when it changes. |
| 1868 TEST_F(RenderWidgetHostTest, CompositorFrameSinkIdChanges) { |
| 1869 const gfx::Size frame_size(50, 50); |
| 1870 const cc::LocalSurfaceId local_surface_id(1, |
| 1871 base::UnguessableToken::Create()); |
| 1872 |
| 1873 // Ignore any IPC message sent so far. |
| 1874 sink_->ClearMessages(); |
| 1875 |
| 1876 // Submit a frame with compositor_frame_sink_id=1 |
| 1877 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 1878 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( |
| 1879 0, 1, local_surface_id, frame, std::vector<IPC::Message>())); |
| 1880 |
| 1881 // Send an ack. The right compositor_frame_sink_id must be sent. |
| 1882 host_->SendReclaimCompositorResources(true /* is_swap_ack */, |
| 1883 cc::ReturnedResourceArray()); |
| 1884 ASSERT_EQ(1u, sink_->message_count()); |
| 1885 { |
| 1886 const IPC::Message* msg = sink_->GetMessageAt(0); |
| 1887 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); |
| 1888 ViewMsg_ReclaimCompositorResources::Param params; |
| 1889 ViewMsg_ReclaimCompositorResources::Read(msg, ¶ms); |
| 1890 EXPECT_EQ(1u, std::get<0>(params)); // compositor_frame_sink_id |
| 1891 } |
| 1892 sink_->ClearMessages(); |
| 1893 |
| 1894 // Submit a frame with compositor_frame_sink_id=2. Verify that view_ is |
| 1895 // notified of the change in id. |
| 1896 view_->reset_did_change_compositor_frame_sink(); |
| 1897 frame = MakeCompositorFrame(1.f, frame_size); |
| 1898 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( |
| 1899 2, 2, local_surface_id, frame, std::vector<IPC::Message>())); |
| 1900 EXPECT_TRUE(view_->did_change_compositor_frame_sink()); |
| 1901 |
| 1902 // Send an ack. The right compositor_frame_sink_id must be sent. |
| 1903 host_->SendReclaimCompositorResources(true /* is_swap_ack */, |
| 1904 cc::ReturnedResourceArray()); |
| 1905 ASSERT_EQ(1u, sink_->message_count()); |
| 1906 { |
| 1907 const IPC::Message* msg = sink_->GetMessageAt(0); |
| 1908 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); |
| 1909 ViewMsg_ReclaimCompositorResources::Param params; |
| 1910 ViewMsg_ReclaimCompositorResources::Read(msg, ¶ms); |
| 1911 EXPECT_EQ(2u, std::get<0>(params)); // compositor_frame_sink_id |
| 1912 } |
| 1913 sink_->ClearMessages(); |
| 1914 } |
| 1915 |
1870 } // namespace content | 1916 } // namespace content |
OLD | NEW |