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

Unified Diff: ui/chromeos/touch_exploration_controller_unittest.cc

Issue 330763007: Swipe Gestures for Accessibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gesture-vlogs
Patch Set: Removed line that Evy was working on Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ae742c2d6c1cb48c243cf0a0db4aa7b9526b08f9 100644
--- a/ui/chromeos/touch_exploration_controller_unittest.cc
+++ b/ui/chromeos/touch_exploration_controller_unittest.cc
@@ -13,6 +13,7 @@
#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"
@@ -20,7 +21,7 @@
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 +38,11 @@ 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 +53,11 @@ 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 {
- return events_;
- }
+
+ 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 +93,25 @@ 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() ||
evy 2014/06/26 00:02:36 A previous comment from Dominic: When there are m
+ all_events[i]->IsGestureEvent()) {
+ 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 +119,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 +170,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 +222,64 @@ 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());
+ EXPECT_EQ(key_event1->code(), key_event2->code());
+ EXPECT_EQ(key_event1->flags(), key_event2->flags());
+}
+
#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 AssertDirectionalNavigationEvents(const ScopedVector<ui::Event>& events,
+ 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 +300,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 +314,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 +344,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 +389,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 +398,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 +413,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();
@@ -339,7 +422,7 @@ TEST_F(TouchExplorationTest, TurnOnMidTouch) {
generator_->MoveTouchId(gfx::Point(13, 14), 2);
generator_->ReleaseTouchId(2);
AdvanceSimulatedTimePastTapDelay();
-
+ 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 +443,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 +462,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 +476,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 +490,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());
tdresser 2014/06/26 13:31:49 It looks like you're caching |GetCapturedLocatedEv
EXPECT_TRUE(cursor_client()->IsCursorVisible());
EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled());
@@ -419,6 +505,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 +554,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);
@@ -497,12 +584,13 @@ TEST_F(TouchExplorationTest, FirstFingerLifted) {
// 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 +603,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 +631,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 +641,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 +656,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 +673,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 +706,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 +730,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 +748,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 +771,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 +793,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 +815,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 +831,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 +857,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 +872,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 +892,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 +914,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 +934,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 +954,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 +972,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 +998,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 +1019,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 +1041,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 +1073,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 +1086,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);
+ simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
+ generator_->MoveTouch(second_location);
+ 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.
+ AssertDirectionalNavigationEvents(captured_events, direction);
+ EXPECT_TRUE(IsInNoFingersDownState());
+ EXPECT_FALSE(IsInTouchToMouseMode());
+ EXPECT_FALSE(IsInGestureInProgressState());
+ ClearCapturedEvents();
+ }
+}
+
} // namespace ui
« ui/chromeos/touch_exploration_controller.h ('K') | « ui/chromeos/touch_exploration_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698