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

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

Issue 2774373002: Use MojoCompositorFrameSink in RendererCompositorFrameSink (Closed)
Patch Set: Fixed mac Created 3 years, 8 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 16 matching lines...) Expand all
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
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::MojoCompositorFrameSinkClientPtr client;
572 cc::mojom::MojoCompositorFrameSinkClientRequest client_request =
573 mojo::MakeRequest(&client);
574 renderer_compositor_frame_sink_ =
575 base::MakeUnique<FakeRendererCompositorFrameSink>(
576 std::move(sink), std::move(client_request));
577 host_->RequestMojoCompositorFrameSink(std::move(sink_request),
578 std::move(client));
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
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_;
739 755
740 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); 756 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest);
741 }; 757 };
742 758
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1928 blink::WebGestureDeviceTouchscreen, 1944 blink::WebGestureDeviceTouchscreen,
1929 ui::LatencyInfo()); 1945 ui::LatencyInfo());
1930 1946
1931 1947
1932 // Tests RWHI::ForwardWheelEventWithLatencyInfo(). 1948 // Tests RWHI::ForwardWheelEventWithLatencyInfo().
1933 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo()); 1949 SimulateWheelEventWithLatencyInfo(-5, 0, 0, true, ui::LatencyInfo());
1934 1950
1935 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); 1951 ASSERT_FALSE(host_->input_router()->HasPendingEvents());
1936 } 1952 }
1937 1953
1938 // Checks whether RWHI properly keeps track of the last compositor_frame_sink_id
1939 // and notifies the view_ when it changes.
1940 TEST_F(RenderWidgetHostTest, CompositorFrameSinkIdChanges) {
1941 const gfx::Size frame_size(50, 50);
1942 const cc::LocalSurfaceId local_surface_id(1,
1943 base::UnguessableToken::Create());
1944
1945 // Ignore any IPC message sent so far.
1946 sink_->ClearMessages();
1947
1948 // Submit a frame with compositor_frame_sink_id=1
1949 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
1950 host_->OnMessageReceived(
1951 ViewHostMsg_SwapCompositorFrame(0, 1, local_surface_id, frame));
1952
1953 // Send an ack. The right compositor_frame_sink_id must be sent.
1954 host_->SendReclaimCompositorResources(true /* is_swap_ack */,
1955 cc::ReturnedResourceArray());
1956 ASSERT_EQ(1u, sink_->message_count());
1957 {
1958 const IPC::Message* msg = sink_->GetMessageAt(0);
1959 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type());
1960 ViewMsg_ReclaimCompositorResources::Param params;
1961 ViewMsg_ReclaimCompositorResources::Read(msg, &params);
1962 EXPECT_EQ(1u, std::get<0>(params)); // compositor_frame_sink_id
1963 }
1964 sink_->ClearMessages();
1965
1966 // Submit a frame with compositor_frame_sink_id=2. Verify that view_ is
1967 // notified of the change in id.
1968 view_->reset_did_change_compositor_frame_sink();
1969 frame = MakeCompositorFrame(1.f, frame_size);
1970 host_->OnMessageReceived(
1971 ViewHostMsg_SwapCompositorFrame(2, 2, local_surface_id, frame));
1972 EXPECT_TRUE(view_->did_change_compositor_frame_sink());
1973
1974 // Send an ack. The right compositor_frame_sink_id must be sent.
1975 host_->SendReclaimCompositorResources(true /* is_swap_ack */,
1976 cc::ReturnedResourceArray());
1977 ASSERT_EQ(1u, sink_->message_count());
1978 {
1979 const IPC::Message* msg = sink_->GetMessageAt(0);
1980 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type());
1981 ViewMsg_ReclaimCompositorResources::Param params;
1982 ViewMsg_ReclaimCompositorResources::Read(msg, &params);
1983 EXPECT_EQ(2u, std::get<0>(params)); // compositor_frame_sink_id
1984 }
1985 sink_->ClearMessages();
1986 }
1987
1988 // Check that if messages of a frame arrive earlier than the frame itself, we 1954 // Check that if messages of a frame arrive earlier than the frame itself, we
1989 // queue the messages until the frame arrives and then process them. 1955 // queue the messages until the frame arrives and then process them.
1990 TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) { 1956 TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) {
1991 const uint32_t frame_token = 99; 1957 const uint32_t frame_token = 99;
1992 const gfx::Size frame_size(50, 50); 1958 const gfx::Size frame_size(50, 50);
1993 const cc::LocalSurfaceId local_surface_id(1, 1959 const cc::LocalSurfaceId local_surface_id(1,
1994 base::UnguessableToken::Create()); 1960 base::UnguessableToken::Create());
1995 std::vector<IPC::Message> messages; 1961 std::vector<IPC::Message> messages;
1996 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); 1962 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
1997 1963
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2191 EXPECT_EQ(0u, host_->processed_frame_messages_count()); 2157 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2192 2158
2193 frame = MakeCompositorFrame(1.f, frame_size); 2159 frame = MakeCompositorFrame(1.f, frame_size);
2194 frame.metadata.frame_token = frame_token3; 2160 frame.metadata.frame_token = frame_token3;
2195 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); 2161 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2196 EXPECT_EQ(0u, host_->queued_messages_.size()); 2162 EXPECT_EQ(0u, host_->queued_messages_.size());
2197 EXPECT_EQ(1u, host_->processed_frame_messages_count()); 2163 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2198 } 2164 }
2199 2165
2200 } // namespace content 2166 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698