gesture_provider_unittest.cc 154 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/events/gesture_detection/gesture_provider.h"
  5. #include <stddef.h>
  6. #include <memory>
  7. #include "base/check.h"
  8. #include "base/location.h"
  9. #include "base/run_loop.h"
  10. #include "base/task/single_thread_task_runner.h"
  11. #include "base/test/metrics/histogram_tester.h"
  12. #include "base/test/task_environment.h"
  13. #include "base/threading/thread_task_runner_handle.h"
  14. #include "base/time/time.h"
  15. #include "build/build_config.h"
  16. #include "testing/gtest/include/gtest/gtest.h"
  17. #include "ui/events/event_constants.h"
  18. #include "ui/events/gesture_detection/gesture_event_data.h"
  19. #include "ui/events/gesture_detection/motion_event.h"
  20. #include "ui/events/test/motion_event_test_utils.h"
  21. #include "ui/events/types/event_type.h"
  22. #include "ui/gfx/geometry/point_f.h"
  23. using base::TimeTicks;
  24. using ui::test::MockMotionEvent;
  25. namespace ui {
  26. namespace {
  27. const float kFakeCoordX = 42.f;
  28. const float kFakeCoordY = 24.f;
  29. const base::TimeDelta kOneSecond = base::Seconds(1);
  30. const base::TimeDelta kOneMicrosecond = base::Microseconds(1);
  31. const base::TimeDelta kDeltaTimeForFlingSequences = base::Milliseconds(5);
  32. const float kMockTouchRadius = MockMotionEvent::TOUCH_MAJOR / 2;
  33. const float kMaxTwoFingerTapSeparation = 300;
  34. GestureProvider::Config CreateDefaultConfig() {
  35. GestureProvider::Config sConfig;
  36. // The longpress timeout is non-zero only to indicate ordering with respect to
  37. // the showpress timeout.
  38. sConfig.gesture_detector_config.showpress_timeout = base::TimeDelta();
  39. sConfig.gesture_detector_config.shortpress_timeout = kOneMicrosecond;
  40. sConfig.gesture_detector_config.longpress_timeout = kOneMicrosecond * 2;
  41. // A valid doubletap timeout should always be non-zero. The value is used not
  42. // only to trigger the timeout that confirms the tap event, but also to gate
  43. // whether the second tap is in fact a double-tap (using a strict inequality
  44. // between times for the first up and the second down events). We use 4
  45. // microseconds simply to allow several intermediate events to occur before
  46. // the second tap at microsecond intervals.
  47. sConfig.gesture_detector_config.double_tap_timeout = kOneMicrosecond * 4;
  48. sConfig.gesture_detector_config.double_tap_min_time = kOneMicrosecond * 2;
  49. return sConfig;
  50. }
  51. gfx::RectF BoundsForSingleMockTouchAtLocation(float x, float y) {
  52. float diameter = MockMotionEvent::TOUCH_MAJOR;
  53. return gfx::RectF(x - diameter / 2, y - diameter / 2, diameter, diameter);
  54. }
  55. } // namespace
  56. class GestureProviderTest : public testing::Test, public GestureProviderClient {
  57. public:
  58. GestureProviderTest()
  59. : task_environment_(
  60. base::test::SingleThreadTaskEnvironment::MainThreadType::UI) {}
  61. ~GestureProviderTest() override {}
  62. static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
  63. MotionEvent::Action action,
  64. float x,
  65. float y) {
  66. return MockMotionEvent(action, event_time, x, y);
  67. }
  68. static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
  69. MotionEvent::Action action,
  70. float x0,
  71. float y0,
  72. float x1,
  73. float y1) {
  74. return MockMotionEvent(action, event_time, x0, y0, x1, y1);
  75. }
  76. static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
  77. MotionEvent::Action action,
  78. float x0,
  79. float y0,
  80. float x1,
  81. float y1,
  82. float x2,
  83. float y2) {
  84. return MockMotionEvent(action, event_time, x0, y0, x1, y1, x2, y2);
  85. }
  86. static MockMotionEvent ObtainMotionEvent(
  87. base::TimeTicks event_time,
  88. MotionEvent::Action action,
  89. const std::vector<gfx::PointF>& positions) {
  90. switch (positions.size()) {
  91. case 1:
  92. return MockMotionEvent(
  93. action, event_time, positions[0].x(), positions[0].y());
  94. case 2:
  95. return MockMotionEvent(action,
  96. event_time,
  97. positions[0].x(),
  98. positions[0].y(),
  99. positions[1].x(),
  100. positions[1].y());
  101. case 3:
  102. return MockMotionEvent(action,
  103. event_time,
  104. positions[0].x(),
  105. positions[0].y(),
  106. positions[1].x(),
  107. positions[1].y(),
  108. positions[2].x(),
  109. positions[2].y());
  110. default:
  111. CHECK(false) << "MockMotionEvent only supports 1-3 pointers";
  112. return MockMotionEvent();
  113. }
  114. }
  115. static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
  116. MotionEvent::Action action) {
  117. return ObtainMotionEvent(event_time, action, kFakeCoordX, kFakeCoordY);
  118. }
  119. // Test
  120. void SetUp() override { SetUpWithConfig(GetDefaultConfig()); }
  121. void TearDown() override {
  122. gestures_.clear();
  123. gesture_provider_.reset();
  124. }
  125. // GestureProviderClient
  126. void OnGestureEvent(const GestureEventData& gesture) override {
  127. EXPECT_EQ(GestureDeviceType::DEVICE_TOUCHSCREEN,
  128. gesture.details.device_type());
  129. if (gesture.type() == ET_GESTURE_SCROLL_BEGIN)
  130. active_scroll_begin_event_ = std::make_unique<GestureEventData>(gesture);
  131. gestures_.push_back(gesture);
  132. }
  133. bool RequiresDoubleTapGestureEvents() const override {
  134. return should_process_double_tap_events_;
  135. }
  136. void SetUpWithConfig(const GestureProvider::Config& config) {
  137. gesture_provider_ = std::make_unique<GestureProvider>(config, this);
  138. gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
  139. }
  140. void ResetGestureDetection() {
  141. gesture_provider_->ResetDetection();
  142. gestures_.clear();
  143. }
  144. bool CancelActiveTouchSequence() {
  145. if (!gesture_provider_->current_down_event())
  146. return false;
  147. return gesture_provider_->OnTouchEvent(
  148. *gesture_provider_->current_down_event()->Cancel());
  149. }
  150. bool HasReceivedGesture(EventType type) const {
  151. for (size_t i = 0; i < gestures_.size(); ++i) {
  152. if (gestures_[i].type() == type)
  153. return true;
  154. }
  155. return false;
  156. }
  157. const GestureEventData& GetMostRecentGestureEvent() const {
  158. EXPECT_FALSE(gestures_.empty());
  159. return gestures_.back();
  160. }
  161. const GestureEventData& GetNthMostRecentGestureEvent(size_t n) const {
  162. EXPECT_FALSE(gestures_.empty());
  163. return GetReceivedGesture(GetReceivedGestureCount() - 1 - n);
  164. }
  165. EventType GetNthMostRecentGestureEventType(size_t n) const {
  166. return GetNthMostRecentGestureEvent(n).type();
  167. }
  168. EventType GetMostRecentGestureEventType() const {
  169. EXPECT_FALSE(gestures_.empty());
  170. return gestures_.back().type();
  171. }
  172. size_t GetReceivedGestureCount() const { return gestures_.size(); }
  173. const GestureEventData& GetReceivedGesture(size_t index) const {
  174. EXPECT_LT(index, GetReceivedGestureCount());
  175. return gestures_[index];
  176. }
  177. const GestureEventData* GetActiveScrollBeginEvent() const {
  178. return active_scroll_begin_event_ ? active_scroll_begin_event_.get() : NULL;
  179. }
  180. const GestureProvider::Config& GetDefaultConfig() const {
  181. static GestureProvider::Config sConfig = CreateDefaultConfig();
  182. return sConfig;
  183. }
  184. float GetTouchSlop() const {
  185. return GetDefaultConfig().gesture_detector_config.touch_slop;
  186. }
  187. float GetMinScalingSpan() const {
  188. return GetDefaultConfig().scale_gesture_detector_config.min_scaling_span;
  189. }
  190. float GetMinSwipeVelocity() const {
  191. return GetDefaultConfig().gesture_detector_config.minimum_swipe_velocity;
  192. }
  193. base::TimeDelta GetLongPressTimeout() const {
  194. return GetDefaultConfig().gesture_detector_config.longpress_timeout;
  195. }
  196. base::TimeDelta GetShowPressTimeout() const {
  197. return GetDefaultConfig().gesture_detector_config.showpress_timeout;
  198. }
  199. base::TimeDelta GetDoubleTapTimeout() const {
  200. return GetDefaultConfig().gesture_detector_config.double_tap_timeout;
  201. }
  202. base::TimeDelta GetDoubleTapMinTime() const {
  203. return GetDefaultConfig().gesture_detector_config.double_tap_min_time;
  204. }
  205. base::TimeDelta GetValidDoubleTapDelay() const {
  206. return (GetDoubleTapTimeout() + GetDoubleTapMinTime()) / 2;
  207. }
  208. void EnableBeginEndTypes() {
  209. GestureProvider::Config config = GetDefaultConfig();
  210. config.gesture_begin_end_types_enabled = true;
  211. SetUpWithConfig(config);
  212. }
  213. void EnableSwipe() {
  214. GestureProvider::Config config = GetDefaultConfig();
  215. config.gesture_detector_config.swipe_enabled = true;
  216. SetUpWithConfig(config);
  217. }
  218. void EnableTwoFingerTap(float max_distance_for_two_finger_tap,
  219. base::TimeDelta two_finger_tap_timeout) {
  220. GestureProvider::Config config = GetDefaultConfig();
  221. config.gesture_detector_config.two_finger_tap_enabled = true;
  222. config.gesture_detector_config.two_finger_tap_max_separation =
  223. max_distance_for_two_finger_tap;
  224. config.gesture_detector_config.two_finger_tap_timeout =
  225. two_finger_tap_timeout;
  226. SetUpWithConfig(config);
  227. }
  228. void SetMinPinchUpdateSpanDelta(float min_pinch_update_span_delta) {
  229. GestureProvider::Config config = GetDefaultConfig();
  230. config.scale_gesture_detector_config.min_pinch_update_span_delta =
  231. min_pinch_update_span_delta;
  232. SetUpWithConfig(config);
  233. }
  234. void SetMinMaxGestureBoundsLength(float min_gesture_bound_length,
  235. float max_gesture_bound_length) {
  236. GestureProvider::Config config = GetDefaultConfig();
  237. config.min_gesture_bounds_length = min_gesture_bound_length;
  238. config.max_gesture_bounds_length = max_gesture_bound_length;
  239. SetUpWithConfig(config);
  240. }
  241. void SetShowPressAndLongPressTimeout(base::TimeDelta showpress_timeout,
  242. base::TimeDelta shortpress_timeout,
  243. base::TimeDelta longpress_timeout) {
  244. GestureProvider::Config config = GetDefaultConfig();
  245. config.gesture_detector_config.showpress_timeout = showpress_timeout;
  246. config.gesture_detector_config.shortpress_timeout = shortpress_timeout;
  247. config.gesture_detector_config.longpress_timeout = longpress_timeout;
  248. SetUpWithConfig(config);
  249. }
  250. void SetSingleTapRepeatInterval(int repeat_interval) {
  251. GestureProvider::Config config = GetDefaultConfig();
  252. config.gesture_detector_config.single_tap_repeat_interval = repeat_interval;
  253. SetUpWithConfig(config);
  254. }
  255. void SetStylusButtonAcceleratedLongPress(bool enabled) {
  256. GestureProvider::Config config = GetDefaultConfig();
  257. config.gesture_detector_config.stylus_button_accelerated_longpress_enabled =
  258. enabled;
  259. SetUpWithConfig(config);
  260. }
  261. void SetDeepPressAcceleratedLongPress(bool enabled) {
  262. GestureProvider::Config config = GetDefaultConfig();
  263. config.gesture_detector_config.deep_press_accelerated_longpress_enabled =
  264. enabled;
  265. SetUpWithConfig(config);
  266. }
  267. bool HasDownEvent() const { return gesture_provider_->current_down_event(); }
  268. protected:
  269. void CheckScrollEventSequenceForEndActionType(
  270. MotionEvent::Action end_action_type) {
  271. base::TimeTicks event_time = base::TimeTicks::Now();
  272. const float scroll_to_x = kFakeCoordX + 100;
  273. const float scroll_to_y = kFakeCoordY + 100;
  274. int motion_event_id = 3;
  275. int motion_event_flags = EF_SHIFT_DOWN | EF_CAPS_LOCK_ON;
  276. MockMotionEvent event =
  277. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  278. event.SetPrimaryPointerId(motion_event_id);
  279. event.set_flags(motion_event_flags);
  280. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  281. EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
  282. EXPECT_EQ(
  283. GetMostRecentGestureEvent().unique_touch_event_id,
  284. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  285. uint32_t primary_unique_touch_event_id =
  286. GetMostRecentGestureEvent().unique_touch_event_id;
  287. event =
  288. ObtainMotionEvent(event_time + kOneSecond, MotionEvent::Action::MOVE,
  289. scroll_to_x, scroll_to_y);
  290. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  291. event.SetPrimaryPointerId(motion_event_id);
  292. event.set_flags(motion_event_flags);
  293. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  294. EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
  295. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  296. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  297. EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
  298. EXPECT_EQ(event.GetToolType(0),
  299. GetMostRecentGestureEvent().primary_tool_type);
  300. EXPECT_EQ(
  301. primary_unique_touch_event_id,
  302. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  303. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
  304. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y),
  305. GetMostRecentGestureEvent().details.bounding_box_f());
  306. ASSERT_EQ(3U, GetReceivedGestureCount()) << "Only TapDown, "
  307. "ScrollBegin and ScrollBy "
  308. "should have been sent";
  309. EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
  310. EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id);
  311. EXPECT_EQ(primary_unique_touch_event_id,
  312. GetReceivedGesture(1).details.primary_unique_touch_event_id());
  313. EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(1).time)
  314. << "ScrollBegin should have the time of the Action::MOVE";
  315. event = ObtainMotionEvent(
  316. event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y);
  317. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  318. event.SetPrimaryPointerId(motion_event_id);
  319. gesture_provider_->OnTouchEvent(event);
  320. EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
  321. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
  322. EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
  323. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  324. EXPECT_EQ(event.GetToolType(0),
  325. GetMostRecentGestureEvent().primary_tool_type);
  326. EXPECT_EQ(
  327. primary_unique_touch_event_id,
  328. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  329. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  330. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y),
  331. GetMostRecentGestureEvent().details.bounding_box_f());
  332. }
  333. void OneFingerSwipe(float vx, float vy) {
  334. std::vector<gfx::Vector2dF> velocities;
  335. velocities.push_back(gfx::Vector2dF(vx, vy));
  336. MultiFingerSwipe(velocities);
  337. }
  338. void TwoFingerSwipe(float vx0, float vy0, float vx1, float vy1) {
  339. std::vector<gfx::Vector2dF> velocities;
  340. velocities.push_back(gfx::Vector2dF(vx0, vy0));
  341. velocities.push_back(gfx::Vector2dF(vx1, vy1));
  342. MultiFingerSwipe(velocities);
  343. }
  344. void ThreeFingerSwipe(float vx0,
  345. float vy0,
  346. float vx1,
  347. float vy1,
  348. float vx2,
  349. float vy2) {
  350. std::vector<gfx::Vector2dF> velocities;
  351. velocities.push_back(gfx::Vector2dF(vx0, vy0));
  352. velocities.push_back(gfx::Vector2dF(vx1, vy1));
  353. velocities.push_back(gfx::Vector2dF(vx2, vy2));
  354. MultiFingerSwipe(velocities);
  355. }
  356. void MultiFingerSwipe(std::vector<gfx::Vector2dF> velocities) {
  357. ASSERT_GT(velocities.size(), 0U);
  358. base::TimeTicks event_time = base::TimeTicks::Now();
  359. std::vector<gfx::PointF> positions(velocities.size());
  360. for (size_t i = 0; i < positions.size(); ++i)
  361. positions[i] = gfx::PointF(kFakeCoordX * (i + 1), kFakeCoordY * (i + 1));
  362. float dt = kDeltaTimeForFlingSequences.InSecondsF();
  363. // Each pointer down should be a separate event.
  364. for (size_t i = 0; i < positions.size(); ++i) {
  365. const size_t pointer_count = i + 1;
  366. std::vector<gfx::PointF> event_positions(pointer_count);
  367. event_positions.assign(positions.begin(),
  368. positions.begin() + pointer_count);
  369. MockMotionEvent event = ObtainMotionEvent(
  370. event_time,
  371. pointer_count > 1 ? MotionEvent::Action::POINTER_DOWN
  372. : MotionEvent::Action::DOWN,
  373. event_positions);
  374. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  375. }
  376. for (size_t i = 0; i < positions.size(); ++i)
  377. positions[i] += gfx::ScaleVector2d(velocities[i], dt);
  378. MockMotionEvent event =
  379. ObtainMotionEvent(event_time + kDeltaTimeForFlingSequences,
  380. MotionEvent::Action::MOVE, positions);
  381. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  382. for (size_t i = 0; i < positions.size(); ++i)
  383. positions[i] += gfx::ScaleVector2d(velocities[i], dt);
  384. event = ObtainMotionEvent(event_time + 2 * kDeltaTimeForFlingSequences,
  385. MotionEvent::Action::MOVE, positions);
  386. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  387. event = ObtainMotionEvent(event_time + 2 * kDeltaTimeForFlingSequences,
  388. MotionEvent::Action::POINTER_UP, positions);
  389. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  390. }
  391. static void RunTasksAndWait(base::TimeDelta delay) {
  392. base::RunLoop run_loop;
  393. base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
  394. FROM_HERE, run_loop.QuitClosure(), delay);
  395. run_loop.Run();
  396. }
  397. std::vector<GestureEventData> gestures_;
  398. std::unique_ptr<GestureProvider> gesture_provider_;
  399. std::unique_ptr<GestureEventData> active_scroll_begin_event_;
  400. base::test::SingleThreadTaskEnvironment task_environment_;
  401. bool should_process_double_tap_events_ = true;
  402. };
  403. // Verify that a DOWN has the same unique_touch_event_id and
  404. // primary_touch_event_id
  405. TEST_F(GestureProviderTest, GestureTapPrimaryUniqueTouchEventId) {
  406. base::TimeTicks event_time = base::TimeTicks::Now();
  407. int motion_event_id = 6;
  408. int motion_event_flags = EF_CONTROL_DOWN | EF_ALT_DOWN;
  409. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  410. MockMotionEvent event =
  411. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  412. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  413. event.SetPrimaryPointerId(motion_event_id);
  414. event.set_flags(motion_event_flags);
  415. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  416. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  417. EXPECT_EQ(
  418. GetMostRecentGestureEvent().unique_touch_event_id,
  419. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  420. }
  421. // Verify that a DOWN followed shortly by an UP will trigger a single tap.
  422. TEST_F(GestureProviderTest, GestureTap) {
  423. base::TimeTicks event_time = base::TimeTicks::Now();
  424. int motion_event_id = 6;
  425. int motion_event_flags = EF_CONTROL_DOWN | EF_ALT_DOWN;
  426. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  427. MockMotionEvent event =
  428. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  429. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  430. event.SetPrimaryPointerId(motion_event_id);
  431. event.set_flags(motion_event_flags);
  432. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  433. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  434. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  435. EXPECT_EQ(event.GetToolType(0),
  436. GetMostRecentGestureEvent().primary_tool_type);
  437. EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
  438. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
  439. GetMostRecentGestureEvent().details.bounding_box_f());
  440. EXPECT_EQ(
  441. GetMostRecentGestureEvent().unique_touch_event_id,
  442. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  443. uint32_t primary_unique_touch_event_id =
  444. GetMostRecentGestureEvent().unique_touch_event_id;
  445. event =
  446. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
  447. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  448. event.SetPrimaryPointerId(motion_event_id);
  449. event.set_flags(motion_event_flags);
  450. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  451. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  452. // Ensure tap details have been set.
  453. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  454. EXPECT_EQ(event.GetToolType(0),
  455. GetMostRecentGestureEvent().primary_tool_type);
  456. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  457. EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
  458. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  459. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
  460. GetMostRecentGestureEvent().details.bounding_box_f());
  461. EXPECT_EQ(
  462. primary_unique_touch_event_id,
  463. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  464. }
  465. // Verify that a DOWN followed shortly by an UP will trigger
  466. // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled.
  467. TEST_F(GestureProviderTest, GestureTapWithDelay) {
  468. base::TimeTicks event_time = base::TimeTicks::Now();
  469. int motion_event_id = 6;
  470. int motion_event_flags = EF_CONTROL_DOWN | EF_ALT_DOWN | EF_CAPS_LOCK_ON;
  471. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  472. MockMotionEvent event =
  473. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  474. event.SetPrimaryPointerId(motion_event_id);
  475. event.set_flags(motion_event_flags);
  476. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  477. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  478. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  479. EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
  480. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  481. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
  482. GetMostRecentGestureEvent().details.bounding_box_f());
  483. EXPECT_EQ(
  484. GetMostRecentGestureEvent().unique_touch_event_id,
  485. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  486. uint32_t primary_unique_touch_event_id =
  487. GetMostRecentGestureEvent().unique_touch_event_id;
  488. event =
  489. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
  490. event.SetPrimaryPointerId(motion_event_id);
  491. event.set_flags(motion_event_flags);
  492. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  493. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  494. // Ensure tap details have been set.
  495. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  496. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  497. EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
  498. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  499. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
  500. GetMostRecentGestureEvent().details.bounding_box_f());
  501. EXPECT_EQ(event.GetEventTime(), GetMostRecentGestureEvent().time);
  502. EXPECT_EQ(
  503. primary_unique_touch_event_id,
  504. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  505. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP));
  506. RunTasksAndWait(GetDoubleTapTimeout());
  507. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP));
  508. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  509. EXPECT_EQ(event.GetEventTime(), GetMostRecentGestureEvent().time);
  510. EXPECT_EQ(
  511. primary_unique_touch_event_id,
  512. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  513. }
  514. // Verify that a DOWN followed by a MOVE will trigger fling, but won't trigger
  515. // either short-press or long-press.
  516. TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) {
  517. base::TimeTicks event_time = TimeTicks::Now();
  518. base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
  519. int motion_event_id = 6;
  520. int motion_event_flags = EF_ALT_DOWN;
  521. MockMotionEvent event =
  522. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  523. event.SetPrimaryPointerId(motion_event_id);
  524. event.set_flags(motion_event_flags);
  525. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  526. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  527. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  528. EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
  529. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  530. EXPECT_EQ(
  531. GetMostRecentGestureEvent().unique_touch_event_id,
  532. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  533. uint32_t primary_unique_touch_event_id =
  534. GetMostRecentGestureEvent().unique_touch_event_id;
  535. event = ObtainMotionEvent(event_time + delta_time, MotionEvent::Action::MOVE,
  536. kFakeCoordX * 10, kFakeCoordY * 10);
  537. event.SetPrimaryPointerId(motion_event_id);
  538. event.set_flags(motion_event_flags);
  539. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  540. EXPECT_EQ(
  541. primary_unique_touch_event_id,
  542. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  543. event =
  544. ObtainMotionEvent(event_time + delta_time * 2, MotionEvent::Action::UP,
  545. kFakeCoordX * 10, kFakeCoordY * 10);
  546. event.SetPrimaryPointerId(motion_event_id);
  547. event.set_flags(motion_event_flags);
  548. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  549. EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
  550. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  551. EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
  552. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  553. EXPECT_EQ(
  554. primary_unique_touch_event_id,
  555. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  556. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SHORT_PRESS));
  557. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
  558. EXPECT_EQ(
  559. BoundsForSingleMockTouchAtLocation(kFakeCoordX * 10, kFakeCoordY * 10),
  560. GetMostRecentGestureEvent().details.bounding_box_f());
  561. }
  562. // Verify that for a normal scroll the following events are sent:
  563. // - ET_GESTURE_SCROLL_BEGIN
  564. // - ET_GESTURE_SCROLL_UPDATE
  565. // - ET_GESTURE_SCROLL_END
  566. TEST_F(GestureProviderTest, ScrollEventActionUpSequence) {
  567. CheckScrollEventSequenceForEndActionType(MotionEvent::Action::UP);
  568. }
  569. // Verify that for a cancelled scroll the following events are sent:
  570. // - ET_GESTURE_SCROLL_BEGIN
  571. // - ET_GESTURE_SCROLL_UPDATE
  572. // - ET_GESTURE_SCROLL_END
  573. TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) {
  574. CheckScrollEventSequenceForEndActionType(MotionEvent::Action::CANCEL);
  575. }
  576. // Verify that for a normal fling (fling after scroll) the following events are
  577. // sent:
  578. // - ET_GESTURE_SCROLL_BEGIN
  579. // - ET_SCROLL_FLING_START
  580. TEST_F(GestureProviderTest, FlingEventSequence) {
  581. base::TimeTicks event_time = base::TimeTicks::Now();
  582. base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
  583. int motion_event_id = 6;
  584. MockMotionEvent event =
  585. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  586. event.SetPrimaryPointerId(motion_event_id);
  587. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  588. EXPECT_EQ(
  589. GetMostRecentGestureEvent().unique_touch_event_id,
  590. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  591. uint32_t primary_unique_touch_event_id =
  592. GetMostRecentGestureEvent().unique_touch_event_id;
  593. event = ObtainMotionEvent(event_time + delta_time, MotionEvent::Action::MOVE,
  594. kFakeCoordX * 5, kFakeCoordY * 5);
  595. event.SetPrimaryPointerId(motion_event_id);
  596. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  597. EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
  598. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  599. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
  600. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  601. EXPECT_EQ(
  602. primary_unique_touch_event_id,
  603. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  604. ASSERT_EQ(3U, GetReceivedGestureCount());
  605. ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
  606. EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id);
  607. EXPECT_EQ(primary_unique_touch_event_id,
  608. GetReceivedGesture(1).details.primary_unique_touch_event_id());
  609. // We don't want to take a dependency here on exactly how hints are calculated
  610. // for a fling (eg. may depend on velocity), so just validate the direction.
  611. int hint_x = GetReceivedGesture(1).details.scroll_x_hint();
  612. int hint_y = GetReceivedGesture(1).details.scroll_y_hint();
  613. EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y)
  614. << "ScrollBegin hint should be in positive X axis";
  615. event =
  616. ObtainMotionEvent(event_time + delta_time * 2, MotionEvent::Action::UP,
  617. kFakeCoordX * 10, kFakeCoordY * 10);
  618. event.SetPrimaryPointerId(motion_event_id);
  619. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  620. EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
  621. EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
  622. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  623. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  624. EXPECT_EQ(
  625. primary_unique_touch_event_id,
  626. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  627. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
  628. EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time)
  629. << "FlingStart should have the time of the Action::UP";
  630. }
  631. TEST_F(GestureProviderTest, GestureCancelledOnCancelEvent) {
  632. const base::TimeTicks event_time = TimeTicks::Now();
  633. MockMotionEvent event =
  634. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  635. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  636. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  637. EXPECT_EQ(
  638. GetMostRecentGestureEvent().unique_touch_event_id,
  639. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  640. uint32_t primary_unique_touch_event_id =
  641. GetMostRecentGestureEvent().unique_touch_event_id;
  642. RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
  643. kOneMicrosecond);
  644. EXPECT_EQ(ET_GESTURE_SHOW_PRESS, GetNthMostRecentGestureEventType(2));
  645. EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
  646. EXPECT_EQ(
  647. primary_unique_touch_event_id,
  648. GetNthMostRecentGestureEvent(1).details.primary_unique_touch_event_id());
  649. EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
  650. EXPECT_EQ(
  651. primary_unique_touch_event_id,
  652. GetNthMostRecentGestureEvent(0).details.primary_unique_touch_event_id());
  653. // A cancellation event may be triggered for a number of reasons, e.g.,
  654. // from a context-menu-triggering long press resulting in loss of focus.
  655. EXPECT_TRUE(CancelActiveTouchSequence());
  656. EXPECT_EQ(
  657. primary_unique_touch_event_id,
  658. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  659. EXPECT_FALSE(HasDownEvent());
  660. // A final Action::UP should have no effect.
  661. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  662. MotionEvent::Action::UP);
  663. EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
  664. }
  665. TEST_F(GestureProviderTest, GestureCancelledOnDetectionReset) {
  666. const base::TimeTicks event_time = TimeTicks::Now();
  667. MockMotionEvent event =
  668. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  669. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  670. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  671. EXPECT_EQ(
  672. GetMostRecentGestureEvent().unique_touch_event_id,
  673. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  674. uint32_t primary_unique_touch_event_id =
  675. GetMostRecentGestureEvent().unique_touch_event_id;
  676. RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
  677. kOneMicrosecond);
  678. EXPECT_EQ(ET_GESTURE_SHOW_PRESS, GetNthMostRecentGestureEventType(2));
  679. EXPECT_EQ(
  680. primary_unique_touch_event_id,
  681. GetNthMostRecentGestureEvent(2).details.primary_unique_touch_event_id());
  682. EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
  683. EXPECT_EQ(
  684. primary_unique_touch_event_id,
  685. GetNthMostRecentGestureEvent(1).details.primary_unique_touch_event_id());
  686. EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
  687. EXPECT_EQ(
  688. primary_unique_touch_event_id,
  689. GetNthMostRecentGestureEvent(0).details.primary_unique_touch_event_id());
  690. ResetGestureDetection();
  691. EXPECT_FALSE(HasDownEvent());
  692. // A final Action::UP should have no effect.
  693. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  694. MotionEvent::Action::UP);
  695. EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
  696. }
  697. TEST_F(GestureProviderTest, TapPendingConfirmationCancelledOnCancelEvent) {
  698. const base::TimeTicks event_time = TimeTicks::Now();
  699. MockMotionEvent event =
  700. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  701. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  702. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  703. EXPECT_EQ(
  704. GetMostRecentGestureEvent().unique_touch_event_id,
  705. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  706. uint32_t primary_unique_touch_event_id =
  707. GetMostRecentGestureEvent().unique_touch_event_id;
  708. event =
  709. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
  710. gesture_provider_->OnTouchEvent(event);
  711. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  712. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  713. EXPECT_EQ(
  714. primary_unique_touch_event_id,
  715. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  716. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  717. MotionEvent::Action::CANCEL);
  718. gesture_provider_->OnTouchEvent(event);
  719. EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetMostRecentGestureEventType());
  720. EXPECT_EQ(
  721. primary_unique_touch_event_id,
  722. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  723. }
  724. TEST_F(GestureProviderTest, NoTapAfterScrollBegins) {
  725. base::TimeTicks event_time = base::TimeTicks::Now();
  726. MockMotionEvent event =
  727. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  728. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  729. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  730. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  731. EXPECT_EQ(
  732. GetMostRecentGestureEvent().unique_touch_event_id,
  733. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  734. uint32_t primary_unique_touch_event_id =
  735. GetMostRecentGestureEvent().unique_touch_event_id;
  736. event =
  737. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
  738. kFakeCoordX + 50, kFakeCoordY + 50);
  739. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  740. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
  741. EXPECT_EQ(
  742. primary_unique_touch_event_id,
  743. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  744. event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::Action::UP,
  745. kFakeCoordX + 50, kFakeCoordY + 50);
  746. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  747. EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
  748. EXPECT_EQ(
  749. primary_unique_touch_event_id,
  750. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  751. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
  752. }
  753. TEST_F(GestureProviderTest, DoubleTap) {
  754. base::TimeTicks event_time = base::TimeTicks::Now();
  755. MockMotionEvent event =
  756. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  757. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  758. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  759. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  760. EXPECT_EQ(
  761. GetMostRecentGestureEvent().unique_touch_event_id,
  762. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  763. uint32_t primary_unique_touch_event_id =
  764. GetMostRecentGestureEvent().unique_touch_event_id;
  765. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  766. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  767. gesture_provider_->OnTouchEvent(event);
  768. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  769. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  770. EXPECT_EQ(
  771. primary_unique_touch_event_id,
  772. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  773. event_time += GetValidDoubleTapDelay();
  774. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  775. kFakeCoordY);
  776. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  777. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  778. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  779. EXPECT_EQ(
  780. GetMostRecentGestureEvent().unique_touch_event_id,
  781. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  782. primary_unique_touch_event_id =
  783. GetMostRecentGestureEvent().unique_touch_event_id;
  784. // Moving a very small amount of distance should not trigger the double tap
  785. // drag zoom mode.
  786. event =
  787. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
  788. kFakeCoordX, kFakeCoordY + 1);
  789. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  790. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  791. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  792. EXPECT_EQ(
  793. primary_unique_touch_event_id,
  794. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  795. event =
  796. ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  797. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY + 1);
  798. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  799. const GestureEventData& double_tap = GetMostRecentGestureEvent();
  800. EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type());
  801. // Ensure tap details have been set.
  802. EXPECT_EQ(10, double_tap.details.bounding_box().width());
  803. EXPECT_EQ(10, double_tap.details.bounding_box().height());
  804. EXPECT_EQ(1, double_tap.details.tap_count());
  805. EXPECT_EQ(primary_unique_touch_event_id,
  806. double_tap.details.primary_unique_touch_event_id());
  807. }
  808. TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) {
  809. const base::TimeTicks down_time_1 = TimeTicks::Now();
  810. const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
  811. MockMotionEvent event =
  812. ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
  813. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  814. EXPECT_EQ(
  815. GetMostRecentGestureEvent().unique_touch_event_id,
  816. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  817. uint32_t primary_unique_touch_event_id =
  818. GetMostRecentGestureEvent().unique_touch_event_id;
  819. event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
  820. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  821. gesture_provider_->OnTouchEvent(event);
  822. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  823. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  824. EXPECT_EQ(
  825. primary_unique_touch_event_id,
  826. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  827. event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
  828. kFakeCoordY);
  829. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  830. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  831. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  832. EXPECT_EQ(
  833. GetMostRecentGestureEvent().unique_touch_event_id,
  834. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  835. primary_unique_touch_event_id =
  836. GetMostRecentGestureEvent().unique_touch_event_id;
  837. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
  838. MotionEvent::Action::MOVE, kFakeCoordX,
  839. kFakeCoordY + 100);
  840. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  841. ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
  842. EXPECT_EQ(
  843. primary_unique_touch_event_id,
  844. GetNthMostRecentGestureEvent(1).details.primary_unique_touch_event_id());
  845. ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
  846. EXPECT_EQ(
  847. primary_unique_touch_event_id,
  848. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  849. EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
  850. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100),
  851. GetMostRecentGestureEvent().details.bounding_box_f());
  852. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
  853. MotionEvent::Action::MOVE, kFakeCoordX,
  854. kFakeCoordY + 200);
  855. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  856. ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
  857. EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
  858. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 200),
  859. GetMostRecentGestureEvent().details.bounding_box_f());
  860. EXPECT_EQ(
  861. primary_unique_touch_event_id,
  862. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  863. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
  864. MotionEvent::Action::MOVE, kFakeCoordX,
  865. kFakeCoordY + 100);
  866. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  867. ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
  868. EXPECT_GT(1.f, GetMostRecentGestureEvent().details.scale());
  869. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100),
  870. GetMostRecentGestureEvent().details.bounding_box_f());
  871. EXPECT_EQ(
  872. primary_unique_touch_event_id,
  873. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  874. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 4,
  875. MotionEvent::Action::UP, kFakeCoordX,
  876. kFakeCoordY - 200);
  877. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  878. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
  879. EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
  880. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY - 200),
  881. GetMostRecentGestureEvent().details.bounding_box_f());
  882. EXPECT_EQ(
  883. primary_unique_touch_event_id,
  884. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  885. }
  886. // Generate a scroll gesture and verify that the resulting scroll motion event
  887. // has both absolute and relative position information.
  888. TEST_F(GestureProviderTest, ScrollUpdateValues) {
  889. const float delta_x = 16;
  890. const float delta_y = 84;
  891. const float raw_offset_x = 17.3f;
  892. const float raw_offset_y = 13.7f;
  893. const base::TimeTicks event_time = TimeTicks::Now();
  894. MockMotionEvent event =
  895. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  896. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  897. EXPECT_EQ(
  898. GetMostRecentGestureEvent().unique_touch_event_id,
  899. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  900. uint32_t primary_unique_touch_event_id =
  901. GetMostRecentGestureEvent().unique_touch_event_id;
  902. // Move twice so that we get two ET_GESTURE_SCROLL_UPDATE events and can
  903. // compare the relative and absolute coordinates.
  904. event =
  905. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
  906. kFakeCoordX - delta_x / 2, kFakeCoordY - delta_y / 2);
  907. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  908. EXPECT_EQ(
  909. primary_unique_touch_event_id,
  910. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  911. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  912. MotionEvent::Action::MOVE, kFakeCoordX - delta_x,
  913. kFakeCoordY - delta_y);
  914. event.SetRawOffset(raw_offset_x, raw_offset_y);
  915. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  916. // Make sure the reported gesture event has all the expected details.
  917. ASSERT_LT(0U, GetReceivedGestureCount());
  918. GestureEventData gesture = GetMostRecentGestureEvent();
  919. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
  920. EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
  921. EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
  922. EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
  923. EXPECT_EQ(kFakeCoordX - delta_x + raw_offset_x, gesture.raw_x);
  924. EXPECT_EQ(kFakeCoordY - delta_y + raw_offset_y, gesture.raw_y);
  925. EXPECT_EQ(1, gesture.details.touch_points());
  926. // No horizontal delta because of snapping.
  927. EXPECT_EQ(0, gesture.details.scroll_x());
  928. EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y());
  929. EXPECT_EQ(primary_unique_touch_event_id,
  930. gesture.details.primary_unique_touch_event_id());
  931. }
  932. // Verify that fractional scroll deltas are rounded as expected and that
  933. // fractional scrolling doesn't break scroll snapping.
  934. TEST_F(GestureProviderTest, FractionalScroll) {
  935. const float delta_x = 0.4f;
  936. const float delta_y = 5.2f;
  937. const base::TimeTicks event_time = TimeTicks::Now();
  938. MockMotionEvent event =
  939. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  940. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  941. EXPECT_EQ(
  942. GetMostRecentGestureEvent().unique_touch_event_id,
  943. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  944. uint32_t primary_unique_touch_event_id =
  945. GetMostRecentGestureEvent().unique_touch_event_id;
  946. // Skip past the touch slop and move back.
  947. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  948. kFakeCoordY + 100);
  949. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  950. EXPECT_EQ(
  951. primary_unique_touch_event_id,
  952. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  953. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE);
  954. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  955. EXPECT_EQ(
  956. primary_unique_touch_event_id,
  957. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  958. // Now move up slowly, mostly vertically but with a (fractional) bit of
  959. // horizontal motion.
  960. for (int i = 1; i <= 10; i++) {
  961. event = ObtainMotionEvent(
  962. event_time + kOneMicrosecond * i, MotionEvent::Action::MOVE,
  963. kFakeCoordX + delta_x * i, kFakeCoordY + delta_y * i);
  964. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  965. ASSERT_LT(0U, GetReceivedGestureCount());
  966. GestureEventData gesture = GetMostRecentGestureEvent();
  967. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
  968. EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time);
  969. EXPECT_EQ(1, gesture.details.touch_points());
  970. EXPECT_EQ(primary_unique_touch_event_id,
  971. gesture.details.primary_unique_touch_event_id());
  972. // Verify that the event co-ordinates are still the precise values we
  973. // supplied.
  974. EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x);
  975. EXPECT_FLOAT_EQ(kFakeCoordY + delta_y * i, gesture.y);
  976. // Verify that we're scrolling vertically by the expected amount
  977. // (modulo rounding).
  978. EXPECT_GE(gesture.details.scroll_y(), (int)delta_y);
  979. EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1);
  980. // And that there has been no horizontal motion at all.
  981. EXPECT_EQ(0, gesture.details.scroll_x());
  982. }
  983. }
  984. // Generate a scroll gesture and verify that the resulting scroll begin event
  985. // has the expected hint values.
  986. TEST_F(GestureProviderTest, ScrollBeginValues) {
  987. const float delta_x = 14;
  988. const float delta_y = 48;
  989. // These are the deltas after subtracting slop region and railing.
  990. const float delta_x_hint = 0;
  991. const float delta_y_hint = 40.32f;
  992. const base::TimeTicks event_time = TimeTicks::Now();
  993. MockMotionEvent event =
  994. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  995. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  996. EXPECT_EQ(
  997. GetMostRecentGestureEvent().unique_touch_event_id,
  998. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  999. uint32_t primary_unique_touch_event_id =
  1000. GetMostRecentGestureEvent().unique_touch_event_id;
  1001. // Move twice such that the first event isn't sufficient to start
  1002. // scrolling on it's own.
  1003. event =
  1004. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
  1005. kFakeCoordX + 2, kFakeCoordY + 1);
  1006. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1007. EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
  1008. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  1009. MotionEvent::Action::MOVE, kFakeCoordX + delta_x,
  1010. kFakeCoordY + delta_y);
  1011. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1012. EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
  1013. const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent();
  1014. ASSERT_TRUE(scroll_begin_gesture);
  1015. EXPECT_EQ(delta_x_hint, scroll_begin_gesture->details.scroll_x_hint());
  1016. EXPECT_EQ(delta_y_hint, scroll_begin_gesture->details.scroll_y_hint());
  1017. EXPECT_EQ(primary_unique_touch_event_id,
  1018. scroll_begin_gesture->details.primary_unique_touch_event_id());
  1019. }
  1020. // The following three tests verify that slop regions are checked for
  1021. // one and two finger scrolls. Three-finger tap doesn't exist, so,
  1022. // no slop region check is needed for three-finger scrolls.
  1023. TEST_F(GestureProviderTest, SlopRegionCheckOnOneFingerScroll) {
  1024. EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
  1025. const float scaled_touch_slop = GetTouchSlop();
  1026. base::TimeTicks event_time = base::TimeTicks::Now();
  1027. MockMotionEvent event =
  1028. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
  1029. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1030. EXPECT_EQ(
  1031. GetMostRecentGestureEvent().unique_touch_event_id,
  1032. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  1033. uint32_t primary_unique_touch_event_id =
  1034. GetMostRecentGestureEvent().unique_touch_event_id;
  1035. // Move within slop region.
  1036. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 0,
  1037. scaled_touch_slop / 2);
  1038. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1039. // Exceed slop region.
  1040. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 0,
  1041. 2 * scaled_touch_slop);
  1042. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1043. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 0,
  1044. 2 * scaled_touch_slop);
  1045. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1046. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  1047. EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
  1048. EXPECT_EQ(primary_unique_touch_event_id,
  1049. GetReceivedGesture(1).details.primary_unique_touch_event_id());
  1050. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
  1051. EXPECT_EQ(primary_unique_touch_event_id,
  1052. GetReceivedGesture(2).details.primary_unique_touch_event_id());
  1053. EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(3).type());
  1054. EXPECT_EQ(primary_unique_touch_event_id,
  1055. GetReceivedGesture(3).details.primary_unique_touch_event_id());
  1056. EXPECT_EQ(4U, GetReceivedGestureCount());
  1057. }
  1058. TEST_F(GestureProviderTest, SlopRegionCheckOnTwoFingerScroll) {
  1059. EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
  1060. const float scaled_touch_slop = GetTouchSlop();
  1061. base::TimeTicks event_time = base::TimeTicks::Now();
  1062. MockMotionEvent event =
  1063. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
  1064. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1065. EXPECT_EQ(
  1066. GetMostRecentGestureEvent().unique_touch_event_id,
  1067. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  1068. uint32_t primary_unique_touch_event_id =
  1069. GetMostRecentGestureEvent().unique_touch_event_id;
  1070. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
  1071. kMaxTwoFingerTapSeparation / 2, 0);
  1072. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1073. EXPECT_EQ(
  1074. primary_unique_touch_event_id,
  1075. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  1076. // Move within slop region: two-finger tap happens.
  1077. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 0,
  1078. scaled_touch_slop / 2,
  1079. kMaxTwoFingerTapSeparation / 2, 0);
  1080. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1081. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 0,
  1082. scaled_touch_slop / 2,
  1083. kMaxTwoFingerTapSeparation / 2, 0);
  1084. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1085. EXPECT_EQ(
  1086. primary_unique_touch_event_id,
  1087. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  1088. // Exceed slop region: scroll.
  1089. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0,
  1090. scaled_touch_slop / 2,
  1091. kMaxTwoFingerTapSeparation / 2, 0);
  1092. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1093. EXPECT_EQ(
  1094. primary_unique_touch_event_id,
  1095. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  1096. event = ObtainMotionEvent(
  1097. event_time, MotionEvent::Action::MOVE, 0, scaled_touch_slop / 2,
  1098. kMaxTwoFingerTapSeparation / 2, 2 * scaled_touch_slop);
  1099. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1100. event = ObtainMotionEvent(
  1101. event_time, MotionEvent::Action::POINTER_UP, 0, scaled_touch_slop / 2,
  1102. kMaxTwoFingerTapSeparation / 2, 2 * scaled_touch_slop);
  1103. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1104. EXPECT_EQ(
  1105. primary_unique_touch_event_id,
  1106. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  1107. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 0,
  1108. scaled_touch_slop / 2);
  1109. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1110. EXPECT_EQ(
  1111. primary_unique_touch_event_id,
  1112. GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
  1113. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  1114. EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(1).type());
  1115. EXPECT_EQ(primary_unique_touch_event_id,
  1116. GetReceivedGesture(1).details.primary_unique_touch_event_id());
  1117. EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type());
  1118. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(3).type());
  1119. EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(4).type());
  1120. EXPECT_EQ(5U, GetReceivedGestureCount());
  1121. }
  1122. // This test simulates cases like (crbug.com/704426) in which some of the events
  1123. // are missing from the event stream.
  1124. TEST_F(GestureProviderTest, SlopRegionCheckOnMissingSecondaryPointerDownEvent) {
  1125. EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
  1126. const float scaled_touch_slop = GetTouchSlop();
  1127. base::TimeTicks event_time = base::TimeTicks::Now();
  1128. MockMotionEvent event =
  1129. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
  1130. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1131. // Don't send Action::POINTER_DOWN event to the gesture_provider.
  1132. // This is for simulating the cases that the Action::POINTER_DOWN event is
  1133. // missing from the event sequence.
  1134. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
  1135. kMaxTwoFingerTapSeparation / 2, 0);
  1136. event.MovePoint(1, 0, 3 * scaled_touch_slop);
  1137. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1138. event.ReleasePointAtIndex(0);
  1139. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1140. event.ReleasePoint();
  1141. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1142. // No scroll happens since the source pointer down event for the moved
  1143. // pointer is not found. No two finger tap happens since one of the pointers
  1144. // moved beyond its slop region.
  1145. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  1146. EXPECT_EQ(1U, GetReceivedGestureCount());
  1147. }
  1148. TEST_F(GestureProviderTest, NoSlopRegionCheckOnThreeFingerScroll) {
  1149. EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
  1150. const float scaled_touch_slop = GetTouchSlop();
  1151. base::TimeTicks event_time = base::TimeTicks::Now();
  1152. MockMotionEvent event =
  1153. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
  1154. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1155. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
  1156. kMaxTwoFingerTapSeparation / 2, 0);
  1157. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1158. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
  1159. kMaxTwoFingerTapSeparation / 2, 0,
  1160. 2 * kMaxTwoFingerTapSeparation, 0);
  1161. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1162. // Move within slop region, three-finger scroll always happens.
  1163. event = ObtainMotionEvent(
  1164. event_time, MotionEvent::Action::MOVE, 0, scaled_touch_slop / 2,
  1165. kMaxTwoFingerTapSeparation / 2, 0, 2 * kMaxTwoFingerTapSeparation, 0);
  1166. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1167. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  1168. EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
  1169. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
  1170. EXPECT_EQ(3U, GetReceivedGestureCount());
  1171. }
  1172. TEST_F(GestureProviderTest, ScrollStartWithSecondaryPointer) {
  1173. EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
  1174. const float scaled_touch_slop = GetTouchSlop();
  1175. base::TimeTicks event_time = base::TimeTicks::Now();
  1176. MockMotionEvent event =
  1177. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
  1178. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1179. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
  1180. kMaxTwoFingerTapSeparation / 2, 0);
  1181. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1182. // Wait for the two finger tap timeout, and put the second pointer down.
  1183. event_time += kOneSecond;
  1184. event.set_event_time(event_time);
  1185. event.ReleasePointAtIndex(0);
  1186. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1187. event.MovePoint(0, kMaxTwoFingerTapSeparation / 2, 2 * scaled_touch_slop);
  1188. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1189. event.ReleasePoint();
  1190. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1191. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  1192. EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
  1193. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
  1194. EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(3).type());
  1195. EXPECT_EQ(4U, GetReceivedGestureCount());
  1196. }
  1197. TEST_F(GestureProviderTest, NoFlingBeforeExeedingSlopRegion) {
  1198. base::TimeTicks event_time = base::TimeTicks::Now();
  1199. base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
  1200. MockMotionEvent event = ObtainMotionEvent(event_time + delta_time,
  1201. MotionEvent::Action::DOWN, 0, 0);
  1202. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1203. event = ObtainMotionEvent(event_time + 2 * delta_time,
  1204. MotionEvent::Action::POINTER_DOWN, 0, 0, 10, 0);
  1205. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1206. // Fast pointer movements within touch slop region.
  1207. event = ObtainMotionEvent(event_time + 3 * delta_time,
  1208. MotionEvent::Action::MOVE, 1, 0, 11, 0);
  1209. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1210. event = ObtainMotionEvent(event_time + 4 * delta_time,
  1211. MotionEvent::Action::MOVE, 2, 0, 12, 0);
  1212. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1213. event = ObtainMotionEvent(event_time + 5 * delta_time,
  1214. MotionEvent::Action::MOVE, 3, 0, 13, 0);
  1215. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1216. event.ReleasePointAtIndex(0);
  1217. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1218. event.ReleasePoint();
  1219. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1220. // No fling must happen even though velocity is greater than the required
  1221. // minium.
  1222. EXPECT_EQ(1U, GetReceivedGestureCount());
  1223. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  1224. }
  1225. TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) {
  1226. base::TimeTicks event_time = base::TimeTicks::Now();
  1227. MockMotionEvent event =
  1228. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1229. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1230. event =
  1231. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
  1232. kFakeCoordX * 5, kFakeCoordY * 5);
  1233. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1234. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  1235. MotionEvent::Action::MOVE, kFakeCoordX * 10,
  1236. kFakeCoordY * 10);
  1237. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1238. const base::TimeDelta long_press_timeout =
  1239. GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
  1240. RunTasksAndWait(long_press_timeout);
  1241. // No LONG_TAP as the LONG_PRESS timer is cancelled.
  1242. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SHORT_PRESS));
  1243. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
  1244. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
  1245. }
  1246. // Verify that LONG_TAP is triggered after LONG_PRESS followed by an UP.
  1247. TEST_F(GestureProviderTest, GestureLongTap) {
  1248. base::TimeTicks event_time = base::TimeTicks::Now();
  1249. MockMotionEvent event =
  1250. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1251. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1252. const base::TimeDelta long_press_timeout =
  1253. GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
  1254. RunTasksAndWait(long_press_timeout);
  1255. EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
  1256. EXPECT_EQ(1, GetNthMostRecentGestureEvent(1).details.touch_points());
  1257. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
  1258. GetNthMostRecentGestureEvent(1).details.bounding_box_f());
  1259. EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
  1260. EXPECT_EQ(1, GetNthMostRecentGestureEvent(0).details.touch_points());
  1261. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
  1262. GetNthMostRecentGestureEvent(0).details.bounding_box_f());
  1263. event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::Action::UP);
  1264. gesture_provider_->OnTouchEvent(event);
  1265. EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType());
  1266. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1267. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
  1268. GetMostRecentGestureEvent().details.bounding_box_f());
  1269. }
  1270. TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) {
  1271. base::TimeTicks event_time = base::TimeTicks::Now();
  1272. MockMotionEvent event =
  1273. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1274. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1275. const base::TimeDelta long_press_timeout =
  1276. GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
  1277. RunTasksAndWait(long_press_timeout);
  1278. EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
  1279. EXPECT_EQ(1, GetNthMostRecentGestureEvent(1).details.touch_points());
  1280. EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
  1281. EXPECT_EQ(1, GetNthMostRecentGestureEvent(0).details.touch_points());
  1282. event = ObtainMotionEvent(event_time + long_press_timeout,
  1283. MotionEvent::Action::MOVE, kFakeCoordX + 100,
  1284. kFakeCoordY + 100);
  1285. gesture_provider_->OnTouchEvent(event);
  1286. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
  1287. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1288. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1289. event = ObtainMotionEvent(event_time + long_press_timeout,
  1290. MotionEvent::Action::UP);
  1291. gesture_provider_->OnTouchEvent(event);
  1292. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
  1293. }
  1294. TEST_F(GestureProviderTest, DeepPressAcceleratedLongPress) {
  1295. SetDeepPressAcceleratedLongPress(true);
  1296. base::TimeTicks event_time = base::TimeTicks::Now();
  1297. MockMotionEvent event =
  1298. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1299. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  1300. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1301. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1302. MotionEvent::Action::MOVE);
  1303. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  1304. event.SetClassification(MotionEvent::Classification::DEEP_PRESS);
  1305. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1306. EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
  1307. EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
  1308. }
  1309. TEST_F(GestureProviderTest, StylusButtonCausesLongPress) {
  1310. SetStylusButtonAcceleratedLongPress(true);
  1311. base::TimeTicks event_time = base::TimeTicks::Now();
  1312. MockMotionEvent event =
  1313. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1314. event.SetToolType(0, MotionEvent::ToolType::STYLUS);
  1315. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1316. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1317. MotionEvent::Action::MOVE);
  1318. event.SetToolType(0, MotionEvent::ToolType::STYLUS);
  1319. event.set_flags(EF_LEFT_MOUSE_BUTTON);
  1320. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1321. EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
  1322. EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
  1323. }
  1324. TEST_F(GestureProviderTest, DisabledStylusButtonDoesNotCauseLongPress) {
  1325. SetStylusButtonAcceleratedLongPress(false);
  1326. base::TimeTicks event_time = base::TimeTicks::Now();
  1327. MockMotionEvent event =
  1328. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1329. event.SetToolType(0, MotionEvent::ToolType::STYLUS);
  1330. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1331. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1332. MotionEvent::Action::MOVE);
  1333. event.SetToolType(0, MotionEvent::ToolType::STYLUS);
  1334. event.set_flags(EF_LEFT_MOUSE_BUTTON);
  1335. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1336. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SHORT_PRESS));
  1337. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
  1338. }
  1339. TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) {
  1340. base::TimeTicks event_time = base::TimeTicks::Now();
  1341. int motion_event_id = 6;
  1342. MockMotionEvent event = ObtainMotionEvent(
  1343. event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
  1344. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1345. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1346. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1347. gesture_provider_->OnTouchEvent(event);
  1348. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  1349. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1350. event_time += GetValidDoubleTapDelay();
  1351. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  1352. kFakeCoordY);
  1353. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1354. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1355. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1356. EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
  1357. const base::TimeDelta long_press_timeout =
  1358. GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
  1359. RunTasksAndWait(long_press_timeout);
  1360. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SHORT_PRESS));
  1361. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
  1362. event = ObtainMotionEvent(event_time + long_press_timeout,
  1363. MotionEvent::Action::MOVE, kFakeCoordX + 20,
  1364. kFakeCoordY + 20);
  1365. event.SetPrimaryPointerId(motion_event_id);
  1366. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1367. EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
  1368. EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
  1369. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  1370. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1371. EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
  1372. event =
  1373. ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond,
  1374. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY + 1);
  1375. event.SetPrimaryPointerId(motion_event_id);
  1376. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1377. EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
  1378. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  1379. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1380. EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress());
  1381. }
  1382. // Verify that the touch slop region is removed from the first scroll delta to
  1383. // avoid a jump when starting to scroll.
  1384. TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) {
  1385. const float touch_slop = GetTouchSlop();
  1386. const float scroll_delta = 5;
  1387. base::TimeTicks event_time = base::TimeTicks::Now();
  1388. MockMotionEvent event =
  1389. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1390. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1391. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  1392. MotionEvent::Action::MOVE, kFakeCoordX,
  1393. kFakeCoordY + touch_slop + scroll_delta);
  1394. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1395. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
  1396. GestureEventData gesture = GetMostRecentGestureEvent();
  1397. EXPECT_EQ(0, gesture.details.scroll_x());
  1398. EXPECT_EQ(scroll_delta, gesture.details.scroll_y());
  1399. EXPECT_EQ(1, gesture.details.touch_points());
  1400. }
  1401. // Verify that movement within the touch slop region does not generate a scroll,
  1402. // and that the slop region is correct even when using fractional coordinates.
  1403. TEST_F(GestureProviderTest, NoScrollWithinTouchSlop) {
  1404. const float touch_slop = GetTouchSlop();
  1405. const float scale_factor = 2.5f;
  1406. const int touch_slop_pixels = static_cast<int>(scale_factor * touch_slop);
  1407. base::TimeTicks event_time = base::TimeTicks::Now();
  1408. MockMotionEvent event =
  1409. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1410. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1411. event = ObtainMotionEvent(
  1412. event_time + kOneMicrosecond * 2, MotionEvent::Action::MOVE,
  1413. kFakeCoordX + touch_slop_pixels / scale_factor, kFakeCoordY);
  1414. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1415. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1416. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  1417. MotionEvent::Action::MOVE, kFakeCoordX,
  1418. kFakeCoordY + touch_slop_pixels / scale_factor);
  1419. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1420. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1421. event = ObtainMotionEvent(
  1422. event_time + kOneMicrosecond * 2, MotionEvent::Action::MOVE,
  1423. kFakeCoordX - touch_slop_pixels / scale_factor, kFakeCoordY);
  1424. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1425. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1426. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  1427. MotionEvent::Action::MOVE, kFakeCoordX,
  1428. kFakeCoordY - touch_slop_pixels / scale_factor);
  1429. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1430. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1431. event = ObtainMotionEvent(
  1432. event_time + kOneMicrosecond * 2, MotionEvent::Action::MOVE, kFakeCoordX,
  1433. kFakeCoordY + (touch_slop_pixels + 1.f) / scale_factor);
  1434. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1435. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1436. }
  1437. TEST_F(GestureProviderTest, NoDoubleTapWhenTooRapid) {
  1438. base::TimeTicks event_time = base::TimeTicks::Now();
  1439. MockMotionEvent event =
  1440. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1441. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1442. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1443. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1444. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1445. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1446. gesture_provider_->OnTouchEvent(event);
  1447. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  1448. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1449. // If the second tap follows the first in too short a time span, no double-tap
  1450. // will occur.
  1451. event_time += (GetDoubleTapMinTime() / 2);
  1452. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  1453. kFakeCoordY);
  1454. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1455. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1456. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1457. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1458. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1459. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1460. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  1461. }
  1462. TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) {
  1463. // Ensure that double-tap gestures can be disabled.
  1464. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  1465. base::TimeTicks event_time = base::TimeTicks::Now();
  1466. MockMotionEvent event = ObtainMotionEvent(
  1467. event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
  1468. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1469. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1470. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1471. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1472. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1473. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  1474. event_time += GetValidDoubleTapDelay();
  1475. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  1476. kFakeCoordY);
  1477. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1478. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1479. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1480. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1481. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1482. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  1483. // Ensure that double-tap gestures can be interrupted.
  1484. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  1485. event_time = base::TimeTicks::Now();
  1486. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  1487. kFakeCoordY);
  1488. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1489. EXPECT_EQ(5U, GetReceivedGestureCount());
  1490. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1491. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1492. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1493. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  1494. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  1495. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  1496. // Ensure that double-tap gestures can be resumed.
  1497. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  1498. event_time += GetValidDoubleTapDelay();
  1499. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  1500. kFakeCoordY);
  1501. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1502. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1503. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1504. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1505. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1506. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  1507. event_time += GetValidDoubleTapDelay();
  1508. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  1509. kFakeCoordY);
  1510. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1511. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1512. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1513. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1514. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1515. EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, GetMostRecentGestureEventType());
  1516. }
  1517. TEST_F(GestureProviderTest, NoDoubleTapWhenConsumerDoesntWantIt) {
  1518. // Double tap gestures are supported by the platform but the current consumer
  1519. // doesn't want it.
  1520. should_process_double_tap_events_ = false;
  1521. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  1522. base::TimeTicks event_time = base::TimeTicks::Now();
  1523. MockMotionEvent event = ObtainMotionEvent(
  1524. event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
  1525. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1526. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1527. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1528. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1529. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1530. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  1531. event_time += GetValidDoubleTapDelay();
  1532. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  1533. kFakeCoordY);
  1534. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1535. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1536. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1537. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1538. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1539. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  1540. // The consumer now wants to receive double taps.
  1541. should_process_double_tap_events_ = true;
  1542. event_time = base::TimeTicks::Now();
  1543. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  1544. kFakeCoordY);
  1545. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1546. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1547. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1548. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1549. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1550. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  1551. event_time += GetValidDoubleTapDelay();
  1552. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  1553. kFakeCoordY);
  1554. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1555. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1556. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1557. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1558. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1559. EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, GetMostRecentGestureEventType());
  1560. }
  1561. TEST_F(GestureProviderTest, NoDelayedTapWhenDoubleTapSupportToggled) {
  1562. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  1563. base::TimeTicks event_time = base::TimeTicks::Now();
  1564. MockMotionEvent event = ObtainMotionEvent(
  1565. event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
  1566. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1567. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1568. EXPECT_EQ(1U, GetReceivedGestureCount());
  1569. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  1570. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1571. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1572. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  1573. EXPECT_EQ(2U, GetReceivedGestureCount());
  1574. // Disabling double-tap during the tap timeout should flush the delayed tap.
  1575. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  1576. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  1577. EXPECT_EQ(3U, GetReceivedGestureCount());
  1578. // No further timeout gestures should arrive.
  1579. const base::TimeDelta long_press_timeout =
  1580. GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
  1581. RunTasksAndWait(long_press_timeout);
  1582. EXPECT_EQ(3U, GetReceivedGestureCount());
  1583. }
  1584. TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) {
  1585. const base::TimeTicks down_time_1 = TimeTicks::Now();
  1586. const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
  1587. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  1588. MockMotionEvent event =
  1589. ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
  1590. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1591. event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
  1592. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1593. gesture_provider_->OnTouchEvent(event);
  1594. event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
  1595. kFakeCoordY);
  1596. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1597. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
  1598. MotionEvent::Action::MOVE, kFakeCoordX,
  1599. kFakeCoordY + 100);
  1600. // The move should become a scroll, as doubletap drag zoom is disabled.
  1601. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1602. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1603. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
  1604. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
  1605. MotionEvent::Action::MOVE, kFakeCoordX,
  1606. kFakeCoordY + 200);
  1607. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1608. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
  1609. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1610. EXPECT_EQ(down_time_2 + kOneMicrosecond * 2,
  1611. GetMostRecentGestureEvent().time);
  1612. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
  1613. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
  1614. MotionEvent::Action::UP, kFakeCoordX,
  1615. kFakeCoordY + 200);
  1616. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1617. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
  1618. }
  1619. // Verify that double tap drag zoom feature is not invoked when the gesture
  1620. // handler is told to disable double tap gesture detection.
  1621. // The second tap sequence should be treated just as the first would be.
  1622. TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPage) {
  1623. const base::TimeTicks down_time_1 = TimeTicks::Now();
  1624. const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
  1625. gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
  1626. MockMotionEvent event =
  1627. ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
  1628. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1629. event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
  1630. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1631. gesture_provider_->OnTouchEvent(event);
  1632. event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
  1633. kFakeCoordY);
  1634. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1635. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
  1636. MotionEvent::Action::MOVE, kFakeCoordX,
  1637. kFakeCoordY + 100);
  1638. // The move should become a scroll, as double tap drag zoom is disabled.
  1639. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1640. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1641. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
  1642. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
  1643. MotionEvent::Action::MOVE, kFakeCoordX,
  1644. kFakeCoordY + 200);
  1645. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1646. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
  1647. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1648. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
  1649. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
  1650. MotionEvent::Action::UP, kFakeCoordX,
  1651. kFakeCoordY + 200);
  1652. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1653. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
  1654. }
  1655. // Verify that updating double tap support during a double tap drag zoom
  1656. // disables double tap detection after the gesture has ended.
  1657. TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) {
  1658. base::TimeTicks down_time_1 = TimeTicks::Now();
  1659. base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
  1660. gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
  1661. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  1662. // Start a double-tap drag gesture.
  1663. MockMotionEvent event =
  1664. ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
  1665. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1666. event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
  1667. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1668. gesture_provider_->OnTouchEvent(event);
  1669. event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
  1670. kFakeCoordY);
  1671. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1672. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
  1673. MotionEvent::Action::MOVE, kFakeCoordX,
  1674. kFakeCoordY + 100);
  1675. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1676. EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
  1677. EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
  1678. EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
  1679. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1680. // Simulate setting a fixed page scale (or a mobile viewport);
  1681. // this should not disrupt the current double-tap gesture.
  1682. gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
  1683. // Double tap zoom updates should continue.
  1684. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
  1685. MotionEvent::Action::MOVE, kFakeCoordX,
  1686. kFakeCoordY + 200);
  1687. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1688. EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
  1689. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1690. EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
  1691. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
  1692. MotionEvent::Action::UP, kFakeCoordX,
  1693. kFakeCoordY + 200);
  1694. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1695. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
  1696. EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
  1697. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1698. // The double-tap gesture has finished, but the page scale is fixed.
  1699. // The same event sequence should not generate any double tap gestures.
  1700. gestures_.clear();
  1701. down_time_1 += kOneMicrosecond * 40;
  1702. down_time_2 += kOneMicrosecond * 40;
  1703. // Start a double-tap drag gesture.
  1704. event = ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
  1705. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1706. event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
  1707. MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
  1708. gesture_provider_->OnTouchEvent(event);
  1709. event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
  1710. kFakeCoordY);
  1711. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1712. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
  1713. MotionEvent::Action::MOVE, kFakeCoordX,
  1714. kFakeCoordY + 100);
  1715. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1716. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1717. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
  1718. // Double tap zoom updates should not be sent.
  1719. // Instead, the second tap drag becomes a scroll gesture sequence.
  1720. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
  1721. MotionEvent::Action::MOVE, kFakeCoordX,
  1722. kFakeCoordY + 200);
  1723. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1724. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
  1725. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
  1726. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
  1727. MotionEvent::Action::UP, kFakeCoordX,
  1728. kFakeCoordY + 200);
  1729. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1730. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
  1731. }
  1732. // Verify that pinch zoom sends the proper event sequence.
  1733. TEST_F(GestureProviderTest, PinchZoom) {
  1734. base::TimeTicks event_time = base::TimeTicks::Now();
  1735. const float touch_slop = GetTouchSlop();
  1736. const float raw_offset_x = 3.2f;
  1737. const float raw_offset_y = 4.3f;
  1738. int motion_event_id = 6;
  1739. gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
  1740. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  1741. gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
  1742. int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
  1743. int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
  1744. MockMotionEvent event =
  1745. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1746. event.SetPrimaryPointerId(motion_event_id);
  1747. event.SetRawOffset(raw_offset_x, raw_offset_y);
  1748. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1749. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1750. EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
  1751. EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
  1752. EXPECT_EQ(kFakeCoordX + raw_offset_x, GetMostRecentGestureEvent().raw_x);
  1753. EXPECT_EQ(kFakeCoordY + raw_offset_y, GetMostRecentGestureEvent().raw_y);
  1754. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1755. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
  1756. GetMostRecentGestureEvent().details.bounding_box_f());
  1757. // Toggling double-tap support should not take effect until the next sequence.
  1758. gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
  1759. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
  1760. kFakeCoordX, kFakeCoordY, secondary_coord_x,
  1761. secondary_coord_y);
  1762. event.SetPrimaryPointerId(motion_event_id);
  1763. event.SetRawOffset(raw_offset_x, raw_offset_y);
  1764. gesture_provider_->OnTouchEvent(event);
  1765. EXPECT_EQ(1U, GetReceivedGestureCount());
  1766. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1767. EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
  1768. GetMostRecentGestureEvent().details.bounding_box_f());
  1769. secondary_coord_x += 5 * touch_slop;
  1770. secondary_coord_y += 5 * touch_slop;
  1771. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  1772. kFakeCoordY, secondary_coord_x, secondary_coord_y);
  1773. event.SetPrimaryPointerId(motion_event_id);
  1774. event.SetRawOffset(raw_offset_x, raw_offset_y);
  1775. // Toggling double-tap support should not take effect until the next sequence.
  1776. gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
  1777. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1778. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  1779. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  1780. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
  1781. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  1782. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
  1783. EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2, GetReceivedGesture(3).x);
  1784. EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2, GetReceivedGesture(3).y);
  1785. EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2 + raw_offset_x,
  1786. GetReceivedGesture(3).raw_x);
  1787. EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2 + raw_offset_y,
  1788. GetReceivedGesture(3).raw_y);
  1789. EXPECT_EQ(
  1790. gfx::RectF(kFakeCoordX - kMockTouchRadius, kFakeCoordY - kMockTouchRadius,
  1791. secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
  1792. secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
  1793. GetMostRecentGestureEvent().details.bounding_box_f());
  1794. secondary_coord_x += 2 * touch_slop;
  1795. secondary_coord_y += 2 * touch_slop;
  1796. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  1797. kFakeCoordY, secondary_coord_x, secondary_coord_y);
  1798. event.SetPrimaryPointerId(motion_event_id);
  1799. // Toggling double-tap support should not take effect until the next sequence.
  1800. gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
  1801. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1802. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  1803. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
  1804. EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
  1805. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  1806. EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
  1807. EXPECT_EQ(
  1808. gfx::RectF(kFakeCoordX - kMockTouchRadius, kFakeCoordY - kMockTouchRadius,
  1809. secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
  1810. secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
  1811. GetMostRecentGestureEvent().details.bounding_box_f());
  1812. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP,
  1813. kFakeCoordX, kFakeCoordY, secondary_coord_x,
  1814. secondary_coord_y);
  1815. event.SetPrimaryPointerId(motion_event_id);
  1816. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1817. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  1818. EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
  1819. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  1820. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
  1821. EXPECT_EQ(
  1822. gfx::RectF(kFakeCoordX - kMockTouchRadius, kFakeCoordY - kMockTouchRadius,
  1823. secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
  1824. secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
  1825. GetMostRecentGestureEvent().details.bounding_box_f());
  1826. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  1827. gesture_provider_->OnTouchEvent(event);
  1828. EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
  1829. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1830. EXPECT_EQ(
  1831. gfx::RectF(kFakeCoordX - kMockTouchRadius, kFakeCoordY - kMockTouchRadius,
  1832. kMockTouchRadius * 2, kMockTouchRadius * 2),
  1833. GetMostRecentGestureEvent().details.bounding_box_f());
  1834. }
  1835. // Verify that no accidental pinching occurs if the touch size is large relative
  1836. // to the min scaling span when the touch major value is used in scaling.
  1837. TEST_F(GestureProviderTest, NoPinchZoomWithFatFinger) {
  1838. base::TimeTicks event_time = base::TimeTicks::Now();
  1839. const float kFatFingerSize = GetMinScalingSpan() * 3.f;
  1840. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  1841. gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
  1842. MockMotionEvent event =
  1843. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1844. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1845. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  1846. EXPECT_EQ(1U, GetReceivedGestureCount());
  1847. event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::Action::MOVE);
  1848. event.SetTouchMajor(0.1f);
  1849. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1850. EXPECT_EQ(1U, GetReceivedGestureCount());
  1851. event =
  1852. ObtainMotionEvent(event_time + kOneSecond * 2, MotionEvent::Action::MOVE,
  1853. kFakeCoordX + 1.f, kFakeCoordY);
  1854. event.SetTouchMajor(1.f);
  1855. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1856. EXPECT_EQ(1U, GetReceivedGestureCount());
  1857. event =
  1858. ObtainMotionEvent(event_time + kOneSecond * 3, MotionEvent::Action::MOVE);
  1859. event.SetTouchMajor(kFatFingerSize * 3.5f);
  1860. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1861. EXPECT_EQ(1U, GetReceivedGestureCount());
  1862. event =
  1863. ObtainMotionEvent(event_time + kOneSecond * 4, MotionEvent::Action::MOVE);
  1864. event.SetTouchMajor(kFatFingerSize * 5.f);
  1865. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1866. EXPECT_EQ(1U, GetReceivedGestureCount());
  1867. event =
  1868. ObtainMotionEvent(event_time + kOneSecond * 4, MotionEvent::Action::MOVE,
  1869. kFakeCoordX + 50.f, kFakeCoordY - 25.f);
  1870. event.SetTouchMajor(kFatFingerSize * 10.f);
  1871. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1872. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
  1873. event =
  1874. ObtainMotionEvent(event_time + kOneSecond * 4, MotionEvent::Action::MOVE,
  1875. kFakeCoordX + 100.f, kFakeCoordY - 50.f);
  1876. event.SetTouchMajor(kFatFingerSize * 5.f);
  1877. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1878. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
  1879. }
  1880. // Verify that multi-finger swipe sends the proper event sequence.
  1881. TEST_F(GestureProviderTest, MultiFingerSwipe) {
  1882. EnableSwipe();
  1883. gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
  1884. const float min_swipe_velocity = GetMinSwipeVelocity();
  1885. // One finger - swipe right
  1886. OneFingerSwipe(2 * min_swipe_velocity, 0);
  1887. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1888. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
  1889. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1890. ResetGestureDetection();
  1891. // One finger - swipe left
  1892. OneFingerSwipe(-2 * min_swipe_velocity, 0);
  1893. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1894. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
  1895. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1896. ResetGestureDetection();
  1897. // One finger - swipe down
  1898. OneFingerSwipe(0, 2 * min_swipe_velocity);
  1899. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1900. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
  1901. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1902. ResetGestureDetection();
  1903. // One finger - swipe up
  1904. OneFingerSwipe(0, -2 * min_swipe_velocity);
  1905. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1906. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
  1907. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  1908. ResetGestureDetection();
  1909. // Two fingers
  1910. // Swipe right.
  1911. TwoFingerSwipe(min_swipe_velocity * 2, 0, min_swipe_velocity * 2, 0);
  1912. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1913. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
  1914. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  1915. ResetGestureDetection();
  1916. // Swipe left.
  1917. TwoFingerSwipe(-min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
  1918. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1919. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
  1920. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  1921. ResetGestureDetection();
  1922. // No swipe with different touch directions.
  1923. TwoFingerSwipe(min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
  1924. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1925. ResetGestureDetection();
  1926. // No swipe without a dominant direction.
  1927. TwoFingerSwipe(min_swipe_velocity * 2,
  1928. min_swipe_velocity * 2,
  1929. min_swipe_velocity * 2,
  1930. min_swipe_velocity * 2);
  1931. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1932. ResetGestureDetection();
  1933. // Swipe down with non-zero velocities on both axes and dominant direction.
  1934. TwoFingerSwipe(-min_swipe_velocity,
  1935. min_swipe_velocity * 4,
  1936. -min_swipe_velocity,
  1937. min_swipe_velocity * 4);
  1938. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1939. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
  1940. EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_left());
  1941. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  1942. ResetGestureDetection();
  1943. // Swipe up with non-zero velocities on both axes.
  1944. TwoFingerSwipe(min_swipe_velocity,
  1945. -min_swipe_velocity * 4,
  1946. min_swipe_velocity,
  1947. -min_swipe_velocity * 4);
  1948. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1949. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
  1950. EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
  1951. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  1952. ResetGestureDetection();
  1953. // No swipe without sufficient velocity.
  1954. TwoFingerSwipe(min_swipe_velocity / 2, 0, 0, 0);
  1955. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1956. ResetGestureDetection();
  1957. // Swipe up with one small and one medium velocity in slightly different but
  1958. // not opposing directions.
  1959. TwoFingerSwipe(min_swipe_velocity / 2,
  1960. min_swipe_velocity / 2,
  1961. 0,
  1962. min_swipe_velocity * 2);
  1963. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1964. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
  1965. EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
  1966. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  1967. ResetGestureDetection();
  1968. // No swipe in orthogonal directions.
  1969. TwoFingerSwipe(min_swipe_velocity * 2, 0, 0, min_swipe_velocity * 7);
  1970. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1971. ResetGestureDetection();
  1972. // Three finger swipe in same directions.
  1973. ThreeFingerSwipe(min_swipe_velocity * 2,
  1974. 0,
  1975. min_swipe_velocity * 3,
  1976. 0,
  1977. min_swipe_velocity * 4,
  1978. 0);
  1979. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1980. EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
  1981. EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
  1982. ResetGestureDetection();
  1983. // No three finger swipe in different directions.
  1984. ThreeFingerSwipe(min_swipe_velocity * 2,
  1985. 0,
  1986. 0,
  1987. min_swipe_velocity * 3,
  1988. min_swipe_velocity * 4,
  1989. 0);
  1990. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
  1991. }
  1992. // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
  1993. // so LONG_PRESS and LONG_TAP won't be triggered.
  1994. TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) {
  1995. base::TimeTicks event_time = base::TimeTicks::Now();
  1996. MockMotionEvent event =
  1997. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  1998. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  1999. const base::TimeDelta long_press_timeout =
  2000. GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
  2001. RunTasksAndWait(long_press_timeout);
  2002. EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
  2003. EXPECT_EQ(1, GetNthMostRecentGestureEvent(1).details.touch_points());
  2004. EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
  2005. EXPECT_EQ(1, GetNthMostRecentGestureEvent(0).details.touch_points());
  2006. EXPECT_TRUE(CancelActiveTouchSequence());
  2007. EXPECT_FALSE(HasDownEvent());
  2008. event = ObtainMotionEvent(event_time + long_press_timeout,
  2009. MotionEvent::Action::UP);
  2010. gesture_provider_->OnTouchEvent(event);
  2011. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
  2012. }
  2013. // Verify that inserting a touch cancel event will trigger proper touch and
  2014. // gesture sequence cancellation.
  2015. TEST_F(GestureProviderTest, CancelActiveTouchSequence) {
  2016. base::TimeTicks event_time = base::TimeTicks::Now();
  2017. int motion_event_id = 6;
  2018. EXPECT_FALSE(CancelActiveTouchSequence());
  2019. EXPECT_EQ(0U, GetReceivedGestureCount());
  2020. MockMotionEvent event =
  2021. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2022. event.SetPrimaryPointerId(motion_event_id);
  2023. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2024. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2025. EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
  2026. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2027. ASSERT_TRUE(CancelActiveTouchSequence());
  2028. EXPECT_FALSE(HasDownEvent());
  2029. // Subsequent MotionEvent's are dropped until Action::DOWN.
  2030. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  2031. MotionEvent::Action::MOVE);
  2032. EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
  2033. event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
  2034. MotionEvent::Action::UP);
  2035. EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
  2036. event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
  2037. MotionEvent::Action::DOWN);
  2038. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2039. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2040. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2041. }
  2042. TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) {
  2043. const base::TimeTicks down_time_1 = TimeTicks::Now();
  2044. const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
  2045. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  2046. MockMotionEvent event =
  2047. ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
  2048. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2049. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2050. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2051. event =
  2052. ObtainMotionEvent(down_time_1 + kOneMicrosecond, MotionEvent::Action::UP);
  2053. gesture_provider_->OnTouchEvent(event);
  2054. EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
  2055. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2056. event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN);
  2057. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2058. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2059. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2060. event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
  2061. MotionEvent::Action::MOVE, kFakeCoordX,
  2062. kFakeCoordY - 30);
  2063. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2064. EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
  2065. EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
  2066. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2067. event = ObtainMotionEvent(
  2068. down_time_2 + kOneMicrosecond * 2, MotionEvent::Action::POINTER_DOWN,
  2069. kFakeCoordX, kFakeCoordY - 30, kFakeCoordX + 50, kFakeCoordY + 50);
  2070. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2071. EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
  2072. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  2073. const size_t gesture_count = GetReceivedGestureCount();
  2074. event = ObtainMotionEvent(
  2075. down_time_2 + kOneMicrosecond * 3, MotionEvent::Action::POINTER_UP,
  2076. kFakeCoordX, kFakeCoordY - 30, kFakeCoordX + 50, kFakeCoordY + 50);
  2077. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2078. EXPECT_EQ(gesture_count, GetReceivedGestureCount());
  2079. event = ObtainMotionEvent(down_time_2 + kOneSecond, MotionEvent::Action::UP);
  2080. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2081. EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
  2082. }
  2083. // Verify that gesture begin and gesture end events are dispatched correctly.
  2084. TEST_F(GestureProviderTest, GestureBeginAndEnd) {
  2085. EnableBeginEndTypes();
  2086. base::TimeTicks event_time = base::TimeTicks::Now();
  2087. const float raw_offset_x = 7.5f;
  2088. const float raw_offset_y = 5.7f;
  2089. EXPECT_EQ(0U, GetReceivedGestureCount());
  2090. MockMotionEvent event =
  2091. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 1, 1);
  2092. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2093. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2094. EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
  2095. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2096. EXPECT_EQ(2U, GetReceivedGestureCount());
  2097. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2098. EXPECT_EQ(1, GetMostRecentGestureEvent().x);
  2099. EXPECT_EQ(1, GetMostRecentGestureEvent().y);
  2100. EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
  2101. EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
  2102. EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius, 1 - kMockTouchRadius,
  2103. kMockTouchRadius * 2, kMockTouchRadius * 2),
  2104. GetMostRecentGestureEvent().details.bounding_box_f());
  2105. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 1, 1,
  2106. 2, 2);
  2107. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2108. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2109. EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
  2110. EXPECT_EQ(3U, GetReceivedGestureCount());
  2111. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  2112. EXPECT_EQ(2, GetMostRecentGestureEvent().x);
  2113. EXPECT_EQ(2, GetMostRecentGestureEvent().y);
  2114. EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
  2115. EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
  2116. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 1, 1,
  2117. 2, 2, 3, 3);
  2118. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2119. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2120. EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
  2121. EXPECT_EQ(4U, GetReceivedGestureCount());
  2122. EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
  2123. EXPECT_EQ(3, GetMostRecentGestureEvent().x);
  2124. EXPECT_EQ(3, GetMostRecentGestureEvent().y);
  2125. EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
  2126. EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
  2127. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 1, 1,
  2128. 2, 2, 3, 3);
  2129. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2130. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2131. EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
  2132. EXPECT_EQ(5U, GetReceivedGestureCount());
  2133. EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
  2134. EXPECT_EQ(1, GetMostRecentGestureEvent().x);
  2135. EXPECT_EQ(1, GetMostRecentGestureEvent().y);
  2136. EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
  2137. EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
  2138. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 2, 2,
  2139. 3, 3, 4, 4);
  2140. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2141. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2142. EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
  2143. EXPECT_EQ(6U, GetReceivedGestureCount());
  2144. EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
  2145. EXPECT_EQ(4, GetMostRecentGestureEvent().x);
  2146. EXPECT_EQ(4, GetMostRecentGestureEvent().y);
  2147. EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
  2148. EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
  2149. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 2, 2,
  2150. 3, 3, 4, 4);
  2151. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2152. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2153. EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
  2154. EXPECT_EQ(7U, GetReceivedGestureCount());
  2155. EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
  2156. EXPECT_EQ(2, GetMostRecentGestureEvent().x);
  2157. EXPECT_EQ(2, GetMostRecentGestureEvent().y);
  2158. EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
  2159. EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
  2160. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 3, 3,
  2161. 4, 4);
  2162. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2163. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2164. EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
  2165. EXPECT_EQ(8U, GetReceivedGestureCount());
  2166. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  2167. EXPECT_EQ(3, GetMostRecentGestureEvent().x);
  2168. EXPECT_EQ(3, GetMostRecentGestureEvent().y);
  2169. EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
  2170. EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
  2171. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 4, 4);
  2172. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2173. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2174. EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
  2175. EXPECT_EQ(9U, GetReceivedGestureCount());
  2176. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2177. EXPECT_EQ(4, GetMostRecentGestureEvent().x);
  2178. EXPECT_EQ(4, GetMostRecentGestureEvent().y);
  2179. EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
  2180. EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
  2181. }
  2182. // Verify that gesture begin and gesture end events are dispatched correctly
  2183. // when an Action::CANCEL is received.
  2184. TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) {
  2185. EnableBeginEndTypes();
  2186. base::TimeTicks event_time = base::TimeTicks::Now();
  2187. EXPECT_EQ(0U, GetReceivedGestureCount());
  2188. MockMotionEvent event =
  2189. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 1, 1);
  2190. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2191. EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
  2192. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2193. EXPECT_EQ(2U, GetReceivedGestureCount());
  2194. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2195. EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius, 1 - kMockTouchRadius,
  2196. kMockTouchRadius * 2, kMockTouchRadius * 2),
  2197. GetMostRecentGestureEvent().details.bounding_box_f());
  2198. EXPECT_EQ(1, GetMostRecentGestureEvent().x);
  2199. EXPECT_EQ(1, GetMostRecentGestureEvent().y);
  2200. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 1, 1,
  2201. 2, 2);
  2202. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2203. EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
  2204. EXPECT_EQ(3U, GetReceivedGestureCount());
  2205. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  2206. EXPECT_EQ(2, GetMostRecentGestureEvent().x);
  2207. EXPECT_EQ(2, GetMostRecentGestureEvent().y);
  2208. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 1, 1,
  2209. 2, 2, 3, 3);
  2210. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2211. EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
  2212. EXPECT_EQ(4U, GetReceivedGestureCount());
  2213. EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
  2214. EXPECT_EQ(3, GetMostRecentGestureEvent().x);
  2215. EXPECT_EQ(3, GetMostRecentGestureEvent().y);
  2216. event = ObtainMotionEvent(event_time, MotionEvent::Action::CANCEL, 1, 1, 2, 2,
  2217. 3, 3);
  2218. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2219. EXPECT_EQ(5U, GetReceivedGestureCount());
  2220. EXPECT_EQ(3, GetReceivedGesture(4).details.touch_points());
  2221. EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(4).type());
  2222. EXPECT_EQ(1, GetMostRecentGestureEvent().x);
  2223. EXPECT_EQ(1, GetMostRecentGestureEvent().y);
  2224. event =
  2225. ObtainMotionEvent(event_time, MotionEvent::Action::CANCEL, 1, 1, 3, 3);
  2226. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2227. EXPECT_EQ(6U, GetReceivedGestureCount());
  2228. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  2229. EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEvent().type());
  2230. EXPECT_EQ(1, GetMostRecentGestureEvent().x);
  2231. EXPECT_EQ(1, GetMostRecentGestureEvent().y);
  2232. event = ObtainMotionEvent(event_time, MotionEvent::Action::CANCEL, 3, 3);
  2233. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2234. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2235. EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEvent().type());
  2236. EXPECT_EQ(3, GetMostRecentGestureEvent().x);
  2237. EXPECT_EQ(3, GetMostRecentGestureEvent().y);
  2238. }
  2239. // Test a simple two finger tap
  2240. TEST_F(GestureProviderTest, TwoFingerTap) {
  2241. // The time between Action::POINTER_DOWN and Action::POINTER_UP must be <= the
  2242. // two finger tap delay.
  2243. EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
  2244. const float scaled_touch_slop = GetTouchSlop();
  2245. base::TimeTicks event_time = base::TimeTicks::Now();
  2246. MockMotionEvent event =
  2247. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
  2248. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2249. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 0,
  2250. scaled_touch_slop / 2);
  2251. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
  2252. kMaxTwoFingerTapSeparation / 2, 0);
  2253. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2254. event = ObtainMotionEvent(
  2255. event_time, MotionEvent::Action::MOVE, 0, -scaled_touch_slop / 2,
  2256. kMaxTwoFingerTapSeparation / 2 + scaled_touch_slop / 2, 0);
  2257. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2258. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 0, 0,
  2259. kMaxTwoFingerTapSeparation, 0);
  2260. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2261. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  2262. EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(1).type());
  2263. EXPECT_EQ(2U, GetReceivedGestureCount());
  2264. EXPECT_EQ(kMockTouchRadius * 2,
  2265. GetReceivedGesture(1).details.first_finger_width());
  2266. EXPECT_EQ(kMockTouchRadius * 2,
  2267. GetReceivedGesture(1).details.first_finger_height());
  2268. }
  2269. // Test preventing a two finger tap via finger movement.
  2270. TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) {
  2271. EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
  2272. const float scaled_touch_slop = GetTouchSlop();
  2273. base::TimeTicks event_time = base::TimeTicks::Now();
  2274. MockMotionEvent event = ObtainMotionEvent(
  2275. event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
  2276. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2277. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
  2278. kFakeCoordX, kFakeCoordY, kFakeCoordX, kFakeCoordY);
  2279. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2280. event = ObtainMotionEvent(
  2281. event_time, MotionEvent::Action::MOVE, kFakeCoordX, kFakeCoordY,
  2282. kFakeCoordX + 2 * scaled_touch_slop + 2, kFakeCoordY);
  2283. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2284. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP,
  2285. kFakeCoordX, kFakeCoordY, kFakeCoordX, kFakeCoordY);
  2286. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2287. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  2288. EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
  2289. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
  2290. // d_x = 2 * scaled_touch_slop + 2,
  2291. // d_focus_x = scaled_touch_slop + 1,
  2292. // touch_slop / event.GetPointerCount() is deducted from first scroll,
  2293. // scroll_x = scaled_touch_slop + 1 - scaled_touch_slop / 2
  2294. EXPECT_FLOAT_EQ(scaled_touch_slop / 2 + 1,
  2295. GetReceivedGesture(2).details.scroll_x());
  2296. EXPECT_EQ(0, GetReceivedGesture(2).details.scroll_y());
  2297. EXPECT_EQ(3U, GetReceivedGestureCount());
  2298. }
  2299. // Test preventing a two finger tap by waiting too long before releasing the
  2300. // secondary pointer.
  2301. TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) {
  2302. base::TimeDelta two_finger_tap_timeout = kOneSecond;
  2303. EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout);
  2304. base::TimeTicks event_time = base::TimeTicks::Now();
  2305. MockMotionEvent event = ObtainMotionEvent(
  2306. event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
  2307. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2308. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  2309. kFakeCoordY);
  2310. event = ObtainMotionEvent(
  2311. event_time, MotionEvent::Action::POINTER_DOWN, kFakeCoordX, kFakeCoordY,
  2312. kFakeCoordX + kMaxTwoFingerTapSeparation / 2, kFakeCoordY);
  2313. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2314. event = ObtainMotionEvent(
  2315. event_time + kOneSecond + kOneMicrosecond,
  2316. MotionEvent::Action::POINTER_UP, kFakeCoordX, kFakeCoordY,
  2317. kFakeCoordX + kMaxTwoFingerTapSeparation / 2, kFakeCoordY);
  2318. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2319. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  2320. EXPECT_EQ(1U, GetReceivedGestureCount());
  2321. }
  2322. // Test preventing a two finger tap by pressing the secondary pointer too far
  2323. // from the first
  2324. TEST_F(GestureProviderTest, TwoFingerTapCancelledByDistanceBetweenPointers) {
  2325. EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
  2326. base::TimeTicks event_time = base::TimeTicks::Now();
  2327. MockMotionEvent event = ObtainMotionEvent(
  2328. event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
  2329. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2330. event = ObtainMotionEvent(
  2331. event_time, MotionEvent::Action::POINTER_DOWN, kFakeCoordX, kFakeCoordY,
  2332. kFakeCoordX + kMaxTwoFingerTapSeparation, kFakeCoordY);
  2333. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2334. event = ObtainMotionEvent(
  2335. event_time, MotionEvent::Action::POINTER_UP, kFakeCoordX, kFakeCoordY,
  2336. kFakeCoordX + kMaxTwoFingerTapSeparation, kFakeCoordY);
  2337. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2338. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
  2339. EXPECT_EQ(1U, GetReceivedGestureCount());
  2340. }
  2341. // Verify that the event that starts the pinch-zoom by exceeding the touch-slop
  2342. // also generates an update.
  2343. TEST_F(GestureProviderTest, PinchExceedingSlopCausesUpdate) {
  2344. base::TimeTicks event_time = base::TimeTicks::Now();
  2345. const float touch_slop = GetTouchSlop();
  2346. const float min_scaling_span = GetMinScalingSpan();
  2347. const float raw_offset_x = 3.2f;
  2348. const float raw_offset_y = 4.3f;
  2349. int motion_event_id = 6;
  2350. gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
  2351. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  2352. gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
  2353. int secondary_coord_x = kFakeCoordX;
  2354. int secondary_coord_y = kFakeCoordY + min_scaling_span + 1;
  2355. // First Finger Down
  2356. MockMotionEvent event =
  2357. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2358. event.SetPrimaryPointerId(motion_event_id);
  2359. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2360. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2361. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2362. EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
  2363. EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
  2364. // Second Finger Down
  2365. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
  2366. kFakeCoordX, kFakeCoordY, secondary_coord_x,
  2367. secondary_coord_y);
  2368. event.SetPrimaryPointerId(motion_event_id);
  2369. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2370. gesture_provider_->OnTouchEvent(event);
  2371. EXPECT_EQ(1U, GetReceivedGestureCount());
  2372. // Move second finger by exactly the touch slop. This shouldn't yet generate
  2373. // a Pinch Begin.
  2374. secondary_coord_y += touch_slop * 2;
  2375. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  2376. kFakeCoordY, secondary_coord_x, secondary_coord_y);
  2377. event.SetPrimaryPointerId(motion_event_id);
  2378. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2379. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2380. EXPECT_EQ(3U, GetReceivedGestureCount());
  2381. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  2382. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
  2383. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
  2384. // Move second finger that should *just* cross the slop threshold.
  2385. secondary_coord_y += 1;
  2386. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  2387. kFakeCoordY, secondary_coord_x, secondary_coord_y);
  2388. event.SetPrimaryPointerId(motion_event_id);
  2389. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2390. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2391. EXPECT_EQ(6U, GetReceivedGestureCount());
  2392. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetNthMostRecentGestureEventType(2));
  2393. EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
  2394. EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetNthMostRecentGestureEventType(0));
  2395. EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
  2396. }
  2397. // Verify that the event that stops the pinch-zoom by exceeding the min scaling
  2398. // span also generates an update.
  2399. TEST_F(GestureProviderTest, PinchBelowMinSpanCausesUpdate) {
  2400. base::TimeTicks event_time = base::TimeTicks::Now();
  2401. const float touch_slop = GetTouchSlop();
  2402. const float min_scaling_span = GetMinScalingSpan();
  2403. const float raw_offset_x = 3.2f;
  2404. const float raw_offset_y = 4.3f;
  2405. int motion_event_id = 6;
  2406. gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
  2407. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  2408. gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
  2409. int secondary_coord_x = kFakeCoordX;
  2410. int secondary_coord_y = kFakeCoordY + min_scaling_span + touch_slop * 3;
  2411. // First Finger Down
  2412. MockMotionEvent event =
  2413. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2414. event.SetPrimaryPointerId(motion_event_id);
  2415. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2416. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2417. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2418. EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
  2419. EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
  2420. // Second Finger Down
  2421. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
  2422. kFakeCoordX, kFakeCoordY, secondary_coord_x,
  2423. secondary_coord_y);
  2424. event.SetPrimaryPointerId(motion_event_id);
  2425. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2426. gesture_provider_->OnTouchEvent(event);
  2427. EXPECT_EQ(1U, GetReceivedGestureCount());
  2428. // Move second finger enough to exceed the touch slop and start zooming.
  2429. secondary_coord_y -= (touch_slop * 2 + 1);
  2430. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  2431. kFakeCoordY, secondary_coord_x, secondary_coord_y);
  2432. event.SetPrimaryPointerId(motion_event_id);
  2433. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2434. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2435. EXPECT_EQ(5U, GetReceivedGestureCount());
  2436. EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetNthMostRecentGestureEventType(3));
  2437. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetNthMostRecentGestureEventType(2));
  2438. EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
  2439. EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetNthMostRecentGestureEventType(0));
  2440. // Move second finger so that the span becomes smaller than the min scaling
  2441. // span. The pinch should end but we should receive an update before it does.
  2442. secondary_coord_y -= touch_slop * 2;
  2443. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  2444. kFakeCoordY, secondary_coord_x, secondary_coord_y);
  2445. event.SetPrimaryPointerId(motion_event_id);
  2446. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2447. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2448. EXPECT_EQ(8U, GetReceivedGestureCount());
  2449. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetNthMostRecentGestureEventType(2));
  2450. EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetNthMostRecentGestureEventType(1));
  2451. EXPECT_GT(1.f, GetNthMostRecentGestureEvent(1).details.scale());
  2452. EXPECT_EQ(ET_GESTURE_PINCH_END, GetNthMostRecentGestureEventType(0));
  2453. }
  2454. // Verify that the pinch isn't started until it becomes larger than the min
  2455. // scaling span.
  2456. TEST_F(GestureProviderTest, PinchExceedingSlopWithinMinScale) {
  2457. base::TimeTicks event_time = base::TimeTicks::Now();
  2458. const float touch_slop = GetTouchSlop();
  2459. const float min_scaling_span = GetMinScalingSpan();
  2460. const float raw_offset_x = 3.2f;
  2461. const float raw_offset_y = 4.3f;
  2462. int motion_event_id = 6;
  2463. gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
  2464. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  2465. gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
  2466. int secondary_coord_x = kFakeCoordX;
  2467. int secondary_coord_y = kFakeCoordY + min_scaling_span / 4;
  2468. // This test only makes sense if the min_scaling_span is greater than the
  2469. // touch slop span.
  2470. ASSERT_GT(min_scaling_span, touch_slop * 2);
  2471. // First Finger Down
  2472. MockMotionEvent event =
  2473. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2474. event.SetPrimaryPointerId(motion_event_id);
  2475. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2476. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2477. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2478. EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
  2479. EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
  2480. // Second Finger Down
  2481. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
  2482. kFakeCoordX, kFakeCoordY, secondary_coord_x,
  2483. secondary_coord_y);
  2484. event.SetPrimaryPointerId(motion_event_id);
  2485. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2486. gesture_provider_->OnTouchEvent(event);
  2487. EXPECT_EQ(1U, GetReceivedGestureCount());
  2488. // Move second finger to exceed the touch slop. This shouldn't yet generate
  2489. // a Pinch Begin since we're still within the minimum scaling span.
  2490. secondary_coord_y += touch_slop * 2 + 1;
  2491. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  2492. kFakeCoordY, secondary_coord_x, secondary_coord_y);
  2493. event.SetPrimaryPointerId(motion_event_id);
  2494. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2495. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2496. EXPECT_EQ(3U, GetReceivedGestureCount());
  2497. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  2498. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
  2499. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
  2500. // Move second finger that should *just* cross the min scaling span threshold.
  2501. secondary_coord_y = kFakeCoordY + min_scaling_span + 1;
  2502. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  2503. kFakeCoordY, secondary_coord_x, secondary_coord_y);
  2504. event.SetPrimaryPointerId(motion_event_id);
  2505. event.SetRawOffset(raw_offset_x, raw_offset_y);
  2506. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2507. EXPECT_EQ(6U, GetReceivedGestureCount());
  2508. EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetNthMostRecentGestureEventType(2));
  2509. EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
  2510. EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetNthMostRecentGestureEventType(0));
  2511. // The scale must start from the min scale span threshold, rather than from
  2512. // the touch_slop so it should be very small.
  2513. EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
  2514. EXPECT_GT(1.01f, GetMostRecentGestureEvent().details.scale());
  2515. }
  2516. // Verify that pinch zoom only sends updates which exceed the
  2517. // min_pinch_update_span_delta.
  2518. TEST_F(GestureProviderTest, PinchZoomWithThreshold) {
  2519. const float kMinPinchUpdateDistance = 5;
  2520. base::TimeTicks event_time = base::TimeTicks::Now();
  2521. const float touch_slop = GetTouchSlop();
  2522. SetMinPinchUpdateSpanDelta(kMinPinchUpdateDistance);
  2523. gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
  2524. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  2525. gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
  2526. int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
  2527. int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
  2528. // First finger down.
  2529. MockMotionEvent event =
  2530. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2531. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2532. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2533. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2534. // Second finger down.
  2535. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
  2536. kFakeCoordX, kFakeCoordY, secondary_coord_x,
  2537. secondary_coord_y);
  2538. gesture_provider_->OnTouchEvent(event);
  2539. EXPECT_EQ(1U, GetReceivedGestureCount());
  2540. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2541. // Move second finger.
  2542. secondary_coord_x += 5 * touch_slop;
  2543. secondary_coord_y += 5 * touch_slop;
  2544. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  2545. kFakeCoordY, secondary_coord_x, secondary_coord_y);
  2546. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2547. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  2548. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
  2549. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
  2550. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
  2551. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
  2552. // Small move, shouldn't trigger pinch.
  2553. gestures_.clear();
  2554. event = ObtainMotionEvent(
  2555. event_time, MotionEvent::Action::MOVE, kFakeCoordX, kFakeCoordY,
  2556. secondary_coord_x + kMinPinchUpdateDistance, secondary_coord_y);
  2557. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2558. EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
  2559. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  2560. // Small move, but combined with the previous move, should trigger pinch. We
  2561. // need to overshoot kMinPinchUpdateDistance by a fair bit, as the span
  2562. // calculation factors in touch radius.
  2563. const float kOvershootMinPinchUpdateDistance = 3;
  2564. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
  2565. kFakeCoordY,
  2566. secondary_coord_x + kMinPinchUpdateDistance +
  2567. kOvershootMinPinchUpdateDistance,
  2568. secondary_coord_y);
  2569. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2570. EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
  2571. EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
  2572. }
  2573. // Verify that the min gesture bound setting is honored.
  2574. TEST_F(GestureProviderTest, MinGestureBoundsLength) {
  2575. const float kMinGestureBoundsLength = 10.f * kMockTouchRadius;
  2576. SetMinMaxGestureBoundsLength(kMinGestureBoundsLength, 0.f);
  2577. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  2578. base::TimeTicks event_time = base::TimeTicks::Now();
  2579. MockMotionEvent event =
  2580. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2581. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2582. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2583. EXPECT_EQ(kMinGestureBoundsLength,
  2584. GetMostRecentGestureEvent().details.bounding_box_f().width());
  2585. EXPECT_EQ(kMinGestureBoundsLength,
  2586. GetMostRecentGestureEvent().details.bounding_box_f().height());
  2587. event =
  2588. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
  2589. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2590. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2591. EXPECT_EQ(kMinGestureBoundsLength,
  2592. GetMostRecentGestureEvent().details.bounding_box_f().width());
  2593. EXPECT_EQ(kMinGestureBoundsLength,
  2594. GetMostRecentGestureEvent().details.bounding_box_f().height());
  2595. }
  2596. TEST_F(GestureProviderTest, MaxGestureBoundsLength) {
  2597. const float kMaxGestureBoundsLength = kMockTouchRadius / 10.f;
  2598. SetMinMaxGestureBoundsLength(0.f, kMaxGestureBoundsLength);
  2599. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  2600. base::TimeTicks event_time = base::TimeTicks::Now();
  2601. MockMotionEvent event =
  2602. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2603. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2604. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2605. EXPECT_EQ(kMaxGestureBoundsLength,
  2606. GetMostRecentGestureEvent().details.bounding_box_f().width());
  2607. EXPECT_EQ(kMaxGestureBoundsLength,
  2608. GetMostRecentGestureEvent().details.bounding_box_f().height());
  2609. event =
  2610. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
  2611. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2612. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2613. EXPECT_EQ(kMaxGestureBoundsLength,
  2614. GetMostRecentGestureEvent().details.bounding_box_f().width());
  2615. EXPECT_EQ(kMaxGestureBoundsLength,
  2616. GetMostRecentGestureEvent().details.bounding_box_f().height());
  2617. }
  2618. TEST_F(GestureProviderTest, ZeroRadiusBoundingBox) {
  2619. base::TimeTicks event_time = base::TimeTicks::Now();
  2620. MockMotionEvent event =
  2621. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 20);
  2622. event.SetTouchMajor(0);
  2623. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2624. EXPECT_EQ(gfx::RectF(10, 20, 0, 0),
  2625. GetMostRecentGestureEvent().details.bounding_box_f());
  2626. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 10,
  2627. 20, 110, 120);
  2628. event.SetTouchMajor(0);
  2629. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2630. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 10, 20, 110,
  2631. 150);
  2632. event.SetTouchMajor(0);
  2633. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2634. EXPECT_EQ(gfx::RectF(10, 20, 100, 130),
  2635. GetMostRecentGestureEvent().details.bounding_box_f());
  2636. }
  2637. // Verify that the min/max gesture bound settings are not applied to stylus
  2638. // or mouse-derived MotionEvents.
  2639. TEST_F(GestureProviderTest, NoMinOrMaxGestureBoundsLengthWithStylusOrMouse) {
  2640. const float kMinGestureBoundsLength = 5.f * kMockTouchRadius;
  2641. const float kMaxGestureBoundsLength = 10.f * kMockTouchRadius;
  2642. SetMinMaxGestureBoundsLength(kMinGestureBoundsLength,
  2643. kMaxGestureBoundsLength);
  2644. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  2645. base::TimeTicks event_time = base::TimeTicks::Now();
  2646. MockMotionEvent event =
  2647. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2648. event.SetTouchMajor(0);
  2649. event.SetToolType(0, MotionEvent::ToolType::MOUSE);
  2650. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2651. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2652. EXPECT_EQ(MotionEvent::ToolType::MOUSE,
  2653. GetMostRecentGestureEvent().primary_tool_type);
  2654. EXPECT_EQ(0.f, GetMostRecentGestureEvent().details.bounding_box_f().width());
  2655. EXPECT_EQ(0.f, GetMostRecentGestureEvent().details.bounding_box_f().height());
  2656. event =
  2657. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
  2658. event.SetTouchMajor(1);
  2659. event.SetToolType(0, MotionEvent::ToolType::STYLUS);
  2660. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2661. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2662. EXPECT_EQ(MotionEvent::ToolType::STYLUS,
  2663. GetMostRecentGestureEvent().primary_tool_type);
  2664. EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().width());
  2665. EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().height());
  2666. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2667. event.SetTouchMajor(2.f * kMaxGestureBoundsLength);
  2668. event.SetToolType(0, MotionEvent::ToolType::MOUSE);
  2669. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2670. EXPECT_EQ(MotionEvent::ToolType::MOUSE,
  2671. GetMostRecentGestureEvent().primary_tool_type);
  2672. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2673. EXPECT_EQ(2.f * kMaxGestureBoundsLength,
  2674. GetMostRecentGestureEvent().details.bounding_box_f().width());
  2675. EXPECT_EQ(2.f * kMaxGestureBoundsLength,
  2676. GetMostRecentGestureEvent().details.bounding_box_f().height());
  2677. event =
  2678. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
  2679. event.SetTouchMajor(2.f * kMaxGestureBoundsLength);
  2680. event.SetToolType(0, MotionEvent::ToolType::ERASER);
  2681. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2682. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2683. EXPECT_EQ(MotionEvent::ToolType::ERASER,
  2684. GetMostRecentGestureEvent().primary_tool_type);
  2685. EXPECT_EQ(2.f * kMaxGestureBoundsLength,
  2686. GetMostRecentGestureEvent().details.bounding_box_f().width());
  2687. EXPECT_EQ(2.f * kMaxGestureBoundsLength,
  2688. GetMostRecentGestureEvent().details.bounding_box_f().height());
  2689. }
  2690. #if BUILDFLAG(IS_MAC) && defined(ARCH_CPU_ARM64)
  2691. // https://crbug.com/1222659
  2692. #define MAYBE_BoundingBoxForShowPressAndTapGesture \
  2693. DISABLED_BoundingBoxForShowPressAndTapGesture
  2694. #else
  2695. #define MAYBE_BoundingBoxForShowPressAndTapGesture \
  2696. BoundingBoxForShowPressAndTapGesture
  2697. #endif
  2698. // Test the bounding box for show press and tap gestures.
  2699. TEST_F(GestureProviderTest, MAYBE_BoundingBoxForShowPressAndTapGesture) {
  2700. base::TimeTicks event_time = base::TimeTicks::Now();
  2701. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  2702. base::TimeDelta showpress_timeout = kOneMicrosecond;
  2703. base::TimeDelta shortpress_timeout = kOneSecond;
  2704. base::TimeDelta longpress_timeout = kOneSecond * 2;
  2705. SetShowPressAndLongPressTimeout(showpress_timeout, shortpress_timeout,
  2706. longpress_timeout);
  2707. MockMotionEvent event =
  2708. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 10);
  2709. event.SetTouchMajor(10);
  2710. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2711. EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
  2712. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2713. EXPECT_EQ(gfx::RectF(5, 5, 10, 10),
  2714. GetMostRecentGestureEvent().details.bounding_box_f());
  2715. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  2716. MotionEvent::Action::MOVE, 11, 9);
  2717. event.SetTouchMajor(20);
  2718. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2719. event = ObtainMotionEvent(event_time + kOneMicrosecond,
  2720. MotionEvent::Action::MOVE, 8, 11);
  2721. event.SetTouchMajor(10);
  2722. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2723. RunTasksAndWait(showpress_timeout + kOneMicrosecond);
  2724. EXPECT_EQ(ET_GESTURE_SHOW_PRESS, GetMostRecentGestureEventType());
  2725. EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
  2726. GetMostRecentGestureEvent().details.bounding_box_f());
  2727. event =
  2728. ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
  2729. event.SetTouchMajor(30);
  2730. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2731. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2732. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  2733. EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
  2734. EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
  2735. GetMostRecentGestureEvent().details.bounding_box_f());
  2736. }
  2737. TEST_F(GestureProviderTest, SingleTapRepeat) {
  2738. SetSingleTapRepeatInterval(3);
  2739. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  2740. base::TimeTicks event_time = base::TimeTicks::Now();
  2741. MockMotionEvent event =
  2742. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2743. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2744. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2745. gesture_provider_->OnTouchEvent(event);
  2746. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2747. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  2748. // A second tap after the double-tap timeout window will not increment
  2749. // the tap count.
  2750. event_time += GetDoubleTapTimeout() + kOneMicrosecond;
  2751. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2752. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2753. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2754. gesture_provider_->OnTouchEvent(event);
  2755. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2756. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  2757. // A secondary tap within the tap repeat period should increment
  2758. // the tap count.
  2759. event_time += GetValidDoubleTapDelay();
  2760. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2761. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2762. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2763. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2764. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2765. EXPECT_EQ(2, GetMostRecentGestureEvent().details.tap_count());
  2766. // A secondary tap within the tap repeat location threshold should increment
  2767. // the tap count.
  2768. event_time += GetValidDoubleTapDelay();
  2769. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  2770. kFakeCoordY + GetTouchSlop() / 2);
  2771. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2772. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2773. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2774. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2775. EXPECT_EQ(3, GetMostRecentGestureEvent().details.tap_count());
  2776. // The tap count should reset after hitting the repeat length.
  2777. event_time += GetValidDoubleTapDelay();
  2778. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2779. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2780. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2781. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2782. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2783. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  2784. // If double-tap is enabled, the tap repeat count should always be 1.
  2785. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
  2786. event_time += GetValidDoubleTapDelay();
  2787. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2788. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2789. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2790. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2791. RunTasksAndWait(GetDoubleTapTimeout());
  2792. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2793. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  2794. event_time += GetValidDoubleTapDelay();
  2795. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2796. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2797. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2798. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2799. RunTasksAndWait(GetDoubleTapTimeout());
  2800. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2801. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  2802. }
  2803. TEST_F(GestureProviderTest, SingleTapRepeatLengthOfOne) {
  2804. SetSingleTapRepeatInterval(1);
  2805. gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
  2806. base::TimeTicks event_time = base::TimeTicks::Now();
  2807. MockMotionEvent event =
  2808. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2809. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2810. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2811. gesture_provider_->OnTouchEvent(event);
  2812. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2813. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  2814. // Repeated taps should still produce a tap count of 1 if the
  2815. // tap repeat length is 1.
  2816. event_time += GetValidDoubleTapDelay();
  2817. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2818. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2819. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2820. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2821. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2822. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  2823. event_time += GetValidDoubleTapDelay();
  2824. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
  2825. kFakeCoordY + GetTouchSlop() / 2);
  2826. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2827. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2828. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2829. EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
  2830. EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
  2831. }
  2832. // Test for Event.MaxDragDistance.* histograms with taps.
  2833. TEST_F(GestureProviderTest, MaxDragDistanceHistogramsWithTap) {
  2834. base::HistogramTester histograms_tester;
  2835. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 0);
  2836. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 0);
  2837. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 0);
  2838. // A tap of type FINGER adds appropriate counts.
  2839. base::TimeTicks event_time = base::TimeTicks::Now();
  2840. MockMotionEvent event =
  2841. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2842. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2843. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2844. event_time += kOneMicrosecond;
  2845. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2846. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2847. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2848. histograms_tester.ExpectBucketCount("Event.MaxDragDistance.FINGER", 0, 1);
  2849. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 0);
  2850. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
  2851. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 0);
  2852. // A tap of type STYLUS adds appropriate counts.
  2853. event_time += kOneMicrosecond;
  2854. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2855. event.SetToolType(0, MotionEvent::ToolType::STYLUS);
  2856. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2857. event_time += kOneMicrosecond;
  2858. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2859. event.SetToolType(0, MotionEvent::ToolType::STYLUS);
  2860. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2861. histograms_tester.ExpectBucketCount("Event.MaxDragDistance.STYLUS", 0, 1);
  2862. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 0);
  2863. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
  2864. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 1);
  2865. // A tap of type ERASER adds appropriate counts.
  2866. event_time += kOneMicrosecond;
  2867. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2868. event.SetToolType(0, MotionEvent::ToolType::ERASER);
  2869. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2870. event_time += kOneMicrosecond;
  2871. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2872. event.SetToolType(0, MotionEvent::ToolType::ERASER);
  2873. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2874. histograms_tester.ExpectBucketCount("Event.MaxDragDistance.ERASER", 0, 1);
  2875. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 1);
  2876. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
  2877. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 1);
  2878. // A canceled tap is not counted.
  2879. event_time += kOneMicrosecond;
  2880. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2881. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2882. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2883. event_time += kOneMicrosecond;
  2884. event = ObtainMotionEvent(event_time, MotionEvent::Action::CANCEL);
  2885. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2886. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2887. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 1);
  2888. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
  2889. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 1);
  2890. // A multifinger tap is not counted.
  2891. event_time += kOneMicrosecond;
  2892. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
  2893. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2894. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2895. event_time += kOneMicrosecond;
  2896. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN);
  2897. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2898. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2899. event_time += kOneMicrosecond;
  2900. event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP);
  2901. event.SetToolType(0, MotionEvent::ToolType::STYLUS);
  2902. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2903. event_time += kOneMicrosecond;
  2904. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
  2905. event.SetToolType(0, MotionEvent::ToolType::STYLUS);
  2906. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2907. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 1);
  2908. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
  2909. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 1);
  2910. }
  2911. // Test for Event.MaxDragDistance.* histograms with drags.
  2912. TEST_F(GestureProviderTest, MaxDragDistanceHistogramsWithDrag) {
  2913. base::HistogramTester histograms_tester;
  2914. // A tiny 1px drag is counted in appropriate distance bucket.
  2915. base::TimeTicks event_time = base::TimeTicks::Now();
  2916. MockMotionEvent event =
  2917. ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 10);
  2918. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2919. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2920. event_time += kOneMicrosecond;
  2921. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 10, 11);
  2922. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2923. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2924. event_time += kOneMicrosecond;
  2925. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 10, 11);
  2926. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2927. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2928. histograms_tester.ExpectBucketCount("Event.MaxDragDistance.FINGER", 1, 1);
  2929. // A small 10px drag is counted in appropriate distance bucket.
  2930. event_time += kOneMicrosecond;
  2931. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 10);
  2932. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2933. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2934. event_time += kOneMicrosecond;
  2935. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 10, 20);
  2936. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2937. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2938. event_time += kOneMicrosecond;
  2939. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 10, 20);
  2940. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2941. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2942. histograms_tester.ExpectBucketCount("Event.MaxDragDistance.FINGER", 10, 1);
  2943. // A long 100px drag is counted in appropriate distance bucket.
  2944. event_time += kOneMicrosecond;
  2945. event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 10);
  2946. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2947. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2948. event_time += kOneMicrosecond;
  2949. event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 10, 110);
  2950. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2951. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2952. event_time += kOneMicrosecond;
  2953. event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 10, 110);
  2954. event.SetToolType(0, MotionEvent::ToolType::FINGER);
  2955. EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
  2956. histograms_tester.ExpectBucketCount("Event.MaxDragDistance.FINGER", 100, 1);
  2957. // We have 3 counts in total
  2958. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 0);
  2959. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 3);
  2960. histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 0);
  2961. }
  2962. } // namespace ui