123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507 |
- // Copyright 2014 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "ui/events/gesture_detection/gesture_provider.h"
- #include <stddef.h>
- #include <memory>
- #include "base/check.h"
- #include "base/location.h"
- #include "base/run_loop.h"
- #include "base/task/single_thread_task_runner.h"
- #include "base/test/metrics/histogram_tester.h"
- #include "base/test/task_environment.h"
- #include "base/threading/thread_task_runner_handle.h"
- #include "base/time/time.h"
- #include "build/build_config.h"
- #include "testing/gtest/include/gtest/gtest.h"
- #include "ui/events/event_constants.h"
- #include "ui/events/gesture_detection/gesture_event_data.h"
- #include "ui/events/gesture_detection/motion_event.h"
- #include "ui/events/test/motion_event_test_utils.h"
- #include "ui/events/types/event_type.h"
- #include "ui/gfx/geometry/point_f.h"
- using base::TimeTicks;
- using ui::test::MockMotionEvent;
- namespace ui {
- namespace {
- const float kFakeCoordX = 42.f;
- const float kFakeCoordY = 24.f;
- const base::TimeDelta kOneSecond = base::Seconds(1);
- const base::TimeDelta kOneMicrosecond = base::Microseconds(1);
- const base::TimeDelta kDeltaTimeForFlingSequences = base::Milliseconds(5);
- const float kMockTouchRadius = MockMotionEvent::TOUCH_MAJOR / 2;
- const float kMaxTwoFingerTapSeparation = 300;
- GestureProvider::Config CreateDefaultConfig() {
- GestureProvider::Config sConfig;
- // The longpress timeout is non-zero only to indicate ordering with respect to
- // the showpress timeout.
- sConfig.gesture_detector_config.showpress_timeout = base::TimeDelta();
- sConfig.gesture_detector_config.shortpress_timeout = kOneMicrosecond;
- sConfig.gesture_detector_config.longpress_timeout = kOneMicrosecond * 2;
- // A valid doubletap timeout should always be non-zero. The value is used not
- // only to trigger the timeout that confirms the tap event, but also to gate
- // whether the second tap is in fact a double-tap (using a strict inequality
- // between times for the first up and the second down events). We use 4
- // microseconds simply to allow several intermediate events to occur before
- // the second tap at microsecond intervals.
- sConfig.gesture_detector_config.double_tap_timeout = kOneMicrosecond * 4;
- sConfig.gesture_detector_config.double_tap_min_time = kOneMicrosecond * 2;
- return sConfig;
- }
- gfx::RectF BoundsForSingleMockTouchAtLocation(float x, float y) {
- float diameter = MockMotionEvent::TOUCH_MAJOR;
- return gfx::RectF(x - diameter / 2, y - diameter / 2, diameter, diameter);
- }
- } // namespace
- class GestureProviderTest : public testing::Test, public GestureProviderClient {
- public:
- GestureProviderTest()
- : task_environment_(
- base::test::SingleThreadTaskEnvironment::MainThreadType::UI) {}
- ~GestureProviderTest() override {}
- static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
- MotionEvent::Action action,
- float x,
- float y) {
- return MockMotionEvent(action, event_time, x, y);
- }
- static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
- MotionEvent::Action action,
- float x0,
- float y0,
- float x1,
- float y1) {
- return MockMotionEvent(action, event_time, x0, y0, x1, y1);
- }
- static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
- MotionEvent::Action action,
- float x0,
- float y0,
- float x1,
- float y1,
- float x2,
- float y2) {
- return MockMotionEvent(action, event_time, x0, y0, x1, y1, x2, y2);
- }
- static MockMotionEvent ObtainMotionEvent(
- base::TimeTicks event_time,
- MotionEvent::Action action,
- const std::vector<gfx::PointF>& positions) {
- switch (positions.size()) {
- case 1:
- return MockMotionEvent(
- action, event_time, positions[0].x(), positions[0].y());
- case 2:
- return MockMotionEvent(action,
- event_time,
- positions[0].x(),
- positions[0].y(),
- positions[1].x(),
- positions[1].y());
- case 3:
- return MockMotionEvent(action,
- event_time,
- positions[0].x(),
- positions[0].y(),
- positions[1].x(),
- positions[1].y(),
- positions[2].x(),
- positions[2].y());
- default:
- CHECK(false) << "MockMotionEvent only supports 1-3 pointers";
- return MockMotionEvent();
- }
- }
- static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
- MotionEvent::Action action) {
- return ObtainMotionEvent(event_time, action, kFakeCoordX, kFakeCoordY);
- }
- // Test
- void SetUp() override { SetUpWithConfig(GetDefaultConfig()); }
- void TearDown() override {
- gestures_.clear();
- gesture_provider_.reset();
- }
- // GestureProviderClient
- void OnGestureEvent(const GestureEventData& gesture) override {
- EXPECT_EQ(GestureDeviceType::DEVICE_TOUCHSCREEN,
- gesture.details.device_type());
- if (gesture.type() == ET_GESTURE_SCROLL_BEGIN)
- active_scroll_begin_event_ = std::make_unique<GestureEventData>(gesture);
- gestures_.push_back(gesture);
- }
- bool RequiresDoubleTapGestureEvents() const override {
- return should_process_double_tap_events_;
- }
- void SetUpWithConfig(const GestureProvider::Config& config) {
- gesture_provider_ = std::make_unique<GestureProvider>(config, this);
- gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
- }
- void ResetGestureDetection() {
- gesture_provider_->ResetDetection();
- gestures_.clear();
- }
- bool CancelActiveTouchSequence() {
- if (!gesture_provider_->current_down_event())
- return false;
- return gesture_provider_->OnTouchEvent(
- *gesture_provider_->current_down_event()->Cancel());
- }
- bool HasReceivedGesture(EventType type) const {
- for (size_t i = 0; i < gestures_.size(); ++i) {
- if (gestures_[i].type() == type)
- return true;
- }
- return false;
- }
- const GestureEventData& GetMostRecentGestureEvent() const {
- EXPECT_FALSE(gestures_.empty());
- return gestures_.back();
- }
- const GestureEventData& GetNthMostRecentGestureEvent(size_t n) const {
- EXPECT_FALSE(gestures_.empty());
- return GetReceivedGesture(GetReceivedGestureCount() - 1 - n);
- }
- EventType GetNthMostRecentGestureEventType(size_t n) const {
- return GetNthMostRecentGestureEvent(n).type();
- }
- EventType GetMostRecentGestureEventType() const {
- EXPECT_FALSE(gestures_.empty());
- return gestures_.back().type();
- }
- size_t GetReceivedGestureCount() const { return gestures_.size(); }
- const GestureEventData& GetReceivedGesture(size_t index) const {
- EXPECT_LT(index, GetReceivedGestureCount());
- return gestures_[index];
- }
- const GestureEventData* GetActiveScrollBeginEvent() const {
- return active_scroll_begin_event_ ? active_scroll_begin_event_.get() : NULL;
- }
- const GestureProvider::Config& GetDefaultConfig() const {
- static GestureProvider::Config sConfig = CreateDefaultConfig();
- return sConfig;
- }
- float GetTouchSlop() const {
- return GetDefaultConfig().gesture_detector_config.touch_slop;
- }
- float GetMinScalingSpan() const {
- return GetDefaultConfig().scale_gesture_detector_config.min_scaling_span;
- }
- float GetMinSwipeVelocity() const {
- return GetDefaultConfig().gesture_detector_config.minimum_swipe_velocity;
- }
- base::TimeDelta GetLongPressTimeout() const {
- return GetDefaultConfig().gesture_detector_config.longpress_timeout;
- }
- base::TimeDelta GetShowPressTimeout() const {
- return GetDefaultConfig().gesture_detector_config.showpress_timeout;
- }
- base::TimeDelta GetDoubleTapTimeout() const {
- return GetDefaultConfig().gesture_detector_config.double_tap_timeout;
- }
- base::TimeDelta GetDoubleTapMinTime() const {
- return GetDefaultConfig().gesture_detector_config.double_tap_min_time;
- }
- base::TimeDelta GetValidDoubleTapDelay() const {
- return (GetDoubleTapTimeout() + GetDoubleTapMinTime()) / 2;
- }
- void EnableBeginEndTypes() {
- GestureProvider::Config config = GetDefaultConfig();
- config.gesture_begin_end_types_enabled = true;
- SetUpWithConfig(config);
- }
- void EnableSwipe() {
- GestureProvider::Config config = GetDefaultConfig();
- config.gesture_detector_config.swipe_enabled = true;
- SetUpWithConfig(config);
- }
- void EnableTwoFingerTap(float max_distance_for_two_finger_tap,
- base::TimeDelta two_finger_tap_timeout) {
- GestureProvider::Config config = GetDefaultConfig();
- config.gesture_detector_config.two_finger_tap_enabled = true;
- config.gesture_detector_config.two_finger_tap_max_separation =
- max_distance_for_two_finger_tap;
- config.gesture_detector_config.two_finger_tap_timeout =
- two_finger_tap_timeout;
- SetUpWithConfig(config);
- }
- void SetMinPinchUpdateSpanDelta(float min_pinch_update_span_delta) {
- GestureProvider::Config config = GetDefaultConfig();
- config.scale_gesture_detector_config.min_pinch_update_span_delta =
- min_pinch_update_span_delta;
- SetUpWithConfig(config);
- }
- void SetMinMaxGestureBoundsLength(float min_gesture_bound_length,
- float max_gesture_bound_length) {
- GestureProvider::Config config = GetDefaultConfig();
- config.min_gesture_bounds_length = min_gesture_bound_length;
- config.max_gesture_bounds_length = max_gesture_bound_length;
- SetUpWithConfig(config);
- }
- void SetShowPressAndLongPressTimeout(base::TimeDelta showpress_timeout,
- base::TimeDelta shortpress_timeout,
- base::TimeDelta longpress_timeout) {
- GestureProvider::Config config = GetDefaultConfig();
- config.gesture_detector_config.showpress_timeout = showpress_timeout;
- config.gesture_detector_config.shortpress_timeout = shortpress_timeout;
- config.gesture_detector_config.longpress_timeout = longpress_timeout;
- SetUpWithConfig(config);
- }
- void SetSingleTapRepeatInterval(int repeat_interval) {
- GestureProvider::Config config = GetDefaultConfig();
- config.gesture_detector_config.single_tap_repeat_interval = repeat_interval;
- SetUpWithConfig(config);
- }
- void SetStylusButtonAcceleratedLongPress(bool enabled) {
- GestureProvider::Config config = GetDefaultConfig();
- config.gesture_detector_config.stylus_button_accelerated_longpress_enabled =
- enabled;
- SetUpWithConfig(config);
- }
- void SetDeepPressAcceleratedLongPress(bool enabled) {
- GestureProvider::Config config = GetDefaultConfig();
- config.gesture_detector_config.deep_press_accelerated_longpress_enabled =
- enabled;
- SetUpWithConfig(config);
- }
- bool HasDownEvent() const { return gesture_provider_->current_down_event(); }
- protected:
- void CheckScrollEventSequenceForEndActionType(
- MotionEvent::Action end_action_type) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- const float scroll_to_x = kFakeCoordX + 100;
- const float scroll_to_y = kFakeCoordY + 100;
- int motion_event_id = 3;
- int motion_event_flags = EF_SHIFT_DOWN | EF_CAPS_LOCK_ON;
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event =
- ObtainMotionEvent(event_time + kOneSecond, MotionEvent::Action::MOVE,
- scroll_to_x, scroll_to_y);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
- EXPECT_EQ(event.GetToolType(0),
- GetMostRecentGestureEvent().primary_tool_type);
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y),
- GetMostRecentGestureEvent().details.bounding_box_f());
- ASSERT_EQ(3U, GetReceivedGestureCount()) << "Only TapDown, "
- "ScrollBegin and ScrollBy "
- "should have been sent";
- EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
- EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id);
- EXPECT_EQ(primary_unique_touch_event_id,
- GetReceivedGesture(1).details.primary_unique_touch_event_id());
- EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(1).time)
- << "ScrollBegin should have the time of the Action::MOVE";
- event = ObtainMotionEvent(
- event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- event.SetPrimaryPointerId(motion_event_id);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
- EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(event.GetToolType(0),
- GetMostRecentGestureEvent().primary_tool_type);
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y),
- GetMostRecentGestureEvent().details.bounding_box_f());
- }
- void OneFingerSwipe(float vx, float vy) {
- std::vector<gfx::Vector2dF> velocities;
- velocities.push_back(gfx::Vector2dF(vx, vy));
- MultiFingerSwipe(velocities);
- }
- void TwoFingerSwipe(float vx0, float vy0, float vx1, float vy1) {
- std::vector<gfx::Vector2dF> velocities;
- velocities.push_back(gfx::Vector2dF(vx0, vy0));
- velocities.push_back(gfx::Vector2dF(vx1, vy1));
- MultiFingerSwipe(velocities);
- }
- void ThreeFingerSwipe(float vx0,
- float vy0,
- float vx1,
- float vy1,
- float vx2,
- float vy2) {
- std::vector<gfx::Vector2dF> velocities;
- velocities.push_back(gfx::Vector2dF(vx0, vy0));
- velocities.push_back(gfx::Vector2dF(vx1, vy1));
- velocities.push_back(gfx::Vector2dF(vx2, vy2));
- MultiFingerSwipe(velocities);
- }
- void MultiFingerSwipe(std::vector<gfx::Vector2dF> velocities) {
- ASSERT_GT(velocities.size(), 0U);
- base::TimeTicks event_time = base::TimeTicks::Now();
- std::vector<gfx::PointF> positions(velocities.size());
- for (size_t i = 0; i < positions.size(); ++i)
- positions[i] = gfx::PointF(kFakeCoordX * (i + 1), kFakeCoordY * (i + 1));
- float dt = kDeltaTimeForFlingSequences.InSecondsF();
- // Each pointer down should be a separate event.
- for (size_t i = 0; i < positions.size(); ++i) {
- const size_t pointer_count = i + 1;
- std::vector<gfx::PointF> event_positions(pointer_count);
- event_positions.assign(positions.begin(),
- positions.begin() + pointer_count);
- MockMotionEvent event = ObtainMotionEvent(
- event_time,
- pointer_count > 1 ? MotionEvent::Action::POINTER_DOWN
- : MotionEvent::Action::DOWN,
- event_positions);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- }
- for (size_t i = 0; i < positions.size(); ++i)
- positions[i] += gfx::ScaleVector2d(velocities[i], dt);
- MockMotionEvent event =
- ObtainMotionEvent(event_time + kDeltaTimeForFlingSequences,
- MotionEvent::Action::MOVE, positions);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- for (size_t i = 0; i < positions.size(); ++i)
- positions[i] += gfx::ScaleVector2d(velocities[i], dt);
- event = ObtainMotionEvent(event_time + 2 * kDeltaTimeForFlingSequences,
- MotionEvent::Action::MOVE, positions);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + 2 * kDeltaTimeForFlingSequences,
- MotionEvent::Action::POINTER_UP, positions);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- }
- static void RunTasksAndWait(base::TimeDelta delay) {
- base::RunLoop run_loop;
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE, run_loop.QuitClosure(), delay);
- run_loop.Run();
- }
- std::vector<GestureEventData> gestures_;
- std::unique_ptr<GestureProvider> gesture_provider_;
- std::unique_ptr<GestureEventData> active_scroll_begin_event_;
- base::test::SingleThreadTaskEnvironment task_environment_;
- bool should_process_double_tap_events_ = true;
- };
- // Verify that a DOWN has the same unique_touch_event_id and
- // primary_touch_event_id
- TEST_F(GestureProviderTest, GestureTapPrimaryUniqueTouchEventId) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- int motion_event_id = 6;
- int motion_event_flags = EF_CONTROL_DOWN | EF_ALT_DOWN;
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- }
- // Verify that a DOWN followed shortly by an UP will trigger a single tap.
- TEST_F(GestureProviderTest, GestureTap) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- int motion_event_id = 6;
- int motion_event_flags = EF_CONTROL_DOWN | EF_ALT_DOWN;
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(event.GetToolType(0),
- GetMostRecentGestureEvent().primary_tool_type);
- EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
- GetMostRecentGestureEvent().details.bounding_box_f());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- // Ensure tap details have been set.
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- EXPECT_EQ(event.GetToolType(0),
- GetMostRecentGestureEvent().primary_tool_type);
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
- GetMostRecentGestureEvent().details.bounding_box_f());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- }
- // Verify that a DOWN followed shortly by an UP will trigger
- // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled.
- TEST_F(GestureProviderTest, GestureTapWithDelay) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- int motion_event_id = 6;
- int motion_event_flags = EF_CONTROL_DOWN | EF_ALT_DOWN | EF_CAPS_LOCK_ON;
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
- GetMostRecentGestureEvent().details.bounding_box_f());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- // Ensure tap details have been set.
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
- GetMostRecentGestureEvent().details.bounding_box_f());
- EXPECT_EQ(event.GetEventTime(), GetMostRecentGestureEvent().time);
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP));
- RunTasksAndWait(GetDoubleTapTimeout());
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP));
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(event.GetEventTime(), GetMostRecentGestureEvent().time);
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- }
- // Verify that a DOWN followed by a MOVE will trigger fling, but won't trigger
- // either short-press or long-press.
- TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) {
- base::TimeTicks event_time = TimeTicks::Now();
- base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
- int motion_event_id = 6;
- int motion_event_flags = EF_ALT_DOWN;
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event = ObtainMotionEvent(event_time + delta_time, MotionEvent::Action::MOVE,
- kFakeCoordX * 10, kFakeCoordY * 10);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event =
- ObtainMotionEvent(event_time + delta_time * 2, MotionEvent::Action::UP,
- kFakeCoordX * 10, kFakeCoordY * 10);
- event.SetPrimaryPointerId(motion_event_id);
- event.set_flags(motion_event_flags);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SHORT_PRESS));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
- EXPECT_EQ(
- BoundsForSingleMockTouchAtLocation(kFakeCoordX * 10, kFakeCoordY * 10),
- GetMostRecentGestureEvent().details.bounding_box_f());
- }
- // Verify that for a normal scroll the following events are sent:
- // - ET_GESTURE_SCROLL_BEGIN
- // - ET_GESTURE_SCROLL_UPDATE
- // - ET_GESTURE_SCROLL_END
- TEST_F(GestureProviderTest, ScrollEventActionUpSequence) {
- CheckScrollEventSequenceForEndActionType(MotionEvent::Action::UP);
- }
- // Verify that for a cancelled scroll the following events are sent:
- // - ET_GESTURE_SCROLL_BEGIN
- // - ET_GESTURE_SCROLL_UPDATE
- // - ET_GESTURE_SCROLL_END
- TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) {
- CheckScrollEventSequenceForEndActionType(MotionEvent::Action::CANCEL);
- }
- // Verify that for a normal fling (fling after scroll) the following events are
- // sent:
- // - ET_GESTURE_SCROLL_BEGIN
- // - ET_SCROLL_FLING_START
- TEST_F(GestureProviderTest, FlingEventSequence) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
- int motion_event_id = 6;
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetPrimaryPointerId(motion_event_id);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event = ObtainMotionEvent(event_time + delta_time, MotionEvent::Action::MOVE,
- kFakeCoordX * 5, kFakeCoordY * 5);
- event.SetPrimaryPointerId(motion_event_id);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- ASSERT_EQ(3U, GetReceivedGestureCount());
- ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
- EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id);
- EXPECT_EQ(primary_unique_touch_event_id,
- GetReceivedGesture(1).details.primary_unique_touch_event_id());
- // We don't want to take a dependency here on exactly how hints are calculated
- // for a fling (eg. may depend on velocity), so just validate the direction.
- int hint_x = GetReceivedGesture(1).details.scroll_x_hint();
- int hint_y = GetReceivedGesture(1).details.scroll_y_hint();
- EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y)
- << "ScrollBegin hint should be in positive X axis";
- event =
- ObtainMotionEvent(event_time + delta_time * 2, MotionEvent::Action::UP,
- kFakeCoordX * 10, kFakeCoordY * 10);
- event.SetPrimaryPointerId(motion_event_id);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
- EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
- EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time)
- << "FlingStart should have the time of the Action::UP";
- }
- TEST_F(GestureProviderTest, GestureCancelledOnCancelEvent) {
- const base::TimeTicks event_time = TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
- kOneMicrosecond);
- EXPECT_EQ(ET_GESTURE_SHOW_PRESS, GetNthMostRecentGestureEventType(2));
- EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetNthMostRecentGestureEvent(1).details.primary_unique_touch_event_id());
- EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetNthMostRecentGestureEvent(0).details.primary_unique_touch_event_id());
- // A cancellation event may be triggered for a number of reasons, e.g.,
- // from a context-menu-triggering long press resulting in loss of focus.
- EXPECT_TRUE(CancelActiveTouchSequence());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- EXPECT_FALSE(HasDownEvent());
- // A final Action::UP should have no effect.
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::UP);
- EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
- }
- TEST_F(GestureProviderTest, GestureCancelledOnDetectionReset) {
- const base::TimeTicks event_time = TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
- kOneMicrosecond);
- EXPECT_EQ(ET_GESTURE_SHOW_PRESS, GetNthMostRecentGestureEventType(2));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetNthMostRecentGestureEvent(2).details.primary_unique_touch_event_id());
- EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetNthMostRecentGestureEvent(1).details.primary_unique_touch_event_id());
- EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetNthMostRecentGestureEvent(0).details.primary_unique_touch_event_id());
- ResetGestureDetection();
- EXPECT_FALSE(HasDownEvent());
- // A final Action::UP should have no effect.
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::UP);
- EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
- }
- TEST_F(GestureProviderTest, TapPendingConfirmationCancelledOnCancelEvent) {
- const base::TimeTicks event_time = TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::CANCEL);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetMostRecentGestureEventType());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- }
- TEST_F(GestureProviderTest, NoTapAfterScrollBegins) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
- kFakeCoordX + 50, kFakeCoordY + 50);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::Action::UP,
- kFakeCoordX + 50, kFakeCoordY + 50);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
- }
- TEST_F(GestureProviderTest, DoubleTap) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- // Moving a very small amount of distance should not trigger the double tap
- // drag zoom mode.
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
- kFakeCoordX, kFakeCoordY + 1);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY + 1);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- const GestureEventData& double_tap = GetMostRecentGestureEvent();
- EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type());
- // Ensure tap details have been set.
- EXPECT_EQ(10, double_tap.details.bounding_box().width());
- EXPECT_EQ(10, double_tap.details.bounding_box().height());
- EXPECT_EQ(1, double_tap.details.tap_count());
- EXPECT_EQ(primary_unique_touch_event_id,
- double_tap.details.primary_unique_touch_event_id());
- }
- TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) {
- const base::TimeTicks down_time_1 = TimeTicks::Now();
- const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
- MockMotionEvent event =
- ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 100);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetNthMostRecentGestureEvent(1).details.primary_unique_touch_event_id());
- ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100),
- GetMostRecentGestureEvent().details.bounding_box_f());
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
- EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 200),
- GetMostRecentGestureEvent().details.bounding_box_f());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 100);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
- EXPECT_GT(1.f, GetMostRecentGestureEvent().details.scale());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100),
- GetMostRecentGestureEvent().details.bounding_box_f());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 4,
- MotionEvent::Action::UP, kFakeCoordX,
- kFakeCoordY - 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
- EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY - 200),
- GetMostRecentGestureEvent().details.bounding_box_f());
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- }
- // Generate a scroll gesture and verify that the resulting scroll motion event
- // has both absolute and relative position information.
- TEST_F(GestureProviderTest, ScrollUpdateValues) {
- const float delta_x = 16;
- const float delta_y = 84;
- const float raw_offset_x = 17.3f;
- const float raw_offset_y = 13.7f;
- const base::TimeTicks event_time = TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- // Move twice so that we get two ET_GESTURE_SCROLL_UPDATE events and can
- // compare the relative and absolute coordinates.
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
- kFakeCoordX - delta_x / 2, kFakeCoordY - delta_y / 2);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX - delta_x,
- kFakeCoordY - delta_y);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- // Make sure the reported gesture event has all the expected details.
- ASSERT_LT(0U, GetReceivedGestureCount());
- GestureEventData gesture = GetMostRecentGestureEvent();
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
- EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
- EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
- EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
- EXPECT_EQ(kFakeCoordX - delta_x + raw_offset_x, gesture.raw_x);
- EXPECT_EQ(kFakeCoordY - delta_y + raw_offset_y, gesture.raw_y);
- EXPECT_EQ(1, gesture.details.touch_points());
- // No horizontal delta because of snapping.
- EXPECT_EQ(0, gesture.details.scroll_x());
- EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y());
- EXPECT_EQ(primary_unique_touch_event_id,
- gesture.details.primary_unique_touch_event_id());
- }
- // Verify that fractional scroll deltas are rounded as expected and that
- // fractional scrolling doesn't break scroll snapping.
- TEST_F(GestureProviderTest, FractionalScroll) {
- const float delta_x = 0.4f;
- const float delta_y = 5.2f;
- const base::TimeTicks event_time = TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- // Skip past the touch slop and move back.
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 100);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- // Now move up slowly, mostly vertically but with a (fractional) bit of
- // horizontal motion.
- for (int i = 1; i <= 10; i++) {
- event = ObtainMotionEvent(
- event_time + kOneMicrosecond * i, MotionEvent::Action::MOVE,
- kFakeCoordX + delta_x * i, kFakeCoordY + delta_y * i);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- ASSERT_LT(0U, GetReceivedGestureCount());
- GestureEventData gesture = GetMostRecentGestureEvent();
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
- EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time);
- EXPECT_EQ(1, gesture.details.touch_points());
- EXPECT_EQ(primary_unique_touch_event_id,
- gesture.details.primary_unique_touch_event_id());
- // Verify that the event co-ordinates are still the precise values we
- // supplied.
- EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x);
- EXPECT_FLOAT_EQ(kFakeCoordY + delta_y * i, gesture.y);
- // Verify that we're scrolling vertically by the expected amount
- // (modulo rounding).
- EXPECT_GE(gesture.details.scroll_y(), (int)delta_y);
- EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1);
- // And that there has been no horizontal motion at all.
- EXPECT_EQ(0, gesture.details.scroll_x());
- }
- }
- // Generate a scroll gesture and verify that the resulting scroll begin event
- // has the expected hint values.
- TEST_F(GestureProviderTest, ScrollBeginValues) {
- const float delta_x = 14;
- const float delta_y = 48;
- // These are the deltas after subtracting slop region and railing.
- const float delta_x_hint = 0;
- const float delta_y_hint = 40.32f;
- const base::TimeTicks event_time = TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- // Move twice such that the first event isn't sufficient to start
- // scrolling on it's own.
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
- kFakeCoordX + 2, kFakeCoordY + 1);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX + delta_x,
- kFakeCoordY + delta_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
- const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent();
- ASSERT_TRUE(scroll_begin_gesture);
- EXPECT_EQ(delta_x_hint, scroll_begin_gesture->details.scroll_x_hint());
- EXPECT_EQ(delta_y_hint, scroll_begin_gesture->details.scroll_y_hint());
- EXPECT_EQ(primary_unique_touch_event_id,
- scroll_begin_gesture->details.primary_unique_touch_event_id());
- }
- // The following three tests verify that slop regions are checked for
- // one and two finger scrolls. Three-finger tap doesn't exist, so,
- // no slop region check is needed for three-finger scrolls.
- TEST_F(GestureProviderTest, SlopRegionCheckOnOneFingerScroll) {
- EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
- const float scaled_touch_slop = GetTouchSlop();
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- // Move within slop region.
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 0,
- scaled_touch_slop / 2);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- // Exceed slop region.
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 0,
- 2 * scaled_touch_slop);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 0,
- 2 * scaled_touch_slop);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
- EXPECT_EQ(primary_unique_touch_event_id,
- GetReceivedGesture(1).details.primary_unique_touch_event_id());
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
- EXPECT_EQ(primary_unique_touch_event_id,
- GetReceivedGesture(2).details.primary_unique_touch_event_id());
- EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(3).type());
- EXPECT_EQ(primary_unique_touch_event_id,
- GetReceivedGesture(3).details.primary_unique_touch_event_id());
- EXPECT_EQ(4U, GetReceivedGestureCount());
- }
- TEST_F(GestureProviderTest, SlopRegionCheckOnTwoFingerScroll) {
- EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
- const float scaled_touch_slop = GetTouchSlop();
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- GetMostRecentGestureEvent().unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- uint32_t primary_unique_touch_event_id =
- GetMostRecentGestureEvent().unique_touch_event_id;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
- kMaxTwoFingerTapSeparation / 2, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- // Move within slop region: two-finger tap happens.
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 0,
- scaled_touch_slop / 2,
- kMaxTwoFingerTapSeparation / 2, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 0,
- scaled_touch_slop / 2,
- kMaxTwoFingerTapSeparation / 2, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- // Exceed slop region: scroll.
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0,
- scaled_touch_slop / 2,
- kMaxTwoFingerTapSeparation / 2, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event = ObtainMotionEvent(
- event_time, MotionEvent::Action::MOVE, 0, scaled_touch_slop / 2,
- kMaxTwoFingerTapSeparation / 2, 2 * scaled_touch_slop);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(
- event_time, MotionEvent::Action::POINTER_UP, 0, scaled_touch_slop / 2,
- kMaxTwoFingerTapSeparation / 2, 2 * scaled_touch_slop);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 0,
- scaled_touch_slop / 2);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(
- primary_unique_touch_event_id,
- GetMostRecentGestureEvent().details.primary_unique_touch_event_id());
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(1).type());
- EXPECT_EQ(primary_unique_touch_event_id,
- GetReceivedGesture(1).details.primary_unique_touch_event_id());
- EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(3).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(4).type());
- EXPECT_EQ(5U, GetReceivedGestureCount());
- }
- // This test simulates cases like (crbug.com/704426) in which some of the events
- // are missing from the event stream.
- TEST_F(GestureProviderTest, SlopRegionCheckOnMissingSecondaryPointerDownEvent) {
- EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
- const float scaled_touch_slop = GetTouchSlop();
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- // Don't send Action::POINTER_DOWN event to the gesture_provider.
- // This is for simulating the cases that the Action::POINTER_DOWN event is
- // missing from the event sequence.
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
- kMaxTwoFingerTapSeparation / 2, 0);
- event.MovePoint(1, 0, 3 * scaled_touch_slop);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event.ReleasePointAtIndex(0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event.ReleasePoint();
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- // No scroll happens since the source pointer down event for the moved
- // pointer is not found. No two finger tap happens since one of the pointers
- // moved beyond its slop region.
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- EXPECT_EQ(1U, GetReceivedGestureCount());
- }
- TEST_F(GestureProviderTest, NoSlopRegionCheckOnThreeFingerScroll) {
- EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
- const float scaled_touch_slop = GetTouchSlop();
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
- kMaxTwoFingerTapSeparation / 2, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
- kMaxTwoFingerTapSeparation / 2, 0,
- 2 * kMaxTwoFingerTapSeparation, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- // Move within slop region, three-finger scroll always happens.
- event = ObtainMotionEvent(
- event_time, MotionEvent::Action::MOVE, 0, scaled_touch_slop / 2,
- kMaxTwoFingerTapSeparation / 2, 0, 2 * kMaxTwoFingerTapSeparation, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
- EXPECT_EQ(3U, GetReceivedGestureCount());
- }
- TEST_F(GestureProviderTest, ScrollStartWithSecondaryPointer) {
- EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
- const float scaled_touch_slop = GetTouchSlop();
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
- kMaxTwoFingerTapSeparation / 2, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- // Wait for the two finger tap timeout, and put the second pointer down.
- event_time += kOneSecond;
- event.set_event_time(event_time);
- event.ReleasePointAtIndex(0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event.MovePoint(0, kMaxTwoFingerTapSeparation / 2, 2 * scaled_touch_slop);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event.ReleasePoint();
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(3).type());
- EXPECT_EQ(4U, GetReceivedGestureCount());
- }
- TEST_F(GestureProviderTest, NoFlingBeforeExeedingSlopRegion) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
- MockMotionEvent event = ObtainMotionEvent(event_time + delta_time,
- MotionEvent::Action::DOWN, 0, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + 2 * delta_time,
- MotionEvent::Action::POINTER_DOWN, 0, 0, 10, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- // Fast pointer movements within touch slop region.
- event = ObtainMotionEvent(event_time + 3 * delta_time,
- MotionEvent::Action::MOVE, 1, 0, 11, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + 4 * delta_time,
- MotionEvent::Action::MOVE, 2, 0, 12, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + 5 * delta_time,
- MotionEvent::Action::MOVE, 3, 0, 13, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event.ReleasePointAtIndex(0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event.ReleasePoint();
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- // No fling must happen even though velocity is greater than the required
- // minium.
- EXPECT_EQ(1U, GetReceivedGestureCount());
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- }
- TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::MOVE,
- kFakeCoordX * 5, kFakeCoordY * 5);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX * 10,
- kFakeCoordY * 10);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- const base::TimeDelta long_press_timeout =
- GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
- RunTasksAndWait(long_press_timeout);
- // No LONG_TAP as the LONG_PRESS timer is cancelled.
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SHORT_PRESS));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
- }
- // Verify that LONG_TAP is triggered after LONG_PRESS followed by an UP.
- TEST_F(GestureProviderTest, GestureLongTap) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- const base::TimeDelta long_press_timeout =
- GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
- RunTasksAndWait(long_press_timeout);
- EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(1, GetNthMostRecentGestureEvent(1).details.touch_points());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
- GetNthMostRecentGestureEvent(1).details.bounding_box_f());
- EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
- EXPECT_EQ(1, GetNthMostRecentGestureEvent(0).details.touch_points());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
- GetNthMostRecentGestureEvent(0).details.bounding_box_f());
- event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::Action::UP);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
- GetMostRecentGestureEvent().details.bounding_box_f());
- }
- TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- const base::TimeDelta long_press_timeout =
- GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
- RunTasksAndWait(long_press_timeout);
- EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(1, GetNthMostRecentGestureEvent(1).details.touch_points());
- EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
- EXPECT_EQ(1, GetNthMostRecentGestureEvent(0).details.touch_points());
- event = ObtainMotionEvent(event_time + long_press_timeout,
- MotionEvent::Action::MOVE, kFakeCoordX + 100,
- kFakeCoordY + 100);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- event = ObtainMotionEvent(event_time + long_press_timeout,
- MotionEvent::Action::UP);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
- }
- TEST_F(GestureProviderTest, DeepPressAcceleratedLongPress) {
- SetDeepPressAcceleratedLongPress(true);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::MOVE);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- event.SetClassification(MotionEvent::Classification::DEEP_PRESS);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
- }
- TEST_F(GestureProviderTest, StylusButtonCausesLongPress) {
- SetStylusButtonAcceleratedLongPress(true);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::STYLUS);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::MOVE);
- event.SetToolType(0, MotionEvent::ToolType::STYLUS);
- event.set_flags(EF_LEFT_MOUSE_BUTTON);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
- }
- TEST_F(GestureProviderTest, DisabledStylusButtonDoesNotCauseLongPress) {
- SetStylusButtonAcceleratedLongPress(false);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::STYLUS);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::MOVE);
- event.SetToolType(0, MotionEvent::ToolType::STYLUS);
- event.set_flags(EF_LEFT_MOUSE_BUTTON);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SHORT_PRESS));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
- }
- TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- int motion_event_id = 6;
- MockMotionEvent event = ObtainMotionEvent(
- event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
- const base::TimeDelta long_press_timeout =
- GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
- RunTasksAndWait(long_press_timeout);
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SHORT_PRESS));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
- event = ObtainMotionEvent(event_time + long_press_timeout,
- MotionEvent::Action::MOVE, kFakeCoordX + 20,
- kFakeCoordY + 20);
- event.SetPrimaryPointerId(motion_event_id);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
- event =
- ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY + 1);
- event.SetPrimaryPointerId(motion_event_id);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress());
- }
- // Verify that the touch slop region is removed from the first scroll delta to
- // avoid a jump when starting to scroll.
- TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) {
- const float touch_slop = GetTouchSlop();
- const float scroll_delta = 5;
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + touch_slop + scroll_delta);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
- GestureEventData gesture = GetMostRecentGestureEvent();
- EXPECT_EQ(0, gesture.details.scroll_x());
- EXPECT_EQ(scroll_delta, gesture.details.scroll_y());
- EXPECT_EQ(1, gesture.details.touch_points());
- }
- // Verify that movement within the touch slop region does not generate a scroll,
- // and that the slop region is correct even when using fractional coordinates.
- TEST_F(GestureProviderTest, NoScrollWithinTouchSlop) {
- const float touch_slop = GetTouchSlop();
- const float scale_factor = 2.5f;
- const int touch_slop_pixels = static_cast<int>(scale_factor * touch_slop);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(
- event_time + kOneMicrosecond * 2, MotionEvent::Action::MOVE,
- kFakeCoordX + touch_slop_pixels / scale_factor, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + touch_slop_pixels / scale_factor);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- event = ObtainMotionEvent(
- event_time + kOneMicrosecond * 2, MotionEvent::Action::MOVE,
- kFakeCoordX - touch_slop_pixels / scale_factor, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY - touch_slop_pixels / scale_factor);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- event = ObtainMotionEvent(
- event_time + kOneMicrosecond * 2, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + (touch_slop_pixels + 1.f) / scale_factor);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- }
- TEST_F(GestureProviderTest, NoDoubleTapWhenTooRapid) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- // If the second tap follows the first in too short a time span, no double-tap
- // will occur.
- event_time += (GetDoubleTapMinTime() / 2);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- }
- TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) {
- // Ensure that double-tap gestures can be disabled.
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event = ObtainMotionEvent(
- event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- // Ensure that double-tap gestures can be interrupted.
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- event_time = base::TimeTicks::Now();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(5U, GetReceivedGestureCount());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- // Ensure that double-tap gestures can be resumed.
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, GetMostRecentGestureEventType());
- }
- TEST_F(GestureProviderTest, NoDoubleTapWhenConsumerDoesntWantIt) {
- // Double tap gestures are supported by the platform but the current consumer
- // doesn't want it.
- should_process_double_tap_events_ = false;
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event = ObtainMotionEvent(
- event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- // The consumer now wants to receive double taps.
- should_process_double_tap_events_ = true;
- event_time = base::TimeTicks::Now();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, GetMostRecentGestureEventType());
- }
- TEST_F(GestureProviderTest, NoDelayedTapWhenDoubleTapSupportToggled) {
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event = ObtainMotionEvent(
- event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1U, GetReceivedGestureCount());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- EXPECT_EQ(2U, GetReceivedGestureCount());
- // Disabling double-tap during the tap timeout should flush the delayed tap.
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(3U, GetReceivedGestureCount());
- // No further timeout gestures should arrive.
- const base::TimeDelta long_press_timeout =
- GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
- RunTasksAndWait(long_press_timeout);
- EXPECT_EQ(3U, GetReceivedGestureCount());
- }
- TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) {
- const base::TimeTicks down_time_1 = TimeTicks::Now();
- const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- MockMotionEvent event =
- ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- gesture_provider_->OnTouchEvent(event);
- event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 100);
- // The move should become a scroll, as doubletap drag zoom is disabled.
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(down_time_2 + kOneMicrosecond * 2,
- GetMostRecentGestureEvent().time);
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
- MotionEvent::Action::UP, kFakeCoordX,
- kFakeCoordY + 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
- }
- // Verify that double tap drag zoom feature is not invoked when the gesture
- // handler is told to disable double tap gesture detection.
- // The second tap sequence should be treated just as the first would be.
- TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPage) {
- const base::TimeTicks down_time_1 = TimeTicks::Now();
- const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
- gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
- MockMotionEvent event =
- ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- gesture_provider_->OnTouchEvent(event);
- event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 100);
- // The move should become a scroll, as double tap drag zoom is disabled.
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
- MotionEvent::Action::UP, kFakeCoordX,
- kFakeCoordY + 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
- }
- // Verify that updating double tap support during a double tap drag zoom
- // disables double tap detection after the gesture has ended.
- TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) {
- base::TimeTicks down_time_1 = TimeTicks::Now();
- base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
- gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- // Start a double-tap drag gesture.
- MockMotionEvent event =
- ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- gesture_provider_->OnTouchEvent(event);
- event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 100);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
- EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- // Simulate setting a fixed page scale (or a mobile viewport);
- // this should not disrupt the current double-tap gesture.
- gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
- // Double tap zoom updates should continue.
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
- MotionEvent::Action::UP, kFakeCoordX,
- kFakeCoordY + 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
- EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- // The double-tap gesture has finished, but the page scale is fixed.
- // The same event sequence should not generate any double tap gestures.
- gestures_.clear();
- down_time_1 += kOneMicrosecond * 40;
- down_time_2 += kOneMicrosecond * 40;
- // Start a double-tap drag gesture.
- event = ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
- MotionEvent::Action::UP, kFakeCoordX, kFakeCoordY);
- gesture_provider_->OnTouchEvent(event);
- event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 100);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
- // Double tap zoom updates should not be sent.
- // Instead, the second tap drag becomes a scroll gesture sequence.
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY + 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
- MotionEvent::Action::UP, kFakeCoordX,
- kFakeCoordY + 200);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
- }
- // Verify that pinch zoom sends the proper event sequence.
- TEST_F(GestureProviderTest, PinchZoom) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- const float touch_slop = GetTouchSlop();
- const float raw_offset_x = 3.2f;
- const float raw_offset_y = 4.3f;
- int motion_event_id = 6;
- gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
- int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
- int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
- EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
- EXPECT_EQ(kFakeCoordX + raw_offset_x, GetMostRecentGestureEvent().raw_x);
- EXPECT_EQ(kFakeCoordY + raw_offset_y, GetMostRecentGestureEvent().raw_y);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
- GetMostRecentGestureEvent().details.bounding_box_f());
- // Toggling double-tap support should not take effect until the next sequence.
- gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
- kFakeCoordX, kFakeCoordY, secondary_coord_x,
- secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(1U, GetReceivedGestureCount());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
- GetMostRecentGestureEvent().details.bounding_box_f());
- secondary_coord_x += 5 * touch_slop;
- secondary_coord_y += 5 * touch_slop;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY, secondary_coord_x, secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- // Toggling double-tap support should not take effect until the next sequence.
- gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
- EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2, GetReceivedGesture(3).x);
- EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2, GetReceivedGesture(3).y);
- EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2 + raw_offset_x,
- GetReceivedGesture(3).raw_x);
- EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2 + raw_offset_y,
- GetReceivedGesture(3).raw_y);
- EXPECT_EQ(
- gfx::RectF(kFakeCoordX - kMockTouchRadius, kFakeCoordY - kMockTouchRadius,
- secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
- secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
- GetMostRecentGestureEvent().details.bounding_box_f());
- secondary_coord_x += 2 * touch_slop;
- secondary_coord_y += 2 * touch_slop;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY, secondary_coord_x, secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- // Toggling double-tap support should not take effect until the next sequence.
- gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
- EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
- EXPECT_EQ(
- gfx::RectF(kFakeCoordX - kMockTouchRadius, kFakeCoordY - kMockTouchRadius,
- secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
- secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
- GetMostRecentGestureEvent().details.bounding_box_f());
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP,
- kFakeCoordX, kFakeCoordY, secondary_coord_x,
- secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
- EXPECT_EQ(
- gfx::RectF(kFakeCoordX - kMockTouchRadius, kFakeCoordY - kMockTouchRadius,
- secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
- secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
- GetMostRecentGestureEvent().details.bounding_box_f());
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(
- gfx::RectF(kFakeCoordX - kMockTouchRadius, kFakeCoordY - kMockTouchRadius,
- kMockTouchRadius * 2, kMockTouchRadius * 2),
- GetMostRecentGestureEvent().details.bounding_box_f());
- }
- // Verify that no accidental pinching occurs if the touch size is large relative
- // to the min scaling span when the touch major value is used in scaling.
- TEST_F(GestureProviderTest, NoPinchZoomWithFatFinger) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- const float kFatFingerSize = GetMinScalingSpan() * 3.f;
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1U, GetReceivedGestureCount());
- event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::Action::MOVE);
- event.SetTouchMajor(0.1f);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(1U, GetReceivedGestureCount());
- event =
- ObtainMotionEvent(event_time + kOneSecond * 2, MotionEvent::Action::MOVE,
- kFakeCoordX + 1.f, kFakeCoordY);
- event.SetTouchMajor(1.f);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(1U, GetReceivedGestureCount());
- event =
- ObtainMotionEvent(event_time + kOneSecond * 3, MotionEvent::Action::MOVE);
- event.SetTouchMajor(kFatFingerSize * 3.5f);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(1U, GetReceivedGestureCount());
- event =
- ObtainMotionEvent(event_time + kOneSecond * 4, MotionEvent::Action::MOVE);
- event.SetTouchMajor(kFatFingerSize * 5.f);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(1U, GetReceivedGestureCount());
- event =
- ObtainMotionEvent(event_time + kOneSecond * 4, MotionEvent::Action::MOVE,
- kFakeCoordX + 50.f, kFakeCoordY - 25.f);
- event.SetTouchMajor(kFatFingerSize * 10.f);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
- event =
- ObtainMotionEvent(event_time + kOneSecond * 4, MotionEvent::Action::MOVE,
- kFakeCoordX + 100.f, kFakeCoordY - 50.f);
- event.SetTouchMajor(kFatFingerSize * 5.f);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
- }
- // Verify that multi-finger swipe sends the proper event sequence.
- TEST_F(GestureProviderTest, MultiFingerSwipe) {
- EnableSwipe();
- gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
- const float min_swipe_velocity = GetMinSwipeVelocity();
- // One finger - swipe right
- OneFingerSwipe(2 * min_swipe_velocity, 0);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // One finger - swipe left
- OneFingerSwipe(-2 * min_swipe_velocity, 0);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // One finger - swipe down
- OneFingerSwipe(0, 2 * min_swipe_velocity);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // One finger - swipe up
- OneFingerSwipe(0, -2 * min_swipe_velocity);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // Two fingers
- // Swipe right.
- TwoFingerSwipe(min_swipe_velocity * 2, 0, min_swipe_velocity * 2, 0);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // Swipe left.
- TwoFingerSwipe(-min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // No swipe with different touch directions.
- TwoFingerSwipe(min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
- ResetGestureDetection();
- // No swipe without a dominant direction.
- TwoFingerSwipe(min_swipe_velocity * 2,
- min_swipe_velocity * 2,
- min_swipe_velocity * 2,
- min_swipe_velocity * 2);
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
- ResetGestureDetection();
- // Swipe down with non-zero velocities on both axes and dominant direction.
- TwoFingerSwipe(-min_swipe_velocity,
- min_swipe_velocity * 4,
- -min_swipe_velocity,
- min_swipe_velocity * 4);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
- EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_left());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // Swipe up with non-zero velocities on both axes.
- TwoFingerSwipe(min_swipe_velocity,
- -min_swipe_velocity * 4,
- min_swipe_velocity,
- -min_swipe_velocity * 4);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
- EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // No swipe without sufficient velocity.
- TwoFingerSwipe(min_swipe_velocity / 2, 0, 0, 0);
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
- ResetGestureDetection();
- // Swipe up with one small and one medium velocity in slightly different but
- // not opposing directions.
- TwoFingerSwipe(min_swipe_velocity / 2,
- min_swipe_velocity / 2,
- 0,
- min_swipe_velocity * 2);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
- EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // No swipe in orthogonal directions.
- TwoFingerSwipe(min_swipe_velocity * 2, 0, 0, min_swipe_velocity * 7);
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
- ResetGestureDetection();
- // Three finger swipe in same directions.
- ThreeFingerSwipe(min_swipe_velocity * 2,
- 0,
- min_swipe_velocity * 3,
- 0,
- min_swipe_velocity * 4,
- 0);
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
- EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
- EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
- ResetGestureDetection();
- // No three finger swipe in different directions.
- ThreeFingerSwipe(min_swipe_velocity * 2,
- 0,
- 0,
- min_swipe_velocity * 3,
- min_swipe_velocity * 4,
- 0);
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
- }
- // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
- // so LONG_PRESS and LONG_TAP won't be triggered.
- TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- const base::TimeDelta long_press_timeout =
- GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
- RunTasksAndWait(long_press_timeout);
- EXPECT_EQ(ET_GESTURE_SHORT_PRESS, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(1, GetNthMostRecentGestureEvent(1).details.touch_points());
- EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetNthMostRecentGestureEventType(0));
- EXPECT_EQ(1, GetNthMostRecentGestureEvent(0).details.touch_points());
- EXPECT_TRUE(CancelActiveTouchSequence());
- EXPECT_FALSE(HasDownEvent());
- event = ObtainMotionEvent(event_time + long_press_timeout,
- MotionEvent::Action::UP);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
- }
- // Verify that inserting a touch cancel event will trigger proper touch and
- // gesture sequence cancellation.
- TEST_F(GestureProviderTest, CancelActiveTouchSequence) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- int motion_event_id = 6;
- EXPECT_FALSE(CancelActiveTouchSequence());
- EXPECT_EQ(0U, GetReceivedGestureCount());
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetPrimaryPointerId(motion_event_id);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- ASSERT_TRUE(CancelActiveTouchSequence());
- EXPECT_FALSE(HasDownEvent());
- // Subsequent MotionEvent's are dropped until Action::DOWN.
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::MOVE);
- EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
- MotionEvent::Action::UP);
- EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
- MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- }
- TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) {
- const base::TimeTicks down_time_1 = TimeTicks::Now();
- const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- MockMotionEvent event =
- ObtainMotionEvent(down_time_1, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- event =
- ObtainMotionEvent(down_time_1 + kOneMicrosecond, MotionEvent::Action::UP);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- event = ObtainMotionEvent(down_time_2, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
- MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY - 30);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- event = ObtainMotionEvent(
- down_time_2 + kOneMicrosecond * 2, MotionEvent::Action::POINTER_DOWN,
- kFakeCoordX, kFakeCoordY - 30, kFakeCoordX + 50, kFakeCoordY + 50);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- const size_t gesture_count = GetReceivedGestureCount();
- event = ObtainMotionEvent(
- down_time_2 + kOneMicrosecond * 3, MotionEvent::Action::POINTER_UP,
- kFakeCoordX, kFakeCoordY - 30, kFakeCoordX + 50, kFakeCoordY + 50);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(gesture_count, GetReceivedGestureCount());
- event = ObtainMotionEvent(down_time_2 + kOneSecond, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
- }
- // Verify that gesture begin and gesture end events are dispatched correctly.
- TEST_F(GestureProviderTest, GestureBeginAndEnd) {
- EnableBeginEndTypes();
- base::TimeTicks event_time = base::TimeTicks::Now();
- const float raw_offset_x = 7.5f;
- const float raw_offset_y = 5.7f;
- EXPECT_EQ(0U, GetReceivedGestureCount());
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 1, 1);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(2U, GetReceivedGestureCount());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(1, GetMostRecentGestureEvent().x);
- EXPECT_EQ(1, GetMostRecentGestureEvent().y);
- EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
- EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
- EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius, 1 - kMockTouchRadius,
- kMockTouchRadius * 2, kMockTouchRadius * 2),
- GetMostRecentGestureEvent().details.bounding_box_f());
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 1, 1,
- 2, 2);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
- EXPECT_EQ(3U, GetReceivedGestureCount());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(2, GetMostRecentGestureEvent().x);
- EXPECT_EQ(2, GetMostRecentGestureEvent().y);
- EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
- EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 1, 1,
- 2, 2, 3, 3);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
- EXPECT_EQ(4U, GetReceivedGestureCount());
- EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(3, GetMostRecentGestureEvent().x);
- EXPECT_EQ(3, GetMostRecentGestureEvent().y);
- EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
- EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 1, 1,
- 2, 2, 3, 3);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
- EXPECT_EQ(5U, GetReceivedGestureCount());
- EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(1, GetMostRecentGestureEvent().x);
- EXPECT_EQ(1, GetMostRecentGestureEvent().y);
- EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
- EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 2, 2,
- 3, 3, 4, 4);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
- EXPECT_EQ(6U, GetReceivedGestureCount());
- EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(4, GetMostRecentGestureEvent().x);
- EXPECT_EQ(4, GetMostRecentGestureEvent().y);
- EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
- EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 2, 2,
- 3, 3, 4, 4);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
- EXPECT_EQ(7U, GetReceivedGestureCount());
- EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(2, GetMostRecentGestureEvent().x);
- EXPECT_EQ(2, GetMostRecentGestureEvent().y);
- EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
- EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 3, 3,
- 4, 4);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
- EXPECT_EQ(8U, GetReceivedGestureCount());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(3, GetMostRecentGestureEvent().x);
- EXPECT_EQ(3, GetMostRecentGestureEvent().y);
- EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
- EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 4, 4);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
- EXPECT_EQ(9U, GetReceivedGestureCount());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(4, GetMostRecentGestureEvent().x);
- EXPECT_EQ(4, GetMostRecentGestureEvent().y);
- EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
- EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
- }
- // Verify that gesture begin and gesture end events are dispatched correctly
- // when an Action::CANCEL is received.
- TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) {
- EnableBeginEndTypes();
- base::TimeTicks event_time = base::TimeTicks::Now();
- EXPECT_EQ(0U, GetReceivedGestureCount());
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 1, 1);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(2U, GetReceivedGestureCount());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius, 1 - kMockTouchRadius,
- kMockTouchRadius * 2, kMockTouchRadius * 2),
- GetMostRecentGestureEvent().details.bounding_box_f());
- EXPECT_EQ(1, GetMostRecentGestureEvent().x);
- EXPECT_EQ(1, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 1, 1,
- 2, 2);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
- EXPECT_EQ(3U, GetReceivedGestureCount());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(2, GetMostRecentGestureEvent().x);
- EXPECT_EQ(2, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 1, 1,
- 2, 2, 3, 3);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
- EXPECT_EQ(4U, GetReceivedGestureCount());
- EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(3, GetMostRecentGestureEvent().x);
- EXPECT_EQ(3, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::CANCEL, 1, 1, 2, 2,
- 3, 3);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(5U, GetReceivedGestureCount());
- EXPECT_EQ(3, GetReceivedGesture(4).details.touch_points());
- EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(4).type());
- EXPECT_EQ(1, GetMostRecentGestureEvent().x);
- EXPECT_EQ(1, GetMostRecentGestureEvent().y);
- event =
- ObtainMotionEvent(event_time, MotionEvent::Action::CANCEL, 1, 1, 3, 3);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(6U, GetReceivedGestureCount());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEvent().type());
- EXPECT_EQ(1, GetMostRecentGestureEvent().x);
- EXPECT_EQ(1, GetMostRecentGestureEvent().y);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::CANCEL, 3, 3);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEvent().type());
- EXPECT_EQ(3, GetMostRecentGestureEvent().x);
- EXPECT_EQ(3, GetMostRecentGestureEvent().y);
- }
- // Test a simple two finger tap
- TEST_F(GestureProviderTest, TwoFingerTap) {
- // The time between Action::POINTER_DOWN and Action::POINTER_UP must be <= the
- // two finger tap delay.
- EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
- const float scaled_touch_slop = GetTouchSlop();
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 0, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 0,
- scaled_touch_slop / 2);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 0, 0,
- kMaxTwoFingerTapSeparation / 2, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(
- event_time, MotionEvent::Action::MOVE, 0, -scaled_touch_slop / 2,
- kMaxTwoFingerTapSeparation / 2 + scaled_touch_slop / 2, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP, 0, 0,
- kMaxTwoFingerTapSeparation, 0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(1).type());
- EXPECT_EQ(2U, GetReceivedGestureCount());
- EXPECT_EQ(kMockTouchRadius * 2,
- GetReceivedGesture(1).details.first_finger_width());
- EXPECT_EQ(kMockTouchRadius * 2,
- GetReceivedGesture(1).details.first_finger_height());
- }
- // Test preventing a two finger tap via finger movement.
- TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) {
- EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
- const float scaled_touch_slop = GetTouchSlop();
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event = ObtainMotionEvent(
- event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
- kFakeCoordX, kFakeCoordY, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(
- event_time, MotionEvent::Action::MOVE, kFakeCoordX, kFakeCoordY,
- kFakeCoordX + 2 * scaled_touch_slop + 2, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP,
- kFakeCoordX, kFakeCoordY, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
- // d_x = 2 * scaled_touch_slop + 2,
- // d_focus_x = scaled_touch_slop + 1,
- // touch_slop / event.GetPointerCount() is deducted from first scroll,
- // scroll_x = scaled_touch_slop + 1 - scaled_touch_slop / 2
- EXPECT_FLOAT_EQ(scaled_touch_slop / 2 + 1,
- GetReceivedGesture(2).details.scroll_x());
- EXPECT_EQ(0, GetReceivedGesture(2).details.scroll_y());
- EXPECT_EQ(3U, GetReceivedGestureCount());
- }
- // Test preventing a two finger tap by waiting too long before releasing the
- // secondary pointer.
- TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) {
- base::TimeDelta two_finger_tap_timeout = kOneSecond;
- EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event = ObtainMotionEvent(
- event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY);
- event = ObtainMotionEvent(
- event_time, MotionEvent::Action::POINTER_DOWN, kFakeCoordX, kFakeCoordY,
- kFakeCoordX + kMaxTwoFingerTapSeparation / 2, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(
- event_time + kOneSecond + kOneMicrosecond,
- MotionEvent::Action::POINTER_UP, kFakeCoordX, kFakeCoordY,
- kFakeCoordX + kMaxTwoFingerTapSeparation / 2, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- EXPECT_EQ(1U, GetReceivedGestureCount());
- }
- // Test preventing a two finger tap by pressing the secondary pointer too far
- // from the first
- TEST_F(GestureProviderTest, TwoFingerTapCancelledByDistanceBetweenPointers) {
- EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event = ObtainMotionEvent(
- event_time, MotionEvent::Action::DOWN, kFakeCoordX, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(
- event_time, MotionEvent::Action::POINTER_DOWN, kFakeCoordX, kFakeCoordY,
- kFakeCoordX + kMaxTwoFingerTapSeparation, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(
- event_time, MotionEvent::Action::POINTER_UP, kFakeCoordX, kFakeCoordY,
- kFakeCoordX + kMaxTwoFingerTapSeparation, kFakeCoordY);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
- EXPECT_EQ(1U, GetReceivedGestureCount());
- }
- // Verify that the event that starts the pinch-zoom by exceeding the touch-slop
- // also generates an update.
- TEST_F(GestureProviderTest, PinchExceedingSlopCausesUpdate) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- const float touch_slop = GetTouchSlop();
- const float min_scaling_span = GetMinScalingSpan();
- const float raw_offset_x = 3.2f;
- const float raw_offset_y = 4.3f;
- int motion_event_id = 6;
- gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
- int secondary_coord_x = kFakeCoordX;
- int secondary_coord_y = kFakeCoordY + min_scaling_span + 1;
- // First Finger Down
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
- EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
- // Second Finger Down
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
- kFakeCoordX, kFakeCoordY, secondary_coord_x,
- secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(1U, GetReceivedGestureCount());
- // Move second finger by exactly the touch slop. This shouldn't yet generate
- // a Pinch Begin.
- secondary_coord_y += touch_slop * 2;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY, secondary_coord_x, secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(3U, GetReceivedGestureCount());
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
- // Move second finger that should *just* cross the slop threshold.
- secondary_coord_y += 1;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY, secondary_coord_x, secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(6U, GetReceivedGestureCount());
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetNthMostRecentGestureEventType(2));
- EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetNthMostRecentGestureEventType(0));
- EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
- }
- // Verify that the event that stops the pinch-zoom by exceeding the min scaling
- // span also generates an update.
- TEST_F(GestureProviderTest, PinchBelowMinSpanCausesUpdate) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- const float touch_slop = GetTouchSlop();
- const float min_scaling_span = GetMinScalingSpan();
- const float raw_offset_x = 3.2f;
- const float raw_offset_y = 4.3f;
- int motion_event_id = 6;
- gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
- int secondary_coord_x = kFakeCoordX;
- int secondary_coord_y = kFakeCoordY + min_scaling_span + touch_slop * 3;
- // First Finger Down
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
- EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
- // Second Finger Down
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
- kFakeCoordX, kFakeCoordY, secondary_coord_x,
- secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(1U, GetReceivedGestureCount());
- // Move second finger enough to exceed the touch slop and start zooming.
- secondary_coord_y -= (touch_slop * 2 + 1);
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY, secondary_coord_x, secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(5U, GetReceivedGestureCount());
- EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetNthMostRecentGestureEventType(3));
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetNthMostRecentGestureEventType(2));
- EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetNthMostRecentGestureEventType(0));
- // Move second finger so that the span becomes smaller than the min scaling
- // span. The pinch should end but we should receive an update before it does.
- secondary_coord_y -= touch_slop * 2;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY, secondary_coord_x, secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(8U, GetReceivedGestureCount());
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetNthMostRecentGestureEventType(2));
- EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetNthMostRecentGestureEventType(1));
- EXPECT_GT(1.f, GetNthMostRecentGestureEvent(1).details.scale());
- EXPECT_EQ(ET_GESTURE_PINCH_END, GetNthMostRecentGestureEventType(0));
- }
- // Verify that the pinch isn't started until it becomes larger than the min
- // scaling span.
- TEST_F(GestureProviderTest, PinchExceedingSlopWithinMinScale) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- const float touch_slop = GetTouchSlop();
- const float min_scaling_span = GetMinScalingSpan();
- const float raw_offset_x = 3.2f;
- const float raw_offset_y = 4.3f;
- int motion_event_id = 6;
- gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
- int secondary_coord_x = kFakeCoordX;
- int secondary_coord_y = kFakeCoordY + min_scaling_span / 4;
- // This test only makes sense if the min_scaling_span is greater than the
- // touch slop span.
- ASSERT_GT(min_scaling_span, touch_slop * 2);
- // First Finger Down
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
- EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
- // Second Finger Down
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
- kFakeCoordX, kFakeCoordY, secondary_coord_x,
- secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(1U, GetReceivedGestureCount());
- // Move second finger to exceed the touch slop. This shouldn't yet generate
- // a Pinch Begin since we're still within the minimum scaling span.
- secondary_coord_y += touch_slop * 2 + 1;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY, secondary_coord_x, secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(3U, GetReceivedGestureCount());
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
- // Move second finger that should *just* cross the min scaling span threshold.
- secondary_coord_y = kFakeCoordY + min_scaling_span + 1;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY, secondary_coord_x, secondary_coord_y);
- event.SetPrimaryPointerId(motion_event_id);
- event.SetRawOffset(raw_offset_x, raw_offset_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(6U, GetReceivedGestureCount());
- EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetNthMostRecentGestureEventType(2));
- EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetNthMostRecentGestureEventType(1));
- EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetNthMostRecentGestureEventType(0));
- // The scale must start from the min scale span threshold, rather than from
- // the touch_slop so it should be very small.
- EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
- EXPECT_GT(1.01f, GetMostRecentGestureEvent().details.scale());
- }
- // Verify that pinch zoom only sends updates which exceed the
- // min_pinch_update_span_delta.
- TEST_F(GestureProviderTest, PinchZoomWithThreshold) {
- const float kMinPinchUpdateDistance = 5;
- base::TimeTicks event_time = base::TimeTicks::Now();
- const float touch_slop = GetTouchSlop();
- SetMinPinchUpdateSpanDelta(kMinPinchUpdateDistance);
- gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
- int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
- int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
- // First finger down.
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- // Second finger down.
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN,
- kFakeCoordX, kFakeCoordY, secondary_coord_x,
- secondary_coord_y);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(1U, GetReceivedGestureCount());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- // Move second finger.
- secondary_coord_x += 5 * touch_slop;
- secondary_coord_y += 5 * touch_slop;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY, secondary_coord_x, secondary_coord_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
- // Small move, shouldn't trigger pinch.
- gestures_.clear();
- event = ObtainMotionEvent(
- event_time, MotionEvent::Action::MOVE, kFakeCoordX, kFakeCoordY,
- secondary_coord_x + kMinPinchUpdateDistance, secondary_coord_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- // Small move, but combined with the previous move, should trigger pinch. We
- // need to overshoot kMinPinchUpdateDistance by a fair bit, as the span
- // calculation factors in touch radius.
- const float kOvershootMinPinchUpdateDistance = 3;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, kFakeCoordX,
- kFakeCoordY,
- secondary_coord_x + kMinPinchUpdateDistance +
- kOvershootMinPinchUpdateDistance,
- secondary_coord_y);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
- }
- // Verify that the min gesture bound setting is honored.
- TEST_F(GestureProviderTest, MinGestureBoundsLength) {
- const float kMinGestureBoundsLength = 10.f * kMockTouchRadius;
- SetMinMaxGestureBoundsLength(kMinGestureBoundsLength, 0.f);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(kMinGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().width());
- EXPECT_EQ(kMinGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().height());
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(kMinGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().width());
- EXPECT_EQ(kMinGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().height());
- }
- TEST_F(GestureProviderTest, MaxGestureBoundsLength) {
- const float kMaxGestureBoundsLength = kMockTouchRadius / 10.f;
- SetMinMaxGestureBoundsLength(0.f, kMaxGestureBoundsLength);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(kMaxGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().width());
- EXPECT_EQ(kMaxGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().height());
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(kMaxGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().width());
- EXPECT_EQ(kMaxGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().height());
- }
- TEST_F(GestureProviderTest, ZeroRadiusBoundingBox) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 20);
- event.SetTouchMajor(0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(gfx::RectF(10, 20, 0, 0),
- GetMostRecentGestureEvent().details.bounding_box_f());
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN, 10,
- 20, 110, 120);
- event.SetTouchMajor(0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 10, 20, 110,
- 150);
- event.SetTouchMajor(0);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(gfx::RectF(10, 20, 100, 130),
- GetMostRecentGestureEvent().details.bounding_box_f());
- }
- // Verify that the min/max gesture bound settings are not applied to stylus
- // or mouse-derived MotionEvents.
- TEST_F(GestureProviderTest, NoMinOrMaxGestureBoundsLengthWithStylusOrMouse) {
- const float kMinGestureBoundsLength = 5.f * kMockTouchRadius;
- const float kMaxGestureBoundsLength = 10.f * kMockTouchRadius;
- SetMinMaxGestureBoundsLength(kMinGestureBoundsLength,
- kMaxGestureBoundsLength);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetTouchMajor(0);
- event.SetToolType(0, MotionEvent::ToolType::MOUSE);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(MotionEvent::ToolType::MOUSE,
- GetMostRecentGestureEvent().primary_tool_type);
- EXPECT_EQ(0.f, GetMostRecentGestureEvent().details.bounding_box_f().width());
- EXPECT_EQ(0.f, GetMostRecentGestureEvent().details.bounding_box_f().height());
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
- event.SetTouchMajor(1);
- event.SetToolType(0, MotionEvent::ToolType::STYLUS);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(MotionEvent::ToolType::STYLUS,
- GetMostRecentGestureEvent().primary_tool_type);
- EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().width());
- EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().height());
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetTouchMajor(2.f * kMaxGestureBoundsLength);
- event.SetToolType(0, MotionEvent::ToolType::MOUSE);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(MotionEvent::ToolType::MOUSE,
- GetMostRecentGestureEvent().primary_tool_type);
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(2.f * kMaxGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().width());
- EXPECT_EQ(2.f * kMaxGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().height());
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
- event.SetTouchMajor(2.f * kMaxGestureBoundsLength);
- event.SetToolType(0, MotionEvent::ToolType::ERASER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(MotionEvent::ToolType::ERASER,
- GetMostRecentGestureEvent().primary_tool_type);
- EXPECT_EQ(2.f * kMaxGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().width());
- EXPECT_EQ(2.f * kMaxGestureBoundsLength,
- GetMostRecentGestureEvent().details.bounding_box_f().height());
- }
- #if BUILDFLAG(IS_MAC) && defined(ARCH_CPU_ARM64)
- // https://crbug.com/1222659
- #define MAYBE_BoundingBoxForShowPressAndTapGesture \
- DISABLED_BoundingBoxForShowPressAndTapGesture
- #else
- #define MAYBE_BoundingBoxForShowPressAndTapGesture \
- BoundingBoxForShowPressAndTapGesture
- #endif
- // Test the bounding box for show press and tap gestures.
- TEST_F(GestureProviderTest, MAYBE_BoundingBoxForShowPressAndTapGesture) {
- base::TimeTicks event_time = base::TimeTicks::Now();
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- base::TimeDelta showpress_timeout = kOneMicrosecond;
- base::TimeDelta shortpress_timeout = kOneSecond;
- base::TimeDelta longpress_timeout = kOneSecond * 2;
- SetShowPressAndLongPressTimeout(showpress_timeout, shortpress_timeout,
- longpress_timeout);
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 10);
- event.SetTouchMajor(10);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(gfx::RectF(5, 5, 10, 10),
- GetMostRecentGestureEvent().details.bounding_box_f());
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::MOVE, 11, 9);
- event.SetTouchMajor(20);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time + kOneMicrosecond,
- MotionEvent::Action::MOVE, 8, 11);
- event.SetTouchMajor(10);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- RunTasksAndWait(showpress_timeout + kOneMicrosecond);
- EXPECT_EQ(ET_GESTURE_SHOW_PRESS, GetMostRecentGestureEventType());
- EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
- GetMostRecentGestureEvent().details.bounding_box_f());
- event =
- ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::Action::UP);
- event.SetTouchMajor(30);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
- EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
- GetMostRecentGestureEvent().details.bounding_box_f());
- }
- TEST_F(GestureProviderTest, SingleTapRepeat) {
- SetSingleTapRepeatInterval(3);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- // A second tap after the double-tap timeout window will not increment
- // the tap count.
- event_time += GetDoubleTapTimeout() + kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- // A secondary tap within the tap repeat period should increment
- // the tap count.
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(2, GetMostRecentGestureEvent().details.tap_count());
- // A secondary tap within the tap repeat location threshold should increment
- // the tap count.
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY + GetTouchSlop() / 2);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(3, GetMostRecentGestureEvent().details.tap_count());
- // The tap count should reset after hitting the repeat length.
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- // If double-tap is enabled, the tap repeat count should always be 1.
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- RunTasksAndWait(GetDoubleTapTimeout());
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- RunTasksAndWait(GetDoubleTapTimeout());
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- }
- TEST_F(GestureProviderTest, SingleTapRepeatLengthOfOne) {
- SetSingleTapRepeatInterval(1);
- gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- gesture_provider_->OnTouchEvent(event);
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- // Repeated taps should still produce a tap count of 1 if the
- // tap repeat length is 1.
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- event_time += GetValidDoubleTapDelay();
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, kFakeCoordX,
- kFakeCoordY + GetTouchSlop() / 2);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
- EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
- }
- // Test for Event.MaxDragDistance.* histograms with taps.
- TEST_F(GestureProviderTest, MaxDragDistanceHistogramsWithTap) {
- base::HistogramTester histograms_tester;
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 0);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 0);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 0);
- // A tap of type FINGER adds appropriate counts.
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- histograms_tester.ExpectBucketCount("Event.MaxDragDistance.FINGER", 0, 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 0);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 0);
- // A tap of type STYLUS adds appropriate counts.
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::STYLUS);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- event.SetToolType(0, MotionEvent::ToolType::STYLUS);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- histograms_tester.ExpectBucketCount("Event.MaxDragDistance.STYLUS", 0, 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 0);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 1);
- // A tap of type ERASER adds appropriate counts.
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::ERASER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- event.SetToolType(0, MotionEvent::ToolType::ERASER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- histograms_tester.ExpectBucketCount("Event.MaxDragDistance.ERASER", 0, 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 1);
- // A canceled tap is not counted.
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::CANCEL);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 1);
- // A multifinger tap is not counted.
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_DOWN);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::POINTER_UP);
- event.SetToolType(0, MotionEvent::ToolType::STYLUS);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP);
- event.SetToolType(0, MotionEvent::ToolType::STYLUS);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 1);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 1);
- }
- // Test for Event.MaxDragDistance.* histograms with drags.
- TEST_F(GestureProviderTest, MaxDragDistanceHistogramsWithDrag) {
- base::HistogramTester histograms_tester;
- // A tiny 1px drag is counted in appropriate distance bucket.
- base::TimeTicks event_time = base::TimeTicks::Now();
- MockMotionEvent event =
- ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 10);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 10, 11);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 10, 11);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- histograms_tester.ExpectBucketCount("Event.MaxDragDistance.FINGER", 1, 1);
- // A small 10px drag is counted in appropriate distance bucket.
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 10);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 10, 20);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 10, 20);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- histograms_tester.ExpectBucketCount("Event.MaxDragDistance.FINGER", 10, 1);
- // A long 100px drag is counted in appropriate distance bucket.
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::DOWN, 10, 10);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::MOVE, 10, 110);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- event_time += kOneMicrosecond;
- event = ObtainMotionEvent(event_time, MotionEvent::Action::UP, 10, 110);
- event.SetToolType(0, MotionEvent::ToolType::FINGER);
- EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
- histograms_tester.ExpectBucketCount("Event.MaxDragDistance.FINGER", 100, 1);
- // We have 3 counts in total
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.ERASER", 0);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.FINGER", 3);
- histograms_tester.ExpectTotalCount("Event.MaxDragDistance.STYLUS", 0);
- }
- } // namespace ui
|