| 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 "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" | 8 #include "base/location.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 MockRenderWidgetHost(RenderWidgetHostDelegate* delegate, | 132 MockRenderWidgetHost(RenderWidgetHostDelegate* delegate, |
| 133 RenderProcessHost* process, | 133 RenderProcessHost* process, |
| 134 int routing_id) | 134 int routing_id) |
| 135 : RenderWidgetHostImpl( | 135 : RenderWidgetHostImpl( |
| 136 delegate, | 136 delegate, |
| 137 process, | 137 process, |
| 138 routing_id, | 138 routing_id, |
| 139 GpuSurfaceTracker::Get()->AddSurfaceForRenderer(process->GetID(), | 139 GpuSurfaceTracker::Get()->AddSurfaceForRenderer(process->GetID(), |
| 140 routing_id), | 140 routing_id), |
| 141 false), | 141 false), |
| 142 unresponsive_timer_fired_(false) { | 142 unresponsive_timer_fired_(false), |
| 143 new_content_rendering_timeout_fired_(false) { |
| 143 acked_touch_event_type_ = blink::WebInputEvent::Undefined; | 144 acked_touch_event_type_ = blink::WebInputEvent::Undefined; |
| 144 } | 145 } |
| 145 | 146 |
| 146 // Allow poking at a few private members. | 147 // Allow poking at a few private members. |
| 147 using RenderWidgetHostImpl::GetResizeParams; | 148 using RenderWidgetHostImpl::GetResizeParams; |
| 148 using RenderWidgetHostImpl::OnUpdateRect; | 149 using RenderWidgetHostImpl::OnUpdateRect; |
| 149 using RenderWidgetHostImpl::RendererExited; | 150 using RenderWidgetHostImpl::RendererExited; |
| 150 using RenderWidgetHostImpl::SetInitialRenderSizeParams; | 151 using RenderWidgetHostImpl::SetInitialRenderSizeParams; |
| 151 using RenderWidgetHostImpl::old_resize_params_; | 152 using RenderWidgetHostImpl::old_resize_params_; |
| 152 using RenderWidgetHostImpl::is_hidden_; | 153 using RenderWidgetHostImpl::is_hidden_; |
| 153 using RenderWidgetHostImpl::resize_ack_pending_; | 154 using RenderWidgetHostImpl::resize_ack_pending_; |
| 154 using RenderWidgetHostImpl::input_router_; | 155 using RenderWidgetHostImpl::input_router_; |
| 155 | 156 |
| 156 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, | 157 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, |
| 157 InputEventAckState ack_result) override { | 158 InputEventAckState ack_result) override { |
| 158 // Sniff touch acks. | 159 // Sniff touch acks. |
| 159 acked_touch_event_type_ = event.event.type; | 160 acked_touch_event_type_ = event.event.type; |
| 160 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); | 161 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); |
| 161 } | 162 } |
| 162 | 163 |
| 163 bool unresponsive_timer_fired() const { | 164 bool unresponsive_timer_fired() const { |
| 164 return unresponsive_timer_fired_; | 165 return unresponsive_timer_fired_; |
| 165 } | 166 } |
| 166 | 167 |
| 168 bool new_content_rendering_timeout_fired() const { |
| 169 return new_content_rendering_timeout_fired_; |
| 170 } |
| 171 |
| 167 void DisableGestureDebounce() { | 172 void DisableGestureDebounce() { |
| 168 input_router_.reset(new InputRouterImpl( | 173 input_router_.reset(new InputRouterImpl( |
| 169 process_, this, this, routing_id_, InputRouterImpl::Config())); | 174 process_, this, this, routing_id_, InputRouterImpl::Config())); |
| 170 } | 175 } |
| 171 | 176 |
| 172 WebInputEvent::Type acked_touch_event_type() const { | 177 WebInputEvent::Type acked_touch_event_type() const { |
| 173 return acked_touch_event_type_; | 178 return acked_touch_event_type_; |
| 174 } | 179 } |
| 175 | 180 |
| 176 void SetupForInputRouterTest() { | 181 void SetupForInputRouterTest() { |
| 177 input_router_.reset(new MockInputRouter(this)); | 182 input_router_.reset(new MockInputRouter(this)); |
| 178 } | 183 } |
| 179 | 184 |
| 180 MockInputRouter* mock_input_router() { | 185 MockInputRouter* mock_input_router() { |
| 181 return static_cast<MockInputRouter*>(input_router_.get()); | 186 return static_cast<MockInputRouter*>(input_router_.get()); |
| 182 } | 187 } |
| 183 | 188 |
| 184 protected: | 189 protected: |
| 185 void NotifyRendererUnresponsive() override { | 190 void NotifyRendererUnresponsive() override { |
| 186 unresponsive_timer_fired_ = true; | 191 unresponsive_timer_fired_ = true; |
| 187 } | 192 } |
| 188 | 193 |
| 194 void NotifyNewContentRenderingTimeoutForTesting() override { |
| 195 new_content_rendering_timeout_fired_ = true; |
| 196 } |
| 197 |
| 189 bool unresponsive_timer_fired_; | 198 bool unresponsive_timer_fired_; |
| 199 bool new_content_rendering_timeout_fired_; |
| 190 WebInputEvent::Type acked_touch_event_type_; | 200 WebInputEvent::Type acked_touch_event_type_; |
| 191 | 201 |
| 192 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); | 202 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); |
| 193 }; | 203 }; |
| 194 | 204 |
| 195 namespace { | 205 namespace { |
| 196 | 206 |
| 197 // RenderWidgetHostProcess ----------------------------------------------------- | 207 // RenderWidgetHostProcess ----------------------------------------------------- |
| 198 | 208 |
| 199 class RenderWidgetHostProcess : public MockRenderProcessHost { | 209 class RenderWidgetHostProcess : public MockRenderProcessHost { |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 INPUT_EVENT_ACK_STATE_CONSUMED); | 1095 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1086 | 1096 |
| 1087 // Wait long enough for first timeout and see if it fired. | 1097 // Wait long enough for first timeout and see if it fired. |
| 1088 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 1098 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1089 FROM_HERE, base::MessageLoop::QuitClosure(), | 1099 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 1090 TimeDelta::FromMicroseconds(20)); | 1100 TimeDelta::FromMicroseconds(20)); |
| 1091 base::MessageLoop::current()->Run(); | 1101 base::MessageLoop::current()->Run(); |
| 1092 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 1102 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 1093 } | 1103 } |
| 1094 | 1104 |
| 1105 // Test that the rendering timeout for newly loaded content fires |
| 1106 // when enough time passes without receiving a new compositor frame. |
| 1107 TEST_F(RenderWidgetHostTest, NewContentRenderingTimeout) { |
| 1108 host_->set_new_content_rendering_delay_for_testing( |
| 1109 base::TimeDelta::FromMicroseconds(10)); |
| 1110 |
| 1111 // Test immediate start and stop, ensuring that the timeout doesn't fire. |
| 1112 host_->StartNewContentRenderingTimeout(); |
| 1113 host_->StopNewContentRenderingTimeout(); |
| 1114 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1115 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 1116 TimeDelta::FromMicroseconds(20)); |
| 1117 base::MessageLoop::current()->Run(); |
| 1118 |
| 1119 EXPECT_FALSE(host_->new_content_rendering_timeout_fired()); |
| 1120 |
| 1121 // Test with a long delay to ensure that it does fire this time. |
| 1122 host_->StartNewContentRenderingTimeout(); |
| 1123 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1124 FROM_HERE, base::MessageLoop::QuitClosure(), |
| 1125 TimeDelta::FromMicroseconds(20)); |
| 1126 base::MessageLoop::current()->Run(); |
| 1127 EXPECT_TRUE(host_->new_content_rendering_timeout_fired()); |
| 1128 } |
| 1129 |
| 1095 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) { | 1130 std::string GetInputMessageTypes(RenderWidgetHostProcess* process) { |
| 1096 std::string result; | 1131 std::string result; |
| 1097 for (size_t i = 0; i < process->sink().message_count(); ++i) { | 1132 for (size_t i = 0; i < process->sink().message_count(); ++i) { |
| 1098 const IPC::Message *message = process->sink().GetMessageAt(i); | 1133 const IPC::Message *message = process->sink().GetMessageAt(i); |
| 1099 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); | 1134 EXPECT_EQ(InputMsg_HandleInputEvent::ID, message->type()); |
| 1100 InputMsg_HandleInputEvent::Param params; | 1135 InputMsg_HandleInputEvent::Param params; |
| 1101 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); | 1136 EXPECT_TRUE(InputMsg_HandleInputEvent::Read(message, ¶ms)); |
| 1102 const WebInputEvent* event = base::get<0>(params); | 1137 const WebInputEvent* event = base::get<0>(params); |
| 1103 if (i != 0) | 1138 if (i != 0) |
| 1104 result += " "; | 1139 result += " "; |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 // Having an initial size set means that the size information had been sent | 1583 // Having an initial size set means that the size information had been sent |
| 1549 // with the reqiest to new up the RenderView and so subsequent WasResized | 1584 // with the reqiest to new up the RenderView and so subsequent WasResized |
| 1550 // calls should not result in new IPC (unless the size has actually changed). | 1585 // calls should not result in new IPC (unless the size has actually changed). |
| 1551 host_->WasResized(); | 1586 host_->WasResized(); |
| 1552 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); | 1587 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Resize::ID)); |
| 1553 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); | 1588 EXPECT_EQ(initial_size_, host_->old_resize_params_->new_size); |
| 1554 EXPECT_TRUE(host_->resize_ack_pending_); | 1589 EXPECT_TRUE(host_->resize_ack_pending_); |
| 1555 } | 1590 } |
| 1556 | 1591 |
| 1557 } // namespace content | 1592 } // namespace content |
| OLD | NEW |