Index: ui/chromeos/touch_exploration_controller_unittest.cc |
diff --git a/ui/chromeos/touch_exploration_controller_unittest.cc b/ui/chromeos/touch_exploration_controller_unittest.cc |
index 86582f0ff06b5bc06698b094700dc7c677d3e52e..013515cf10f044159c55ce4a109c922e014d16e0 100644 |
--- a/ui/chromeos/touch_exploration_controller_unittest.cc |
+++ b/ui/chromeos/touch_exploration_controller_unittest.cc |
@@ -13,14 +13,16 @@ |
#include "ui/aura/window.h" |
#include "ui/events/event.h" |
#include "ui/events/event_utils.h" |
+#include "ui/events/gestures/gesture_provider_aura.h" |
#include "ui/gfx/geometry/point.h" |
#include "ui/gl/gl_implementation.h" |
#include "ui/gl/gl_surface.h" |
+ |
tdresser
2014/06/25 14:48:41
Remove extra newline.
lisayin
2014/06/25 22:51:05
Done.
|
namespace ui { |
namespace { |
-// Records all mouse and touch events. |
+// Records all mouse, touch, gesture, and key events. |
class EventCapturer : public ui::EventHandler { |
public: |
EventCapturer() {} |
@@ -37,6 +39,12 @@ class EventCapturer : public ui::EventHandler { |
} else if (event->IsTouchEvent()) { |
events_.push_back( |
new ui::TouchEvent(static_cast<ui::TouchEvent&>(*event))); |
+ } else if (event->IsGestureEvent()) { |
+ events_.push_back( |
+ new ui::GestureEvent(static_cast<ui::GestureEvent&>(*event))); |
+ } else if (event->IsKeyEvent()) { |
+ events_.push_back( |
+ new ui::KeyEvent(static_cast<ui::KeyEvent&>(*event))); |
} else { |
return; |
} |
@@ -47,12 +55,13 @@ class EventCapturer : public ui::EventHandler { |
// exit early with a sensible error rather than letting the test time out. |
ASSERT_LT(events_.size(), 100u); |
} |
- const ScopedVector<ui::LocatedEvent>& captured_events() const { |
+ |
+ const ScopedVector<ui::Event>& captured_events() const { |
return events_; |
} |
private: |
- ScopedVector<ui::LocatedEvent> events_; |
+ ScopedVector<ui::Event> events_; |
DISALLOW_COPY_AND_ASSIGN(EventCapturer); |
}; |
@@ -88,13 +97,26 @@ class TouchExplorationTest : public aura::test::AuraTestBase { |
protected: |
aura::client::CursorClient* cursor_client() { return cursor_client_.get(); } |
- const ScopedVector<ui::LocatedEvent>& GetCapturedEvents() { |
+ const ScopedVector<ui::Event>& GetCapturedEvents() { |
return event_capturer_.captured_events(); |
} |
- std::vector<ui::LocatedEvent*> GetCapturedEventsOfType(int type) { |
- const ScopedVector<ui::LocatedEvent>& all_events = GetCapturedEvents(); |
- std::vector<ui::LocatedEvent*> events; |
+ std::vector<ui::LocatedEvent*> GetCapturedLocatedEvents() { |
+ const ScopedVector<ui::Event>& all_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> located_events; |
+ for (size_t i = 0; i < all_events.size(); ++i) { |
+ if (all_events[i]->IsMouseEvent() || |
+ all_events[i]->IsTouchEvent() || |
+ all_events[i]->IsGestureEvent()) { |
tdresser
2014/06/25 14:48:40
Indentation.
git cl format is worth taking a look
lisayin
2014/06/25 22:51:05
Done.
|
+ located_events.push_back(static_cast<ui::LocatedEvent*>(all_events[i])); |
+ } |
+ } |
+ return located_events; |
+ } |
+ |
+ std::vector<ui::Event*> GetCapturedEventsOfType(int type) { |
+ const ScopedVector<ui::Event>& all_events = GetCapturedEvents(); |
+ std::vector<ui::Event*> events; |
for (size_t i = 0; i < all_events.size(); ++i) { |
if (type == all_events[i]->type()) |
events.push_back(all_events[i]); |
@@ -102,6 +124,16 @@ class TouchExplorationTest : public aura::test::AuraTestBase { |
return events; |
} |
+ std::vector<ui::LocatedEvent*> GetCapturedLocatedEventsOfType(int type) { |
+ std::vector<ui::LocatedEvent*> located_events = GetCapturedLocatedEvents(); |
+ std::vector<ui::LocatedEvent*> events; |
+ for (size_t i = 0; i < located_events.size(); ++i) { |
+ if (type == located_events[i]->type()) |
+ events.push_back(located_events[i]); |
+ } |
+ return events; |
+ } |
+ |
void ClearCapturedEvents() { |
event_capturer_.Reset(); |
} |
@@ -143,6 +175,11 @@ class TouchExplorationTest : public aura::test::AuraTestBase { |
return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); |
} |
+ bool IsInGestureInProgressState() { |
+ return touch_exploration_controller_ |
+ ->IsInGestureInProgressStateForTesting(); |
+ } |
+ |
base::TimeDelta Now() { |
// This is the same as what EventTimeForNow() does, but here we do it |
// with our simulated clock. |
@@ -190,16 +227,62 @@ void ConfirmEventsAreMouseAndEqual(ui::Event* e1, ui::Event* e2) { |
EXPECT_EQ(mouse_event1->flags(), mouse_event2->flags()); |
} |
+// Executes a number of assertions to confirm that |e1| and |e2| are key events |
+// and are equal to each other. |
+void ConfirmEventsAreKeyAndEqual(ui::Event* e1, ui::Event* e2) { |
+ ASSERT_TRUE(e1->IsKeyEvent()); |
+ ASSERT_TRUE(e2->IsKeyEvent()); |
+ ui::KeyEvent* key_event1 = static_cast<ui::KeyEvent*>(e1); |
+ ui::KeyEvent* key_event2 = static_cast<ui::KeyEvent*>(e2); |
+ EXPECT_EQ(key_event1->type(), key_event2->type()); |
+ EXPECT_EQ(key_event1->key_code(), key_event2->key_code()); |
dmazzoni
2014/06/25 05:06:02
Assert flags also - to check that modifier keys ar
lisayin
2014/06/25 22:51:05
Done.
|
+} |
+ |
#define CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(e1, e2) \ |
ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreTouchAndEqual(e1, e2)) |
#define CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(e1, e2) \ |
ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreMouseAndEqual(e1, e2)) |
+#define CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(e1, e2) \ |
+ ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreKeyAndEqual(e1, e2)) |
+ |
// TODO(mfomitchev): Need to investigate why we don't get mouse enter/exit |
// events when running these tests as part of ui_unittests. We do get them when |
// the tests are run as part of ash unit tests. |
+// If a swipe has been successfully completed, then six key events will be |
+// dispatched that correspond to shift+search+direction |
+void SwipeSuccessfullyCompleted(const ScopedVector<ui::Event>& events, |
dmazzoni
2014/06/25 05:06:02
Maybe call this "AssertDirectionalNavigationEvents
lisayin
2014/06/25 22:51:05
Done.
|
+ ui::KeyboardCode direction) { |
+ ASSERT_EQ(6U, events.size()); |
+ std::vector<ui::KeyEvent> key_sequence; |
+ ui::KeyEvent shift_pressed( |
+ ui::ET_KEY_PRESSED, ui::VKEY_SHIFT, ui::EF_SHIFT_DOWN, false); |
+ ui::KeyEvent search_pressed( |
+ ui::ET_KEY_PRESSED, ui::VKEY_LWIN, ui::EF_SHIFT_DOWN, false); |
+ ui::KeyEvent direction_pressed( |
+ ui::ET_KEY_PRESSED, direction, ui::EF_SHIFT_DOWN, false); |
+ ui::KeyEvent direction_released( |
+ ui::ET_KEY_RELEASED, direction, ui::EF_SHIFT_DOWN, false); |
+ ui::KeyEvent search_released( |
+ ui::ET_KEY_RELEASED, VKEY_LWIN, ui::EF_SHIFT_DOWN, false); |
+ ui::KeyEvent shift_released( |
+ ui::ET_KEY_RELEASED, ui::VKEY_SHIFT, ui::EF_NONE, false); |
+ CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&shift_pressed, |
+ static_cast<ui::KeyEvent*>(events[0])); |
+ CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&search_pressed, |
+ static_cast<ui::KeyEvent*>(events[1])); |
+ CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&direction_pressed, |
+ static_cast<ui::KeyEvent*>(events[2])); |
+ CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&direction_released, |
+ static_cast<ui::KeyEvent*>(events[3])); |
+ CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&search_released, |
+ static_cast<ui::KeyEvent*>(events[4])); |
+ CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&shift_released, |
+ static_cast<ui::KeyEvent*>(events[5])); |
+} |
+ |
TEST_F(TouchExplorationTest, EntersTouchToMouseModeAfterPressAndDelay) { |
SwitchTouchExplorationMode(true); |
EXPECT_FALSE(IsInTouchToMouseMode()); |
@@ -220,6 +303,7 @@ TEST_F(TouchExplorationTest, EntersTouchToMouseModeAfterMoveOutsideSlop) { |
EXPECT_FALSE(IsInTouchToMouseMode()); |
generator_->MoveTouch(gfx::Point(11, 12 + half_slop)); |
EXPECT_FALSE(IsInTouchToMouseMode()); |
+ AdvanceSimulatedTimePastTapDelay(); |
generator_->MoveTouch(gfx::Point(11 + slop + 1, 12)); |
EXPECT_TRUE(IsInTouchToMouseMode()); |
} |
@@ -233,7 +317,7 @@ TEST_F(TouchExplorationTest, OneFingerTap) { |
AdvanceSimulatedTimePastTapDelay(); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(1U, events.size()); |
EXPECT_EQ(location, events[0]->location()); |
@@ -263,7 +347,7 @@ TEST_F(TouchExplorationTest, ActualMouseMovesUnaffected) { |
AdvanceSimulatedTimePastTapDelay(); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(4U, events.size()); |
EXPECT_EQ(location_start, events[0]->location()); |
@@ -308,7 +392,7 @@ TEST_F(TouchExplorationTest, TurnOnMidTouch) { |
generator_->Dispatch(&touch_move); |
EXPECT_TRUE(cursor_client()->IsCursorVisible()); |
EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(1u, captured_events.size()); |
CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_move); |
ClearCapturedEvents(); |
@@ -317,7 +401,8 @@ TEST_F(TouchExplorationTest, TurnOnMidTouch) { |
generator_->PressTouchId(2); |
AdvanceSimulatedTimePastTapDelay(); |
EXPECT_TRUE(IsInTouchToMouseMode()); |
- ScopedVector<ui::LocatedEvent>::const_iterator it; |
+ captured_events = GetCapturedLocatedEvents(); |
+ std::vector<ui::LocatedEvent*>::const_iterator it; |
for (it = captured_events.begin(); it != captured_events.end(); ++it) { |
if ((*it)->type() == ui::ET_MOUSE_MOVED) |
break; |
@@ -331,6 +416,7 @@ TEST_F(TouchExplorationTest, TurnOnMidTouch) { |
1, |
Now()); |
generator_->Dispatch(&touch_release); |
+ captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(1u, captured_events.size()); |
CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_release); |
ClearCapturedEvents(); |
@@ -338,8 +424,8 @@ TEST_F(TouchExplorationTest, TurnOnMidTouch) { |
// The move and release from the second finger should get rewritten. |
generator_->MoveTouchId(gfx::Point(13, 14), 2); |
generator_->ReleaseTouchId(2); |
- AdvanceSimulatedTimePastTapDelay(); |
- |
+ AdvanceSimulatedTimePastTapDelay(); ///////////???? |
tdresser
2014/06/25 14:48:41
(///////////????)?
lisayin
2014/06/25 22:51:05
Done.
|
+ captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(2u, captured_events.size()); |
EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); |
EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); |
@@ -360,11 +446,11 @@ TEST_F(TouchExplorationTest, TwoFingerTouch) { |
generator_->Dispatch(&touch_press); |
EXPECT_TRUE(cursor_client()->IsCursorVisible()); |
EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
// TODO(mfomitchev): mouse enter/exit events |
// There will be a ET_MOUSE_EXITED event synthesized when the mouse cursor is |
// hidden - ignore it. |
- ScopedVector<ui::LocatedEvent>::const_iterator it; |
+ std::vector<ui::LocatedEvent*>::const_iterator it; |
for (it = captured_events.begin(); it != captured_events.end(); ++it) { |
if ((*it)->type() == ui::ET_TOUCH_PRESSED) { |
CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(*it, &touch_press); |
@@ -379,6 +465,7 @@ TEST_F(TouchExplorationTest, TwoFingerTouch) { |
2, |
Now()); |
generator_->Dispatch(&touch_move); |
+ captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(1u, captured_events.size()); |
CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_move); |
ClearCapturedEvents(); |
@@ -392,6 +479,7 @@ TEST_F(TouchExplorationTest, TwoFingerTouch) { |
generator_->Dispatch(&mouse_move); |
// TODO(mfomitchev): mouse enter/exit events |
// Ignore synthesized ET_MOUSE_ENTERED/ET_MOUSE_EXITED |
+ captured_events = GetCapturedLocatedEvents(); |
for (it = captured_events.begin(); it != captured_events.end(); ++it) { |
if ((*it)->type() == ui::ET_MOUSE_MOVED) { |
CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(*it, &mouse_move); |
@@ -405,7 +493,8 @@ TEST_F(TouchExplorationTest, TwoFingerTouch) { |
// is touching. |
gfx::Point touch1_location = gfx::Point(15, 16); |
generator_->MoveTouchId(touch1_location, 1); |
- EXPECT_EQ(0u, GetCapturedEvents().size()); |
+ captured_events = GetCapturedLocatedEvents(); |
+ EXPECT_EQ(0u, GetCapturedLocatedEvents().size()); |
EXPECT_TRUE(cursor_client()->IsCursorVisible()); |
EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); |
@@ -419,6 +508,7 @@ TEST_F(TouchExplorationTest, TwoFingerTouch) { |
2, |
Now()); |
generator_->Dispatch(&touch_release); |
+ captured_events = GetCapturedLocatedEvents(); |
EXPECT_FALSE(IsInTouchToMouseMode()); |
ASSERT_EQ(captured_events.size(), 1u); |
EXPECT_EQ(touch1_location, captured_events[0]->location()); |
@@ -467,7 +557,7 @@ TEST_F(TouchExplorationTest, MultiFingerTouch) { |
generator_->Dispatch(&touch3_release); |
generator_->Dispatch(&touch4_release); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(7u, captured_events.size()); |
CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch3_press); |
CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[1], &touch3_move1); |
@@ -488,21 +578,22 @@ TEST_F(TouchExplorationTest, FirstFingerLifted) { |
SwitchTouchExplorationMode(true); |
generator_->PressTouchId(1); |
generator_->PressTouchId(2); |
- gfx::Point touch2_location(10, 11); |
+ gfx::Point touch2_location(10, 11); |
tdresser
2014/06/25 14:48:41
A bunch of indentation issues around here.
lisayin
2014/06/25 22:51:05
Done.
|
generator_->MoveTouchId(touch2_location, 2); |
generator_->PressTouchId(3); |
gfx::Point touch3_location(20, 21); |
generator_->MoveTouchId(touch3_location, 3); |
ClearCapturedEvents(); |
- // Release of finger 1 should be ignored. |
+ // Release of finger 1 should be ignored. |
generator_->ReleaseTouchId(1); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(0u, captured_events.size()); |
// Move of finger 2 should be passed through. |
gfx::Point touch2_new_location(20, 11); |
generator_->MoveTouchId(touch2_new_location, 2); |
+ captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(1u, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); |
EXPECT_EQ(touch2_new_location, captured_events[0]->location()); |
@@ -515,7 +606,12 @@ TEST_F(TouchExplorationTest, FirstFingerLifted) { |
2, |
Now()); |
generator_->Dispatch(&touch2_release); |
+ captured_events = GetCapturedLocatedEvents(); |
+ |
ASSERT_EQ(1u, captured_events.size()); |
+ EXPECT_EQ(touch2_release.type(), captured_events[0]->type()); |
+ EXPECT_EQ(touch2_release.touch_id(), |
+ (static_cast<ui::TouchEvent*>(captured_events[0]))->touch_id()); |
CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch2_release); |
} |
@@ -538,7 +634,7 @@ TEST_F(TouchExplorationTest, SecondFingerLifted) { |
// Release of finger 2 should be rewritten as a move to the location |
// of the first finger. |
generator_->ReleaseTouchId(2); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(1u, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); |
EXPECT_EQ(2, static_cast<ui::TouchEvent*>(captured_events[0])->touch_id()); |
@@ -548,6 +644,7 @@ TEST_F(TouchExplorationTest, SecondFingerLifted) { |
// Move of finger 1 should be rewritten as a move of finger 2. |
gfx::Point touch1_new_location(0, 41); |
generator_->MoveTouchId(touch1_new_location, 1); |
+ captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(1u, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); |
EXPECT_EQ(2, static_cast<ui::TouchEvent*>(captured_events[0])->touch_id()); |
@@ -562,6 +659,7 @@ TEST_F(TouchExplorationTest, SecondFingerLifted) { |
1, |
Now()); |
generator_->Dispatch(&touch1_release); |
+ captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(1u, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); |
EXPECT_EQ(2, static_cast<ui::TouchEvent*>(captured_events[0])->touch_id()); |
@@ -578,7 +676,7 @@ TEST_F(TouchExplorationTest, TimerFiresLateDuringTouchExploration) { |
simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
generator_->PressTouchId(2); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(1U, events.size()); |
EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
@@ -611,7 +709,7 @@ TEST_F(TouchExplorationTest, TimerFiresLateAfterTap) { |
AdvanceSimulatedTimePastTapDelay(); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(2U, events.size()); |
EXPECT_EQ(location0, events[0]->location()); |
EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
@@ -635,7 +733,7 @@ TEST_F(TouchExplorationTest, DoubleTap) { |
AdvanceSimulatedTimePastTapDelay(); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(1U, events.size()); |
EXPECT_EQ(tap_location, events[0]->location()); |
@@ -653,7 +751,7 @@ TEST_F(TouchExplorationTest, DoubleTap) { |
generator_->PressTouch(); |
generator_->ReleaseTouch(); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(2U, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
EXPECT_EQ(tap_location, captured_events[0]->location()); |
@@ -676,7 +774,7 @@ TEST_F(TouchExplorationTest, DoubleTapLongPress) { |
AdvanceSimulatedTimePastTapDelay(); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(1U, events.size()); |
EXPECT_EQ(tap_location, events[0]->location()); |
@@ -698,7 +796,7 @@ TEST_F(TouchExplorationTest, DoubleTapLongPress) { |
simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); |
generator_->ReleaseTouch(); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(2U, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
EXPECT_EQ(tap_location, captured_events[0]->location()); |
@@ -720,6 +818,8 @@ TEST_F(TouchExplorationTest, SingleTap) { |
gfx::Point initial_location(11, 12); |
generator_->set_current_location(initial_location); |
generator_->PressTouch(); |
+ AdvanceSimulatedTimePastTapDelay(); |
+ ClearCapturedEvents(); |
// Move to another location for single tap |
gfx::Point tap_location(22, 23); |
@@ -734,7 +834,7 @@ TEST_F(TouchExplorationTest, SingleTap) { |
generator_->PressTouch(); |
generator_->ReleaseTouch(); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(4U, captured_events.size()); |
EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); |
EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); |
@@ -760,7 +860,7 @@ TEST_F(TouchExplorationTest, DoubleTapNoTouchExplore) { |
generator_->PressTouch(); |
generator_->ReleaseTouch(); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(0U, captured_events.size()); |
} |
@@ -775,7 +875,7 @@ TEST_F(TouchExplorationTest, SplitTap) { |
// Tap and hold at one location, and get a mouse move event in touch explore. |
EnterTouchExplorationModeAtLocation(initial_touch_location); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(1U, events.size()); |
EXPECT_EQ(initial_touch_location, events[0]->location()); |
@@ -795,7 +895,7 @@ TEST_F(TouchExplorationTest, SplitTap) { |
generator_->Dispatch(&split_tap_release); |
EXPECT_FALSE(IsInNoFingersDownState()); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(2U, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
@@ -817,7 +917,7 @@ TEST_F(TouchExplorationTest, SplitTapRelease) { |
EnterTouchExplorationModeAtLocation(initial_touch_location); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(1U, events.size()); |
ClearCapturedEvents(); |
@@ -837,7 +937,7 @@ TEST_F(TouchExplorationTest, SplitTapRelease) { |
generator_->Dispatch(&split_tap_release); |
EXPECT_TRUE(IsInNoFingersDownState()); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(2U, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
@@ -857,7 +957,7 @@ TEST_F(TouchExplorationTest, SplitTapLongPress) { |
// Tap and hold at one location, and get a mouse move event in touch explore. |
EnterTouchExplorationModeAtLocation(initial_touch_location); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(1U, events.size()); |
ClearCapturedEvents(); |
@@ -875,7 +975,7 @@ TEST_F(TouchExplorationTest, SplitTapLongPress) { |
generator_->Dispatch(&split_tap_release); |
EXPECT_FALSE(IsInNoFingersDownState()); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(2U, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
@@ -901,7 +1001,7 @@ TEST_F(TouchExplorationTest, SplitTapReleaseLongPress) { |
// Tap and hold at one location, and get a mouse move event in touch explore. |
EnterTouchExplorationModeAtLocation(initial_touch_location); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(1U, events.size()); |
ClearCapturedEvents(); |
@@ -922,7 +1022,7 @@ TEST_F(TouchExplorationTest, SplitTapReleaseLongPress) { |
generator_->Dispatch(&split_tap_release); |
EXPECT_TRUE(IsInTouchToMouseMode()); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(2U, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
@@ -944,7 +1044,7 @@ TEST_F(TouchExplorationTest, SplitTapLongPressMultiFinger) { |
EnterTouchExplorationModeAtLocation(initial_touch_location); |
std::vector<ui::LocatedEvent*> events = |
- GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
+ GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
ASSERT_EQ(1U, events.size()); |
EXPECT_EQ(initial_touch_location, events[0]->location()); |
@@ -976,7 +1076,7 @@ TEST_F(TouchExplorationTest, SplitTapLongPressMultiFinger) { |
ui::ET_TOUCH_RELEASED, third_touch_location, 2, Now()); |
generator_->Dispatch(&third_tap_release); |
- const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
+ std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
ASSERT_EQ(2U, captured_events.size()); |
EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
@@ -989,4 +1089,90 @@ TEST_F(TouchExplorationTest, SplitTapLongPressMultiFinger) { |
EXPECT_TRUE(IsInNoFingersDownState()); |
} |
+// Finger must have moved more than slop, faster than the minimum swipe |
+// velocity, and before the tap timer fires in order to enter |
+// GestureInProgress state. Otherwise, if the tap timer fires before the a |
+// gesture is completed, enter touch exploration. |
+TEST_F(TouchExplorationTest, EnterGestureInProgressState) { |
+ SwitchTouchExplorationMode(true); |
+ EXPECT_FALSE(IsInTouchToMouseMode()); |
+ EXPECT_FALSE(IsInGestureInProgressState()); |
+ float delta_distance = gesture_detector_config_.touch_slop + 1; |
+ ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 1), 0, Now()); |
+ generator_->Dispatch(&first_press); |
+ gfx::Point second_location(delta_distance, 1); |
dmazzoni
2014/06/25 05:06:02
Nit: indentation
lisayin
2014/06/25 22:51:05
Done.
|
+ generator_->MoveTouch(second_location); |
dmazzoni
2014/06/25 05:06:02
Wouldn't this have the same timestamp and therefor
lisayin
2014/06/25 22:51:05
Done.
|
+ EXPECT_TRUE(IsInGestureInProgressState()); |
+ EXPECT_FALSE(IsInTouchToMouseMode()); |
+ const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
+ ASSERT_EQ(0U, captured_events.size()); |
+ |
+ // Exit out of gesture mode once grace period is over and enter touch |
+ // exploration. |
+ AdvanceSimulatedTimePastTapDelay(); |
+ ASSERT_EQ(1U, captured_events.size()); |
+ EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); |
+ EXPECT_TRUE(IsInTouchToMouseMode()); |
+ EXPECT_FALSE(IsInGestureInProgressState()); |
+} |
+ |
+ |
+// A swipe+direction gesture should trigger a Shift+Search+Direction |
+// keyboard event. |
+TEST_F(TouchExplorationTest, GestureSwipe) { |
+ SwitchTouchExplorationMode(true); |
+ std::vector<ui::KeyboardCode> directions; |
+ directions.push_back(ui::VKEY_RIGHT); |
+ directions.push_back(ui::VKEY_LEFT); |
+ directions.push_back(ui::VKEY_UP); |
+ directions.push_back(ui::VKEY_DOWN); |
+ |
+ for (std::vector<ui::KeyboardCode>::const_iterator it = directions.begin(); |
+ it != directions.end(); |
+ ++it) { |
+ int x = 30; |
+ int y = 31; |
+ ui::TouchEvent origin(ui::ET_TOUCH_PRESSED, gfx::Point(x, y), 0, Now()); |
+ generator_->Dispatch(&origin); |
+ |
+ ui::KeyboardCode direction = *it; |
+ float delta_distance = gesture_detector_config_.touch_slop + 1; |
+ scoped_ptr<gfx::Point> swipe; |
+ switch (direction) { |
+ case ui::VKEY_RIGHT: |
+ swipe.reset(new gfx::Point(x + delta_distance, y)); |
+ break; |
+ case ui::VKEY_LEFT: |
+ swipe.reset(new gfx::Point(x - delta_distance, y)); |
+ break; |
+ case ui::VKEY_UP: |
+ swipe.reset(new gfx::Point(x, y - delta_distance)); |
+ break; |
+ case ui::VKEY_DOWN: |
+ swipe.reset(new gfx::Point(x, y + delta_distance)); |
+ break; |
+ default: |
+ return; |
+ } |
+ |
+ // A swipe is made when a fling starts |
+ float delta_time = |
+ delta_distance / gesture_detector_config_.maximum_fling_velocity; |
+ simulated_clock_->Advance(base::TimeDelta::FromSecondsD(delta_time)); |
+ generator_->MoveTouch(*swipe); |
+ EXPECT_TRUE(IsInGestureInProgressState()); |
+ EXPECT_FALSE(IsInTouchToMouseMode()); |
+ const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
+ ASSERT_EQ(0U, captured_events.size()); |
+ generator_->ReleaseTouch(); |
+ |
+ // The swipe registered and sent the appropriate key events. |
+ SwipeSuccessfullyCompleted(captured_events, direction); |
+ EXPECT_TRUE(IsInNoFingersDownState()); |
+ EXPECT_FALSE(IsInTouchToMouseMode()); |
+ EXPECT_FALSE(IsInGestureInProgressState()); |
+ ClearCapturedEvents(); |
+ } |
+} |
+ |
} // namespace ui |