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

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: c 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 1730 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) {
1987 const uint32_t frame_token = 99;
1988 const gfx::Size frame_size(50, 50);
1989 const cc::LocalSurfaceId local_surface_id(1,
1990 base::UnguessableToken::Create());
1991 std::vector<IPC::Message> messages;
1992 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
1993
1994 EXPECT_EQ(0u, host_->queued_messages_.size());
1995 EXPECT_EQ(0u, host_->processed_frame_messages_count());
1996
1997 host_->OnMessageReceived(
1998 ViewHostMsg_FrameSwapMessages(0, frame_token, messages));
1999 EXPECT_EQ(1u, host_->queued_messages_.size());
2000 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2001
2002 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2003 frame.metadata.frame_token = frame_token;
2004 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2005 EXPECT_EQ(0u, host_->queued_messages_.size());
2006 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2007 }
2008
2009 TEST_F(RenderWidgetHostTest, FrameToken_FrameThenMessage) {
2010 const uint32_t frame_token = 99;
2011 const gfx::Size frame_size(50, 50);
2012 const cc::LocalSurfaceId local_surface_id(1,
2013 base::UnguessableToken::Create());
2014 std::vector<IPC::Message> messages;
2015 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
2016
2017 EXPECT_EQ(0u, host_->queued_messages_.size());
2018 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2019
2020 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2021 frame.metadata.frame_token = frame_token;
2022 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2023 EXPECT_EQ(0u, host_->queued_messages_.size());
2024 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2025
2026 host_->OnMessageReceived(
2027 ViewHostMsg_FrameSwapMessages(0, frame_token, messages));
2028 EXPECT_EQ(0u, host_->queued_messages_.size());
2029 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2030 }
2031
2032 TEST_F(RenderWidgetHostTest, FrameToken_MultipleMessagesThenTokens) {
2033 const uint32_t frame_token1 = 99;
2034 const uint32_t frame_token2 = 100;
2035 const gfx::Size frame_size(50, 50);
2036 const cc::LocalSurfaceId local_surface_id(1,
2037 base::UnguessableToken::Create());
2038 std::vector<IPC::Message> messages1;
2039 std::vector<IPC::Message> messages2;
2040 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
2041 messages2.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6));
2042
2043 EXPECT_EQ(0u, host_->queued_messages_.size());
2044 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2045
2046 host_->OnMessageReceived(
2047 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1));
2048 EXPECT_EQ(1u, host_->queued_messages_.size());
2049 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2050
2051 host_->OnMessageReceived(
2052 ViewHostMsg_FrameSwapMessages(0, frame_token2, messages2));
2053 EXPECT_EQ(2u, host_->queued_messages_.size());
2054 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2055
2056 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2057 frame.metadata.frame_token = frame_token1;
2058 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2059 EXPECT_EQ(1u, host_->queued_messages_.size());
2060 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2061
2062 frame = MakeCompositorFrame(1.f, frame_size);
2063 frame.metadata.frame_token = frame_token2;
2064 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2065 EXPECT_EQ(0u, host_->queued_messages_.size());
2066 EXPECT_EQ(2u, host_->processed_frame_messages_count());
2067 }
2068
2069 TEST_F(RenderWidgetHostTest, FrameToken_MultipleTokensThenMessages) {
2070 const uint32_t frame_token1 = 99;
2071 const uint32_t frame_token2 = 100;
2072 const gfx::Size frame_size(50, 50);
2073 const cc::LocalSurfaceId local_surface_id(1,
2074 base::UnguessableToken::Create());
2075 std::vector<IPC::Message> messages1;
2076 std::vector<IPC::Message> messages2;
2077 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
2078 messages2.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6));
2079
2080 EXPECT_EQ(0u, host_->queued_messages_.size());
2081 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2082
2083 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2084 frame.metadata.frame_token = frame_token1;
2085 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2086 EXPECT_EQ(0u, host_->queued_messages_.size());
2087 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2088
2089 frame = MakeCompositorFrame(1.f, frame_size);
2090 frame.metadata.frame_token = frame_token2;
2091 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2092 EXPECT_EQ(0u, host_->queued_messages_.size());
2093 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2094
2095 host_->OnMessageReceived(
2096 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1));
2097 EXPECT_EQ(0u, host_->queued_messages_.size());
2098 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2099
2100 host_->OnMessageReceived(
2101 ViewHostMsg_FrameSwapMessages(0, frame_token2, messages2));
2102 EXPECT_EQ(0u, host_->queued_messages_.size());
2103 EXPECT_EQ(2u, host_->processed_frame_messages_count());
2104 }
2105
2106 TEST_F(RenderWidgetHostTest, FrameToken_DroppedFrame) {
2107 const uint32_t frame_token1 = 99;
2108 const uint32_t frame_token2 = 100;
2109 const gfx::Size frame_size(50, 50);
2110 const cc::LocalSurfaceId local_surface_id(1,
2111 base::UnguessableToken::Create());
2112 std::vector<IPC::Message> messages1;
2113 std::vector<IPC::Message> messages2;
2114 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5));
2115 messages2.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6));
2116
2117 EXPECT_EQ(0u, host_->queued_messages_.size());
2118 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2119
2120 host_->OnMessageReceived(
2121 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1));
2122 EXPECT_EQ(1u, host_->queued_messages_.size());
2123 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2124
2125 host_->OnMessageReceived(
2126 ViewHostMsg_FrameSwapMessages(0, frame_token2, messages2));
2127 EXPECT_EQ(2u, host_->queued_messages_.size());
2128 EXPECT_EQ(0u, host_->processed_frame_messages_count());
2129
2130 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size);
2131 frame.metadata.frame_token = frame_token2;
2132 host_->SubmitCompositorFrame(local_surface_id, std::move(frame));
2133 EXPECT_EQ(0u, host_->queued_messages_.size());
2134 EXPECT_EQ(1u, host_->processed_frame_messages_count());
2135 }
2136
1977 } // namespace content 2137 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698