| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/renderer_host/input/gesture_event_filter.h" | 8 #include "content/browser/renderer_host/input/gesture_event_filter.h" |
| 9 #include "content/browser/renderer_host/input/immediate_input_router.h" | 9 #include "content/browser/renderer_host/input/immediate_input_router.h" |
| 10 #include "content/browser/renderer_host/input/input_router_client.h" | 10 #include "content/browser/renderer_host/input/input_router_client.h" |
| 11 #include "content/browser/renderer_host/input/input_router_unittest.h" |
| 12 #include "content/browser/renderer_host/input/mock_input_router_client.h" |
| 11 #include "content/common/content_constants_internal.h" | 13 #include "content/common/content_constants_internal.h" |
| 12 #include "content/common/edit_command.h" | 14 #include "content/common/edit_command.h" |
| 13 #include "content/common/input_messages.h" | 15 #include "content/common/input_messages.h" |
| 14 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
| 15 #include "content/public/test/mock_render_process_host.h" | 17 #include "content/public/test/mock_render_process_host.h" |
| 16 #include "content/public/test/test_browser_context.h" | 18 #include "content/public/test/test_browser_context.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/base/keycodes/keyboard_codes.h" | 20 #include "ui/base/keycodes/keyboard_codes.h" |
| 19 | 21 |
| 20 #if defined(OS_WIN) || defined(USE_AURA) | 22 #if defined(OS_WIN) || defined(USE_AURA) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 if (!equivalent) | 95 if (!equivalent) |
| 94 return false; | 96 return false; |
| 95 } | 97 } |
| 96 | 98 |
| 97 return true; | 99 return true; |
| 98 } | 100 } |
| 99 #endif // defined(OS_WIN) || defined(USE_AURA) | 101 #endif // defined(OS_WIN) || defined(USE_AURA) |
| 100 | 102 |
| 101 } // namespace | 103 } // namespace |
| 102 | 104 |
| 103 class MockInputRouterClient : public InputRouterClient { | 105 class ImmediateInputRouterTest : public InputRouterTest { |
| 104 public: | 106 public: |
| 105 MockInputRouterClient() | 107 ImmediateInputRouterTest() {} |
| 106 : input_router_(NULL), | 108 virtual ~ImmediateInputRouterTest() {} |
| 107 in_flight_event_count_(0), | 109 |
| 108 has_touch_handler_(false), | 110 protected: |
| 109 ack_count_(0), | 111 // InputRouterTest |
| 110 unexpected_event_ack_called_(false), | 112 virtual scoped_ptr<InputRouter> CreateInputRouter(RenderProcessHost* process, |
| 111 ack_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), | 113 InputRouterClient* client, |
| 112 filter_state_(INPUT_EVENT_ACK_STATE_NOT_CONSUMED), | 114 int routing_id) OVERRIDE { |
| 113 is_shortcut_(false), | 115 return scoped_ptr<InputRouter>( |
| 114 allow_send_key_event_(true), | 116 new ImmediateInputRouter(process, client, routing_id)); |
| 115 send_called_(false), | |
| 116 send_immediately_called_(false) { | |
| 117 } | |
| 118 virtual ~MockInputRouterClient() { | |
| 119 } | 117 } |
| 120 | 118 |
| 121 // InputRouterClient | 119 void SendInputEventACK(WebKit::WebInputEvent::Type type, |
| 122 virtual InputEventAckState FilterInputEvent( | |
| 123 const WebInputEvent& input_event, | |
| 124 const ui::LatencyInfo& latency_info) OVERRIDE { | |
| 125 return filter_state_; | |
| 126 } | |
| 127 | |
| 128 // Called each time a WebInputEvent IPC is sent. | |
| 129 virtual void IncrementInFlightEventCount() OVERRIDE { | |
| 130 ++in_flight_event_count_; | |
| 131 } | |
| 132 | |
| 133 // Called each time a WebInputEvent ACK IPC is received. | |
| 134 virtual void DecrementInFlightEventCount() OVERRIDE { | |
| 135 --in_flight_event_count_; | |
| 136 } | |
| 137 | |
| 138 // Called when the renderer notifies that it has touch event handlers. | |
| 139 virtual void OnHasTouchEventHandlers(bool has_handlers) OVERRIDE { | |
| 140 has_touch_handler_ = has_handlers; | |
| 141 } | |
| 142 | |
| 143 virtual bool OnSendKeyboardEvent( | |
| 144 const NativeWebKeyboardEvent& key_event, | |
| 145 const ui::LatencyInfo& latency_info, | |
| 146 bool* is_shortcut) OVERRIDE { | |
| 147 send_called_ = true; | |
| 148 sent_key_event_ = key_event; | |
| 149 *is_shortcut = is_shortcut_; | |
| 150 | |
| 151 return allow_send_key_event_; | |
| 152 } | |
| 153 | |
| 154 virtual bool OnSendWheelEvent( | |
| 155 const MouseWheelEventWithLatencyInfo& wheel_event) OVERRIDE { | |
| 156 send_called_ = true; | |
| 157 sent_wheel_event_ = wheel_event; | |
| 158 | |
| 159 return true; | |
| 160 } | |
| 161 | |
| 162 virtual bool OnSendMouseEvent( | |
| 163 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE { | |
| 164 send_called_ = true; | |
| 165 sent_mouse_event_ = mouse_event; | |
| 166 | |
| 167 return true; | |
| 168 } | |
| 169 | |
| 170 virtual bool OnSendTouchEvent( | |
| 171 const TouchEventWithLatencyInfo& touch_event) OVERRIDE { | |
| 172 send_called_ = true; | |
| 173 sent_touch_event_ = touch_event; | |
| 174 | |
| 175 return true; | |
| 176 } | |
| 177 | |
| 178 virtual bool OnSendGestureEvent( | |
| 179 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE { | |
| 180 send_called_ = true; | |
| 181 sent_gesture_event_ = gesture_event; | |
| 182 | |
| 183 return input_router_->ShouldForwardGestureEvent(gesture_event); | |
| 184 } | |
| 185 | |
| 186 virtual bool OnSendMouseEventImmediately( | |
| 187 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE { | |
| 188 send_immediately_called_ = true; | |
| 189 immediately_sent_mouse_event_ = mouse_event; | |
| 190 | |
| 191 return true; | |
| 192 } | |
| 193 | |
| 194 virtual bool OnSendTouchEventImmediately( | |
| 195 const TouchEventWithLatencyInfo& touch_event) OVERRIDE { | |
| 196 send_immediately_called_ = true; | |
| 197 immediately_sent_touch_event_ = touch_event; | |
| 198 | |
| 199 return true; | |
| 200 } | |
| 201 | |
| 202 virtual bool OnSendGestureEventImmediately( | |
| 203 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE { | |
| 204 send_immediately_called_ = true; | |
| 205 immediately_sent_gesture_event_ = gesture_event; | |
| 206 | |
| 207 return true; | |
| 208 } | |
| 209 | |
| 210 // Called upon event ack receipt from the renderer. | |
| 211 virtual void OnKeyboardEventAck(const NativeWebKeyboardEvent& event, | |
| 212 InputEventAckState ack_result) OVERRIDE { | |
| 213 VLOG(1) << __FUNCTION__ << " called!"; | |
| 214 acked_key_event_ = event; | |
| 215 RecordAckCalled(ack_result); | |
| 216 } | |
| 217 virtual void OnWheelEventAck(const WebMouseWheelEvent& event, | |
| 218 InputEventAckState ack_result) OVERRIDE { | |
| 219 VLOG(1) << __FUNCTION__ << " called!"; | |
| 220 acked_wheel_event_ = event; | |
| 221 RecordAckCalled(ack_result); | |
| 222 } | |
| 223 virtual void OnTouchEventAck(const TouchEventWithLatencyInfo& event, | |
| 224 InputEventAckState ack_result) OVERRIDE { | |
| 225 VLOG(1) << __FUNCTION__ << " called!"; | |
| 226 acked_touch_event_ = event; | |
| 227 RecordAckCalled(ack_result); | |
| 228 } | |
| 229 virtual void OnGestureEventAck(const WebGestureEvent& event, | |
| 230 InputEventAckState ack_result) OVERRIDE { | |
| 231 VLOG(1) << __FUNCTION__ << " called!"; | |
| 232 RecordAckCalled(ack_result); | |
| 233 } | |
| 234 virtual void OnUnexpectedEventAck(bool bad_message) OVERRIDE { | |
| 235 VLOG(1) << __FUNCTION__ << " called!"; | |
| 236 unexpected_event_ack_called_ = true; | |
| 237 } | |
| 238 | |
| 239 void ExpectSendCalled(bool called) { | |
| 240 EXPECT_EQ(called, send_called_); | |
| 241 send_called_ = false; | |
| 242 } | |
| 243 void ExpectSendImmediatelyCalled(bool called) { | |
| 244 EXPECT_EQ(called, send_immediately_called_); | |
| 245 send_immediately_called_ = false; | |
| 246 } | |
| 247 void ExpectAckCalled(int times) { | |
| 248 EXPECT_EQ(times, ack_count_); | |
| 249 ack_count_ = 0; | |
| 250 } | |
| 251 | |
| 252 void set_input_router(InputRouter* input_router) { | |
| 253 input_router_ = input_router; | |
| 254 } | |
| 255 bool has_touch_handler() const { return has_touch_handler_; } | |
| 256 InputEventAckState ack_state() const { return ack_state_; } | |
| 257 void set_filter_state(InputEventAckState filter_state) { | |
| 258 filter_state_ = filter_state; | |
| 259 } | |
| 260 bool unexpected_event_ack_called() const { | |
| 261 return unexpected_event_ack_called_; | |
| 262 } | |
| 263 const NativeWebKeyboardEvent& acked_keyboard_event() { | |
| 264 return acked_key_event_; | |
| 265 } | |
| 266 const WebMouseWheelEvent& acked_wheel_event() { | |
| 267 return acked_wheel_event_; | |
| 268 } | |
| 269 const TouchEventWithLatencyInfo& acked_touch_event() { | |
| 270 return acked_touch_event_; | |
| 271 } | |
| 272 void set_is_shortcut(bool is_shortcut) { | |
| 273 is_shortcut_ = is_shortcut; | |
| 274 } | |
| 275 void set_allow_send_key_event(bool allow) { | |
| 276 allow_send_key_event_ = allow; | |
| 277 } | |
| 278 const NativeWebKeyboardEvent& sent_key_event() { | |
| 279 return sent_key_event_; | |
| 280 } | |
| 281 const MouseWheelEventWithLatencyInfo& sent_wheel_event() { | |
| 282 return sent_wheel_event_; | |
| 283 } | |
| 284 const MouseEventWithLatencyInfo& sent_mouse_event() { | |
| 285 return sent_mouse_event_; | |
| 286 } | |
| 287 const GestureEventWithLatencyInfo& sent_gesture_event() { | |
| 288 return sent_gesture_event_; | |
| 289 } | |
| 290 const MouseEventWithLatencyInfo& immediately_sent_mouse_event() { | |
| 291 return immediately_sent_mouse_event_; | |
| 292 } | |
| 293 const TouchEventWithLatencyInfo& immediately_sent_touch_event() { | |
| 294 return immediately_sent_touch_event_; | |
| 295 } | |
| 296 const GestureEventWithLatencyInfo& immediately_sent_gesture_event() { | |
| 297 return immediately_sent_gesture_event_; | |
| 298 } | |
| 299 | |
| 300 private: | |
| 301 void RecordAckCalled(InputEventAckState ack_result) { | |
| 302 ++ack_count_; | |
| 303 ack_state_ = ack_result; | |
| 304 } | |
| 305 | |
| 306 InputRouter* input_router_; | |
| 307 int in_flight_event_count_; | |
| 308 bool has_touch_handler_; | |
| 309 | |
| 310 int ack_count_; | |
| 311 bool unexpected_event_ack_called_; | |
| 312 InputEventAckState ack_state_; | |
| 313 InputEventAckState filter_state_; | |
| 314 NativeWebKeyboardEvent acked_key_event_; | |
| 315 WebMouseWheelEvent acked_wheel_event_; | |
| 316 TouchEventWithLatencyInfo acked_touch_event_; | |
| 317 | |
| 318 bool is_shortcut_; | |
| 319 bool allow_send_key_event_; | |
| 320 bool send_called_; | |
| 321 NativeWebKeyboardEvent sent_key_event_; | |
| 322 MouseWheelEventWithLatencyInfo sent_wheel_event_; | |
| 323 MouseEventWithLatencyInfo sent_mouse_event_; | |
| 324 TouchEventWithLatencyInfo sent_touch_event_; | |
| 325 GestureEventWithLatencyInfo sent_gesture_event_; | |
| 326 | |
| 327 bool send_immediately_called_; | |
| 328 MouseEventWithLatencyInfo immediately_sent_mouse_event_; | |
| 329 TouchEventWithLatencyInfo immediately_sent_touch_event_; | |
| 330 GestureEventWithLatencyInfo immediately_sent_gesture_event_; | |
| 331 }; | |
| 332 | |
| 333 class ImmediateInputRouterTest : public testing::Test { | |
| 334 public: | |
| 335 ImmediateInputRouterTest() { | |
| 336 } | |
| 337 virtual ~ImmediateInputRouterTest() { | |
| 338 } | |
| 339 | |
| 340 protected: | |
| 341 // testing::Test | |
| 342 virtual void SetUp() { | |
| 343 browser_context_.reset(new TestBrowserContext()); | |
| 344 process_.reset(new MockRenderProcessHost(browser_context_.get())); | |
| 345 client_.reset(new MockInputRouterClient()); | |
| 346 input_router_.reset(new ImmediateInputRouter( | |
| 347 process_.get(), | |
| 348 client_.get(), | |
| 349 MSG_ROUTING_NONE)); | |
| 350 client_->set_input_router(input_router_.get()); | |
| 351 } | |
| 352 virtual void TearDown() { | |
| 353 // Process all pending tasks to avoid leaks. | |
| 354 base::MessageLoop::current()->RunUntilIdle(); | |
| 355 | |
| 356 input_router_.reset(); | |
| 357 client_.reset(); | |
| 358 process_.reset(); | |
| 359 browser_context_.reset(); | |
| 360 } | |
| 361 | |
| 362 void SendInputEventACK(WebInputEvent::Type type, | |
| 363 InputEventAckState ack_result) { | 120 InputEventAckState ack_result) { |
| 364 scoped_ptr<IPC::Message> response( | 121 scoped_ptr<IPC::Message> response( |
| 365 new InputHostMsg_HandleInputEvent_ACK(0, type, ack_result, | 122 new InputHostMsg_HandleInputEvent_ACK(0, type, ack_result, |
| 366 ui::LatencyInfo())); | 123 ui::LatencyInfo())); |
| 367 input_router_->OnMessageReceived(*response); | 124 input_router_->OnMessageReceived(*response); |
| 368 } | 125 } |
| 369 | 126 |
| 370 void SimulateKeyboardEvent(WebInputEvent::Type type) { | 127 ImmediateInputRouter* input_router() const { |
| 371 NativeWebKeyboardEvent key_event; | 128 return static_cast<ImmediateInputRouter*>(input_router_.get()); |
| 372 key_event.type = type; | |
| 373 key_event.windowsKeyCode = ui::VKEY_L; // non-null made up value. | |
| 374 input_router_->SendKeyboardEvent(key_event, ui::LatencyInfo()); | |
| 375 client_->ExpectSendCalled(true); | |
| 376 EXPECT_EQ(type, client_->sent_key_event().type); | |
| 377 EXPECT_EQ(key_event.windowsKeyCode, | |
| 378 client_->sent_key_event().windowsKeyCode); | |
| 379 } | |
| 380 | |
| 381 void SimulateWheelEvent(float dX, float dY, int modifiers, bool precise) { | |
| 382 WebMouseWheelEvent wheel_event; | |
| 383 wheel_event.type = WebInputEvent::MouseWheel; | |
| 384 wheel_event.deltaX = dX; | |
| 385 wheel_event.deltaY = dY; | |
| 386 wheel_event.modifiers = modifiers; | |
| 387 wheel_event.hasPreciseScrollingDeltas = precise; | |
| 388 input_router_->SendWheelEvent( | |
| 389 MouseWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo())); | |
| 390 client_->ExpectSendCalled(true); | |
| 391 EXPECT_EQ(wheel_event.type, client_->sent_wheel_event().event.type); | |
| 392 EXPECT_EQ(dX, client_->sent_wheel_event().event.deltaX); | |
| 393 } | |
| 394 | |
| 395 void SimulateMouseMove(int x, int y, int modifiers) { | |
| 396 WebMouseEvent mouse_event; | |
| 397 mouse_event.type = WebInputEvent::MouseMove; | |
| 398 mouse_event.x = mouse_event.windowX = x; | |
| 399 mouse_event.y = mouse_event.windowY = y; | |
| 400 mouse_event.modifiers = modifiers; | |
| 401 input_router_->SendMouseEvent( | |
| 402 MouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo())); | |
| 403 client_->ExpectSendCalled(true); | |
| 404 client_->ExpectSendImmediatelyCalled(true); | |
| 405 EXPECT_EQ(mouse_event.type, client_->sent_mouse_event().event.type); | |
| 406 EXPECT_EQ(x, client_->sent_mouse_event().event.x); | |
| 407 EXPECT_EQ(mouse_event.type, | |
| 408 client_->immediately_sent_mouse_event().event.type); | |
| 409 EXPECT_EQ(x, client_->immediately_sent_mouse_event().event.x); | |
| 410 } | |
| 411 | |
| 412 void SimulateWheelEventWithPhase(WebMouseWheelEvent::Phase phase) { | |
| 413 WebMouseWheelEvent wheel_event; | |
| 414 wheel_event.type = WebInputEvent::MouseWheel; | |
| 415 wheel_event.phase = phase; | |
| 416 input_router_->SendWheelEvent( | |
| 417 MouseWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo())); | |
| 418 client_->ExpectSendCalled(true); | |
| 419 EXPECT_EQ(wheel_event.type, client_->sent_wheel_event().event.type); | |
| 420 EXPECT_EQ(phase, client_->sent_wheel_event().event.phase); | |
| 421 } | |
| 422 | |
| 423 // Inject provided synthetic WebGestureEvent instance. | |
| 424 void SimulateGestureEventCore(WebInputEvent::Type type, | |
| 425 WebGestureEvent::SourceDevice sourceDevice, | |
| 426 WebGestureEvent* gesture_event) { | |
| 427 gesture_event->type = type; | |
| 428 gesture_event->sourceDevice = sourceDevice; | |
| 429 GestureEventWithLatencyInfo gesture_with_latency( | |
| 430 *gesture_event, ui::LatencyInfo()); | |
| 431 input_router_->SendGestureEvent(gesture_with_latency); | |
| 432 client_->ExpectSendCalled(true); | |
| 433 EXPECT_EQ(type, client_->sent_gesture_event().event.type); | |
| 434 EXPECT_EQ(sourceDevice, client_->sent_gesture_event().event.sourceDevice); | |
| 435 } | |
| 436 | |
| 437 // Inject simple synthetic WebGestureEvent instances. | |
| 438 void SimulateGestureEvent(WebInputEvent::Type type, | |
| 439 WebGestureEvent::SourceDevice sourceDevice) { | |
| 440 WebGestureEvent gesture_event; | |
| 441 SimulateGestureEventCore(type, sourceDevice, &gesture_event); | |
| 442 } | |
| 443 | |
| 444 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) { | |
| 445 WebGestureEvent gesture_event; | |
| 446 gesture_event.data.scrollUpdate.deltaX = dX; | |
| 447 gesture_event.data.scrollUpdate.deltaY = dY; | |
| 448 gesture_event.modifiers = modifiers; | |
| 449 SimulateGestureEventCore(WebInputEvent::GestureScrollUpdate, | |
| 450 WebGestureEvent::Touchscreen, &gesture_event); | |
| 451 } | |
| 452 | |
| 453 void SimulateGesturePinchUpdateEvent(float scale, | |
| 454 float anchorX, | |
| 455 float anchorY, | |
| 456 int modifiers) { | |
| 457 WebGestureEvent gesture_event; | |
| 458 gesture_event.data.pinchUpdate.scale = scale; | |
| 459 gesture_event.x = anchorX; | |
| 460 gesture_event.y = anchorY; | |
| 461 gesture_event.modifiers = modifiers; | |
| 462 SimulateGestureEventCore(WebInputEvent::GesturePinchUpdate, | |
| 463 WebGestureEvent::Touchscreen, &gesture_event); | |
| 464 } | |
| 465 | |
| 466 // Inject synthetic GestureFlingStart events. | |
| 467 void SimulateGestureFlingStartEvent( | |
| 468 float velocityX, | |
| 469 float velocityY, | |
| 470 WebGestureEvent::SourceDevice sourceDevice) { | |
| 471 WebGestureEvent gesture_event; | |
| 472 gesture_event.data.flingStart.velocityX = velocityX; | |
| 473 gesture_event.data.flingStart.velocityY = velocityY; | |
| 474 SimulateGestureEventCore(WebInputEvent::GestureFlingStart, sourceDevice, | |
| 475 &gesture_event); | |
| 476 } | |
| 477 | |
| 478 // Set the timestamp for the touch-event. | |
| 479 void SetTouchTimestamp(base::TimeDelta timestamp) { | |
| 480 touch_event_.timeStampSeconds = timestamp.InSecondsF(); | |
| 481 } | |
| 482 | |
| 483 // Sends a touch event (irrespective of whether the page has a touch-event | |
| 484 // handler or not). | |
| 485 void SendTouchEvent() { | |
| 486 input_router_->SendTouchEvent( | |
| 487 TouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo())); | |
| 488 | |
| 489 // Mark all the points as stationary. And remove the points that have been | |
| 490 // released. | |
| 491 int point = 0; | |
| 492 for (unsigned int i = 0; i < touch_event_.touchesLength; ++i) { | |
| 493 if (touch_event_.touches[i].state == WebTouchPoint::StateReleased) | |
| 494 continue; | |
| 495 | |
| 496 touch_event_.touches[point] = touch_event_.touches[i]; | |
| 497 touch_event_.touches[point].state = | |
| 498 WebTouchPoint::StateStationary; | |
| 499 ++point; | |
| 500 } | |
| 501 touch_event_.touchesLength = point; | |
| 502 touch_event_.type = WebInputEvent::Undefined; | |
| 503 } | |
| 504 | |
| 505 int PressTouchPoint(int x, int y) { | |
| 506 if (touch_event_.touchesLength == touch_event_.touchesLengthCap) | |
| 507 return -1; | |
| 508 WebTouchPoint& point = | |
| 509 touch_event_.touches[touch_event_.touchesLength]; | |
| 510 point.id = touch_event_.touchesLength; | |
| 511 point.position.x = point.screenPosition.x = x; | |
| 512 point.position.y = point.screenPosition.y = y; | |
| 513 point.state = WebTouchPoint::StatePressed; | |
| 514 point.radiusX = point.radiusY = 1.f; | |
| 515 ++touch_event_.touchesLength; | |
| 516 touch_event_.type = WebInputEvent::TouchStart; | |
| 517 return point.id; | |
| 518 } | |
| 519 | |
| 520 void MoveTouchPoint(int index, int x, int y) { | |
| 521 CHECK(index >= 0 && index < touch_event_.touchesLengthCap); | |
| 522 WebTouchPoint& point = touch_event_.touches[index]; | |
| 523 point.position.x = point.screenPosition.x = x; | |
| 524 point.position.y = point.screenPosition.y = y; | |
| 525 touch_event_.touches[index].state = WebTouchPoint::StateMoved; | |
| 526 touch_event_.type = WebInputEvent::TouchMove; | |
| 527 } | |
| 528 | |
| 529 void ReleaseTouchPoint(int index) { | |
| 530 CHECK(index >= 0 && index < touch_event_.touchesLengthCap); | |
| 531 touch_event_.touches[index].state = WebTouchPoint::StateReleased; | |
| 532 touch_event_.type = WebInputEvent::TouchEnd; | |
| 533 } | 129 } |
| 534 | 130 |
| 535 void set_debounce_interval_time_ms(int ms) { | 131 void set_debounce_interval_time_ms(int ms) { |
| 536 input_router_->gesture_event_filter()->debounce_interval_time_ms_ = ms; | 132 input_router()->gesture_event_filter()->debounce_interval_time_ms_ = ms; |
| 537 } | 133 } |
| 538 | 134 |
| 539 void set_maximum_tap_gap_time_ms(int delay_ms) { | 135 void set_maximum_tap_gap_time_ms(int delay_ms) { |
| 540 input_router_->gesture_event_filter()->maximum_tap_gap_time_ms_ = delay_ms; | 136 input_router()->gesture_event_filter()->maximum_tap_gap_time_ms_ = delay_ms; |
| 541 } | 137 } |
| 542 | 138 |
| 543 size_t TouchEventQueueSize() { | 139 size_t TouchEventQueueSize() { |
| 544 return touch_event_queue()->GetQueueSize(); | 140 return touch_event_queue()->GetQueueSize(); |
| 545 } | 141 } |
| 546 | 142 |
| 547 const WebTouchEvent& latest_event() const { | 143 const WebTouchEvent& latest_event() const { |
| 548 return touch_event_queue()->GetLatestEvent().event; | 144 return touch_event_queue()->GetLatestEvent().event; |
| 549 } | 145 } |
| 550 | 146 |
| 551 TouchEventQueue* touch_event_queue() const { | 147 TouchEventQueue* touch_event_queue() const { |
| 552 return input_router_->touch_event_queue(); | 148 return input_router()->touch_event_queue(); |
| 553 } | 149 } |
| 554 | 150 |
| 555 unsigned GestureEventLastQueueEventSize() { | 151 unsigned GestureEventLastQueueEventSize() { |
| 556 return gesture_event_filter()->coalesced_gesture_events_.size(); | 152 return gesture_event_filter()->coalesced_gesture_events_.size(); |
| 557 } | 153 } |
| 558 | 154 |
| 559 WebGestureEvent GestureEventSecondFromLastQueueEvent() { | 155 WebGestureEvent GestureEventSecondFromLastQueueEvent() { |
| 560 return gesture_event_filter()->coalesced_gesture_events_.at( | 156 return gesture_event_filter()->coalesced_gesture_events_.at( |
| 561 GestureEventLastQueueEventSize() - 2).event; | 157 GestureEventLastQueueEventSize() - 2).event; |
| 562 } | 158 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 583 | 179 |
| 584 bool FlingInProgress() { | 180 bool FlingInProgress() { |
| 585 return gesture_event_filter()->fling_in_progress_; | 181 return gesture_event_filter()->fling_in_progress_; |
| 586 } | 182 } |
| 587 | 183 |
| 588 bool WillIgnoreNextACK() { | 184 bool WillIgnoreNextACK() { |
| 589 return gesture_event_filter()->ignore_next_ack_; | 185 return gesture_event_filter()->ignore_next_ack_; |
| 590 } | 186 } |
| 591 | 187 |
| 592 GestureEventFilter* gesture_event_filter() const { | 188 GestureEventFilter* gesture_event_filter() const { |
| 593 return input_router_->gesture_event_filter(); | 189 return input_router()->gesture_event_filter(); |
| 594 } | 190 } |
| 595 | |
| 596 scoped_ptr<MockRenderProcessHost> process_; | |
| 597 scoped_ptr<MockInputRouterClient> client_; | |
| 598 scoped_ptr<ImmediateInputRouter> input_router_; | |
| 599 | |
| 600 private: | |
| 601 base::MessageLoopForUI message_loop_; | |
| 602 WebTouchEvent touch_event_; | |
| 603 | |
| 604 scoped_ptr<TestBrowserContext> browser_context_; | |
| 605 }; | 191 }; |
| 606 | 192 |
| 607 #if GTEST_HAS_PARAM_TEST | 193 #if GTEST_HAS_PARAM_TEST |
| 608 // This is for tests that are to be run for all source devices. | 194 // This is for tests that are to be run for all source devices. |
| 609 class ImmediateInputRouterWithSourceTest | 195 class ImmediateInputRouterWithSourceTest |
| 610 : public ImmediateInputRouterTest, | 196 : public ImmediateInputRouterTest, |
| 611 public testing::WithParamInterface<WebGestureEvent::SourceDevice> { | 197 public testing::WithParamInterface<WebGestureEvent::SourceDevice> { |
| 612 }; | 198 }; |
| 613 #endif // GTEST_HAS_PARAM_TEST | 199 #endif // GTEST_HAS_PARAM_TEST |
| 614 | 200 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 | 284 |
| 699 // OnKeyboardEventAck should be triggered without actual ack. | 285 // OnKeyboardEventAck should be triggered without actual ack. |
| 700 client_->ExpectAckCalled(1); | 286 client_->ExpectAckCalled(1); |
| 701 | 287 |
| 702 // As the event was acked already, keyboard event queue should be | 288 // As the event was acked already, keyboard event queue should be |
| 703 // empty. | 289 // empty. |
| 704 ASSERT_EQ(NULL, input_router_->GetLastKeyboardEvent()); | 290 ASSERT_EQ(NULL, input_router_->GetLastKeyboardEvent()); |
| 705 } | 291 } |
| 706 | 292 |
| 707 TEST_F(ImmediateInputRouterTest, ClientCanceledKeyboardEvent) { | 293 TEST_F(ImmediateInputRouterTest, ClientCanceledKeyboardEvent) { |
| 708 client_->set_allow_send_key_event(false); | 294 client_->set_allow_send_event(false); |
| 709 | 295 |
| 710 // Simulate a keyboard event. | 296 // Simulate a keyboard event. |
| 711 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 297 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 712 | 298 |
| 713 // Make sure no input event is sent to the renderer. | 299 // Make sure no input event is sent to the renderer. |
| 714 EXPECT_EQ(0u, process_->sink().message_count()); | 300 EXPECT_EQ(0u, process_->sink().message_count()); |
| 715 client_->ExpectAckCalled(0); | 301 client_->ExpectAckCalled(0); |
| 716 } | 302 } |
| 717 | 303 |
| 718 TEST_F(ImmediateInputRouterTest, ShortcutKeyboardEvent) { | 304 TEST_F(ImmediateInputRouterTest, ShortcutKeyboardEvent) { |
| (...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2159 EXPECT_EQ(1U, process_->sink().message_count()); | 1745 EXPECT_EQ(1U, process_->sink().message_count()); |
| 2160 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 1746 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 2161 InputMsg_HandleInputEvent::ID)); | 1747 InputMsg_HandleInputEvent::ID)); |
| 2162 process_->sink().ClearMessages(); | 1748 process_->sink().ClearMessages(); |
| 2163 | 1749 |
| 2164 // Check that the correct unhandled wheel event was received. | 1750 // Check that the correct unhandled wheel event was received. |
| 2165 EXPECT_EQ(client_->acked_wheel_event().deltaY, -5); | 1751 EXPECT_EQ(client_->acked_wheel_event().deltaY, -5); |
| 2166 } | 1752 } |
| 2167 | 1753 |
| 2168 } // namespace content | 1754 } // namespace content |
| OLD | NEW |