| 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 16 matching lines...) Expand all Loading... |
| 27 #include "content/common/input/synthetic_web_input_event_builders.h" | 27 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 28 #include "content/common/input_messages.h" | 28 #include "content/common/input_messages.h" |
| 29 #include "content/common/resize_params.h" | 29 #include "content/common/resize_params.h" |
| 30 #include "content/common/view_messages.h" | 30 #include "content/common/view_messages.h" |
| 31 #include "content/public/browser/keyboard_event_processing_result.h" | 31 #include "content/public/browser/keyboard_event_processing_result.h" |
| 32 #include "content/public/common/content_features.h" | 32 #include "content/public/common/content_features.h" |
| 33 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
| 34 #include "content/public/test/mock_render_process_host.h" | 34 #include "content/public/test/mock_render_process_host.h" |
| 35 #include "content/public/test/test_browser_context.h" | 35 #include "content/public/test/test_browser_context.h" |
| 36 #include "content/public/test/test_browser_thread_bundle.h" | 36 #include "content/public/test/test_browser_thread_bundle.h" |
| 37 #include "content/test/fake_renderer_compositor_frame_sink.h" |
| 37 #include "content/test/test_render_view_host.h" | 38 #include "content/test/test_render_view_host.h" |
| 39 #include "mojo/public/cpp/bindings/interface_request.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 39 #include "ui/display/screen.h" | 41 #include "ui/display/screen.h" |
| 40 #include "ui/events/base_event_utils.h" | 42 #include "ui/events/base_event_utils.h" |
| 41 #include "ui/events/blink/web_input_event_traits.h" | 43 #include "ui/events/blink/web_input_event_traits.h" |
| 42 #include "ui/events/keycodes/keyboard_codes.h" | 44 #include "ui/events/keycodes/keyboard_codes.h" |
| 43 #include "ui/gfx/canvas.h" | 45 #include "ui/gfx/canvas.h" |
| 44 | 46 |
| 45 #if defined(OS_ANDROID) | 47 #if defined(OS_ANDROID) |
| 46 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 48 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 47 #include "ui/android/screen_android.h" | 49 #include "ui/android/screen_android.h" |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 display::Screen::SetScreenInstance(screen_.get()); | 557 display::Screen::SetScreenInstance(screen_.get()); |
| 556 #endif | 558 #endif |
| 557 host_.reset(new MockRenderWidgetHost(delegate_.get(), process_, | 559 host_.reset(new MockRenderWidgetHost(delegate_.get(), process_, |
| 558 process_->GetNextRoutingID())); | 560 process_->GetNextRoutingID())); |
| 559 view_.reset(new TestView(host_.get())); | 561 view_.reset(new TestView(host_.get())); |
| 560 ConfigureView(view_.get()); | 562 ConfigureView(view_.get()); |
| 561 host_->SetView(view_.get()); | 563 host_->SetView(view_.get()); |
| 562 SetInitialRenderSizeParams(); | 564 SetInitialRenderSizeParams(); |
| 563 host_->Init(); | 565 host_->Init(); |
| 564 host_->DisableGestureDebounce(); | 566 host_->DisableGestureDebounce(); |
| 567 |
| 568 cc::mojom::MojoCompositorFrameSinkPtr sink; |
| 569 cc::mojom::MojoCompositorFrameSinkRequest sink_request = |
| 570 mojo::MakeRequest(&sink); |
| 571 cc::mojom::MojoCompositorFrameSinkClientRequest client_request = |
| 572 mojo::MakeRequest(&renderer_compositor_frame_sink_ptr_); |
| 573 renderer_compositor_frame_sink_ = |
| 574 base::MakeUnique<FakeRendererCompositorFrameSink>( |
| 575 std::move(sink), std::move(client_request)); |
| 576 host_->RequestMojoCompositorFrameSink( |
| 577 std::move(sink_request), |
| 578 std::move(renderer_compositor_frame_sink_ptr_)); |
| 565 } | 579 } |
| 566 | 580 |
| 567 void TearDown() override { | 581 void TearDown() override { |
| 568 view_.reset(); | 582 view_.reset(); |
| 569 host_.reset(); | 583 host_.reset(); |
| 570 delegate_.reset(); | 584 delegate_.reset(); |
| 571 process_ = NULL; | 585 process_ = NULL; |
| 572 browser_context_.reset(); | 586 browser_context_.reset(); |
| 573 | 587 |
| 574 #if defined(USE_AURA) | 588 #if defined(USE_AURA) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. | 737 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. |
| 724 std::unique_ptr<MockRenderWidgetHostDelegate> delegate_; | 738 std::unique_ptr<MockRenderWidgetHostDelegate> delegate_; |
| 725 std::unique_ptr<MockRenderWidgetHost> host_; | 739 std::unique_ptr<MockRenderWidgetHost> host_; |
| 726 std::unique_ptr<TestView> view_; | 740 std::unique_ptr<TestView> view_; |
| 727 std::unique_ptr<display::Screen> screen_; | 741 std::unique_ptr<display::Screen> screen_; |
| 728 bool handle_key_press_event_; | 742 bool handle_key_press_event_; |
| 729 bool handle_mouse_event_; | 743 bool handle_mouse_event_; |
| 730 double last_simulated_event_time_seconds_; | 744 double last_simulated_event_time_seconds_; |
| 731 double simulated_event_time_delta_seconds_; | 745 double simulated_event_time_delta_seconds_; |
| 732 IPC::TestSink* sink_; | 746 IPC::TestSink* sink_; |
| 747 std::unique_ptr<FakeRendererCompositorFrameSink> |
| 748 renderer_compositor_frame_sink_; |
| 733 | 749 |
| 734 private: | 750 private: |
| 735 SyntheticWebTouchEvent touch_event_; | 751 SyntheticWebTouchEvent touch_event_; |
| 736 | 752 |
| 737 TestBrowserThreadBundle thread_bundle_; | 753 TestBrowserThreadBundle thread_bundle_; |
| 738 base::test::ScopedFeatureList feature_list_; | 754 base::test::ScopedFeatureList feature_list_; |
| 755 cc::mojom::MojoCompositorFrameSinkClientPtr |
| 756 renderer_compositor_frame_sink_ptr_; |
| 739 | 757 |
| 740 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); | 758 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); |
| 741 }; | 759 }; |
| 742 | 760 |
| 743 #if GTEST_HAS_PARAM_TEST | 761 #if GTEST_HAS_PARAM_TEST |
| 744 // RenderWidgetHostWithSourceTest ---------------------------------------------- | 762 // RenderWidgetHostWithSourceTest ---------------------------------------------- |
| 745 | 763 |
| 746 // This is for tests that are to be run for all source devices. | 764 // This is for tests that are to be run for all source devices. |
| 747 class RenderWidgetHostWithSourceTest | 765 class RenderWidgetHostWithSourceTest |
| 748 : public RenderWidgetHostTest, | 766 : public RenderWidgetHostTest, |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1923 SimulateGestureEventWithLatencyInfo(WebInputEvent::kGestureScrollUpdate, | 1941 SimulateGestureEventWithLatencyInfo(WebInputEvent::kGestureScrollUpdate, |
| 1924 blink::kWebGestureDeviceTouchscreen, | 1942 blink::kWebGestureDeviceTouchscreen, |
| 1925 ui::LatencyInfo()); | 1943 ui::LatencyInfo()); |
| 1926 | 1944 |
| 1927 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). | 1945 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). |
| 1928 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); | 1946 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); |
| 1929 | 1947 |
| 1930 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); | 1948 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); |
| 1931 } | 1949 } |
| 1932 | 1950 |
| 1933 // Checks whether RWHI properly keeps track of the last compositor_frame_sink_id | |
| 1934 // and notifies the view_ when it changes. | |
| 1935 TEST_F(RenderWidgetHostTest, CompositorFrameSinkIdChanges) { | |
| 1936 const gfx::Size frame_size(50, 50); | |
| 1937 const cc::LocalSurfaceId local_surface_id(1, | |
| 1938 base::UnguessableToken::Create()); | |
| 1939 | |
| 1940 // Ignore any IPC message sent so far. | |
| 1941 sink_->ClearMessages(); | |
| 1942 | |
| 1943 // Submit a frame with compositor_frame_sink_id=1 | |
| 1944 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); | |
| 1945 host_->OnMessageReceived( | |
| 1946 ViewHostMsg_SwapCompositorFrame(0, 1, local_surface_id, frame)); | |
| 1947 | |
| 1948 // Send an ack. The right compositor_frame_sink_id must be sent. | |
| 1949 host_->SendReclaimCompositorResources(true /* is_swap_ack */, | |
| 1950 cc::ReturnedResourceArray()); | |
| 1951 ASSERT_EQ(1u, sink_->message_count()); | |
| 1952 { | |
| 1953 const IPC::Message* msg = sink_->GetMessageAt(0); | |
| 1954 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); | |
| 1955 ViewMsg_ReclaimCompositorResources::Param params; | |
| 1956 ViewMsg_ReclaimCompositorResources::Read(msg, ¶ms); | |
| 1957 EXPECT_EQ(1u, std::get<0>(params)); // compositor_frame_sink_id | |
| 1958 } | |
| 1959 sink_->ClearMessages(); | |
| 1960 | |
| 1961 // Submit a frame with compositor_frame_sink_id=2. Verify that view_ is | |
| 1962 // notified of the change in id. | |
| 1963 view_->reset_did_change_compositor_frame_sink(); | |
| 1964 frame = MakeCompositorFrame(1.f, frame_size); | |
| 1965 host_->OnMessageReceived( | |
| 1966 ViewHostMsg_SwapCompositorFrame(2, 2, local_surface_id, frame)); | |
| 1967 EXPECT_TRUE(view_->did_change_compositor_frame_sink()); | |
| 1968 | |
| 1969 // Send an ack. The right compositor_frame_sink_id must be sent. | |
| 1970 host_->SendReclaimCompositorResources(true /* is_swap_ack */, | |
| 1971 cc::ReturnedResourceArray()); | |
| 1972 ASSERT_EQ(1u, sink_->message_count()); | |
| 1973 { | |
| 1974 const IPC::Message* msg = sink_->GetMessageAt(0); | |
| 1975 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); | |
| 1976 ViewMsg_ReclaimCompositorResources::Param params; | |
| 1977 ViewMsg_ReclaimCompositorResources::Read(msg, ¶ms); | |
| 1978 EXPECT_EQ(2u, std::get<0>(params)); // compositor_frame_sink_id | |
| 1979 } | |
| 1980 sink_->ClearMessages(); | |
| 1981 } | |
| 1982 | |
| 1983 // Check that if messages of a frame arrive earlier than the frame itself, we | 1951 // Check that if messages of a frame arrive earlier than the frame itself, we |
| 1984 // queue the messages until the frame arrives and then process them. | 1952 // queue the messages until the frame arrives and then process them. |
| 1985 TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) { | 1953 TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) { |
| 1986 const uint32_t frame_token = 99; | 1954 const uint32_t frame_token = 99; |
| 1987 const gfx::Size frame_size(50, 50); | 1955 const gfx::Size frame_size(50, 50); |
| 1988 const cc::LocalSurfaceId local_surface_id(1, | 1956 const cc::LocalSurfaceId local_surface_id(1, |
| 1989 base::UnguessableToken::Create()); | 1957 base::UnguessableToken::Create()); |
| 1990 std::vector<IPC::Message> messages; | 1958 std::vector<IPC::Message> messages; |
| 1991 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); | 1959 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); |
| 1992 | 1960 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2186 EXPECT_EQ(0u, host_->processed_frame_messages_count()); | 2154 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2187 | 2155 |
| 2188 frame = MakeCompositorFrame(1.f, frame_size); | 2156 frame = MakeCompositorFrame(1.f, frame_size); |
| 2189 frame.metadata.frame_token = frame_token3; | 2157 frame.metadata.frame_token = frame_token3; |
| 2190 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); | 2158 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2191 EXPECT_EQ(0u, host_->queued_messages_.size()); | 2159 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2192 EXPECT_EQ(1u, host_->processed_frame_messages_count()); | 2160 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
| 2193 } | 2161 } |
| 2194 | 2162 |
| 2195 } // namespace content | 2163 } // namespace content |
| OLD | NEW |