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

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: Rebase 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 void SimulateGestureFlingStartEvent(float velocityX, 235 void SimulateGestureFlingStartEvent(float velocityX,
236 float velocityY, 236 float velocityY,
237 WebGestureDevice sourceDevice) { 237 WebGestureDevice sourceDevice) {
238 SimulateGestureEvent( 238 SimulateGestureEvent(
239 SyntheticWebGestureEventBuilder::BuildFling(velocityX, 239 SyntheticWebGestureEventBuilder::BuildFling(velocityX,
240 velocityY, 240 velocityY,
241 sourceDevice)); 241 sourceDevice));
242 } 242 }
243 243
244 void SimulateTouchEvent(WebInputEvent::Type type) {
245 touch_event_.ResetPoints();
246 int index = PressTouchPoint(0, 0);
247 switch (type) {
248 case WebInputEvent::TouchStart:
249 // Already handled by |PressTouchPoint()|.
250 break;
251 case WebInputEvent::TouchMove:
252 MoveTouchPoint(index, 5, 5);
253 break;
254 case WebInputEvent::TouchEnd:
255 ReleaseTouchPoint(index);
256 break;
257 case WebInputEvent::TouchCancel:
258 CancelTouchPoint(index);
259 break;
260 default:
261 FAIL() << "Invalid touch event type.";
262 break;
263 }
264 SendTouchEvent();
265 }
266
267 void SetTouchTimestamp(base::TimeDelta timestamp) { 244 void SetTouchTimestamp(base::TimeDelta timestamp) {
268 touch_event_.SetTimestamp(timestamp); 245 touch_event_.SetTimestamp(timestamp);
269 } 246 }
270 247
271 void SendTouchEvent() { 248 void SendTouchEvent() {
272 input_router_->SendTouchEvent( 249 input_router_->SendTouchEvent(
273 TouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo())); 250 TouchEventWithLatencyInfo(touch_event_, ui::LatencyInfo()));
274 touch_event_.ResetPoints(); 251 touch_event_.ResetPoints();
275 } 252 }
276 253
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( 755 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(
779 InputMsg_HandleInputEvent::ID)); 756 InputMsg_HandleInputEvent::ID));
780 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 757 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
781 758
782 // Check that the correct unhandled wheel event was received. 759 // Check that the correct unhandled wheel event was received.
783 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5); 760 EXPECT_EQ(ack_handler_->acked_wheel_event().deltaY, -5);
784 } 761 }
785 762
786 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) { 763 TEST_F(InputRouterImplTest, TouchTypesIgnoringAck) {
787 OnHasTouchEventHandlers(true); 764 OnHasTouchEventHandlers(true);
765 // Only acks for TouchCancel should always be ignored.
766 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
767 GetEventWithType(WebInputEvent::TouchStart)));
768 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
769 GetEventWithType(WebInputEvent::TouchMove)));
770 ASSERT_FALSE(WebInputEventTraits::IgnoresAckDisposition(
771 GetEventWithType(WebInputEvent::TouchEnd)));
788 772
789 int start_type = static_cast<int>(WebInputEvent::TouchStart); 773 // Precede the TouchCancel with an appropriate TouchStart;
790 int end_type = static_cast<int>(WebInputEvent::TouchCancel); 774 PressTouchPoint(1, 1);
791 ASSERT_LT(start_type, end_type); 775 SendTouchEvent();
792 for (int i = start_type; i <= end_type; ++i) { 776 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
793 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); 777 ASSERT_EQ(1U, GetSentMessageCountAndResetSink());
794 if (!WebInputEventTraits::IgnoresAckDisposition(GetEventWithType(type))) 778 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount());
795 continue; 779 ASSERT_EQ(0, client_->in_flight_event_count());
796 780
797 // The TouchEventQueue requires an initial TouchStart for it to begin 781 // The TouchCancel ack is always ignored.
798 // forwarding other touch event types. 782 CancelTouchPoint(0);
799 if (type != WebInputEvent::TouchStart) { 783 SendTouchEvent();
800 SimulateTouchEvent(WebInputEvent::TouchStart); 784 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
801 SendInputEventACK(WebInputEvent::TouchStart, 785 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
802 INPUT_EVENT_ACK_STATE_CONSUMED); 786 EXPECT_EQ(0, client_->in_flight_event_count());
803 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); 787 EXPECT_FALSE(HasPendingEvents());
804 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount()); 788 SendInputEventACK(WebInputEvent::TouchCancel,
805 ASSERT_EQ(0, client_->in_flight_event_count()); 789 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
806 } 790 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
807 791 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
808 SimulateTouchEvent(type); 792 EXPECT_FALSE(HasPendingEvents());
809 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
810 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
811 EXPECT_EQ(0, client_->in_flight_event_count());
812 EXPECT_FALSE(HasPendingEvents());
813 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
814 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
815 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
816 EXPECT_FALSE(HasPendingEvents());
817 }
818 } 793 }
819 794
820 TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) { 795 TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) {
821 // We test every gesture type, ensuring that the stream of gestures is valid. 796 // We test every gesture type, ensuring that the stream of gestures is valid.
822 const int kEventTypesLength = 29; 797 const int kEventTypesLength = 29;
823 WebInputEvent::Type eventTypes[kEventTypesLength] = { 798 WebInputEvent::Type eventTypes[kEventTypesLength] = {
824 WebInputEvent::GestureTapDown, 799 WebInputEvent::GestureTapDown,
825 WebInputEvent::GestureShowPress, 800 WebInputEvent::GestureShowPress,
826 WebInputEvent::GestureTapCancel, 801 WebInputEvent::GestureTapCancel,
827 WebInputEvent::GestureScrollBegin, 802 WebInputEvent::GestureScrollBegin,
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 client_overscroll = client_->GetAndResetOverscroll(); 1716 client_overscroll = client_->GetAndResetOverscroll();
1742 EXPECT_EQ(wheel_overscroll.accumulated_overscroll, 1717 EXPECT_EQ(wheel_overscroll.accumulated_overscroll,
1743 client_overscroll.accumulated_overscroll); 1718 client_overscroll.accumulated_overscroll);
1744 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta, 1719 EXPECT_EQ(wheel_overscroll.latest_overscroll_delta,
1745 client_overscroll.latest_overscroll_delta); 1720 client_overscroll.latest_overscroll_delta);
1746 EXPECT_EQ(wheel_overscroll.current_fling_velocity, 1721 EXPECT_EQ(wheel_overscroll.current_fling_velocity,
1747 client_overscroll.current_fling_velocity); 1722 client_overscroll.current_fling_velocity);
1748 } 1723 }
1749 1724
1750 } // namespace content 1725 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/input_router_impl.cc ('k') | content/common/input/gesture_event_stream_validator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698