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

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

Issue 1170623003: Revert "content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h"
9 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
14 #include "content/browser/browser_thread_impl.h" 11 #include "content/browser/browser_thread_impl.h"
15 #include "content/browser/gpu/compositor_util.h" 12 #include "content/browser/gpu/compositor_util.h"
16 #include "content/browser/renderer_host/input/input_router_impl.h" 13 #include "content/browser/renderer_host/input/input_router_impl.h"
17 #include "content/browser/renderer_host/render_widget_host_delegate.h" 14 #include "content/browser/renderer_host/render_widget_host_delegate.h"
18 #include "content/browser/renderer_host/render_widget_host_view_base.h" 15 #include "content/browser/renderer_host/render_widget_host_view_base.h"
19 #include "content/common/input/synthetic_web_input_event_builders.h" 16 #include "content/common/input/synthetic_web_input_event_builders.h"
20 #include "content/common/input_messages.h" 17 #include "content/common/input_messages.h"
21 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
22 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 // while one is in progress (see crbug.com/11007). 972 // while one is in progress (see crbug.com/11007).
976 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) { 973 TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) {
977 // Start with a short timeout. 974 // Start with a short timeout.
978 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); 975 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10));
979 976
980 // Immediately try to add a long 30 second timeout. 977 // Immediately try to add a long 30 second timeout.
981 EXPECT_FALSE(host_->unresponsive_timer_fired()); 978 EXPECT_FALSE(host_->unresponsive_timer_fired());
982 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30)); 979 host_->StartHangMonitorTimeout(TimeDelta::FromSeconds(30));
983 980
984 // Wait long enough for first timeout and see if it fired. 981 // Wait long enough for first timeout and see if it fired.
985 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 982 base::MessageLoop::current()->PostDelayedTask(
986 FROM_HERE, base::MessageLoop::QuitClosure(), 983 FROM_HERE,
984 base::MessageLoop::QuitClosure(),
987 TimeDelta::FromMilliseconds(10)); 985 TimeDelta::FromMilliseconds(10));
988 base::MessageLoop::current()->Run(); 986 base::MessageLoop::current()->Run();
989 EXPECT_TRUE(host_->unresponsive_timer_fired()); 987 EXPECT_TRUE(host_->unresponsive_timer_fired());
990 } 988 }
991 989
992 // Test that the hang monitor timer expires properly if it is started, stopped, 990 // Test that the hang monitor timer expires properly if it is started, stopped,
993 // and then started again. 991 // and then started again.
994 TEST_F(RenderWidgetHostTest, StopAndStartHangMonitorTimeout) { 992 TEST_F(RenderWidgetHostTest, StopAndStartHangMonitorTimeout) {
995 // Start with a short timeout, then stop it. 993 // Start with a short timeout, then stop it.
996 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); 994 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10));
997 host_->StopHangMonitorTimeout(); 995 host_->StopHangMonitorTimeout();
998 996
999 // Start it again to ensure it still works. 997 // Start it again to ensure it still works.
1000 EXPECT_FALSE(host_->unresponsive_timer_fired()); 998 EXPECT_FALSE(host_->unresponsive_timer_fired());
1001 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); 999 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10));
1002 1000
1003 // Wait long enough for first timeout and see if it fired. 1001 // Wait long enough for first timeout and see if it fired.
1004 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1002 base::MessageLoop::current()->PostDelayedTask(
1005 FROM_HERE, base::MessageLoop::QuitClosure(), 1003 FROM_HERE,
1004 base::MessageLoop::QuitClosure(),
1006 TimeDelta::FromMilliseconds(40)); 1005 TimeDelta::FromMilliseconds(40));
1007 base::MessageLoop::current()->Run(); 1006 base::MessageLoop::current()->Run();
1008 EXPECT_TRUE(host_->unresponsive_timer_fired()); 1007 EXPECT_TRUE(host_->unresponsive_timer_fired());
1009 } 1008 }
1010 1009
1011 // Test that the hang monitor timer expires properly if it is started, then 1010 // Test that the hang monitor timer expires properly if it is started, then
1012 // updated to a shorter duration. 1011 // updated to a shorter duration.
1013 TEST_F(RenderWidgetHostTest, ShorterDelayHangMonitorTimeout) { 1012 TEST_F(RenderWidgetHostTest, ShorterDelayHangMonitorTimeout) {
1014 // Start with a timeout. 1013 // Start with a timeout.
1015 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(100)); 1014 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(100));
1016 1015
1017 // Start it again with shorter delay. 1016 // Start it again with shorter delay.
1018 EXPECT_FALSE(host_->unresponsive_timer_fired()); 1017 EXPECT_FALSE(host_->unresponsive_timer_fired());
1019 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(20)); 1018 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(20));
1020 1019
1021 // Wait long enough for the second timeout and see if it fired. 1020 // Wait long enough for the second timeout and see if it fired.
1022 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1021 base::MessageLoop::current()->PostDelayedTask(
1023 FROM_HERE, base::MessageLoop::QuitClosure(), 1022 FROM_HERE,
1023 base::MessageLoop::QuitClosure(),
1024 TimeDelta::FromMilliseconds(25)); 1024 TimeDelta::FromMilliseconds(25));
1025 base::MessageLoop::current()->Run(); 1025 base::MessageLoop::current()->Run();
1026 EXPECT_TRUE(host_->unresponsive_timer_fired()); 1026 EXPECT_TRUE(host_->unresponsive_timer_fired());
1027 } 1027 }
1028 1028
1029 // Test that the hang monitor timer is effectively disabled when the widget is 1029 // Test that the hang monitor timer is effectively disabled when the widget is
1030 // hidden. 1030 // hidden.
1031 TEST_F(RenderWidgetHostTest, HangMonitorTimeoutDisabledForInputWhenHidden) { 1031 TEST_F(RenderWidgetHostTest, HangMonitorTimeoutDisabledForInputWhenHidden) {
1032 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(1)); 1032 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(1));
1033 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); 1033 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false);
1034 1034
1035 // Hiding the widget should deactivate the timeout. 1035 // Hiding the widget should deactivate the timeout.
1036 host_->WasHidden(); 1036 host_->WasHidden();
1037 1037
1038 // The timeout should not fire. 1038 // The timeout should not fire.
1039 EXPECT_FALSE(host_->unresponsive_timer_fired()); 1039 EXPECT_FALSE(host_->unresponsive_timer_fired());
1040 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1040 base::MessageLoop::current()->PostDelayedTask(
1041 FROM_HERE, base::MessageLoop::QuitClosure(), 1041 FROM_HERE,
1042 base::MessageLoop::QuitClosure(),
1042 TimeDelta::FromMicroseconds(2)); 1043 TimeDelta::FromMicroseconds(2));
1043 base::MessageLoop::current()->Run(); 1044 base::MessageLoop::current()->Run();
1044 EXPECT_FALSE(host_->unresponsive_timer_fired()); 1045 EXPECT_FALSE(host_->unresponsive_timer_fired());
1045 1046
1046 // The timeout should never reactivate while hidden. 1047 // The timeout should never reactivate while hidden.
1047 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false); 1048 SimulateMouseEvent(WebInputEvent::MouseMove, 10, 10, 0, false);
1048 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1049 base::MessageLoop::current()->PostDelayedTask(
1049 FROM_HERE, base::MessageLoop::QuitClosure(), 1050 FROM_HERE,
1051 base::MessageLoop::QuitClosure(),
1050 TimeDelta::FromMicroseconds(2)); 1052 TimeDelta::FromMicroseconds(2));
1051 base::MessageLoop::current()->Run(); 1053 base::MessageLoop::current()->Run();
1052 EXPECT_FALSE(host_->unresponsive_timer_fired()); 1054 EXPECT_FALSE(host_->unresponsive_timer_fired());
1053 1055
1054 // Showing the widget should restore the timeout, as the events have 1056 // Showing the widget should restore the timeout, as the events have
1055 // not yet been ack'ed. 1057 // not yet been ack'ed.
1056 host_->WasShown(ui::LatencyInfo()); 1058 host_->WasShown(ui::LatencyInfo());
1057 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1059 base::MessageLoop::current()->PostDelayedTask(
1058 FROM_HERE, base::MessageLoop::QuitClosure(), 1060 FROM_HERE,
1061 base::MessageLoop::QuitClosure(),
1059 TimeDelta::FromMicroseconds(2)); 1062 TimeDelta::FromMicroseconds(2));
1060 base::MessageLoop::current()->Run(); 1063 base::MessageLoop::current()->Run();
1061 EXPECT_TRUE(host_->unresponsive_timer_fired()); 1064 EXPECT_TRUE(host_->unresponsive_timer_fired());
1062 } 1065 }
1063 1066
1064 // Test that the hang monitor catches two input events but only one ack. 1067 // Test that the hang monitor catches two input events but only one ack.
1065 // This can happen if the second input event causes the renderer to hang. 1068 // This can happen if the second input event causes the renderer to hang.
1066 // This test will catch a regression of crbug.com/111185. 1069 // This test will catch a regression of crbug.com/111185.
1067 TEST_F(RenderWidgetHostTest, MultipleInputEvents) { 1070 TEST_F(RenderWidgetHostTest, MultipleInputEvents) {
1068 // Configure the host to wait 10ms before considering 1071 // Configure the host to wait 10ms before considering
1069 // the renderer hung. 1072 // the renderer hung.
1070 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(10)); 1073 host_->set_hung_renderer_delay(base::TimeDelta::FromMicroseconds(10));
1071 1074
1072 // Send two events but only one ack. 1075 // Send two events but only one ack.
1073 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); 1076 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
1074 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); 1077 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
1075 SendInputEventACK(WebInputEvent::RawKeyDown, 1078 SendInputEventACK(WebInputEvent::RawKeyDown,
1076 INPUT_EVENT_ACK_STATE_CONSUMED); 1079 INPUT_EVENT_ACK_STATE_CONSUMED);
1077 1080
1078 // Wait long enough for first timeout and see if it fired. 1081 // Wait long enough for first timeout and see if it fired.
1079 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1082 base::MessageLoop::current()->PostDelayedTask(
1080 FROM_HERE, base::MessageLoop::QuitClosure(), 1083 FROM_HERE,
1084 base::MessageLoop::QuitClosure(),
1081 TimeDelta::FromMicroseconds(20)); 1085 TimeDelta::FromMicroseconds(20));
1082 base::MessageLoop::current()->Run(); 1086 base::MessageLoop::current()->Run();
1083 EXPECT_TRUE(host_->unresponsive_timer_fired()); 1087 EXPECT_TRUE(host_->unresponsive_timer_fired());
1084 } 1088 }
1085 1089
1086 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) { 1090 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) {
1087 std::string result; 1091 std::string result;
1088 for (size_t i = 0; i < process->sink().message_count(); ++i) { 1092 for (size_t i = 0; i < process->sink().message_count(); ++i) {
1089 const IPC::Message *message = process->sink().GetMessageAt(i); 1093 const IPC::Message *message = process->sink().GetMessageAt(i);
1090 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); 1094 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type());
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 // Having an initial size set means that the size information had been sent 1543 // Having an initial size set means that the size information had been sent
1540 // with the reqiest to new up the RenderView and so subsequent WasResized 1544 // with the reqiest to new up the RenderView and so subsequent WasResized
1541 // calls should not result in new IPC (unless the size has actually changed). 1545 // calls should not result in new IPC (unless the size has actually changed).
1542 host_->WasResized(); 1546 host_->WasResized();
1543 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); 1547 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID));
1544 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); 1548 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size);
1545 EXPECT_TRUE(host_->resize_ack_pending_); 1549 EXPECT_TRUE(host_->resize_ack_pending_);
1546 } 1550 }
1547 1551
1548 } // namespace content 1552 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698