| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 #endif | 549 #endif |
| 541 #if defined(OS_ANDROID) | 550 #if defined(OS_ANDROID) |
| 542 ui::SetScreenAndroid(); // calls display::Screen::SetScreenInstance(). | 551 ui::SetScreenAndroid(); // calls display::Screen::SetScreenInstance(). |
| 543 #endif | 552 #endif |
| 544 #if defined(USE_AURA) | 553 #if defined(USE_AURA) |
| 545 screen_.reset(aura::TestScreen::Create(gfx::Size())); | 554 screen_.reset(aura::TestScreen::Create(gfx::Size())); |
| 546 display::Screen::SetScreenInstance(screen_.get()); | 555 display::Screen::SetScreenInstance(screen_.get()); |
| 547 #endif | 556 #endif |
| 548 host_.reset(new MockRenderWidgetHost(delegate_.get(), process_, | 557 host_.reset(new MockRenderWidgetHost(delegate_.get(), process_, |
| 549 process_->GetNextRoutingID())); | 558 process_->GetNextRoutingID())); |
| 550 view_.reset(new TestView(host_.get())); | 559 view_ = new TestView(host_.get()); |
| 551 ConfigureView(view_.get()); | 560 ConfigureView(view_); |
| 552 host_->SetView(view_.get()); | 561 host_->SetView(view_); |
| 553 SetInitialRenderSizeParams(); | 562 SetInitialRenderSizeParams(); |
| 554 host_->Init(); | 563 host_->Init(); |
| 555 host_->DisableGestureDebounce(); | 564 host_->DisableGestureDebounce(); |
| 556 } | 565 } |
| 557 | 566 |
| 558 void TearDown() override { | 567 void TearDown() override { |
| 559 view_.reset(); | |
| 560 host_.reset(); | 568 host_.reset(); |
| 561 delegate_.reset(); | 569 delegate_.reset(); |
| 562 process_ = NULL; | 570 process_ = NULL; |
| 563 browser_context_.reset(); | 571 browser_context_.reset(); |
| 564 | 572 |
| 565 #if defined(USE_AURA) | 573 #if defined(USE_AURA) |
| 566 display::Screen::SetScreenInstance(nullptr); | 574 display::Screen::SetScreenInstance(nullptr); |
| 567 screen_.reset(); | 575 screen_.reset(); |
| 568 #endif | 576 #endif |
| 569 #if defined(USE_AURA) || defined(OS_MACOSX) | 577 #if defined(USE_AURA) || defined(OS_MACOSX) |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 int data_length; | 715 int data_length; |
| 708 if (!iter.ReadData(&data, &data_length)) | 716 if (!iter.ReadData(&data, &data_length)) |
| 709 return NULL; | 717 return NULL; |
| 710 return reinterpret_cast<const WebInputEvent*>(data); | 718 return reinterpret_cast<const WebInputEvent*>(data); |
| 711 } | 719 } |
| 712 | 720 |
| 713 std::unique_ptr<TestBrowserContext> browser_context_; | 721 std::unique_ptr<TestBrowserContext> browser_context_; |
| 714 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. | 722 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. |
| 715 std::unique_ptr<MockRenderWidgetHostDelegate> delegate_; | 723 std::unique_ptr<MockRenderWidgetHostDelegate> delegate_; |
| 716 std::unique_ptr<MockRenderWidgetHost> host_; | 724 std::unique_ptr<MockRenderWidgetHost> host_; |
| 717 std::unique_ptr<TestView> view_; | 725 TestView* view_; |
| 718 std::unique_ptr<display::Screen> screen_; | 726 std::unique_ptr<display::Screen> screen_; |
| 719 bool handle_key_press_event_; | 727 bool handle_key_press_event_; |
| 720 bool handle_mouse_event_; | 728 bool handle_mouse_event_; |
| 721 double last_simulated_event_time_seconds_; | 729 double last_simulated_event_time_seconds_; |
| 722 double simulated_event_time_delta_seconds_; | 730 double simulated_event_time_delta_seconds_; |
| 723 IPC::TestSink* sink_; | 731 IPC::TestSink* sink_; |
| 724 | 732 |
| 725 private: | 733 private: |
| 726 SyntheticWebTouchEvent touch_event_; | 734 SyntheticWebTouchEvent touch_event_; |
| 727 | 735 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 | 927 |
| 920 // Simulate a renderer crash before the update message. Ensure all the | 928 // Simulate a renderer crash before the update message. Ensure all the |
| 921 // resize ack logic is cleared. Must clear the view first so it doesn't get | 929 // resize ack logic is cleared. Must clear the view first so it doesn't get |
| 922 // deleted. | 930 // deleted. |
| 923 host_->SetView(NULL); | 931 host_->SetView(NULL); |
| 924 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); | 932 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); |
| 925 EXPECT_FALSE(host_->resize_ack_pending_); | 933 EXPECT_FALSE(host_->resize_ack_pending_); |
| 926 EXPECT_EQ(gfx::Size(), host_->old_resize_params_->new_size); | 934 EXPECT_EQ(gfx::Size(), host_->old_resize_params_->new_size); |
| 927 | 935 |
| 928 // Reset the view so we can exit the test cleanly. | 936 // Reset the view so we can exit the test cleanly. |
| 929 host_->SetView(view_.get()); | 937 host_->SetView(view_); |
| 930 } | 938 } |
| 931 | 939 |
| 932 // Unable to include render_widget_host_view_mac.h and compile. | 940 // Unable to include render_widget_host_view_mac.h and compile. |
| 933 #if !defined(OS_MACOSX) | 941 #if !defined(OS_MACOSX) |
| 934 // Tests setting background transparency. | 942 // Tests setting background transparency. |
| 935 TEST_F(RenderWidgetHostTest, Background) { | 943 TEST_F(RenderWidgetHostTest, Background) { |
| 936 std::unique_ptr<RenderWidgetHostViewBase> view; | 944 std::unique_ptr<RenderWidgetHostViewBase> view; |
| 937 #if defined(USE_AURA) | 945 #if defined(USE_AURA) |
| 938 view.reset(new RenderWidgetHostViewAura(host_.get(), false)); | 946 view.reset(new RenderWidgetHostViewAura(host_.get(), false)); |
| 939 // TODO(derat): Call this on all platforms: http://crbug.com/102450. | 947 // TODO(derat): Call this on all platforms: http://crbug.com/102450. |
| (...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1929 TEST_F(RenderWidgetHostTest, CompositorFrameSinkIdChanges) { | 1937 TEST_F(RenderWidgetHostTest, CompositorFrameSinkIdChanges) { |
| 1930 const gfx::Size frame_size(50, 50); | 1938 const gfx::Size frame_size(50, 50); |
| 1931 const cc::LocalSurfaceId local_surface_id(1, | 1939 const cc::LocalSurfaceId local_surface_id(1, |
| 1932 base::UnguessableToken::Create()); | 1940 base::UnguessableToken::Create()); |
| 1933 | 1941 |
| 1934 // Ignore any IPC message sent so far. | 1942 // Ignore any IPC message sent so far. |
| 1935 sink_->ClearMessages(); | 1943 sink_->ClearMessages(); |
| 1936 | 1944 |
| 1937 // Submit a frame with compositor_frame_sink_id=1 | 1945 // Submit a frame with compositor_frame_sink_id=1 |
| 1938 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); | 1946 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 1939 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( | 1947 host_->OnMessageReceived( |
| 1940 0, 1, local_surface_id, frame, std::vector<IPC::Message>())); | 1948 ViewHostMsg_SwapCompositorFrame(0, 1, local_surface_id, frame)); |
| 1941 | 1949 |
| 1942 // Send an ack. The right compositor_frame_sink_id must be sent. | 1950 // Send an ack. The right compositor_frame_sink_id must be sent. |
| 1943 host_->SendReclaimCompositorResources(true /* is_swap_ack */, | 1951 host_->SendReclaimCompositorResources(true /* is_swap_ack */, |
| 1944 cc::ReturnedResourceArray()); | 1952 cc::ReturnedResourceArray()); |
| 1945 ASSERT_EQ(1u, sink_->message_count()); | 1953 ASSERT_EQ(1u, sink_->message_count()); |
| 1946 { | 1954 { |
| 1947 const IPC::Message* msg = sink_->GetMessageAt(0); | 1955 const IPC::Message* msg = sink_->GetMessageAt(0); |
| 1948 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); | 1956 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); |
| 1949 ViewMsg_ReclaimCompositorResources::Param params; | 1957 ViewMsg_ReclaimCompositorResources::Param params; |
| 1950 ViewMsg_ReclaimCompositorResources::Read(msg, ¶ms); | 1958 ViewMsg_ReclaimCompositorResources::Read(msg, ¶ms); |
| 1951 EXPECT_EQ(1u, std::get<0>(params)); // compositor_frame_sink_id | 1959 EXPECT_EQ(1u, std::get<0>(params)); // compositor_frame_sink_id |
| 1952 } | 1960 } |
| 1953 sink_->ClearMessages(); | 1961 sink_->ClearMessages(); |
| 1954 | 1962 |
| 1955 // Submit a frame with compositor_frame_sink_id=2. Verify that view_ is | 1963 // Submit a frame with compositor_frame_sink_id=2. Verify that view_ is |
| 1956 // notified of the change in id. | 1964 // notified of the change in id. |
| 1957 view_->reset_did_change_compositor_frame_sink(); | 1965 view_->reset_did_change_compositor_frame_sink(); |
| 1958 frame = MakeCompositorFrame(1.f, frame_size); | 1966 frame = MakeCompositorFrame(1.f, frame_size); |
| 1959 host_->OnMessageReceived(ViewHostMsg_SwapCompositorFrame( | 1967 host_->OnMessageReceived( |
| 1960 2, 2, local_surface_id, frame, std::vector<IPC::Message>())); | 1968 ViewHostMsg_SwapCompositorFrame(2, 2, local_surface_id, frame)); |
| 1961 EXPECT_TRUE(view_->did_change_compositor_frame_sink()); | 1969 EXPECT_TRUE(view_->did_change_compositor_frame_sink()); |
| 1962 | 1970 |
| 1963 // Send an ack. The right compositor_frame_sink_id must be sent. | 1971 // Send an ack. The right compositor_frame_sink_id must be sent. |
| 1964 host_->SendReclaimCompositorResources(true /* is_swap_ack */, | 1972 host_->SendReclaimCompositorResources(true /* is_swap_ack */, |
| 1965 cc::ReturnedResourceArray()); | 1973 cc::ReturnedResourceArray()); |
| 1966 ASSERT_EQ(1u, sink_->message_count()); | 1974 ASSERT_EQ(1u, sink_->message_count()); |
| 1967 { | 1975 { |
| 1968 const IPC::Message* msg = sink_->GetMessageAt(0); | 1976 const IPC::Message* msg = sink_->GetMessageAt(0); |
| 1969 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); | 1977 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type()); |
| 1970 ViewMsg_ReclaimCompositorResources::Param params; | 1978 ViewMsg_ReclaimCompositorResources::Param params; |
| 1971 ViewMsg_ReclaimCompositorResources::Read(msg, ¶ms); | 1979 ViewMsg_ReclaimCompositorResources::Read(msg, ¶ms); |
| 1972 EXPECT_EQ(2u, std::get<0>(params)); // compositor_frame_sink_id | 1980 EXPECT_EQ(2u, std::get<0>(params)); // compositor_frame_sink_id |
| 1973 } | 1981 } |
| 1974 sink_->ClearMessages(); | 1982 sink_->ClearMessages(); |
| 1975 } | 1983 } |
| 1976 | 1984 |
| 1985 // Check that if messages of a frame arrive earlier than the frame itself, we |
| 1986 // queue the messages until the frame arrives and then process them. |
| 1987 TEST_F(RenderWidgetHostTest, FrameToken_MessageThenFrame) { |
| 1988 const uint32_t frame_token = 99; |
| 1989 const gfx::Size frame_size(50, 50); |
| 1990 const cc::LocalSurfaceId local_surface_id(1, |
| 1991 base::UnguessableToken::Create()); |
| 1992 std::vector<IPC::Message> messages; |
| 1993 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); |
| 1994 |
| 1995 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 1996 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 1997 |
| 1998 host_->OnMessageReceived( |
| 1999 ViewHostMsg_FrameSwapMessages(0, frame_token, messages)); |
| 2000 EXPECT_EQ(1u, host_->queued_messages_.size()); |
| 2001 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2002 |
| 2003 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 2004 frame.metadata.frame_token = frame_token; |
| 2005 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2006 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2007 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
| 2008 } |
| 2009 |
| 2010 // Check that if a frame arrives earlier than its messages, we process the |
| 2011 // messages immedtiately. |
| 2012 TEST_F(RenderWidgetHostTest, FrameToken_FrameThenMessage) { |
| 2013 const uint32_t frame_token = 99; |
| 2014 const gfx::Size frame_size(50, 50); |
| 2015 const cc::LocalSurfaceId local_surface_id(1, |
| 2016 base::UnguessableToken::Create()); |
| 2017 std::vector<IPC::Message> messages; |
| 2018 messages.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); |
| 2019 |
| 2020 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2021 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2022 |
| 2023 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 2024 frame.metadata.frame_token = frame_token; |
| 2025 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2026 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2027 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2028 |
| 2029 host_->OnMessageReceived( |
| 2030 ViewHostMsg_FrameSwapMessages(0, frame_token, messages)); |
| 2031 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2032 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
| 2033 } |
| 2034 |
| 2035 // Check that if messages of multiple frames arrive before the frames, we |
| 2036 // process each message once it frame arrives. |
| 2037 TEST_F(RenderWidgetHostTest, FrameToken_MultipleMessagesThenTokens) { |
| 2038 const uint32_t frame_token1 = 99; |
| 2039 const uint32_t frame_token2 = 100; |
| 2040 const gfx::Size frame_size(50, 50); |
| 2041 const cc::LocalSurfaceId local_surface_id(1, |
| 2042 base::UnguessableToken::Create()); |
| 2043 std::vector<IPC::Message> messages1; |
| 2044 std::vector<IPC::Message> messages2; |
| 2045 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); |
| 2046 messages2.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6)); |
| 2047 |
| 2048 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2049 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2050 |
| 2051 host_->OnMessageReceived( |
| 2052 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1)); |
| 2053 EXPECT_EQ(1u, host_->queued_messages_.size()); |
| 2054 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2055 |
| 2056 host_->OnMessageReceived( |
| 2057 ViewHostMsg_FrameSwapMessages(0, frame_token2, messages2)); |
| 2058 EXPECT_EQ(2u, host_->queued_messages_.size()); |
| 2059 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2060 |
| 2061 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 2062 frame.metadata.frame_token = frame_token1; |
| 2063 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2064 EXPECT_EQ(1u, host_->queued_messages_.size()); |
| 2065 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
| 2066 |
| 2067 frame = MakeCompositorFrame(1.f, frame_size); |
| 2068 frame.metadata.frame_token = frame_token2; |
| 2069 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2070 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2071 EXPECT_EQ(2u, host_->processed_frame_messages_count()); |
| 2072 } |
| 2073 |
| 2074 // Check that if multiple frames arrive before their messages, each message is |
| 2075 // processed immediately as soon as it arrives. |
| 2076 TEST_F(RenderWidgetHostTest, FrameToken_MultipleTokensThenMessages) { |
| 2077 const uint32_t frame_token1 = 99; |
| 2078 const uint32_t frame_token2 = 100; |
| 2079 const gfx::Size frame_size(50, 50); |
| 2080 const cc::LocalSurfaceId local_surface_id(1, |
| 2081 base::UnguessableToken::Create()); |
| 2082 std::vector<IPC::Message> messages1; |
| 2083 std::vector<IPC::Message> messages2; |
| 2084 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); |
| 2085 messages2.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6)); |
| 2086 |
| 2087 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2088 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2089 |
| 2090 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 2091 frame.metadata.frame_token = frame_token1; |
| 2092 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2093 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2094 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2095 |
| 2096 frame = MakeCompositorFrame(1.f, frame_size); |
| 2097 frame.metadata.frame_token = frame_token2; |
| 2098 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2099 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2100 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2101 |
| 2102 host_->OnMessageReceived( |
| 2103 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1)); |
| 2104 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2105 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
| 2106 |
| 2107 host_->OnMessageReceived( |
| 2108 ViewHostMsg_FrameSwapMessages(0, frame_token2, messages2)); |
| 2109 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2110 EXPECT_EQ(2u, host_->processed_frame_messages_count()); |
| 2111 } |
| 2112 |
| 2113 // Check that if one frame is lost but its messages arrive, we process the |
| 2114 // messages on the arrival of the next frame. |
| 2115 TEST_F(RenderWidgetHostTest, FrameToken_DroppedFrame) { |
| 2116 const uint32_t frame_token1 = 99; |
| 2117 const uint32_t frame_token2 = 100; |
| 2118 const gfx::Size frame_size(50, 50); |
| 2119 const cc::LocalSurfaceId local_surface_id(1, |
| 2120 base::UnguessableToken::Create()); |
| 2121 std::vector<IPC::Message> messages1; |
| 2122 std::vector<IPC::Message> messages2; |
| 2123 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); |
| 2124 messages2.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6)); |
| 2125 |
| 2126 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2127 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2128 |
| 2129 host_->OnMessageReceived( |
| 2130 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1)); |
| 2131 EXPECT_EQ(1u, host_->queued_messages_.size()); |
| 2132 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2133 |
| 2134 host_->OnMessageReceived( |
| 2135 ViewHostMsg_FrameSwapMessages(0, frame_token2, messages2)); |
| 2136 EXPECT_EQ(2u, host_->queued_messages_.size()); |
| 2137 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2138 |
| 2139 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 2140 frame.metadata.frame_token = frame_token2; |
| 2141 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2142 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2143 EXPECT_EQ(2u, host_->processed_frame_messages_count()); |
| 2144 } |
| 2145 |
| 2146 // Check that if the renderer crashes, we process all queued messages and allow |
| 2147 // smaller frame tokens to be sent by the renderer. |
| 2148 TEST_F(RenderWidgetHostTest, FrameToken_RendererCrash) { |
| 2149 const uint32_t frame_token1 = 99; |
| 2150 const uint32_t frame_token2 = 50; |
| 2151 const uint32_t frame_token3 = 30; |
| 2152 const gfx::Size frame_size(50, 50); |
| 2153 const cc::LocalSurfaceId local_surface_id(1, |
| 2154 base::UnguessableToken::Create()); |
| 2155 std::vector<IPC::Message> messages1; |
| 2156 std::vector<IPC::Message> messages3; |
| 2157 messages1.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(5)); |
| 2158 messages3.push_back(ViewHostMsg_DidFirstVisuallyNonEmptyPaint(6)); |
| 2159 |
| 2160 host_->OnMessageReceived( |
| 2161 ViewHostMsg_FrameSwapMessages(0, frame_token1, messages1)); |
| 2162 EXPECT_EQ(1u, host_->queued_messages_.size()); |
| 2163 EXPECT_EQ(0u, host_->processed_frame_messages_count()); |
| 2164 |
| 2165 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); |
| 2166 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2167 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
| 2168 host_->Init(); |
| 2169 |
| 2170 cc::CompositorFrame frame = MakeCompositorFrame(1.f, frame_size); |
| 2171 frame.metadata.frame_token = frame_token2; |
| 2172 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2173 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2174 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
| 2175 |
| 2176 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); |
| 2177 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2178 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
| 2179 host_->Init(); |
| 2180 |
| 2181 host_->OnMessageReceived( |
| 2182 ViewHostMsg_FrameSwapMessages(0, frame_token3, messages3)); |
| 2183 EXPECT_EQ(1u, host_->queued_messages_.size()); |
| 2184 EXPECT_EQ(1u, host_->processed_frame_messages_count()); |
| 2185 |
| 2186 frame = MakeCompositorFrame(1.f, frame_size); |
| 2187 frame.metadata.frame_token = frame_token3; |
| 2188 host_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2189 EXPECT_EQ(0u, host_->queued_messages_.size()); |
| 2190 EXPECT_EQ(2u, host_->processed_frame_messages_count()); |
| 2191 } |
| 2192 |
| 1977 } // namespace content | 2193 } // namespace content |
| OLD | NEW |