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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } | 422 } |
423 | 423 |
424 // TestView -------------------------------------------------------------------- | 424 // TestView -------------------------------------------------------------------- |
425 | 425 |
426 // This test view allows us to specify the size, and keep track of acked | 426 // This test view allows us to specify the size, and keep track of acked |
427 // touch-events. | 427 // touch-events. |
428 class TestView : public TestRenderWidgetHostView { | 428 class TestView : public TestRenderWidgetHostView { |
429 public: | 429 public: |
430 explicit TestView(RenderWidgetHostImpl* rwh) | 430 explicit TestView(RenderWidgetHostImpl* rwh) |
431 : TestRenderWidgetHostView(rwh), | 431 : TestRenderWidgetHostView(rwh), |
| 432 unhandled_wheel_event_count_(0), |
432 acked_event_count_(0), | 433 acked_event_count_(0), |
433 gesture_event_type_(-1), | 434 gesture_event_type_(-1), |
434 use_fake_physical_backing_size_(false), | 435 use_fake_physical_backing_size_(false), |
435 ack_result_(INPUT_EVENT_ACK_STATE_UNKNOWN) { | 436 ack_result_(INPUT_EVENT_ACK_STATE_UNKNOWN) { |
436 } | 437 } |
437 | 438 |
438 // Sets the bounds returned by GetViewBounds. | 439 // Sets the bounds returned by GetViewBounds. |
439 void set_bounds(const gfx::Rect& bounds) { | 440 void set_bounds(const gfx::Rect& bounds) { |
440 bounds_ = bounds; | 441 bounds_ = bounds; |
441 } | 442 } |
442 | 443 |
443 const WebTouchEvent& acked_event() const { return acked_event_; } | 444 const WebTouchEvent& acked_event() const { return acked_event_; } |
444 int acked_event_count() const { return acked_event_count_; } | 445 int acked_event_count() const { return acked_event_count_; } |
445 void ClearAckedEvent() { | 446 void ClearAckedEvent() { |
446 acked_event_.type = blink::WebInputEvent::Undefined; | 447 acked_event_.type = blink::WebInputEvent::Undefined; |
447 acked_event_count_ = 0; | 448 acked_event_count_ = 0; |
448 } | 449 } |
449 | 450 |
450 const WebMouseWheelEvent& unhandled_wheel_event() const { | 451 const WebMouseWheelEvent& unhandled_wheel_event() const { |
451 return unhandled_wheel_event_; | 452 return unhandled_wheel_event_; |
452 } | 453 } |
| 454 int unhandled_wheel_event_count() const { |
| 455 return unhandled_wheel_event_count_; |
| 456 } |
453 int gesture_event_type() const { return gesture_event_type_; } | 457 int gesture_event_type() const { return gesture_event_type_; } |
454 InputEventAckState ack_result() const { return ack_result_; } | 458 InputEventAckState ack_result() const { return ack_result_; } |
455 | 459 |
456 void SetMockPhysicalBackingSize(const gfx::Size& mock_physical_backing_size) { | 460 void SetMockPhysicalBackingSize(const gfx::Size& mock_physical_backing_size) { |
457 use_fake_physical_backing_size_ = true; | 461 use_fake_physical_backing_size_ = true; |
458 mock_physical_backing_size_ = mock_physical_backing_size; | 462 mock_physical_backing_size_ = mock_physical_backing_size; |
459 } | 463 } |
460 void ClearMockPhysicalBackingSize() { | 464 void ClearMockPhysicalBackingSize() { |
461 use_fake_physical_backing_size_ = false; | 465 use_fake_physical_backing_size_ = false; |
462 } | 466 } |
463 | 467 |
464 // RenderWidgetHostView override. | 468 // RenderWidgetHostView override. |
465 virtual gfx::Rect GetViewBounds() const OVERRIDE { | 469 virtual gfx::Rect GetViewBounds() const OVERRIDE { |
466 return bounds_; | 470 return bounds_; |
467 } | 471 } |
468 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch, | 472 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch, |
469 InputEventAckState ack_result) OVERRIDE { | 473 InputEventAckState ack_result) OVERRIDE { |
470 acked_event_ = touch.event; | 474 acked_event_ = touch.event; |
471 ++acked_event_count_; | 475 ++acked_event_count_; |
472 } | 476 } |
473 virtual void UnhandledWheelEvent(const WebMouseWheelEvent& event) OVERRIDE { | 477 virtual void UnhandledWheelEvent(const WebMouseWheelEvent& event) OVERRIDE { |
| 478 unhandled_wheel_event_count_++; |
474 unhandled_wheel_event_ = event; | 479 unhandled_wheel_event_ = event; |
475 } | 480 } |
476 virtual void GestureEventAck(const WebGestureEvent& event, | 481 virtual void GestureEventAck(const WebGestureEvent& event, |
477 InputEventAckState ack_result) OVERRIDE { | 482 InputEventAckState ack_result) OVERRIDE { |
478 gesture_event_type_ = event.type; | 483 gesture_event_type_ = event.type; |
479 ack_result_ = ack_result; | 484 ack_result_ = ack_result; |
480 } | 485 } |
481 virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE { | 486 virtual gfx::Size GetPhysicalBackingSize() const OVERRIDE { |
482 if (use_fake_physical_backing_size_) | 487 if (use_fake_physical_backing_size_) |
483 return mock_physical_backing_size_; | 488 return mock_physical_backing_size_; |
484 return TestRenderWidgetHostView::GetPhysicalBackingSize(); | 489 return TestRenderWidgetHostView::GetPhysicalBackingSize(); |
485 } | 490 } |
486 | 491 |
487 protected: | 492 protected: |
488 WebMouseWheelEvent unhandled_wheel_event_; | 493 WebMouseWheelEvent unhandled_wheel_event_; |
| 494 int unhandled_wheel_event_count_; |
489 WebTouchEvent acked_event_; | 495 WebTouchEvent acked_event_; |
490 int acked_event_count_; | 496 int acked_event_count_; |
491 int gesture_event_type_; | 497 int gesture_event_type_; |
492 gfx::Rect bounds_; | 498 gfx::Rect bounds_; |
493 bool use_fake_physical_backing_size_; | 499 bool use_fake_physical_backing_size_; |
494 gfx::Size mock_physical_backing_size_; | 500 gfx::Size mock_physical_backing_size_; |
495 InputEventAckState ack_result_; | 501 InputEventAckState ack_result_; |
496 | 502 |
497 DISALLOW_COPY_AND_ASSIGN(TestView); | 503 DISALLOW_COPY_AND_ASSIGN(TestView); |
498 }; | 504 }; |
499 | 505 |
500 // MockRenderWidgetHostDelegate -------------------------------------------- | 506 // MockRenderWidgetHostDelegate -------------------------------------------- |
501 | 507 |
502 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { | 508 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
503 public: | 509 public: |
504 MockRenderWidgetHostDelegate() | 510 MockRenderWidgetHostDelegate() |
505 : prehandle_keyboard_event_(false), | 511 : prehandle_keyboard_event_(false), |
506 prehandle_keyboard_event_called_(false), | 512 prehandle_keyboard_event_called_(false), |
507 prehandle_keyboard_event_type_(WebInputEvent::Undefined), | 513 prehandle_keyboard_event_type_(WebInputEvent::Undefined), |
508 unhandled_keyboard_event_called_(false), | 514 unhandled_keyboard_event_called_(false), |
509 unhandled_keyboard_event_type_(WebInputEvent::Undefined) { | 515 unhandled_keyboard_event_type_(WebInputEvent::Undefined), |
| 516 handle_wheel_event_(false), |
| 517 handle_wheel_event_called_(false) { |
510 } | 518 } |
511 virtual ~MockRenderWidgetHostDelegate() {} | 519 virtual ~MockRenderWidgetHostDelegate() {} |
512 | 520 |
513 // Tests that make sure we ignore keyboard event acknowledgments to events we | 521 // Tests that make sure we ignore keyboard event acknowledgments to events we |
514 // didn't send work by making sure we didn't call UnhandledKeyboardEvent(). | 522 // didn't send work by making sure we didn't call UnhandledKeyboardEvent(). |
515 bool unhandled_keyboard_event_called() const { | 523 bool unhandled_keyboard_event_called() const { |
516 return unhandled_keyboard_event_called_; | 524 return unhandled_keyboard_event_called_; |
517 } | 525 } |
518 | 526 |
519 WebInputEvent::Type unhandled_keyboard_event_type() const { | 527 WebInputEvent::Type unhandled_keyboard_event_type() const { |
520 return unhandled_keyboard_event_type_; | 528 return unhandled_keyboard_event_type_; |
521 } | 529 } |
522 | 530 |
523 bool prehandle_keyboard_event_called() const { | 531 bool prehandle_keyboard_event_called() const { |
524 return prehandle_keyboard_event_called_; | 532 return prehandle_keyboard_event_called_; |
525 } | 533 } |
526 | 534 |
527 WebInputEvent::Type prehandle_keyboard_event_type() const { | 535 WebInputEvent::Type prehandle_keyboard_event_type() const { |
528 return prehandle_keyboard_event_type_; | 536 return prehandle_keyboard_event_type_; |
529 } | 537 } |
530 | 538 |
531 void set_prehandle_keyboard_event(bool handle) { | 539 void set_prehandle_keyboard_event(bool handle) { |
532 prehandle_keyboard_event_ = handle; | 540 prehandle_keyboard_event_ = handle; |
533 } | 541 } |
534 | 542 |
| 543 void set_handle_wheel_event(bool handle) { |
| 544 handle_wheel_event_ = handle; |
| 545 } |
| 546 |
| 547 bool handle_wheel_event_called() { |
| 548 return handle_wheel_event_called_; |
| 549 } |
| 550 |
535 protected: | 551 protected: |
536 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 552 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
537 bool* is_keyboard_shortcut) OVERRIDE { | 553 bool* is_keyboard_shortcut) OVERRIDE { |
538 prehandle_keyboard_event_type_ = event.type; | 554 prehandle_keyboard_event_type_ = event.type; |
539 prehandle_keyboard_event_called_ = true; | 555 prehandle_keyboard_event_called_ = true; |
540 return prehandle_keyboard_event_; | 556 return prehandle_keyboard_event_; |
541 } | 557 } |
542 | 558 |
543 virtual void HandleKeyboardEvent( | 559 virtual void HandleKeyboardEvent( |
544 const NativeWebKeyboardEvent& event) OVERRIDE { | 560 const NativeWebKeyboardEvent& event) OVERRIDE { |
545 unhandled_keyboard_event_type_ = event.type; | 561 unhandled_keyboard_event_type_ = event.type; |
546 unhandled_keyboard_event_called_ = true; | 562 unhandled_keyboard_event_called_ = true; |
547 } | 563 } |
548 | 564 |
| 565 virtual bool HandleWheelEvent( |
| 566 const blink::WebMouseWheelEvent& event) OVERRIDE { |
| 567 handle_wheel_event_called_ = true; |
| 568 return handle_wheel_event_; |
| 569 } |
| 570 |
549 private: | 571 private: |
550 bool prehandle_keyboard_event_; | 572 bool prehandle_keyboard_event_; |
551 bool prehandle_keyboard_event_called_; | 573 bool prehandle_keyboard_event_called_; |
552 WebInputEvent::Type prehandle_keyboard_event_type_; | 574 WebInputEvent::Type prehandle_keyboard_event_type_; |
553 | 575 |
554 bool unhandled_keyboard_event_called_; | 576 bool unhandled_keyboard_event_called_; |
555 WebInputEvent::Type unhandled_keyboard_event_type_; | 577 WebInputEvent::Type unhandled_keyboard_event_type_; |
| 578 |
| 579 bool handle_wheel_event_; |
| 580 bool handle_wheel_event_called_; |
556 }; | 581 }; |
557 | 582 |
558 // RenderWidgetHostTest -------------------------------------------------------- | 583 // RenderWidgetHostTest -------------------------------------------------------- |
559 | 584 |
560 class RenderWidgetHostTest : public testing::Test { | 585 class RenderWidgetHostTest : public testing::Test { |
561 public: | 586 public: |
562 RenderWidgetHostTest() | 587 RenderWidgetHostTest() |
563 : process_(NULL), | 588 : process_(NULL), |
564 handle_key_press_event_(false), | 589 handle_key_press_event_(false), |
565 handle_mouse_event_(false) { | 590 handle_mouse_event_(false) { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 SimulateWheelEvent(-5, 0, 0, true); | 1168 SimulateWheelEvent(-5, 0, 0, true); |
1144 | 1169 |
1145 // Make sure we sent the input event to the renderer. | 1170 // Make sure we sent the input event to the renderer. |
1146 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 1171 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
1147 InputMsg_HandleInputEvent::ID)); | 1172 InputMsg_HandleInputEvent::ID)); |
1148 process_->sink().ClearMessages(); | 1173 process_->sink().ClearMessages(); |
1149 | 1174 |
1150 // Send the simulated response from the renderer back. | 1175 // Send the simulated response from the renderer back. |
1151 SendInputEventACK(WebInputEvent::MouseWheel, | 1176 SendInputEventACK(WebInputEvent::MouseWheel, |
1152 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1177 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1178 EXPECT_TRUE(delegate_->handle_wheel_event_called()); |
| 1179 EXPECT_EQ(1, view_->unhandled_wheel_event_count()); |
1153 EXPECT_EQ(-5, view_->unhandled_wheel_event().deltaX); | 1180 EXPECT_EQ(-5, view_->unhandled_wheel_event().deltaX); |
1154 } | 1181 } |
1155 | 1182 |
| 1183 TEST_F(RenderWidgetHostTest, HandleWheelEvent) { |
| 1184 // Indicate that we're going to handle this wheel event |
| 1185 delegate_->set_handle_wheel_event(true); |
| 1186 |
| 1187 SimulateWheelEvent(-5, 0, 0, true); |
| 1188 |
| 1189 // Make sure we sent the input event to the renderer. |
| 1190 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 1191 InputMsg_HandleInputEvent::ID)); |
| 1192 process_->sink().ClearMessages(); |
| 1193 |
| 1194 // Send the simulated response from the renderer back. |
| 1195 SendInputEventACK(WebInputEvent::MouseWheel, |
| 1196 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1197 |
| 1198 // ensure the wheel event handler was invoked |
| 1199 EXPECT_TRUE(delegate_->handle_wheel_event_called()); |
| 1200 |
| 1201 // and that it suppressed the unhandled wheel event handler. |
| 1202 EXPECT_EQ(0, view_->unhandled_wheel_event_count()); |
| 1203 } |
| 1204 |
1156 TEST_F(RenderWidgetHostTest, UnhandledGestureEvent) { | 1205 TEST_F(RenderWidgetHostTest, UnhandledGestureEvent) { |
1157 SimulateGestureEvent(WebInputEvent::GestureTwoFingerTap, | 1206 SimulateGestureEvent(WebInputEvent::GestureTwoFingerTap, |
1158 WebGestureEvent::Touchscreen); | 1207 WebGestureEvent::Touchscreen); |
1159 | 1208 |
1160 // Make sure we sent the input event to the renderer. | 1209 // Make sure we sent the input event to the renderer. |
1161 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 1210 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
1162 InputMsg_HandleInputEvent::ID)); | 1211 InputMsg_HandleInputEvent::ID)); |
1163 process_->sink().ClearMessages(); | 1212 process_->sink().ClearMessages(); |
1164 | 1213 |
1165 // Send the simulated response from the renderer back. | 1214 // Send the simulated response from the renderer back. |
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2559 | 2608 |
2560 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). | 2609 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). |
2561 PressTouchPoint(0, 1); | 2610 PressTouchPoint(0, 1); |
2562 SendTouchEvent(); | 2611 SendTouchEvent(); |
2563 CheckLatencyInfoComponentInMessage( | 2612 CheckLatencyInfoComponentInMessage( |
2564 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); | 2613 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); |
2565 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 2614 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); |
2566 } | 2615 } |
2567 | 2616 |
2568 } // namespace content | 2617 } // namespace content |
OLD | NEW |