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

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

Issue 290473006: Add a TouchEventStreamValidator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 6 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 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 <math.h> 5 #include <math.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 void SimulateGestureFlingStartEvent( 235 void SimulateGestureFlingStartEvent(
236 float velocityX, 236 float velocityX,
237 float velocityY, 237 float velocityY,
238 WebGestureEvent::SourceDevice sourceDevice) { 238 WebGestureEvent::SourceDevice sourceDevice) {
239 SimulateGestureEvent( 239 SimulateGestureEvent(
240 SyntheticWebGestureEventBuilder::BuildFling(velocityX, 240 SyntheticWebGestureEventBuilder::BuildFling(velocityX,
241 velocityY, 241 velocityY,
242 sourceDevice)); 242 sourceDevice));
243 } 243 }
244 244
245 void SimulateTouchEvent(WebInputEvent::Type type) {
246 touch_event_.ResetPoints();
247 int index = PressTouchPoint(0, 0);
248 switch (type) {
249 case WebInputEvent::TouchStart:
250 // Already handled by |PressTouchPoint()|.
251 break;
252 case WebInputEvent::TouchMove:
253 MoveTouchPoint(index, 5, 5);
254 break;
255 case WebInputEvent::TouchEnd:
256 ReleaseTouchPoint(index);
257 break;
258 case WebInputEvent::TouchCancel:
259 CancelTouchPoint(index);
260 break;
261 default:
262 FAIL() << "Invalid touch event type.";
263 break;
264 }
265 SendTouchEvent();
266 }
267
268 void SetTouchTimestamp(base::TimeDelta timestamp) { 245 void SetTouchTimestamp(base::TimeDelta timestamp) {
269 touch_event_.SetTimestamp(timestamp); 246 touch_event_.SetTimestamp(timestamp);
270 } 247 }
271 248
272 void SendTouchEvent() { 249 void SendTouchEvent() {
273 input_router_->SendTouchEvent( 250 input_router_->SendTouchEvent(
274 TouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo())); 251 TouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo()));
275 touch_event_.ResetPoints(); 252 touch_event_.ResetPoints();
276 } 253 }
277 254
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 756 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
780 InputMsg_HandleInputEvent::ID)); 757 InputMsg_HandleInputEvent::ID));
781 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 758 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
782 759
783 // Check that the correct unhandled wheel event was received. 760 // Check that the correct unhandled wheel event was received.
784 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); 761 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5);
785 } 762 }
786 763
787 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { 764 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) {
788 OnHasTouchEventHandlers(true); 765 OnHasTouchEventHandlers(true);
766 // Only acks for TouchCancel should always be ignored.
767 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
768 GetEventWithType(WebInputEvent::TouchStart)));
769 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
770 GetEventWithType(WebInputEvent::TouchMove)));
771 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
772 GetEventWithType(WebInputEvent::TouchEnd)));
789 773
790 int start_type = static_cast<int>(WebInputEvent::TouchStart); 774 // Precede the TouchCancel with an appropriate TouchStart;
791 int end_type = static_cast<int>(WebInputEvent::TouchCancel); 775 PressTouchPoint(1, 1);
792 ASSERT_LT(start_type, end_type); 776 SendTouchEvent();
793 for (int i = start_type; i <= end_type; ++i) { 777 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
794 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); 778 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
795 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type))) 779 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount());
796 continue; 780 ASSERT_EQ(0, client_->in_flight_event_count());
797 781
798 // The TouchEventQueue requires an initial TouchStart for it to begin 782 // The TouchCancel ack is always ignored.
799 // forwarding other touch event types. 783 CancelTouchPoint(0);
800 if (type != WebInputEvent::TouchStart) { 784 SendTouchEvent();
801 SimulateTouchEvent(WebInputEvent::TouchStart); 785 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
802 SendInputEventACK(WebInputEvent::TouchStart, 786 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
803 INPUT_EVENT_ACK_STATE_CONSUMED); 787 EXPECT_EQ(0, client_->in_flight_event_count());
804 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); 788 EXPECT_FALSE(HasPendingEvents());
805 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount()); 789 SendInputEventACK(WebInputEvent::TouchCancel,
806 ASSERT_EQ(0, client_->in_flight_event_count()); 790 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
807 } 791 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
808 792 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
809 SimulateTouchEvent(type); 793 EXPECT_FALSE(HasPendingEvents());
810 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
811 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
812 EXPECT_EQ(0, client_->in_flight_event_count());
813 EXPECT_FALSE(HasPendingEvents());
814 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
815 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
816 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
817 EXPECT_FALSE(HasPendingEvents());
818 }
819 } 794 }
820 795
821 TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) { 796 TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) {
822 // We test every gesture type, ensuring that the stream of gestures is valid. 797 // We test every gesture type, ensuring that the stream of gestures is valid.
823 const int kEventTypesLength = 29; 798 const int kEventTypesLength = 29;
824 WebInputEvent::Type eventTypes[kEventTypesLength] = { 799 WebInputEvent::Type eventTypes[kEventTypesLength] = {
825 WebInputEvent::GestureTapDown, 800 WebInputEvent::GestureTapDown,
826 WebInputEvent::GestureShowPress, 801 WebInputEvent::GestureShowPress,
827 WebInputEvent::GestureTapCancel, 802 WebInputEvent::GestureTapCancel,
828 WebInputEvent::GestureScrollBegin, 803 WebInputEvent::GestureScrollBegin,
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 client_overscroll = client_->GetAndResetOverscroll(); 1709 client_overscroll = client_->GetAndResetOverscroll();
1735 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, 1710 EXPECT_EQ(wheel_overscroll.accumulated_overscroll,
1736 client_overscroll.accumulated_overscroll); 1711 client_overscroll.accumulated_overscroll);
1737 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, 1712 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta,
1738 client_overscroll.latest_overscroll_delta); 1713 client_overscroll.latest_overscroll_delta);
1739 EXPECT_EQ(wheel_overscroll.current_fling_velocity, 1714 EXPECT_EQ(wheel_overscroll.current_fling_velocity,
1740 client_overscroll.current_fling_velocity); 1715 client_overscroll.current_fling_velocity);
1741 } 1716 }
1742 1717
1743 } // namespace content 1718 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698