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

Side by Side Diff: content/browser/renderer_host/input/input_router_impl_unittest.cc

Issue 132083006: Delegate touch handler registration logic to the TouchEventQueue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment cleanup Created 6 years, 11 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 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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/renderer_host/input/gesture_event_filter.h" 9 #include "content/browser/renderer_host/input/gesture_event_filter.h"
10 #include "content/browser/renderer_host/input/input_router_client.h" 10 #include "content/browser/renderer_host/input/input_router_client.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 262 }
263 263
264 bool TouchEventQueueEmpty() const { 264 bool TouchEventQueueEmpty() const {
265 return input_router()->touch_event_queue_->empty(); 265 return input_router()->touch_event_queue_->empty();
266 } 266 }
267 267
268 bool TouchEventTimeoutEnabled() const { 268 bool TouchEventTimeoutEnabled() const {
269 return input_router()->touch_event_queue_->ack_timeout_enabled(); 269 return input_router()->touch_event_queue_->ack_timeout_enabled();
270 } 270 }
271 271
272 void OnHasTouchEventHandlers(bool has_handlers) {
273 input_router_->OnMessageReceived(
274 ViewHostMsg_HasTouchEventHandlers(0, has_handlers));
275 }
276
272 size_t GetSentMessageCountAndResetSink() { 277 size_t GetSentMessageCountAndResetSink() {
273 size_t count = process_->sink().message_count(); 278 size_t count = process_->sink().message_count();
274 process_->sink().ClearMessages(); 279 process_->sink().ClearMessages();
275 return count; 280 return count;
276 } 281 }
277 282
278 scoped_ptr<MockRenderProcessHost> process_; 283 scoped_ptr<MockRenderProcessHost> process_;
279 scoped_ptr<MockInputRouterClient> client_; 284 scoped_ptr<MockInputRouterClient> client_;
280 scoped_ptr<MockInputAckHandler> ack_handler_; 285 scoped_ptr<MockInputAckHandler> ack_handler_;
281 scoped_ptr<InputRouterImpl> input_router_; 286 scoped_ptr<InputRouterImpl> input_router_;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 ASSERT_EQ(WebMouseWheelEvent::PhaseEnded, wheel_event->phase); 527 ASSERT_EQ(WebMouseWheelEvent::PhaseEnded, wheel_event->phase);
523 528
524 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(1)); 529 input_event = GetInputEventFromMessage(*process_->sink().GetMessageAt(1));
525 EXPECT_EQ(WebInputEvent::GestureScrollEnd, input_event->type); 530 EXPECT_EQ(WebInputEvent::GestureScrollEnd, input_event->type);
526 531
527 ASSERT_EQ(2U, GetSentMessageCountAndResetSink()); 532 ASSERT_EQ(2U, GetSentMessageCountAndResetSink());
528 } 533 }
529 534
530 // Tests that touch-events are queued properly. 535 // Tests that touch-events are queued properly.
531 TEST_F(InputRouterImplTest, TouchEventQueue) { 536 TEST_F(InputRouterImplTest, TouchEventQueue) {
537 OnHasTouchEventHandlers(true);
538
532 PressTouchPoint(1, 1); 539 PressTouchPoint(1, 1);
533 SendTouchEvent(); 540 SendTouchEvent();
534 EXPECT_TRUE(client_->GetAndResetFilterEventCalled()); 541 EXPECT_TRUE(client_->GetAndResetFilterEventCalled());
535 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 542 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
536 EXPECT_FALSE(TouchEventQueueEmpty()); 543 EXPECT_FALSE(TouchEventQueueEmpty());
537 544
538 // The second touch should not be sent since one is already in queue. 545 // The second touch should not be sent since one is already in queue.
539 MoveTouchPoint(0, 5, 5); 546 MoveTouchPoint(0, 5, 5);
540 SendTouchEvent(); 547 SendTouchEvent();
541 EXPECT_FALSE(client_->GetAndResetFilterEventCalled()); 548 EXPECT_FALSE(client_->GetAndResetFilterEventCalled());
(...skipping 14 matching lines...) Expand all
556 EXPECT_TRUE(TouchEventQueueEmpty()); 563 EXPECT_TRUE(TouchEventQueueEmpty());
557 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 564 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
558 EXPECT_EQ(WebInputEvent::TouchMove, 565 EXPECT_EQ(WebInputEvent::TouchMove,
559 ack_handler_->acked_touch_event().event.type); 566 ack_handler_->acked_touch_event().event.type);
560 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 567 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
561 } 568 }
562 569
563 // Tests that the touch-queue is emptied if a page stops listening for touch 570 // Tests that the touch-queue is emptied if a page stops listening for touch
564 // events. 571 // events.
565 TEST_F(InputRouterImplTest, TouchEventQueueFlush) { 572 TEST_F(InputRouterImplTest, TouchEventQueueFlush) {
566 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 573 OnHasTouchEventHandlers(true);
567 EXPECT_TRUE(client_->has_touch_handler()); 574 EXPECT_TRUE(client_->has_touch_handler());
568 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 575 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
569 EXPECT_TRUE(TouchEventQueueEmpty()); 576 EXPECT_TRUE(TouchEventQueueEmpty());
570 577
571 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent()); 578 EXPECT_TRUE(input_router_->ShouldForwardTouchEvent());
572 579
573 // Send a touch-press event. 580 // Send a touch-press event.
574 PressTouchPoint(1, 1); 581 PressTouchPoint(1, 1);
575 SendTouchEvent(); 582 SendTouchEvent();
576 EXPECT_FALSE(TouchEventQueueEmpty()); 583 EXPECT_FALSE(TouchEventQueueEmpty());
577 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 584 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
578 585
579 // The page stops listening for touch-events. The touch-event queue should now 586 // The page stops listening for touch-events. The touch-event queue should now
580 // be emptied, but none of the queued touch-events should be sent to the 587 // be emptied, but none of the queued touch-events should be sent to the
581 // renderer. 588 // renderer.
582 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false)); 589 OnHasTouchEventHandlers(false);
583 EXPECT_FALSE(client_->has_touch_handler()); 590 EXPECT_FALSE(client_->has_touch_handler());
584 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 591 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
585 EXPECT_TRUE(TouchEventQueueEmpty()); 592 EXPECT_TRUE(TouchEventQueueEmpty());
586 EXPECT_FALSE(input_router_->ShouldForwardTouchEvent()); 593 EXPECT_FALSE(input_router_->ShouldForwardTouchEvent());
587 } 594 }
588 595
589 #if defined(OS_WIN) || defined(USE_AURA) 596 #if defined(OS_WIN) || defined(USE_AURA)
590 // Tests that the acked events have correct state. (ui::Events are used only on 597 // Tests that the acked events have correct state. (ui::Events are used only on
591 // windows and aura) 598 // windows and aura)
592 TEST_F(InputRouterImplTest, AckedTouchEventState) { 599 TEST_F(InputRouterImplTest, AckedTouchEventState) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 // Check that the second event was sent. 702 // Check that the second event was sent.
696 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 703 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
697 InputMsg_HandleInputEvent::ID)); 704 InputMsg_HandleInputEvent::ID));
698 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 705 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
699 706
700 // Check that the correct unhandled wheel event was received. 707 // Check that the correct unhandled wheel event was received.
701 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); 708 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5);
702 } 709 }
703 710
704 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { 711 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) {
712 OnHasTouchEventHandlers(true);
713
705 int start_type = static_cast<int>(WebInputEvent::TouchStart); 714 int start_type = static_cast<int>(WebInputEvent::TouchStart);
706 int end_type = static_cast<int>(WebInputEvent::TouchCancel); 715 int end_type = static_cast<int>(WebInputEvent::TouchCancel);
707 ASSERT_LT(start_type, end_type); 716 ASSERT_LT(start_type, end_type);
708 for (int i = start_type; i <= end_type; ++i) { 717 for (int i = start_type; i <= end_type; ++i) {
709 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); 718 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i);
710 if (!WebInputEventTraits::IgnoresAckDisposition(type)) 719 if (!WebInputEventTraits::IgnoresAckDisposition(type))
711 continue; 720 continue;
712 721
713 // The TouchEventQueue requires an initial TouchStart for it to begin 722 // The TouchEventQueue requires an initial TouchStart for it to begin
714 // forwarding other touch event types. 723 // forwarding other touch event types.
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 949
941 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT | 950 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT |
942 InputRouter::FIXED_PAGE_SCALE); 951 InputRouter::FIXED_PAGE_SCALE);
943 EXPECT_FALSE(TouchEventTimeoutEnabled()); 952 EXPECT_FALSE(TouchEventTimeoutEnabled());
944 953
945 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE); 954 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE);
946 EXPECT_TRUE(TouchEventTimeoutEnabled()); 955 EXPECT_TRUE(TouchEventTimeoutEnabled());
947 } 956 }
948 957
949 } // namespace content 958 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/input_router_impl.cc ('k') | content/browser/renderer_host/input/touch_event_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698