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

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

Issue 2789773003: Send FrameSwapMessageQueue's messages with a separate IPC (Closed)
Patch Set: Fix rebase mistake 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 // Allow poking at a few private members. 176 // Allow poking at a few private members.
177 using RenderWidgetHostImpl::GetResizeParams; 177 using RenderWidgetHostImpl::GetResizeParams;
178 using RenderWidgetHostImpl::OnUpdateRect; 178 using RenderWidgetHostImpl::OnUpdateRect;
179 using RenderWidgetHostImpl::RendererExited; 179 using RenderWidgetHostImpl::RendererExited;
180 using RenderWidgetHostImpl::SetInitialRenderSizeParams; 180 using RenderWidgetHostImpl::SetInitialRenderSizeParams;
181 using RenderWidgetHostImpl::old_resize_params_; 181 using RenderWidgetHostImpl::old_resize_params_;
182 using RenderWidgetHostImpl::is_hidden_; 182 using RenderWidgetHostImpl::is_hidden_;
183 using RenderWidgetHostImpl::resize_ack_pending_; 183 using RenderWidgetHostImpl::resize_ack_pending_;
184 using RenderWidgetHostImpl::input_router_; 184 using RenderWidgetHostImpl::input_router_;
185 using RenderWidgetHostImpl::queued_messages_;
185 186
186 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, 187 void OnTouchEventAck(const TouchEventWithLatencyInfo& event,
187 InputEventAckState ack_result) override { 188 InputEventAckState ack_result) override {
188 // Sniff touch acks. 189 // Sniff touch acks.
189 acked_touch_event_type_ = event.event.type(); 190 acked_touch_event_type_ = event.event.type();
190 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); 191 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result);
191 } 192 }
192 193
193 void reset_new_content_rendering_timeout_fired() { 194 void reset_new_content_rendering_timeout_fired() {
194 new_content_rendering_timeout_fired_ = false; 195 new_content_rendering_timeout_fired_ = false;
(...skipping 13 matching lines...) Expand all
208 } 209 }
209 210
210 void SetupForInputRouterTest() { 211 void SetupForInputRouterTest() {
211 input_router_.reset(new MockInputRouter(this)); 212 input_router_.reset(new MockInputRouter(this));
212 } 213 }
213 214
214 MockInputRouter* mock_input_router() { 215 MockInputRouter* mock_input_router() {
215 return static_cast<MockInputRouter*>(input_router_.get()); 216 return static_cast<MockInputRouter*>(input_router_.get());
216 } 217 }
217 218
219 uint32_t processed_frame_messages_count() {
220 return processed_frame_messages_count_;
221 }
222
218 protected: 223 protected:
219 void NotifyNewContentRenderingTimeoutForTesting() override { 224 void NotifyNewContentRenderingTimeoutForTesting() override {
220 new_content_rendering_timeout_fired_ = true; 225 new_content_rendering_timeout_fired_ = true;
221 } 226 }
222 227
223 bool new_content_rendering_timeout_fired_; 228 bool new_content_rendering_timeout_fired_;
224 WebInputEvent::Type acked_touch_event_type_; 229 WebInputEvent::Type acked_touch_event_type_;
225 230
226 private: 231 private:
232 void ProcessSwapMessages(std::vector<IPC::Message> messages) override {
233 processed_frame_messages_count_++;
234 }
235 uint32_t processed_frame_messages_count_ = 0;
227 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); 236 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost);
228 }; 237 };
229 238
230 namespace { 239 namespace {
231 240
232 cc::CompositorFrame MakeCompositorFrame(float scale_factor, gfx::Size size) { 241 cc::CompositorFrame MakeCompositorFrame(float scale_factor, gfx::Size size) {
233 cc::CompositorFrame frame; 242 cc::CompositorFrame frame;
234 frame.metadata.device_scale_factor = scale_factor; 243 frame.metadata.device_scale_factor = scale_factor;
235 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, true); 244 frame.metadata.begin_frame_ack = cc::BeginFrameAck(0, 1, 1, true);
236 245
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 TEST_F(RenderWidgetHostTest, CompositorFrameSinkIdChanges) { 1938 TEST_F(RenderWidgetHostTest, CompositorFrameSinkIdChanges) {
1930 const gfx::Size frame_size(50, 50); 1939 const gfx::Size frame_size(50, 50);
1931 const cc::LocalSurfaceId local_surface_id(1, 1940 const cc::LocalSurfaceId local_surface_id(1,
1932 base::UnguessableToken::Create()); 1941 base::UnguessableToken::Create());
1933 1942
1934 // Ignore any IPC message sent so far. 1943 // Ignore any IPC message sent so far.
1935 sink_->ClearMessages(); 1944 sink_->ClearMessages();
1936 1945
1937 // Submit a frame with compositor_frame_sink_id=1 1946 // Submit a frame with compositor_frame_sink_id=1
1938 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); 1947 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
1939 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( 1948 host_->OnMessageReceived(
1940 0, 1, local_surface_id, frame, std::vector<IPC::Message>())); 1949 ViewHostMsg_SwapCompositorFrame(0, 1, local_surface_id, frame));
1941 1950
1942 // Send an ack. The right compositor_frame_sink_id must be sent. 1951 // Send an ack. The right compositor_frame_sink_id must be sent.
1943 host_->SendReclaimCompositorResources(true /* is_swap_ack */, 1952 host_->SendReclaimCompositorResources(true /* is_swap_ack */,
1944 cc::ReturnedResourceArray()); 1953 cc::ReturnedResourceArray());
1945 ASSERT_EQ(1u, sink_->message_count()); 1954 ASSERT_EQ(1u, sink_->message_count());
1946 { 1955 {
1947 const IPC::Message* msg = sink_->GetMessageAt(0); 1956 const IPC::Message* msg = sink_->GetMessageAt(0);
1948 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); 1957 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type());
1949 ViewMsg_ReclaimCompositorResources::Param params; 1958 ViewMsg_ReclaimCompositorResources::Param params;
1950 ViewMsg_ReclaimCompositorResources::Read(msg, &params); 1959 ViewMsg_ReclaimCompositorResources::Read(msg, &params);
1951 EXPECT_EQ(1u, std::get<0>(params)); // compositor_frame_sink_id 1960 EXPECT_EQ(1u, std::get<0>(params)); // compositor_frame_sink_id
1952 } 1961 }
1953 sink_->ClearMessages(); 1962 sink_->ClearMessages();
1954 1963
1955 // Submit a frame with compositor_frame_sink_id=2. Verify that view_ is 1964 // Submit a frame with compositor_frame_sink_id=2. Verify that view_ is
1956 // notified of the change in id. 1965 // notified of the change in id.
1957 view_->reset_did_change_compositor_frame_sink(); 1966 view_->reset_did_change_compositor_frame_sink();
1958 frame = MakeCompositorFrame(1.f, frame_size); 1967 frame = MakeCompositorFrame(1.f, frame_size);
1959 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( 1968 host_->OnMessageReceived(
1960 2, 2, local_surface_id, frame, std::vector<IPC::Message>())); 1969 ViewHostMsg_SwapCompositorFrame(2, 2, local_surface_id, frame));
1961 EXPECT_TRUE(view_->did_change_compositor_frame_sink()); 1970 EXPECT_TRUE(view_->did_change_compositor_frame_sink());
1962 1971
1963 // Send an ack. The right compositor_frame_sink_id must be sent. 1972 // Send an ack. The right compositor_frame_sink_id must be sent.
1964 host_->SendReclaimCompositorResources(true /* is_swap_ack */, 1973 host_->SendReclaimCompositorResources(true /* is_swap_ack */,
1965 cc::ReturnedResourceArray()); 1974 cc::ReturnedResourceArray());
1966 ASSERT_EQ(1u, sink_->message_count()); 1975 ASSERT_EQ(1u, sink_->message_count());
1967 { 1976 {
1968 const IPC::Message* msg = sink_->GetMessageAt(0); 1977 const IPC::Message* msg = sink_->GetMessageAt(0);
1969 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); 1978 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type());
1970 ViewMsg_ReclaimCompositorResources::Param params; 1979 ViewMsg_ReclaimCompositorResources::Param params;
1971 ViewMsg_ReclaimCompositorResources::Read(msg, &params); 1980 ViewMsg_ReclaimCompositorResources::Read(msg, &params);
1972 EXPECT_EQ(2u, std::get<0>(params)); // compositor_frame_sink_id 1981 EXPECT_EQ(2u, std::get<0>(params)); // compositor_frame_sink_id
1973 } 1982 }
1974 sink_->ClearMessages(); 1983 sink_->ClearMessages();
1975 } 1984 }
1976 1985
1986 // Check that if messages of a frame arrive earlier than the frame itself, we
1987 // queue the messages until the frame arrives and then process them.
1988 TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) {
1989 const uint32_t frame_token = 99;
1990 const gfx::Size frame_size(50, 50);
1991 const cc::LocalSurfaceId local_surface_id(1,
1992 base::UnguessableToken::Create());
1993 std::vector<IPC::Message> messages;
1994 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
1995
1996 EXPECT_EQ(0u, host_->queued_messages_.size());
1997 EXPECT_EQ(0u, host_->processed_frame_messages_count());
1998
1999 host_->OnMessageReceived(
2000 ViewHostMsg_FrameSwapMessages(0, frame_token, messages));
2001 EXPECT_EQ(1u, host_->queued_messages_.size());
2002 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2003
2004 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2005 frame.metadata.frame_token = frame_token;
2006 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2007 EXPECT_EQ(0u, host_->queued_messages_.size());
2008 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2009 }
2010
2011 // Check that if a frame arrives earlier than its messages, we process the
2012 // messages immedtiately.
2013 TEST_F(RenderWidgetHostTest, FrameToken_FrameThenMessage) {
2014 const uint32_t frame_token = 99;
2015 const gfx::Size frame_size(50, 50);
2016 const cc::LocalSurfaceId local_surface_id(1,
2017 base::UnguessableToken::Create());
2018 std::vector<IPC::Message> messages;
2019 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
2020
2021 EXPECT_EQ(0u, host_->queued_messages_.size());
2022 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2023
2024 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2025 frame.metadata.frame_token = frame_token;
2026 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2027 EXPECT_EQ(0u, host_->queued_messages_.size());
2028 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2029
2030 host_->OnMessageReceived(
2031 ViewHostMsg_FrameSwapMessages(0, frame_token, messages));
2032 EXPECT_EQ(0u, host_->queued_messages_.size());
2033 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2034 }
2035
2036 // Check that if messages of multiple frames arrive before the frames, we
2037 // process each message once it frame arrives.
2038 TEST_F(RenderWidgetHostTest, FrameToken_MultipleMessagesThenTokens) {
2039 const uint32_t frame_token1 = 99;
2040 const uint32_t frame_token2 = 100;
2041 const gfx::Size frame_size(50, 50);
2042 const cc::LocalSurfaceId local_surface_id(1,
2043 base::UnguessableToken::Create());
2044 std::vector<IPC::Message> messages1;
2045 std::vector<IPC::Message> messages2;
2046 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
2047 messages2.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6));
2048
2049 EXPECT_EQ(0u, host_->queued_messages_.size());
2050 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2051
2052 host_->OnMessageReceived(
2053 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1));
2054 EXPECT_EQ(1u, host_->queued_messages_.size());
2055 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2056
2057 host_->OnMessageReceived(
2058 ViewHostMsg_FrameSwapMessages(0, frame_token2, messages2));
2059 EXPECT_EQ(2u, host_->queued_messages_.size());
2060 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2061
2062 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2063 frame.metadata.frame_token = frame_token1;
2064 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2065 EXPECT_EQ(1u, host_->queued_messages_.size());
2066 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2067
2068 frame = MakeCompositorFrame(1.f, frame_size);
2069 frame.metadata.frame_token = frame_token2;
2070 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2071 EXPECT_EQ(0u, host_->queued_messages_.size());
2072 EXPECT_EQ(2u, host_->processed_frame_messages_count());
2073 }
2074
2075 // Check that if multiple frames arrive before their messages, each message is
2076 // processed immediately as soon as it arrives.
2077 TEST_F(RenderWidgetHostTest, FrameToken_MultipleTokensThenMessages) {
2078 const uint32_t frame_token1 = 99;
2079 const uint32_t frame_token2 = 100;
2080 const gfx::Size frame_size(50, 50);
2081 const cc::LocalSurfaceId local_surface_id(1,
2082 base::UnguessableToken::Create());
2083 std::vector<IPC::Message> messages1;
2084 std::vector<IPC::Message> messages2;
2085 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
2086 messages2.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6));
2087
2088 EXPECT_EQ(0u, host_->queued_messages_.size());
2089 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2090
2091 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2092 frame.metadata.frame_token = frame_token1;
2093 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2094 EXPECT_EQ(0u, host_->queued_messages_.size());
2095 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2096
2097 frame = MakeCompositorFrame(1.f, frame_size);
2098 frame.metadata.frame_token = frame_token2;
2099 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2100 EXPECT_EQ(0u, host_->queued_messages_.size());
2101 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2102
2103 host_->OnMessageReceived(
2104 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1));
2105 EXPECT_EQ(0u, host_->queued_messages_.size());
2106 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2107
2108 host_->OnMessageReceived(
2109 ViewHostMsg_FrameSwapMessages(0, frame_token2, messages2));
2110 EXPECT_EQ(0u, host_->queued_messages_.size());
2111 EXPECT_EQ(2u, host_->processed_frame_messages_count());
2112 }
2113
2114 // Check that if one frame is lost but its messages arrive, we process the
2115 // messages on the arrival of the next frame.
2116 TEST_F(RenderWidgetHostTest, FrameToken_DroppedFrame) {
2117 const uint32_t frame_token1 = 99;
2118 const uint32_t frame_token2 = 100;
2119 const gfx::Size frame_size(50, 50);
2120 const cc::LocalSurfaceId local_surface_id(1,
2121 base::UnguessableToken::Create());
2122 std::vector<IPC::Message> messages1;
2123 std::vector<IPC::Message> messages2;
2124 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
2125 messages2.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6));
2126
2127 EXPECT_EQ(0u, host_->queued_messages_.size());
2128 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2129
2130 host_->OnMessageReceived(
2131 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1));
2132 EXPECT_EQ(1u, host_->queued_messages_.size());
2133 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2134
2135 host_->OnMessageReceived(
2136 ViewHostMsg_FrameSwapMessages(0, frame_token2, messages2));
2137 EXPECT_EQ(2u, host_->queued_messages_.size());
2138 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2139
2140 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2141 frame.metadata.frame_token = frame_token2;
2142 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2143 EXPECT_EQ(0u, host_->queued_messages_.size());
2144 EXPECT_EQ(2u, host_->processed_frame_messages_count());
2145 }
2146
2147 // Check that if the renderer crashes, we drop all queued messages and allow
2148 // smaller frame tokens to be sent by the renderer.
2149 TEST_F(RenderWidgetHostTest, FrameToken_RendererCrash) {
2150 const uint32_t frame_token1 = 99;
2151 const uint32_t frame_token2 = 50;
2152 const uint32_t frame_token3 = 30;
2153 const gfx::Size frame_size(50, 50);
2154 const cc::LocalSurfaceId local_surface_id(1,
2155 base::UnguessableToken::Create());
2156 std::vector<IPC::Message> messages1;
2157 std::vector<IPC::Message> messages3;
2158 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
2159 messages3.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6));
2160
2161 // If we don't do this, then RWHI destroys the view in RendererExited and
2162 // then a crash occurs when we attempt to destroy it again in TearDown().
2163 host_->SetView(nullptr);
2164
2165 host_->OnMessageReceived(
2166 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1));
2167 EXPECT_EQ(1u, host_->queued_messages_.size());
2168 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2169
2170 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
2171 EXPECT_EQ(0u, host_->queued_messages_.size());
2172 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2173 host_->Init();
2174
2175 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2176 frame.metadata.frame_token = frame_token2;
2177 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2178 EXPECT_EQ(0u, host_->queued_messages_.size());
2179 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2180
2181 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
2182 EXPECT_EQ(0u, host_->queued_messages_.size());
2183 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2184 host_->Init();
2185
2186 host_->OnMessageReceived(
2187 ViewHostMsg_FrameSwapMessages(0, frame_token3, messages3));
2188 EXPECT_EQ(1u, host_->queued_messages_.size());
2189 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2190
2191 frame = MakeCompositorFrame(1.f, frame_size);
2192 frame.metadata.frame_token = frame_token3;
2193 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2194 EXPECT_EQ(0u, host_->queued_messages_.size());
2195 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2196 }
2197
1977 } // namespace content 2198 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | content/common/view_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698