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" | |
38 #include "content/test/test_render_view_host.h" | 37 #include "content/test/test_render_view_host.h" |
39 #include "mojo/public/cpp/bindings/interface_request.h" | |
40 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "ui/display/screen.h" | 39 #include "ui/display/screen.h" |
42 #include "ui/events/base_event_utils.h" | 40 #include "ui/events/base_event_utils.h" |
43 #include "ui/events/blink/web_input_event_traits.h" | 41 #include "ui/events/blink/web_input_event_traits.h" |
44 #include "ui/events/keycodes/keyboard_codes.h" | 42 #include "ui/events/keycodes/keyboard_codes.h" |
45 #include "ui/gfx/canvas.h" | 43 #include "ui/gfx/canvas.h" |
46 | 44 |
47 #if defined(OS_ANDROID) | 45 #if defined(OS_ANDROID) |
48 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 46 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
49 #include "ui/android/screen_android.h" | 47 #include "ui/android/screen_android.h" |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 display::Screen::SetScreenInstance(screen_.get()); | 555 display::Screen::SetScreenInstance(screen_.get()); |
558 #endif | 556 #endif |
559 host_.reset(new MockRenderWidgetHost(delegate_.get(), process_, | 557 host_.reset(new MockRenderWidgetHost(delegate_.get(), process_, |
560 process_->GetNextRoutingID())); | 558 process_->GetNextRoutingID())); |
561 view_.reset(new TestView(host_.get())); | 559 view_.reset(new TestView(host_.get())); |
562 ConfigureView(view_.get()); | 560 ConfigureView(view_.get()); |
563 host_->SetView(view_.get()); | 561 host_->SetView(view_.get()); |
564 SetInitialRenderSizeParams(); | 562 SetInitialRenderSizeParams(); |
565 host_->Init(); | 563 host_->Init(); |
566 host_->DisableGestureDebounce(); | 564 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_)); | |
579 } | 565 } |
580 | 566 |
581 void TearDown() override { | 567 void TearDown() override { |
582 view_.reset(); | 568 view_.reset(); |
583 host_.reset(); | 569 host_.reset(); |
584 delegate_.reset(); | 570 delegate_.reset(); |
585 process_ = NULL; | 571 process_ = NULL; |
586 browser_context_.reset(); | 572 browser_context_.reset(); |
587 | 573 |
588 #if defined(USE_AURA) | 574 #if defined(USE_AURA) |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. | 723 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. |
738 std::unique_ptr<MockRenderWidgetHostDelegate> delegate_; | 724 std::unique_ptr<MockRenderWidgetHostDelegate> delegate_; |
739 std::unique_ptr<MockRenderWidgetHost> host_; | 725 std::unique_ptr<MockRenderWidgetHost> host_; |
740 std::unique_ptr<TestView> view_; | 726 std::unique_ptr<TestView> view_; |
741 std::unique_ptr<display::Screen> screen_; | 727 std::unique_ptr<display::Screen> screen_; |
742 bool handle_key_press_event_; | 728 bool handle_key_press_event_; |
743 bool handle_mouse_event_; | 729 bool handle_mouse_event_; |
744 double last_simulated_event_time_seconds_; | 730 double last_simulated_event_time_seconds_; |
745 double simulated_event_time_delta_seconds_; | 731 double simulated_event_time_delta_seconds_; |
746 IPC::TestSink* sink_; | 732 IPC::TestSink* sink_; |
747 std::unique_ptr<FakeRendererCompositorFrameSink> | |
748 renderer_compositor_frame_sink_; | |
749 | 733 |
750 private: | 734 private: |
751 SyntheticWebTouchEvent touch_event_; | 735 SyntheticWebTouchEvent touch_event_; |
752 | 736 |
753 TestBrowserThreadBundle thread_bundle_; | 737 TestBrowserThreadBundle thread_bundle_; |
754 base::test::ScopedFeatureList feature_list_; | 738 base::test::ScopedFeatureList feature_list_; |
755 cc::mojom::MojoCompositorFrameSinkClientPtr | |
756 renderer_compositor_frame_sink_ptr_; | |
757 | 739 |
758 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); | 740 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); |
759 }; | 741 }; |
760 | 742 |
761 #if GTEST_HAS_PARAM_TEST | 743 #if GTEST_HAS_PARAM_TEST |
762 // RenderWidgetHostWithSourceTest ---------------------------------------------- | 744 // RenderWidgetHostWithSourceTest ---------------------------------------------- |
763 | 745 |
764 // This is for tests that are to be run for all source devices. | 746 // This is for tests that are to be run for all source devices. |
765 class RenderWidgetHostWithSourceTest | 747 class RenderWidgetHostWithSourceTest |
766 : public RenderWidgetHostTest, | 748 : public RenderWidgetHostTest, |
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 SimulateGestureEventWithLatencyInfo(WebInputEvent::kGestureScrollUpdate, | 1923 SimulateGestureEventWithLatencyInfo(WebInputEvent::kGestureScrollUpdate, |
1942 blink::kWebGestureDeviceTouchscreen, | 1924 blink::kWebGestureDeviceTouchscreen, |
1943 ui::LatencyInfo()); | 1925 ui::LatencyInfo()); |
1944 | 1926 |
1945 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). | 1927 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). |
1946 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); | 1928 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); |
1947 | 1929 |
1948 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); | 1930 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); |
1949 } | 1931 } |
1950 | 1932 |
| 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 |
1951 // Check that if messages of a frame arrive earlier than the frame itself, we | 1983 // Check that if messages of a frame arrive earlier than the frame itself, we |
1952 // queue the messages until the frame arrives and then process them. | 1984 // queue the messages until the frame arrives and then process them. |
1953 TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) { | 1985 TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) { |
1954 const uint32_t frame_token = 99; | 1986 const uint32_t frame_token = 99; |
1955 const gfx::Size frame_size(50, 50); | 1987 const gfx::Size frame_size(50, 50); |
1956 const cc::LocalSurfaceId local_surface_id(1, | 1988 const cc::LocalSurfaceId local_surface_id(1, |
1957 base::UnguessableToken::Create()); | 1989 base::UnguessableToken::Create()); |
1958 std::vector<IPC::Message> messages; | 1990 std::vector<IPC::Message> messages; |
1959 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); | 1991 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); |
1960 | 1992 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2154 EXPECT_EQ(0u, host_->processed_frame_messages_count()); | 2186 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
2155 | 2187 |
2156 frame = MakeCompositorFrame(1.f, frame_size); | 2188 frame = MakeCompositorFrame(1.f, frame_size); |
2157 frame.metadata.frame_token = frame_token3; | 2189 frame.metadata.frame_token = frame_token3; |
2158 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); | 2190 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
2159 EXPECT_EQ(0u, host_->queued_messages_.size()); | 2191 EXPECT_EQ(0u, host_->queued_messages_.size()); |
2160 EXPECT_EQ(1u, host_->processed_frame_messages_count()); | 2192 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
2161 } | 2193 } |
2162 | 2194 |
2163 } // namespace content | 2195 } // namespace content |
OLD | NEW |