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

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

Issue 18413004: Fix false positive/negative resize_ack_pending_ in RenderWidgetHostImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 5 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/shared_memory.h" 7 #include "base/shared_memory.h"
8 #include "base/timer/timer.h" 8 #include "base/timer/timer.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/renderer_host/backing_store.h" 10 #include "content/browser/renderer_host/backing_store.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 RenderProcessHost* process, 112 RenderProcessHost* process,
113 int routing_id) 113 int routing_id)
114 : RenderWidgetHostImpl(delegate, process, routing_id), 114 : RenderWidgetHostImpl(delegate, process, routing_id),
115 unresponsive_timer_fired_(false) { 115 unresponsive_timer_fired_(false) {
116 } 116 }
117 117
118 // Allow poking at a few private members. 118 // Allow poking at a few private members.
119 using RenderWidgetHostImpl::OnPaintAtSizeAck; 119 using RenderWidgetHostImpl::OnPaintAtSizeAck;
120 using RenderWidgetHostImpl::OnUpdateRect; 120 using RenderWidgetHostImpl::OnUpdateRect;
121 using RenderWidgetHostImpl::RendererExited; 121 using RenderWidgetHostImpl::RendererExited;
122 using RenderWidgetHostImpl::in_flight_size_; 122 using RenderWidgetHostImpl::last_requested_size_;
123 using RenderWidgetHostImpl::is_hidden_; 123 using RenderWidgetHostImpl::is_hidden_;
124 using RenderWidgetHostImpl::resize_ack_pending_; 124 using RenderWidgetHostImpl::resize_ack_pending_;
125 using RenderWidgetHostImpl::gesture_event_filter_; 125 using RenderWidgetHostImpl::gesture_event_filter_;
126 using RenderWidgetHostImpl::touch_event_queue_; 126 using RenderWidgetHostImpl::touch_event_queue_;
127 using RenderWidgetHostImpl::overscroll_controller_; 127 using RenderWidgetHostImpl::overscroll_controller_;
128 128
129 bool unresponsive_timer_fired() const { 129 bool unresponsive_timer_fired() const {
130 return unresponsive_timer_fired_; 130 return unresponsive_timer_fired_;
131 } 131 }
132 132
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 } // namespace 893 } // namespace
894 894
895 // ----------------------------------------------------------------------------- 895 // -----------------------------------------------------------------------------
896 896
897 TEST_F(RenderWidgetHostTest, Resize) { 897 TEST_F(RenderWidgetHostTest, Resize) {
898 // The initial bounds is the empty rect, so setting it to the same thing 898 // The initial bounds is the empty rect, so setting it to the same thing
899 // should do nothing. 899 // should do nothing.
900 view_->set_bounds(gfx::Rect()); 900 view_->set_bounds(gfx::Rect());
901 host_->WasResized(); 901 host_->WasResized();
902 EXPECT_FALSE(host_->resize_ack_pending_); 902 EXPECT_FALSE(host_->resize_ack_pending_);
903 EXPECT_EQ(gfx::Size(), host_->in_flight_size_); 903 EXPECT_EQ(gfx::Size(), host_->last_requested_size_);
904 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 904 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
905 905
906 // Setting the bounds to a "real" rect should send out the notification, 906 // Setting the bounds to a "real" rect should send out the notification.
907 // but should not expect ack for empty physical backing size. 907 // but should not expect ack for empty physical backing size.
908 gfx::Rect original_size(0, 0, 100, 100); 908 gfx::Rect original_size(0, 0, 100, 100);
909 process_->sink().ClearMessages(); 909 process_->sink().ClearMessages();
910 view_->set_bounds(original_size); 910 view_->set_bounds(original_size);
911 view_->SetMockPhysicalBackingSize(gfx::Size()); 911 view_->SetMockPhysicalBackingSize(gfx::Size());
912 host_->WasResized(); 912 host_->WasResized();
913 EXPECT_FALSE(host_->resize_ack_pending_); 913 EXPECT_FALSE(host_->resize_ack_pending_);
914 EXPECT_EQ(original_size.size(), host_->in_flight_size_); 914 EXPECT_EQ(original_size.size(), host_->last_requested_size_);
915 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 915 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
916 916
917 // Setting the bounds to a "real" rect should send out the notification. 917 // Setting the bounds to a "real" rect should send out the notification.
918 // but should not expect ack for only physical backing size change.
918 process_->sink().ClearMessages(); 919 process_->sink().ClearMessages();
919 view_->ClearMockPhysicalBackingSize(); 920 view_->ClearMockPhysicalBackingSize();
920 host_->WasResized(); 921 host_->WasResized();
921 EXPECT_TRUE(host_->resize_ack_pending_); 922 EXPECT_FALSE(host_->resize_ack_pending_);
922 EXPECT_EQ(original_size.size(), host_->in_flight_size_); 923 EXPECT_EQ(original_size.size(), host_->last_requested_size_);
923 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 924 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
924 925
925 // Send out a update that's not a resize ack. This should not clean the 926 // Send out a update that's not a resize ack after setting resize ack pending
926 // resize ack pending flag. 927 // flag. This should not clean the resize ack pending flag.
928 process_->sink().ClearMessages();
929 gfx::Rect second_size(0, 0, 110, 110);
930 EXPECT_FALSE(host_->resize_ack_pending_);
931 view_->set_bounds(second_size);
932 host_->WasResized();
933 EXPECT_TRUE(host_->resize_ack_pending_);
927 ViewHostMsg_UpdateRect_Params params; 934 ViewHostMsg_UpdateRect_Params params;
928 process_->InitUpdateRectParams(&params); 935 process_->InitUpdateRectParams(&params);
929 host_->OnUpdateRect(params); 936 host_->OnUpdateRect(params);
930 EXPECT_TRUE(host_->resize_ack_pending_); 937 EXPECT_TRUE(host_->resize_ack_pending_);
931 EXPECT_EQ(original_size.size(), host_->in_flight_size_); 938 EXPECT_EQ(second_size.size(), host_->last_requested_size_);
932 939
933 // Sending out a new notification should NOT send out a new IPC message since 940 // Sending out a new notification should NOT send out a new IPC message since
934 // a resize ACK is pending. 941 // a resize ACK is pending.
935 gfx::Rect second_size(0, 0, 90, 90); 942 gfx::Rect third_size(0, 0, 120, 120);
936 process_->sink().ClearMessages(); 943 process_->sink().ClearMessages();
937 view_->set_bounds(second_size); 944 view_->set_bounds(third_size);
938 host_->WasResized(); 945 host_->WasResized();
939 EXPECT_TRUE(host_->resize_ack_pending_); 946 EXPECT_TRUE(host_->resize_ack_pending_);
940 EXPECT_EQ(original_size.size(), host_->in_flight_size_); 947 EXPECT_EQ(second_size.size(), host_->last_requested_size_);
941 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 948 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
942 949
943 // Send a update that's a resize ack, but for the original_size we sent. Since 950 // Send a update that's a resize ack, but for the original_size we sent. Since
944 // this isn't the second_size, the message handler should immediately send 951 // this isn't the second_size, the message handler should immediately send
945 // a new resize message for the new size to the renderer. 952 // a new resize message for the new size to the renderer.
946 process_->sink().ClearMessages(); 953 process_->sink().ClearMessages();
947 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; 954 params.flags = ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
948 params.view_size = original_size.size(); 955 params.view_size = original_size.size();
949 host_->OnUpdateRect(params); 956 host_->OnUpdateRect(params);
950 EXPECT_TRUE(host_->resize_ack_pending_); 957 EXPECT_TRUE(host_->resize_ack_pending_);
951 EXPECT_EQ(second_size.size(), host_->in_flight_size_); 958 EXPECT_EQ(third_size.size(), host_->last_requested_size_);
952 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 959 ASSERT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
953 960
954 // Send the resize ack for the latest size. 961 // Send the resize ack for the latest size.
955 process_->sink().ClearMessages(); 962 process_->sink().ClearMessages();
956 params.view_size = second_size.size(); 963 params.view_size = third_size.size();
957 host_->OnUpdateRect(params); 964 host_->OnUpdateRect(params);
958 EXPECT_FALSE(host_->resize_ack_pending_); 965 EXPECT_FALSE(host_->resize_ack_pending_);
959 EXPECT_EQ(gfx::Size(), host_->in_flight_size_); 966 EXPECT_EQ(third_size.size(), host_->last_requested_size_);
960 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); 967 ASSERT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID));
961 968
962 // Now clearing the bounds should send out a notification but we shouldn't 969 // Now clearing the bounds should send out a notification but we shouldn't
963 // expect a resize ack (since the renderer won't ack empty sizes). The message 970 // expect a resize ack (since the renderer won't ack empty sizes). The message
964 // should contain the new size (0x0) and not the previous one that we skipped 971 // should contain the new size (0x0) and not the previous one that we skipped
965 process_->sink().ClearMessages(); 972 process_->sink().ClearMessages();
966 view_->set_bounds(gfx::Rect()); 973 view_->set_bounds(gfx::Rect());
967 host_->WasResized(); 974 host_->WasResized();
968 EXPECT_FALSE(host_->resize_ack_pending_); 975 EXPECT_FALSE(host_->resize_ack_pending_);
969 EXPECT_EQ(gfx::Size(), host_->in_flight_size_); 976 EXPECT_EQ(gfx::Size(), host_->last_requested_size_);
970 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 977 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
971 978
972 // Send a rect that has no area but has either width or height set. 979 // Send a rect that has no area but has either width or height set.
973 process_->sink().ClearMessages(); 980 process_->sink().ClearMessages();
974 view_->set_bounds(gfx::Rect(0, 0, 0, 30)); 981 view_->set_bounds(gfx::Rect(0, 0, 0, 30));
975 host_->WasResized(); 982 host_->WasResized();
976 EXPECT_FALSE(host_->resize_ack_pending_); 983 EXPECT_FALSE(host_->resize_ack_pending_);
977 EXPECT_EQ(gfx::Size(0, 30), host_->in_flight_size_); 984 EXPECT_EQ(gfx::Size(0, 30), host_->last_requested_size_);
978 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 985 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
979 986
980 // Set the same size again. It should not be sent again. 987 // Set the same size again. It should not be sent again.
981 process_->sink().ClearMessages(); 988 process_->sink().ClearMessages();
982 host_->WasResized(); 989 host_->WasResized();
983 EXPECT_FALSE(host_->resize_ack_pending_); 990 EXPECT_FALSE(host_->resize_ack_pending_);
984 EXPECT_EQ(gfx::Size(0, 30), host_->in_flight_size_); 991 EXPECT_EQ(gfx::Size(0, 30), host_->last_requested_size_);
985 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID)); 992 EXPECT_FALSE(process_->sink().GetFirstMessageMatching(ViewMsg_Resize::ID));
986 993
987 // A different size should be sent again, however. 994 // A different size should be sent again, however.
988 view_->set_bounds(gfx::Rect(0, 0, 0, 31)); 995 view_->set_bounds(gfx::Rect(0, 0, 0, 31));
989 host_->WasResized(); 996 host_->WasResized();
990 EXPECT_FALSE(host_->resize_ack_pending_); 997 EXPECT_FALSE(host_->resize_ack_pending_);
991 EXPECT_EQ(gfx::Size(0, 31), host_->in_flight_size_); 998 EXPECT_EQ(gfx::Size(0, 31), host_->last_requested_size_);
992 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 999 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
993 } 1000 }
994 1001
995 // Test for crbug.com/25097. If a renderer crashes between a resize and the 1002 // Test for crbug.com/25097. If a renderer crashes between a resize and the
996 // corresponding update message, we must be sure to clear the resize ack logic. 1003 // corresponding update message, we must be sure to clear the resize ack logic.
997 TEST_F(RenderWidgetHostTest, ResizeThenCrash) { 1004 TEST_F(RenderWidgetHostTest, ResizeThenCrash) {
998 // Setting the bounds to a "real" rect should send out the notification. 1005 // Setting the bounds to a "real" rect should send out the notification.
999 gfx::Rect original_size(0, 0, 100, 100); 1006 gfx::Rect original_size(0, 0, 100, 100);
1000 view_->set_bounds(original_size); 1007 view_->set_bounds(original_size);
1001 host_->WasResized(); 1008 host_->WasResized();
1002 EXPECT_TRUE(host_->resize_ack_pending_); 1009 EXPECT_TRUE(host_->resize_ack_pending_);
1003 EXPECT_EQ(original_size.size(), host_->in_flight_size_); 1010 EXPECT_EQ(original_size.size(), host_->last_requested_size_);
1004 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 1011 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
1005 1012
1006 // Simulate a renderer crash before the update message. Ensure all the 1013 // Simulate a renderer crash before the update message. Ensure all the
1007 // resize ack logic is cleared. Must clear the view first so it doesn't get 1014 // resize ack logic is cleared. Must clear the view first so it doesn't get
1008 // deleted. 1015 // deleted.
1009 host_->SetView(NULL); 1016 host_->SetView(NULL);
1010 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); 1017 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
1011 EXPECT_FALSE(host_->resize_ack_pending_); 1018 EXPECT_FALSE(host_->resize_ack_pending_);
1012 EXPECT_EQ(gfx::Size(), host_->in_flight_size_); 1019 EXPECT_EQ(gfx::Size(), host_->last_requested_size_);
1013 1020
1014 // Reset the view so we can exit the test cleanly. 1021 // Reset the view so we can exit the test cleanly.
1015 host_->SetView(view_.get()); 1022 host_->SetView(view_.get());
1016 } 1023 }
1017 1024
1018 // Tests setting custom background 1025 // Tests setting custom background
1019 TEST_F(RenderWidgetHostTest, Background) { 1026 TEST_F(RenderWidgetHostTest, Background) {
1020 #if !defined(OS_MACOSX) 1027 #if !defined(OS_MACOSX)
1021 scoped_ptr<RenderWidgetHostView> view( 1028 scoped_ptr<RenderWidgetHostView> view(
1022 RenderWidgetHostView::CreateViewForWidget(host_.get())); 1029 RenderWidgetHostView::CreateViewForWidget(host_.get()));
(...skipping 3206 matching lines...) Expand 10 before | Expand all | Expand 10 after
4229 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode()); 4236 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->completed_mode());
4230 4237
4231 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, 4238 SimulateGestureEvent(WebInputEvent::GestureScrollEnd,
4232 WebGestureEvent::Touchscreen); 4239 WebGestureEvent::Touchscreen);
4233 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode()); 4240 EXPECT_EQ(OVERSCROLL_NONE, host_->overscroll_delegate()->current_mode());
4234 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode()); 4241 EXPECT_EQ(OVERSCROLL_EAST, host_->overscroll_delegate()->completed_mode());
4235 process_->sink().ClearMessages(); 4242 process_->sink().ClearMessages();
4236 } 4243 }
4237 4244
4238 } // namespace content 4245 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698