| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/chromeos/touch_exploration_controller.h" | 5 #include "ui/chromeos/touch_exploration_controller.h" |
| 6 | 6 |
| 7 #include "base/test/simple_test_tick_clock.h" | 7 #include "base/test/simple_test_tick_clock.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
| 10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
| 11 #include "ui/aura/test/event_generator.h" | 11 #include "ui/aura/test/event_generator.h" |
| 12 #include "ui/aura/test/test_cursor_client.h" | 12 #include "ui/aura/test/test_cursor_client.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
| 16 #include "ui/events/gestures/gesture_provider_aura.h" | |
| 17 #include "ui/gfx/geometry/point.h" | 16 #include "ui/gfx/geometry/point.h" |
| 18 #include "ui/gl/gl_implementation.h" | 17 #include "ui/gl/gl_implementation.h" |
| 19 #include "ui/gl/gl_surface.h" | 18 #include "ui/gl/gl_surface.h" |
| 20 | 19 |
| 21 namespace ui { | 20 namespace ui { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 // Records all mouse, touch, gesture, and key events. | 23 // Records all mouse and touch events. |
| 25 class EventCapturer : public ui::EventHandler { | 24 class EventCapturer : public ui::EventHandler { |
| 26 public: | 25 public: |
| 27 EventCapturer() {} | 26 EventCapturer() {} |
| 28 virtual ~EventCapturer() {} | 27 virtual ~EventCapturer() {} |
| 29 | 28 |
| 30 void Reset() { | 29 void Reset() { |
| 31 events_.clear(); | 30 events_.clear(); |
| 32 } | 31 } |
| 33 | 32 |
| 34 virtual void OnEvent(ui::Event* event) OVERRIDE { | 33 virtual void OnEvent(ui::Event* event) OVERRIDE { |
| 35 if (event->IsMouseEvent()) { | 34 if (event->IsMouseEvent()) { |
| 36 events_.push_back( | 35 events_.push_back( |
| 37 new ui::MouseEvent(static_cast<ui::MouseEvent&>(*event))); | 36 new ui::MouseEvent(static_cast<ui::MouseEvent&>(*event))); |
| 38 } else if (event->IsTouchEvent()) { | 37 } else if (event->IsTouchEvent()) { |
| 39 events_.push_back( | 38 events_.push_back( |
| 40 new ui::TouchEvent(static_cast<ui::TouchEvent&>(*event))); | 39 new ui::TouchEvent(static_cast<ui::TouchEvent&>(*event))); |
| 41 } else if (event->IsGestureEvent()) { | |
| 42 events_.push_back( | |
| 43 new ui::GestureEvent(static_cast<ui::GestureEvent&>(*event))); | |
| 44 } else if (event->IsKeyEvent()) { | |
| 45 events_.push_back(new ui::KeyEvent(static_cast<ui::KeyEvent&>(*event))); | |
| 46 } else { | 40 } else { |
| 47 return; | 41 return; |
| 48 } | 42 } |
| 49 // Stop event propagation so we don't click on random stuff that | 43 // Stop event propagation so we don't click on random stuff that |
| 50 // might break test assumptions. | 44 // might break test assumptions. |
| 51 event->StopPropagation(); | 45 event->StopPropagation(); |
| 52 // If there is a possibility that we're in an infinite loop, we should | 46 // If there is a possibility that we're in an infinite loop, we should |
| 53 // exit early with a sensible error rather than letting the test time out. | 47 // exit early with a sensible error rather than letting the test time out. |
| 54 ASSERT_LT(events_.size(), 100u); | 48 ASSERT_LT(events_.size(), 100u); |
| 55 } | 49 } |
| 56 | 50 const ScopedVector<ui::LocatedEvent>& captured_events() const { |
| 57 const ScopedVector<ui::Event>& captured_events() const { return events_; } | 51 return events_; |
| 52 } |
| 58 | 53 |
| 59 private: | 54 private: |
| 60 ScopedVector<ui::Event> events_; | 55 ScopedVector<ui::LocatedEvent> events_; |
| 61 | 56 |
| 62 DISALLOW_COPY_AND_ASSIGN(EventCapturer); | 57 DISALLOW_COPY_AND_ASSIGN(EventCapturer); |
| 63 }; | 58 }; |
| 64 | 59 |
| 65 } // namespace | 60 } // namespace |
| 66 | 61 |
| 67 class TouchExplorationTest : public aura::test::AuraTestBase { | 62 class TouchExplorationTest : public aura::test::AuraTestBase { |
| 68 public: | 63 public: |
| 69 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { | 64 TouchExplorationTest() |
| 70 // Tests fail if time is ever 0. | 65 : simulated_clock_(new base::SimpleTestTickClock()) {} |
| 71 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 72 } | |
| 73 virtual ~TouchExplorationTest() {} | 66 virtual ~TouchExplorationTest() {} |
| 74 | 67 |
| 75 virtual void SetUp() OVERRIDE { | 68 virtual void SetUp() OVERRIDE { |
| 76 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) | 69 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) |
| 77 gfx::GLSurface::InitializeOneOffForTests(); | 70 gfx::GLSurface::InitializeOneOffForTests(); |
| 78 aura::test::AuraTestBase::SetUp(); | 71 aura::test::AuraTestBase::SetUp(); |
| 79 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); | 72 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); |
| 80 root_window()->AddPreTargetHandler(&event_capturer_); | 73 root_window()->AddPreTargetHandler(&event_capturer_); |
| 81 generator_.reset(new aura::test::EventGenerator(root_window())); | 74 generator_.reset(new aura::test::EventGenerator(root_window())); |
| 82 // The generator takes ownership of the clock. | 75 // The generator takes ownership of the clock. |
| 83 generator_->SetTickClock(scoped_ptr<base::TickClock>(simulated_clock_)); | 76 generator_->SetTickClock(scoped_ptr<base::TickClock>(simulated_clock_)); |
| 84 cursor_client()->ShowCursor(); | 77 cursor_client()->ShowCursor(); |
| 85 cursor_client()->DisableMouseEvents(); | 78 cursor_client()->DisableMouseEvents(); |
| 86 } | 79 } |
| 87 | 80 |
| 88 virtual void TearDown() OVERRIDE { | 81 virtual void TearDown() OVERRIDE { |
| 89 root_window()->RemovePreTargetHandler(&event_capturer_); | 82 root_window()->RemovePreTargetHandler(&event_capturer_); |
| 90 SwitchTouchExplorationMode(false); | 83 SwitchTouchExplorationMode(false); |
| 91 cursor_client_.reset(); | 84 cursor_client_.reset(); |
| 92 aura::test::AuraTestBase::TearDown(); | 85 aura::test::AuraTestBase::TearDown(); |
| 93 } | 86 } |
| 94 | 87 |
| 95 protected: | 88 protected: |
| 96 aura::client::CursorClient* cursor_client() { return cursor_client_.get(); } | 89 aura::client::CursorClient* cursor_client() { return cursor_client_.get(); } |
| 97 | 90 |
| 98 const ScopedVector<ui::Event>& GetCapturedEvents() { | 91 const ScopedVector<ui::LocatedEvent>& GetCapturedEvents() { |
| 99 return event_capturer_.captured_events(); | 92 return event_capturer_.captured_events(); |
| 100 } | 93 } |
| 101 | 94 |
| 102 std::vector<ui::LocatedEvent*> GetCapturedLocatedEvents() { | 95 std::vector<ui::LocatedEvent*> GetCapturedEventsOfType(int type) { |
| 103 const ScopedVector<ui::Event>& all_events = GetCapturedEvents(); | 96 const ScopedVector<ui::LocatedEvent>& all_events = GetCapturedEvents(); |
| 104 std::vector<ui::LocatedEvent*> located_events; | 97 std::vector<ui::LocatedEvent*> events; |
| 105 for (size_t i = 0; i < all_events.size(); ++i) { | |
| 106 if (all_events[i]->IsMouseEvent() || | |
| 107 all_events[i]->IsTouchEvent() || | |
| 108 all_events[i]->IsGestureEvent()) { | |
| 109 located_events.push_back(static_cast<ui::LocatedEvent*>(all_events[i])); | |
| 110 } | |
| 111 } | |
| 112 return located_events; | |
| 113 } | |
| 114 | |
| 115 std::vector<ui::Event*> GetCapturedEventsOfType(int type) { | |
| 116 const ScopedVector<ui::Event>& all_events = GetCapturedEvents(); | |
| 117 std::vector<ui::Event*> events; | |
| 118 for (size_t i = 0; i < all_events.size(); ++i) { | 98 for (size_t i = 0; i < all_events.size(); ++i) { |
| 119 if (type == all_events[i]->type()) | 99 if (type == all_events[i]->type()) |
| 120 events.push_back(all_events[i]); | 100 events.push_back(all_events[i]); |
| 121 } | 101 } |
| 122 return events; | 102 return events; |
| 123 } | 103 } |
| 124 | |
| 125 std::vector<ui::LocatedEvent*> GetCapturedLocatedEventsOfType(int type) { | |
| 126 std::vector<ui::LocatedEvent*> located_events = GetCapturedLocatedEvents(); | |
| 127 std::vector<ui::LocatedEvent*> events; | |
| 128 for (size_t i = 0; i < located_events.size(); ++i) { | |
| 129 if (type == located_events[i]->type()) | |
| 130 events.push_back(located_events[i]); | |
| 131 } | |
| 132 return events; | |
| 133 } | |
| 134 | 104 |
| 135 void ClearCapturedEvents() { | 105 void ClearCapturedEvents() { |
| 136 event_capturer_.Reset(); | 106 event_capturer_.Reset(); |
| 137 } | 107 } |
| 138 | 108 |
| 139 void AdvanceSimulatedTimePastTapDelay() { | 109 void AdvanceSimulatedTimePastTapDelay() { |
| 140 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); | 110 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
| 141 touch_exploration_controller_->CallTapTimerNowForTesting(); | 111 touch_exploration_controller_->CallTapTimerNowForTesting(); |
| 142 } | 112 } |
| 143 | 113 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 aura::client::GetCursorClient(root_window()); | 147 aura::client::GetCursorClient(root_window()); |
| 178 return cursor_client && | 148 return cursor_client && |
| 179 cursor_client->IsMouseEventsEnabled() && | 149 cursor_client->IsMouseEventsEnabled() && |
| 180 !cursor_client->IsCursorVisible(); | 150 !cursor_client->IsCursorVisible(); |
| 181 } | 151 } |
| 182 | 152 |
| 183 bool IsInNoFingersDownState() { | 153 bool IsInNoFingersDownState() { |
| 184 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); | 154 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); |
| 185 } | 155 } |
| 186 | 156 |
| 187 bool IsInGestureInProgressState() { | |
| 188 return touch_exploration_controller_ | |
| 189 ->IsInGestureInProgressStateForTesting(); | |
| 190 } | |
| 191 | |
| 192 base::TimeDelta Now() { | 157 base::TimeDelta Now() { |
| 193 // This is the same as what EventTimeForNow() does, but here we do it | 158 // This is the same as what EventTimeForNow() does, but here we do it |
| 194 // with our simulated clock. | 159 // with our simulated clock. |
| 195 return base::TimeDelta::FromInternalValue( | 160 return base::TimeDelta::FromInternalValue( |
| 196 simulated_clock_->NowTicks().ToInternalValue()); | 161 simulated_clock_->NowTicks().ToInternalValue()); |
| 197 } | 162 } |
| 198 | 163 |
| 199 scoped_ptr<aura::test::EventGenerator> generator_; | 164 scoped_ptr<aura::test::EventGenerator> generator_; |
| 200 ui::GestureDetector::Config gesture_detector_config_; | 165 ui::GestureDetector::Config gesture_detector_config_; |
| 201 // Owned by |generator_|. | 166 // Owned by |generator_|. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 229 ASSERT_TRUE(e1->IsMouseEvent()); | 194 ASSERT_TRUE(e1->IsMouseEvent()); |
| 230 ASSERT_TRUE(e2->IsMouseEvent()); | 195 ASSERT_TRUE(e2->IsMouseEvent()); |
| 231 ui::MouseEvent* mouse_event1 = static_cast<ui::MouseEvent*>(e1); | 196 ui::MouseEvent* mouse_event1 = static_cast<ui::MouseEvent*>(e1); |
| 232 ui::MouseEvent* mouse_event2 = static_cast<ui::MouseEvent*>(e2); | 197 ui::MouseEvent* mouse_event2 = static_cast<ui::MouseEvent*>(e2); |
| 233 EXPECT_EQ(mouse_event1->type(), mouse_event2->type()); | 198 EXPECT_EQ(mouse_event1->type(), mouse_event2->type()); |
| 234 EXPECT_EQ(mouse_event1->location(), mouse_event2->location()); | 199 EXPECT_EQ(mouse_event1->location(), mouse_event2->location()); |
| 235 EXPECT_EQ(mouse_event1->root_location(), mouse_event2->root_location()); | 200 EXPECT_EQ(mouse_event1->root_location(), mouse_event2->root_location()); |
| 236 EXPECT_EQ(mouse_event1->flags(), mouse_event2->flags()); | 201 EXPECT_EQ(mouse_event1->flags(), mouse_event2->flags()); |
| 237 } | 202 } |
| 238 | 203 |
| 239 // Executes a number of assertions to confirm that |e1| and |e2| are key events | |
| 240 // and are equal to each other. | |
| 241 void ConfirmEventsAreKeyAndEqual(ui::Event* e1, ui::Event* e2) { | |
| 242 ASSERT_TRUE(e1->IsKeyEvent()); | |
| 243 ASSERT_TRUE(e2->IsKeyEvent()); | |
| 244 ui::KeyEvent* key_event1 = static_cast<ui::KeyEvent*>(e1); | |
| 245 ui::KeyEvent* key_event2 = static_cast<ui::KeyEvent*>(e2); | |
| 246 EXPECT_EQ(key_event1->type(), key_event2->type()); | |
| 247 EXPECT_EQ(key_event1->key_code(), key_event2->key_code()); | |
| 248 EXPECT_EQ(key_event1->code(), key_event2->code()); | |
| 249 EXPECT_EQ(key_event1->flags(), key_event2->flags()); | |
| 250 } | |
| 251 | |
| 252 #define CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(e1, e2) \ | 204 #define CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(e1, e2) \ |
| 253 ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreTouchAndEqual(e1, e2)) | 205 ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreTouchAndEqual(e1, e2)) |
| 254 | 206 |
| 255 #define CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(e1, e2) \ | 207 #define CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(e1, e2) \ |
| 256 ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreMouseAndEqual(e1, e2)) | 208 ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreMouseAndEqual(e1, e2)) |
| 257 | 209 |
| 258 #define CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(e1, e2) \ | |
| 259 ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreKeyAndEqual(e1, e2)) | |
| 260 | |
| 261 // TODO(mfomitchev): Need to investigate why we don't get mouse enter/exit | 210 // TODO(mfomitchev): Need to investigate why we don't get mouse enter/exit |
| 262 // events when running these tests as part of ui_unittests. We do get them when | 211 // events when running these tests as part of ui_unittests. We do get them when |
| 263 // the tests are run as part of ash unit tests. | 212 // the tests are run as part of ash unit tests. |
| 264 | 213 |
| 265 // If a swipe has been successfully completed, then six key events will be | |
| 266 // dispatched that correspond to shift+search+direction | |
| 267 void AssertDirectionalNavigationEvents(const ScopedVector<ui::Event>& events, | |
| 268 ui::KeyboardCode direction) { | |
| 269 ASSERT_EQ(6U, events.size()); | |
| 270 ui::KeyEvent shift_pressed( | |
| 271 ui::ET_KEY_PRESSED, ui::VKEY_SHIFT, ui::EF_SHIFT_DOWN, false); | |
| 272 ui::KeyEvent search_pressed( | |
| 273 ui::ET_KEY_PRESSED, ui::VKEY_LWIN, ui::EF_SHIFT_DOWN, false); | |
| 274 ui::KeyEvent direction_pressed( | |
| 275 ui::ET_KEY_PRESSED, direction, ui::EF_SHIFT_DOWN, false); | |
| 276 ui::KeyEvent direction_released( | |
| 277 ui::ET_KEY_RELEASED, direction, ui::EF_SHIFT_DOWN, false); | |
| 278 ui::KeyEvent search_released( | |
| 279 ui::ET_KEY_RELEASED, VKEY_LWIN, ui::EF_SHIFT_DOWN, false); | |
| 280 ui::KeyEvent shift_released( | |
| 281 ui::ET_KEY_RELEASED, ui::VKEY_SHIFT, ui::EF_NONE, false); | |
| 282 CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&shift_pressed, events[0]); | |
| 283 CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&search_pressed, events[1]); | |
| 284 CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&direction_pressed, events[2]); | |
| 285 CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&direction_released, events[3]); | |
| 286 CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&search_released, events[4]); | |
| 287 CONFIRM_EVENTS_ARE_KEY_AND_EQUAL(&shift_released, events[5]); | |
| 288 } | |
| 289 | |
| 290 TEST_F(TouchExplorationTest, EntersTouchToMouseModeAfterPressAndDelay) { | 214 TEST_F(TouchExplorationTest, EntersTouchToMouseModeAfterPressAndDelay) { |
| 291 SwitchTouchExplorationMode(true); | 215 SwitchTouchExplorationMode(true); |
| 292 EXPECT_FALSE(IsInTouchToMouseMode()); | 216 EXPECT_FALSE(IsInTouchToMouseMode()); |
| 293 generator_->PressTouch(); | 217 generator_->PressTouch(); |
| 294 AdvanceSimulatedTimePastTapDelay(); | 218 AdvanceSimulatedTimePastTapDelay(); |
| 295 EXPECT_TRUE(IsInTouchToMouseMode()); | 219 EXPECT_TRUE(IsInTouchToMouseMode()); |
| 296 } | 220 } |
| 297 | 221 |
| 298 TEST_F(TouchExplorationTest, EntersTouchToMouseModeAfterMoveOutsideSlop) { | 222 TEST_F(TouchExplorationTest, EntersTouchToMouseModeAfterMoveOutsideSlop) { |
| 299 int slop = gesture_detector_config_.touch_slop; | 223 int slop = gesture_detector_config_.touch_slop; |
| 300 int half_slop = slop / 2; | 224 int half_slop = slop / 2; |
| 301 | 225 |
| 302 SwitchTouchExplorationMode(true); | 226 SwitchTouchExplorationMode(true); |
| 303 EXPECT_FALSE(IsInTouchToMouseMode()); | 227 EXPECT_FALSE(IsInTouchToMouseMode()); |
| 304 generator_->set_current_location(gfx::Point(11, 12)); | 228 generator_->set_current_location(gfx::Point(11, 12)); |
| 305 generator_->PressTouch(); | 229 generator_->PressTouch(); |
| 306 generator_->MoveTouch(gfx::Point(11 + half_slop, 12)); | 230 generator_->MoveTouch(gfx::Point(11 + half_slop, 12)); |
| 307 EXPECT_FALSE(IsInTouchToMouseMode()); | 231 EXPECT_FALSE(IsInTouchToMouseMode()); |
| 308 generator_->MoveTouch(gfx::Point(11, 12 + half_slop)); | 232 generator_->MoveTouch(gfx::Point(11, 12 + half_slop)); |
| 309 EXPECT_FALSE(IsInTouchToMouseMode()); | 233 EXPECT_FALSE(IsInTouchToMouseMode()); |
| 310 AdvanceSimulatedTimePastTapDelay(); | |
| 311 generator_->MoveTouch(gfx::Point(11 + slop + 1, 12)); | 234 generator_->MoveTouch(gfx::Point(11 + slop + 1, 12)); |
| 312 EXPECT_TRUE(IsInTouchToMouseMode()); | 235 EXPECT_TRUE(IsInTouchToMouseMode()); |
| 313 } | 236 } |
| 314 | 237 |
| 315 TEST_F(TouchExplorationTest, OneFingerTap) { | 238 TEST_F(TouchExplorationTest, OneFingerTap) { |
| 316 SwitchTouchExplorationMode(true); | 239 SwitchTouchExplorationMode(true); |
| 317 gfx::Point location(11, 12); | 240 gfx::Point location(11, 12); |
| 318 generator_->set_current_location(location); | 241 generator_->set_current_location(location); |
| 319 generator_->PressTouch(); | 242 generator_->PressTouch(); |
| 320 generator_->ReleaseTouch(); | 243 generator_->ReleaseTouch(); |
| 321 AdvanceSimulatedTimePastTapDelay(); | 244 AdvanceSimulatedTimePastTapDelay(); |
| 322 | 245 |
| 323 std::vector<ui::LocatedEvent*> events = | 246 std::vector<ui::LocatedEvent*> events = |
| 324 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 247 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 325 ASSERT_EQ(1U, events.size()); | 248 ASSERT_EQ(1U, events.size()); |
| 326 | 249 |
| 327 EXPECT_EQ(location, events[0]->location()); | 250 EXPECT_EQ(location, events[0]->location()); |
| 328 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 251 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
| 329 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 252 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 330 EXPECT_TRUE(IsInNoFingersDownState()); | 253 EXPECT_TRUE(IsInNoFingersDownState()); |
| 331 } | 254 } |
| 332 | 255 |
| 333 TEST_F(TouchExplorationTest, ActualMouseMovesUnaffected) { | 256 TEST_F(TouchExplorationTest, ActualMouseMovesUnaffected) { |
| 334 SwitchTouchExplorationMode(true); | 257 SwitchTouchExplorationMode(true); |
| 335 | 258 |
| 336 gfx::Point location_start(11, 12); | 259 gfx::Point location_start(11, 12); |
| 337 gfx::Point location_end(13, 14); | 260 gfx::Point location_end(13, 14); |
| 338 generator_->set_current_location(location_start); | 261 generator_->set_current_location(location_start); |
| 339 generator_->PressTouch(); | 262 generator_->PressTouch(); |
| 340 AdvanceSimulatedTimePastTapDelay(); | 263 AdvanceSimulatedTimePastTapDelay(); |
| 341 generator_->MoveTouch(location_end); | 264 generator_->MoveTouch(location_end); |
| 342 | 265 |
| 343 gfx::Point location_real_mouse_move(15, 16); | 266 gfx::Point location_real_mouse_move(15, 16); |
| 344 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, | 267 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, |
| 345 location_real_mouse_move, | 268 location_real_mouse_move, |
| 346 location_real_mouse_move, | 269 location_real_mouse_move, |
| 347 0, | 270 0, |
| 348 0); | 271 0); |
| 349 generator_->Dispatch(&mouse_move); | 272 generator_->Dispatch(&mouse_move); |
| 350 generator_->ReleaseTouch(); | 273 generator_->ReleaseTouch(); |
| 351 AdvanceSimulatedTimePastTapDelay(); | 274 AdvanceSimulatedTimePastTapDelay(); |
| 352 | 275 |
| 353 std::vector<ui::LocatedEvent*> events = | 276 std::vector<ui::LocatedEvent*> events = |
| 354 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 277 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 355 ASSERT_EQ(4U, events.size()); | 278 ASSERT_EQ(4U, events.size()); |
| 356 | 279 |
| 357 EXPECT_EQ(location_start, events[0]->location()); | 280 EXPECT_EQ(location_start, events[0]->location()); |
| 358 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 281 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
| 359 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 282 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 360 | 283 |
| 361 EXPECT_EQ(location_end, events[1]->location()); | 284 EXPECT_EQ(location_end, events[1]->location()); |
| 362 EXPECT_TRUE(events[1]->flags() & ui::EF_IS_SYNTHESIZED); | 285 EXPECT_TRUE(events[1]->flags() & ui::EF_IS_SYNTHESIZED); |
| 363 EXPECT_TRUE(events[1]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 286 EXPECT_TRUE(events[1]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 364 | 287 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 389 // affected by the touch exploration mode, while the touch events from another | 312 // affected by the touch exploration mode, while the touch events from another |
| 390 // finger get rewritten. | 313 // finger get rewritten. |
| 391 SwitchTouchExplorationMode(true); | 314 SwitchTouchExplorationMode(true); |
| 392 ui::TouchEvent touch_move(ui::ET_TOUCH_MOVED, | 315 ui::TouchEvent touch_move(ui::ET_TOUCH_MOVED, |
| 393 gfx::Point(11, 12), | 316 gfx::Point(11, 12), |
| 394 1, | 317 1, |
| 395 Now()); | 318 Now()); |
| 396 generator_->Dispatch(&touch_move); | 319 generator_->Dispatch(&touch_move); |
| 397 EXPECT_TRUE(cursor_client()->IsCursorVisible()); | 320 EXPECT_TRUE(cursor_client()->IsCursorVisible()); |
| 398 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); | 321 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); |
| 399 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 322 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 400 ASSERT_EQ(1u, captured_events.size()); | 323 ASSERT_EQ(1u, captured_events.size()); |
| 401 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_move); | 324 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_move); |
| 402 ClearCapturedEvents(); | 325 ClearCapturedEvents(); |
| 403 | 326 |
| 404 // The press from the second finger should get rewritten. | 327 // The press from the second finger should get rewritten. |
| 405 generator_->PressTouchId(2); | 328 generator_->PressTouchId(2); |
| 406 AdvanceSimulatedTimePastTapDelay(); | 329 AdvanceSimulatedTimePastTapDelay(); |
| 407 EXPECT_TRUE(IsInTouchToMouseMode()); | 330 EXPECT_TRUE(IsInTouchToMouseMode()); |
| 408 captured_events = GetCapturedLocatedEvents(); | 331 ScopedVector<ui::LocatedEvent>::const_iterator it; |
| 409 std::vector<ui::LocatedEvent*>::const_iterator it; | |
| 410 for (it = captured_events.begin(); it != captured_events.end(); ++it) { | 332 for (it = captured_events.begin(); it != captured_events.end(); ++it) { |
| 411 if ((*it)->type() == ui::ET_MOUSE_MOVED) | 333 if ((*it)->type() == ui::ET_MOUSE_MOVED) |
| 412 break; | 334 break; |
| 413 } | 335 } |
| 414 EXPECT_NE(captured_events.end(), it); | 336 EXPECT_NE(captured_events.end(), it); |
| 415 ClearCapturedEvents(); | 337 ClearCapturedEvents(); |
| 416 | 338 |
| 417 // The release of the first finger shouldn't be affected. | 339 // The release of the first finger shouldn't be affected. |
| 418 ui::TouchEvent touch_release(ui::ET_TOUCH_RELEASED, | 340 ui::TouchEvent touch_release(ui::ET_TOUCH_RELEASED, |
| 419 gfx::Point(11, 12), | 341 gfx::Point(11, 12), |
| 420 1, | 342 1, |
| 421 Now()); | 343 Now()); |
| 422 generator_->Dispatch(&touch_release); | 344 generator_->Dispatch(&touch_release); |
| 423 captured_events = GetCapturedLocatedEvents(); | |
| 424 ASSERT_EQ(1u, captured_events.size()); | 345 ASSERT_EQ(1u, captured_events.size()); |
| 425 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_release); | 346 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_release); |
| 426 ClearCapturedEvents(); | 347 ClearCapturedEvents(); |
| 427 | 348 |
| 428 // The move and release from the second finger should get rewritten. | 349 // The move and release from the second finger should get rewritten. |
| 429 generator_->MoveTouchId(gfx::Point(13, 14), 2); | 350 generator_->MoveTouchId(gfx::Point(13, 14), 2); |
| 430 generator_->ReleaseTouchId(2); | 351 generator_->ReleaseTouchId(2); |
| 431 AdvanceSimulatedTimePastTapDelay(); | 352 AdvanceSimulatedTimePastTapDelay(); |
| 432 captured_events = GetCapturedLocatedEvents(); | 353 |
| 433 ASSERT_EQ(2u, captured_events.size()); | 354 ASSERT_EQ(2u, captured_events.size()); |
| 434 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); | 355 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); |
| 435 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); | 356 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); |
| 436 EXPECT_TRUE(IsInNoFingersDownState()); | 357 EXPECT_TRUE(IsInNoFingersDownState()); |
| 437 } | 358 } |
| 438 | 359 |
| 439 // If an event is received after the double-tap timeout has elapsed, but | 360 // If an event is received after the double-tap timeout has elapsed, but |
| 440 // before the timer has fired, a mouse move should still be generated. | 361 // before the timer has fired, a mouse move should still be generated. |
| 441 TEST_F(TouchExplorationTest, TimerFiresLateDuringTouchExploration) { | 362 TEST_F(TouchExplorationTest, TimerFiresLateDuringTouchExploration) { |
| 442 SwitchTouchExplorationMode(true); | 363 SwitchTouchExplorationMode(true); |
| 443 | 364 |
| 444 // Send a press, then add another finger after the double-tap timeout. | 365 // Send a press, then add another finger after the double-tap timeout. |
| 445 generator_->PressTouchId(1); | 366 generator_->PressTouchId(1); |
| 446 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); | 367 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
| 447 generator_->PressTouchId(2); | 368 generator_->PressTouchId(2); |
| 448 std::vector<ui::LocatedEvent*> events = | 369 std::vector<ui::LocatedEvent*> events = |
| 449 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 370 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 450 ASSERT_EQ(1U, events.size()); | 371 ASSERT_EQ(1U, events.size()); |
| 451 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 372 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
| 452 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 373 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 453 | 374 |
| 454 generator_->ReleaseTouchId(2); | 375 generator_->ReleaseTouchId(2); |
| 455 generator_->ReleaseTouchId(1); | 376 generator_->ReleaseTouchId(1); |
| 456 AdvanceSimulatedTimePastTapDelay(); | 377 AdvanceSimulatedTimePastTapDelay(); |
| 457 EXPECT_TRUE(IsInNoFingersDownState()); | 378 EXPECT_TRUE(IsInNoFingersDownState()); |
| 458 } | 379 } |
| 459 | 380 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 472 // Send a tap at location2, after the double-tap timeout, but before the | 393 // Send a tap at location2, after the double-tap timeout, but before the |
| 473 // timer fires. | 394 // timer fires. |
| 474 gfx::Point location1(33, 34); | 395 gfx::Point location1(33, 34); |
| 475 generator_->set_current_location(location1); | 396 generator_->set_current_location(location1); |
| 476 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(301)); | 397 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(301)); |
| 477 generator_->PressTouch(); | 398 generator_->PressTouch(); |
| 478 generator_->ReleaseTouch(); | 399 generator_->ReleaseTouch(); |
| 479 AdvanceSimulatedTimePastTapDelay(); | 400 AdvanceSimulatedTimePastTapDelay(); |
| 480 | 401 |
| 481 std::vector<ui::LocatedEvent*> events = | 402 std::vector<ui::LocatedEvent*> events = |
| 482 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 403 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 483 ASSERT_EQ(2U, events.size()); | 404 ASSERT_EQ(2U, events.size()); |
| 484 EXPECT_EQ(location0, events[0]->location()); | 405 EXPECT_EQ(location0, events[0]->location()); |
| 485 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 406 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
| 486 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 407 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 487 EXPECT_EQ(location1, events[1]->location()); | 408 EXPECT_EQ(location1, events[1]->location()); |
| 488 EXPECT_TRUE(events[1]->flags() & ui::EF_IS_SYNTHESIZED); | 409 EXPECT_TRUE(events[1]->flags() & ui::EF_IS_SYNTHESIZED); |
| 489 EXPECT_TRUE(events[1]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 410 EXPECT_TRUE(events[1]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 490 EXPECT_TRUE(IsInNoFingersDownState()); | 411 EXPECT_TRUE(IsInNoFingersDownState()); |
| 491 } | 412 } |
| 492 | 413 |
| 493 // Double-tapping should send a touch press and release through to the location | 414 // Double-tapping should send a touch press and release through to the location |
| 494 // of the last successful touch exploration. | 415 // of the last successful touch exploration. |
| 495 TEST_F(TouchExplorationTest, DoubleTap) { | 416 TEST_F(TouchExplorationTest, DoubleTap) { |
| 496 SwitchTouchExplorationMode(true); | 417 SwitchTouchExplorationMode(true); |
| 497 | 418 |
| 498 // Tap at one location, and get a mouse move event. | 419 // Tap at one location, and get a mouse move event. |
| 499 gfx::Point tap_location(11, 12); | 420 gfx::Point tap_location(11, 12); |
| 500 generator_->set_current_location(tap_location); | 421 generator_->set_current_location(tap_location); |
| 501 generator_->PressTouch(); | 422 generator_->PressTouch(); |
| 502 generator_->ReleaseTouch(); | 423 generator_->ReleaseTouch(); |
| 503 AdvanceSimulatedTimePastTapDelay(); | 424 AdvanceSimulatedTimePastTapDelay(); |
| 504 | 425 |
| 505 std::vector<ui::LocatedEvent*> events = | 426 std::vector<ui::LocatedEvent*> events = |
| 506 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 427 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 507 ASSERT_EQ(1U, events.size()); | 428 ASSERT_EQ(1U, events.size()); |
| 508 | 429 |
| 509 EXPECT_EQ(tap_location, events[0]->location()); | 430 EXPECT_EQ(tap_location, events[0]->location()); |
| 510 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 431 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
| 511 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 432 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 512 ClearCapturedEvents(); | 433 ClearCapturedEvents(); |
| 513 | 434 |
| 514 // Now double-tap at a different location. This should result in | 435 // Now double-tap at a different location. This should result in |
| 515 // a single touch press and release at the location of the tap, | 436 // a single touch press and release at the location of the tap, |
| 516 // not at the location of the double-tap. | 437 // not at the location of the double-tap. |
| 517 gfx::Point double_tap_location(33, 34); | 438 gfx::Point double_tap_location(33, 34); |
| 518 generator_->set_current_location(double_tap_location); | 439 generator_->set_current_location(double_tap_location); |
| 519 generator_->PressTouch(); | 440 generator_->PressTouch(); |
| 520 generator_->ReleaseTouch(); | 441 generator_->ReleaseTouch(); |
| 521 generator_->PressTouch(); | 442 generator_->PressTouch(); |
| 522 generator_->ReleaseTouch(); | 443 generator_->ReleaseTouch(); |
| 523 | 444 |
| 524 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 445 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 525 ASSERT_EQ(2U, captured_events.size()); | 446 ASSERT_EQ(2U, captured_events.size()); |
| 526 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 447 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 527 EXPECT_EQ(tap_location, captured_events[0]->location()); | 448 EXPECT_EQ(tap_location, captured_events[0]->location()); |
| 528 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 449 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 529 EXPECT_EQ(tap_location, captured_events[1]->location()); | 450 EXPECT_EQ(tap_location, captured_events[1]->location()); |
| 530 EXPECT_TRUE(IsInNoFingersDownState()); | 451 EXPECT_TRUE(IsInNoFingersDownState()); |
| 531 } | 452 } |
| 532 | 453 |
| 533 // Double-tapping where the user holds their finger down for the second time | 454 // Double-tapping where the user holds their finger down for the second time |
| 534 // for a longer press should send a touch press and released (right click) | 455 // for a longer press should send a touch press and released (right click) |
| 535 // to the location of the last successful touch exploration. | 456 // to the location of the last successful touch exploration. |
| 536 TEST_F(TouchExplorationTest, DoubleTapLongPress) { | 457 TEST_F(TouchExplorationTest, DoubleTapLongPress) { |
| 537 SwitchTouchExplorationMode(true); | 458 SwitchTouchExplorationMode(true); |
| 538 | 459 |
| 539 // Tap at one location, and get a mouse move event. | 460 // Tap at one location, and get a mouse move event. |
| 540 gfx::Point tap_location(11, 12); | 461 gfx::Point tap_location(11, 12); |
| 541 generator_->set_current_location(tap_location); | 462 generator_->set_current_location(tap_location); |
| 542 generator_->PressTouch(); | 463 generator_->PressTouch(); |
| 543 generator_->ReleaseTouch(); | 464 generator_->ReleaseTouch(); |
| 544 AdvanceSimulatedTimePastTapDelay(); | 465 AdvanceSimulatedTimePastTapDelay(); |
| 545 | 466 |
| 546 std::vector<ui::LocatedEvent*> events = | 467 std::vector<ui::LocatedEvent*> events = |
| 547 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 468 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 548 ASSERT_EQ(1U, events.size()); | 469 ASSERT_EQ(1U, events.size()); |
| 549 | 470 |
| 550 EXPECT_EQ(tap_location, events[0]->location()); | 471 EXPECT_EQ(tap_location, events[0]->location()); |
| 551 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 472 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
| 552 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 473 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 553 ClearCapturedEvents(); | 474 ClearCapturedEvents(); |
| 554 | 475 |
| 555 // Now double-tap and hold at a different location. | 476 // Now double-tap and hold at a different location. |
| 556 // This should result in a single touch long press and release | 477 // This should result in a single touch long press and release |
| 557 // at the location of the tap, not at the location of the double-tap. | 478 // at the location of the tap, not at the location of the double-tap. |
| 558 // There should be a time delay between the touch press and release. | 479 // There should be a time delay between the touch press and release. |
| 559 gfx::Point first_tap_location(33, 34); | 480 gfx::Point first_tap_location(33, 34); |
| 560 generator_->set_current_location(first_tap_location); | 481 generator_->set_current_location(first_tap_location); |
| 561 generator_->PressTouch(); | 482 generator_->PressTouch(); |
| 562 generator_->ReleaseTouch(); | 483 generator_->ReleaseTouch(); |
| 563 gfx::Point second_tap_location(23, 24); | 484 gfx::Point second_tap_location(23, 24); |
| 564 generator_->set_current_location(second_tap_location); | 485 generator_->set_current_location(second_tap_location); |
| 565 generator_->PressTouch(); | 486 generator_->PressTouch(); |
| 566 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); | 487 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); |
| 567 generator_->ReleaseTouch(); | 488 generator_->ReleaseTouch(); |
| 568 | 489 |
| 569 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 490 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 570 ASSERT_EQ(2U, captured_events.size()); | 491 ASSERT_EQ(2U, captured_events.size()); |
| 571 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 492 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 572 EXPECT_EQ(tap_location, captured_events[0]->location()); | 493 EXPECT_EQ(tap_location, captured_events[0]->location()); |
| 573 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); | 494 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); |
| 574 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 495 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 575 EXPECT_EQ(tap_location, captured_events[1]->location()); | 496 EXPECT_EQ(tap_location, captured_events[1]->location()); |
| 576 base::TimeDelta released_time = captured_events[1]->time_stamp(); | 497 base::TimeDelta released_time = captured_events[1]->time_stamp(); |
| 577 EXPECT_EQ(gesture_detector_config_.longpress_timeout, | 498 EXPECT_EQ(gesture_detector_config_.longpress_timeout, |
| 578 released_time - pressed_time); | 499 released_time - pressed_time); |
| 579 } | 500 } |
| 580 | 501 |
| 581 // Single-tapping should send a touch press and release through to the location | 502 // Single-tapping should send a touch press and release through to the location |
| 582 // of the last successful touch exploration if the grace period has not | 503 // of the last successful touch exploration if the grace period has not |
| 583 // elapsed. | 504 // elapsed. |
| 584 TEST_F(TouchExplorationTest, SingleTap) { | 505 TEST_F(TouchExplorationTest, SingleTap) { |
| 585 SwitchTouchExplorationMode(true); | 506 SwitchTouchExplorationMode(true); |
| 586 | 507 |
| 587 // Tap once to simulate a mouse moved event. | 508 // Tap once to simulate a mouse moved event. |
| 588 gfx::Point initial_location(11, 12); | 509 gfx::Point initial_location(11, 12); |
| 589 generator_->set_current_location(initial_location); | 510 generator_->set_current_location(initial_location); |
| 590 generator_->PressTouch(); | 511 generator_->PressTouch(); |
| 591 AdvanceSimulatedTimePastTapDelay(); | |
| 592 ClearCapturedEvents(); | |
| 593 | 512 |
| 594 // Move to another location for single tap | 513 // Move to another location for single tap |
| 595 gfx::Point tap_location(22, 23); | 514 gfx::Point tap_location(22, 23); |
| 596 generator_->MoveTouch(tap_location); | 515 generator_->MoveTouch(tap_location); |
| 597 generator_->ReleaseTouch(); | 516 generator_->ReleaseTouch(); |
| 598 | 517 |
| 599 // Allow time to pass within the grace period of releasing before | 518 // Allow time to pass within the grace period of releasing before |
| 600 // tapping again. | 519 // tapping again. |
| 601 gfx::Point final_location(33, 34); | 520 gfx::Point final_location(33, 34); |
| 602 generator_->set_current_location(final_location); | 521 generator_->set_current_location(final_location); |
| 603 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(250)); | 522 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(250)); |
| 604 generator_->PressTouch(); | 523 generator_->PressTouch(); |
| 605 generator_->ReleaseTouch(); | 524 generator_->ReleaseTouch(); |
| 606 | 525 |
| 607 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 526 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 608 ASSERT_EQ(4U, captured_events.size()); | 527 ASSERT_EQ(4U, captured_events.size()); |
| 609 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); | 528 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); |
| 610 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); | 529 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); |
| 611 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[2]->type()); | 530 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[2]->type()); |
| 612 EXPECT_EQ(tap_location, captured_events[2]->location()); | 531 EXPECT_EQ(tap_location, captured_events[2]->location()); |
| 613 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[3]->type()); | 532 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[3]->type()); |
| 614 EXPECT_EQ(tap_location, captured_events[3]->location()); | 533 EXPECT_EQ(tap_location, captured_events[3]->location()); |
| 615 } | 534 } |
| 616 | 535 |
| 617 // Double-tapping without coming from touch exploration (no previous touch | 536 // Double-tapping without coming from touch exploration (no previous touch |
| 618 // exploration event) should not generate any events. | 537 // exploration event) should not generate any events. |
| 619 TEST_F(TouchExplorationTest, DoubleTapNoTouchExplore) { | 538 TEST_F(TouchExplorationTest, DoubleTapNoTouchExplore) { |
| 620 SwitchTouchExplorationMode(true); | 539 SwitchTouchExplorationMode(true); |
| 621 | 540 |
| 622 // Double-tap without any previous touch. | 541 // Double-tap without any previous touch. |
| 623 // Touch exploration mode has not been entered, so there is no previous | 542 // Touch exploration mode has not been entered, so there is no previous |
| 624 // touch exploration event. The double-tap should be discarded, and no events | 543 // touch exploration event. The double-tap should be discarded, and no events |
| 625 // should be generated at all. | 544 // should be generated at all. |
| 626 gfx::Point double_tap_location(33, 34); | 545 gfx::Point double_tap_location(33, 34); |
| 627 generator_->set_current_location(double_tap_location); | 546 generator_->set_current_location(double_tap_location); |
| 628 generator_->PressTouch(); | 547 generator_->PressTouch(); |
| 629 generator_->ReleaseTouch(); | 548 generator_->ReleaseTouch(); |
| 630 generator_->PressTouch(); | 549 generator_->PressTouch(); |
| 631 generator_->ReleaseTouch(); | 550 generator_->ReleaseTouch(); |
| 632 | 551 |
| 633 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 552 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 634 ASSERT_EQ(0U, captured_events.size()); | 553 ASSERT_EQ(0U, captured_events.size()); |
| 635 } | 554 } |
| 636 | 555 |
| 637 // Tapping and releasing with a second finger when in touch exploration mode | 556 // Tapping and releasing with a second finger when in touch exploration mode |
| 638 // should send a touch press and released to the location of the last | 557 // should send a touch press and released to the location of the last |
| 639 // successful touch exploration and return to touch explore. | 558 // successful touch exploration and return to touch explore. |
| 640 TEST_F(TouchExplorationTest, SplitTap) { | 559 TEST_F(TouchExplorationTest, SplitTap) { |
| 641 SwitchTouchExplorationMode(true); | 560 SwitchTouchExplorationMode(true); |
| 642 gfx::Point initial_touch_location(11, 12); | 561 gfx::Point initial_touch_location(11, 12); |
| 643 gfx::Point second_touch_location(33, 34); | 562 gfx::Point second_touch_location(33, 34); |
| 644 | 563 |
| 645 // Tap and hold at one location, and get a mouse move event in touch explore. | 564 // Tap and hold at one location, and get a mouse move event in touch explore. |
| 646 EnterTouchExplorationModeAtLocation(initial_touch_location); | 565 EnterTouchExplorationModeAtLocation(initial_touch_location); |
| 647 std::vector<ui::LocatedEvent*> events = | 566 std::vector<ui::LocatedEvent*> events = |
| 648 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 567 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 649 ASSERT_EQ(1U, events.size()); | 568 ASSERT_EQ(1U, events.size()); |
| 650 | 569 |
| 651 EXPECT_EQ(initial_touch_location, events[0]->location()); | 570 EXPECT_EQ(initial_touch_location, events[0]->location()); |
| 652 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 571 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
| 653 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 572 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 654 ClearCapturedEvents(); | 573 ClearCapturedEvents(); |
| 655 | 574 |
| 656 // Now tap and release at a different location. This should result in a | 575 // Now tap and release at a different location. This should result in a |
| 657 // single touch and release at the location of the first (held) tap, | 576 // single touch and release at the location of the first (held) tap, |
| 658 // not at the location of the second tap and release. | 577 // not at the location of the second tap and release. |
| 659 // After the release, there is still a finger in touch explore mode. | 578 // After the release, there is still a finger in touch explore mode. |
| 660 ui::TouchEvent split_tap_press( | 579 ui::TouchEvent split_tap_press( |
| 661 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | 580 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); |
| 662 generator_->Dispatch(&split_tap_press); | 581 generator_->Dispatch(&split_tap_press); |
| 663 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 664 ui::TouchEvent split_tap_release( | 582 ui::TouchEvent split_tap_release( |
| 665 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | 583 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); |
| 666 generator_->Dispatch(&split_tap_release); | 584 generator_->Dispatch(&split_tap_release); |
| 667 EXPECT_FALSE(IsInNoFingersDownState()); | 585 EXPECT_FALSE(IsInNoFingersDownState()); |
| 668 | 586 |
| 669 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 587 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 670 ASSERT_EQ(2U, captured_events.size()); | 588 ASSERT_EQ(2U, captured_events.size()); |
| 671 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 589 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 672 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); | 590 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
| 673 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 591 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 674 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); | 592 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); |
| 675 } | 593 } |
| 676 | 594 |
| 677 // If split tap is started but the touch explore finger is released first, | 595 // If split tap is started but the touch explore finger is released first, |
| 678 // there should still be a touch press and release sent to the location of | 596 // there should still be a touch press and release sent to the location of |
| 679 // the last successful touch exploration. | 597 // the last successful touch exploration. |
| 680 // Both fingers should be released after the click goes through. | 598 // Both fingers should be released after the click goes through. |
| 681 TEST_F(TouchExplorationTest, SplitTapRelease) { | 599 TEST_F(TouchExplorationTest, SplitTapRelease) { |
| 682 SwitchTouchExplorationMode(true); | 600 SwitchTouchExplorationMode(true); |
| 683 | 601 |
| 684 gfx::Point initial_touch_location(11, 12); | 602 gfx::Point initial_touch_location(11, 12); |
| 685 gfx::Point second_touch_location(33, 34); | 603 gfx::Point second_touch_location(33, 34); |
| 686 | 604 |
| 687 // Tap and hold at one location, and get a mouse move event in touch explore. | 605 // Tap and hold at one location, and get a mouse move event in touch explore. |
| 688 EnterTouchExplorationModeAtLocation(initial_touch_location); | 606 EnterTouchExplorationModeAtLocation(initial_touch_location); |
| 689 | 607 |
| 690 std::vector<ui::LocatedEvent*> events = | 608 std::vector<ui::LocatedEvent*> events = |
| 691 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 609 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 692 ASSERT_EQ(1U, events.size()); | 610 ASSERT_EQ(1U, events.size()); |
| 693 | 611 |
| 694 ClearCapturedEvents(); | 612 ClearCapturedEvents(); |
| 695 | 613 |
| 696 // Now tap at a different location. Release at the first location, | 614 // Now tap at a different location. Release at the first location, |
| 697 // then release at the second. This should result in a | 615 // then release at the second. This should result in a |
| 698 // single touch and release at the location of the first (held) tap, | 616 // single touch and release at the location of the first (held) tap, |
| 699 // not at the location of the second tap and release. | 617 // not at the location of the second tap and release. |
| 700 ui::TouchEvent split_tap_press( | 618 ui::TouchEvent split_tap_press( |
| 701 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | 619 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); |
| 702 generator_->Dispatch(&split_tap_press); | 620 generator_->Dispatch(&split_tap_press); |
| 703 ui::TouchEvent touch_explore_release( | 621 ui::TouchEvent touch_explore_release( |
| 704 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now()); | 622 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now()); |
| 705 generator_->Dispatch(&touch_explore_release); | 623 generator_->Dispatch(&touch_explore_release); |
| 706 ui::TouchEvent split_tap_release( | 624 ui::TouchEvent split_tap_release( |
| 707 ui::ET_TOUCH_RELEASED, second_touch_location , 1, Now()); | 625 ui::ET_TOUCH_RELEASED, second_touch_location , 1, Now()); |
| 708 generator_->Dispatch(&split_tap_release); | 626 generator_->Dispatch(&split_tap_release); |
| 709 EXPECT_TRUE(IsInNoFingersDownState()); | 627 EXPECT_TRUE(IsInNoFingersDownState()); |
| 710 | 628 |
| 711 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 629 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 712 ASSERT_EQ(2U, captured_events.size()); | 630 ASSERT_EQ(2U, captured_events.size()); |
| 713 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 631 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 714 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); | 632 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
| 715 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 633 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 716 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); | 634 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); |
| 717 } | 635 } |
| 718 | 636 |
| 719 // When in touch exploration mode, making a long press with a second finger | 637 // When in touch exploration mode, making a long press with a second finger |
| 720 // should send a touch press and released to the location of the last | 638 // should send a touch press and released to the location of the last |
| 721 // successful touch exploration. There should be a delay between the | 639 // successful touch exploration. There should be a delay between the |
| 722 // touch and release events (right click). | 640 // touch and release events (right click). |
| 723 TEST_F(TouchExplorationTest, SplitTapLongPress) { | 641 TEST_F(TouchExplorationTest, SplitTapLongPress) { |
| 724 SwitchTouchExplorationMode(true); | 642 SwitchTouchExplorationMode(true); |
| 725 gfx::Point initial_touch_location(11, 12); | 643 gfx::Point initial_touch_location(11, 12); |
| 726 gfx::Point second_touch_location(33, 34); | 644 gfx::Point second_touch_location(33, 34); |
| 727 | 645 |
| 728 // Tap and hold at one location, and get a mouse move event in touch explore. | 646 // Tap and hold at one location, and get a mouse move event in touch explore. |
| 729 EnterTouchExplorationModeAtLocation(initial_touch_location); | 647 EnterTouchExplorationModeAtLocation(initial_touch_location); |
| 730 std::vector<ui::LocatedEvent*> events = | 648 std::vector<ui::LocatedEvent*> events = |
| 731 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 649 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 732 ASSERT_EQ(1U, events.size()); | 650 ASSERT_EQ(1U, events.size()); |
| 733 | 651 |
| 734 ClearCapturedEvents(); | 652 ClearCapturedEvents(); |
| 735 | 653 |
| 736 // Now tap and release at a different location. This should result in a | 654 // Now tap and release at a different location. This should result in a |
| 737 // single touch and release at the location of the first (held) tap, | 655 // single touch and release at the location of the first (held) tap, |
| 738 // not at the location of the second tap and release. | 656 // not at the location of the second tap and release. |
| 739 // After the release, there is still a finger in touch explore mode. | 657 // After the release, there is still a finger in touch explore mode. |
| 740 ui::TouchEvent split_tap_press( | 658 ui::TouchEvent split_tap_press( |
| 741 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | 659 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); |
| 742 generator_->Dispatch(&split_tap_press); | 660 generator_->Dispatch(&split_tap_press); |
| 743 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); | 661 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); |
| 744 ui::TouchEvent split_tap_release( | 662 ui::TouchEvent split_tap_release( |
| 745 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | 663 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); |
| 746 generator_->Dispatch(&split_tap_release); | 664 generator_->Dispatch(&split_tap_release); |
| 747 EXPECT_FALSE(IsInNoFingersDownState()); | 665 EXPECT_FALSE(IsInNoFingersDownState()); |
| 748 | 666 |
| 749 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 667 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 750 ASSERT_EQ(2U, captured_events.size()); | 668 ASSERT_EQ(2U, captured_events.size()); |
| 751 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 669 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 752 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); | 670 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
| 753 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); | 671 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); |
| 754 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 672 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 755 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); | 673 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); |
| 756 base::TimeDelta released_time = captured_events[1]->time_stamp(); | 674 base::TimeDelta released_time = captured_events[1]->time_stamp(); |
| 757 EXPECT_EQ(gesture_detector_config_.longpress_timeout, | 675 EXPECT_EQ(gesture_detector_config_.longpress_timeout, |
| 758 released_time - pressed_time); | 676 released_time - pressed_time); |
| 759 } | 677 } |
| 760 | 678 |
| 761 // If split tap is started but the touch explore finger is released first, | 679 // If split tap is started but the touch explore finger is released first, |
| 762 // there should still be a touch press and release sent to the location of | 680 // there should still be a touch press and release sent to the location of |
| 763 // the last successful touch exploration. If the remaining finger is held | 681 // the last successful touch exploration. If the remaining finger is held |
| 764 // as a longpress, there should be a delay between the sent touch and release | 682 // as a longpress, there should be a delay between the sent touch and release |
| 765 // events (right click).All fingers should be released after the click | 683 // events (right click).All fingers should be released after the click |
| 766 // goes through. | 684 // goes through. |
| 767 TEST_F(TouchExplorationTest, SplitTapReleaseLongPress) { | 685 TEST_F(TouchExplorationTest, SplitTapReleaseLongPress) { |
| 768 SwitchTouchExplorationMode(true); | 686 SwitchTouchExplorationMode(true); |
| 769 gfx::Point initial_touch_location(11, 12); | 687 gfx::Point initial_touch_location(11, 12); |
| 770 gfx::Point second_touch_location(33, 34); | 688 gfx::Point second_touch_location(33, 34); |
| 771 | 689 |
| 772 // Tap and hold at one location, and get a mouse move event in touch explore. | 690 // Tap and hold at one location, and get a mouse move event in touch explore. |
| 773 EnterTouchExplorationModeAtLocation(initial_touch_location); | 691 EnterTouchExplorationModeAtLocation(initial_touch_location); |
| 774 std::vector<ui::LocatedEvent*> events = | 692 std::vector<ui::LocatedEvent*> events = |
| 775 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 693 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 776 ASSERT_EQ(1U, events.size()); | 694 ASSERT_EQ(1U, events.size()); |
| 777 ClearCapturedEvents(); | 695 ClearCapturedEvents(); |
| 778 | 696 |
| 779 // Now tap at a different location. Release at the first location, | 697 // Now tap at a different location. Release at the first location, |
| 780 // then release at the second. This should result in a | 698 // then release at the second. This should result in a |
| 781 // single touch and release at the location of the first (held) tap, | 699 // single touch and release at the location of the first (held) tap, |
| 782 // not at the location of the second tap and release. | 700 // not at the location of the second tap and release. |
| 783 // After the release, TouchToMouseMode should still be on. | 701 // After the release, TouchToMouseMode should still be on. |
| 784 ui::TouchEvent split_tap_press( | 702 ui::TouchEvent split_tap_press( |
| 785 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | 703 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); |
| 786 generator_->Dispatch(&split_tap_press); | 704 generator_->Dispatch(&split_tap_press); |
| 787 ui::TouchEvent touch_explore_release( | 705 ui::TouchEvent touch_explore_release( |
| 788 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now()); | 706 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now()); |
| 789 generator_->Dispatch(&touch_explore_release); | 707 generator_->Dispatch(&touch_explore_release); |
| 790 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); | 708 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); |
| 791 ui::TouchEvent split_tap_release( | 709 ui::TouchEvent split_tap_release( |
| 792 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | 710 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); |
| 793 generator_->Dispatch(&split_tap_release); | 711 generator_->Dispatch(&split_tap_release); |
| 794 EXPECT_TRUE(IsInTouchToMouseMode()); | 712 EXPECT_TRUE(IsInTouchToMouseMode()); |
| 795 | 713 |
| 796 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 714 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 797 ASSERT_EQ(2U, captured_events.size()); | 715 ASSERT_EQ(2U, captured_events.size()); |
| 798 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 716 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 799 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); | 717 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
| 800 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); | 718 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); |
| 801 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 719 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 802 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); | 720 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); |
| 803 base::TimeDelta released_time = captured_events[1]->time_stamp(); | 721 base::TimeDelta released_time = captured_events[1]->time_stamp(); |
| 804 EXPECT_EQ(gesture_detector_config_.longpress_timeout, | 722 EXPECT_EQ(gesture_detector_config_.longpress_timeout, |
| 805 released_time - pressed_time); | 723 released_time - pressed_time); |
| 806 } | 724 } |
| 807 | 725 |
| 808 TEST_F(TouchExplorationTest, SplitTapLongPressMultiFinger) { | 726 TEST_F(TouchExplorationTest, SplitTapLongPressMultiFinger) { |
| 809 SwitchTouchExplorationMode(true); | 727 SwitchTouchExplorationMode(true); |
| 810 gfx::Point initial_touch_location(11, 12); | 728 gfx::Point initial_touch_location(11, 12); |
| 811 gfx::Point second_touch_location(33, 34); | 729 gfx::Point second_touch_location(33, 34); |
| 812 gfx::Point third_touch_location(16, 17); | 730 gfx::Point third_touch_location(16, 17); |
| 813 | 731 |
| 814 // Tap and hold at one location, and get a mouse move event in touch explore. | 732 // Tap and hold at one location, and get a mouse move event in touch explore. |
| 815 EnterTouchExplorationModeAtLocation(initial_touch_location); | 733 EnterTouchExplorationModeAtLocation(initial_touch_location); |
| 816 | 734 |
| 817 std::vector<ui::LocatedEvent*> events = | 735 std::vector<ui::LocatedEvent*> events = |
| 818 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 736 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); |
| 819 ASSERT_EQ(1U, events.size()); | 737 ASSERT_EQ(1U, events.size()); |
| 820 | 738 |
| 821 EXPECT_EQ(initial_touch_location, events[0]->location()); | 739 EXPECT_EQ(initial_touch_location, events[0]->location()); |
| 822 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 740 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
| 823 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 741 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 824 ClearCapturedEvents(); | 742 ClearCapturedEvents(); |
| 825 | 743 |
| 826 // Now tap at a different location and hold for long press. | 744 // Now tap at a different location and hold for long press. |
| 827 ui::TouchEvent split_tap_press( | 745 ui::TouchEvent split_tap_press( |
| 828 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | 746 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 840 ui::TouchEvent touch_explore_release( | 758 ui::TouchEvent touch_explore_release( |
| 841 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now()); | 759 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now()); |
| 842 generator_->Dispatch(&touch_explore_release); | 760 generator_->Dispatch(&touch_explore_release); |
| 843 ui::TouchEvent split_tap_release( | 761 ui::TouchEvent split_tap_release( |
| 844 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | 762 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); |
| 845 generator_->Dispatch(&split_tap_release); | 763 generator_->Dispatch(&split_tap_release); |
| 846 ui::TouchEvent third_tap_release( | 764 ui::TouchEvent third_tap_release( |
| 847 ui::ET_TOUCH_RELEASED, third_touch_location, 2, Now()); | 765 ui::ET_TOUCH_RELEASED, third_touch_location, 2, Now()); |
| 848 generator_->Dispatch(&third_tap_release); | 766 generator_->Dispatch(&third_tap_release); |
| 849 | 767 |
| 850 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 768 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 851 ASSERT_EQ(2U, captured_events.size()); | 769 ASSERT_EQ(2U, captured_events.size()); |
| 852 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 770 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 853 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); | 771 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); |
| 854 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); | 772 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); |
| 855 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 773 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 856 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); | 774 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); |
| 857 base::TimeDelta released_time = captured_events[1]->time_stamp(); | 775 base::TimeDelta released_time = captured_events[1]->time_stamp(); |
| 858 EXPECT_EQ(gesture_detector_config_.longpress_timeout, | 776 EXPECT_EQ(gesture_detector_config_.longpress_timeout, |
| 859 released_time - pressed_time); | 777 released_time - pressed_time); |
| 860 EXPECT_TRUE(IsInNoFingersDownState()); | 778 EXPECT_TRUE(IsInNoFingersDownState()); |
| 861 } | 779 } |
| 862 | 780 |
| 863 // If the second finger is pressed soon after the first, the second | 781 // If the second finger is pressed soon after the first, the second |
| 864 // finger passes through and the first does not. However, The press is | 782 // finger passes through and the first does not. However, The press is |
| 865 // released after the second finger is lifted to go into the wait state. | 783 // released after the second finger is lifted to go into the wait state. |
| 866 TEST_F(TouchExplorationTest, TwoToOneFingerReleaseSecond) { | 784 TEST_F(TouchExplorationTest, TwoToOneFingerReleaseSecond) { |
| 867 gfx::Point first_touch_location = gfx::Point(7, 7); | 785 gfx::Point first_touch_location = gfx::Point(7, 7); |
| 868 gfx::Point second_touch_location = gfx::Point(10, 11); | 786 gfx::Point second_touch_location = gfx::Point(10, 11); |
| 869 EnterTwoToOne(first_touch_location, second_touch_location); | 787 EnterTwoToOne(first_touch_location, second_touch_location); |
| 870 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 788 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 871 ASSERT_EQ(captured_events.size(), 1u); | 789 ASSERT_EQ(captured_events.size(), 1u); |
| 872 ClearCapturedEvents(); | 790 ClearCapturedEvents(); |
| 873 | 791 |
| 874 // Confirm events from the second finger go through as is. | 792 // Confirm events from the second finger go through as is. |
| 875 gfx::Point second_touch_move_location = gfx::Point(20, 21); | 793 gfx::Point second_touch_move_location = gfx::Point(20, 21); |
| 876 ui::TouchEvent second_touch_move( | 794 ui::TouchEvent second_touch_move( |
| 877 ui::ET_TOUCH_MOVED, | 795 ui::ET_TOUCH_MOVED, |
| 878 second_touch_move_location, | 796 second_touch_move_location, |
| 879 1, | 797 1, |
| 880 Now()); | 798 Now()); |
| 881 generator_->Dispatch(&second_touch_move); | 799 generator_->Dispatch(&second_touch_move); |
| 882 captured_events = GetCapturedLocatedEvents(); | |
| 883 ASSERT_EQ(1u, captured_events.size()); | 800 ASSERT_EQ(1u, captured_events.size()); |
| 884 ClearCapturedEvents(); | 801 ClearCapturedEvents(); |
| 885 | 802 |
| 886 // Events from the first finger should still not go through while the second | 803 // Events from the first finger should still not go through while the second |
| 887 // finger is touching. | 804 // finger is touching. |
| 888 gfx::Point first_touch_move_location = gfx::Point(15, 16); | 805 gfx::Point first_touch_move_location = gfx::Point(15, 16); |
| 889 generator_->MoveTouchId(first_touch_move_location, 0); | 806 generator_->MoveTouchId(first_touch_move_location, 0); |
| 890 captured_events = GetCapturedLocatedEvents(); | 807 EXPECT_EQ(0u, GetCapturedEvents().size()); |
| 891 EXPECT_EQ(0u, captured_events.size()); | |
| 892 EXPECT_TRUE(cursor_client()->IsCursorVisible()); | 808 EXPECT_TRUE(cursor_client()->IsCursorVisible()); |
| 893 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); | 809 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); |
| 894 | 810 |
| 895 // A release of the second finger should send an event, as the state | 811 // A release of the second finger should send an event, as the state |
| 896 // changes to the wait state. | 812 // changes to the wait state. |
| 897 ui::TouchEvent second_touch_release( | 813 ui::TouchEvent second_touch_release( |
| 898 ui::ET_TOUCH_RELEASED, second_touch_move_location, 1, Now()); | 814 ui::ET_TOUCH_RELEASED, second_touch_move_location, 1, Now()); |
| 899 generator_->Dispatch(&second_touch_release); | 815 generator_->Dispatch(&second_touch_release); |
| 900 EXPECT_FALSE(IsInTouchToMouseMode()); | 816 EXPECT_FALSE(IsInTouchToMouseMode()); |
| 901 captured_events = GetCapturedLocatedEvents(); | |
| 902 ASSERT_EQ(captured_events.size(), 1u); | 817 ASSERT_EQ(captured_events.size(), 1u); |
| 903 ClearCapturedEvents(); | 818 ClearCapturedEvents(); |
| 904 | 819 |
| 905 // No events should be sent after the second finger is lifted. | 820 // No events should be sent after the second finger is lifted. |
| 906 | 821 |
| 907 ui::TouchEvent unsent_move(ui::ET_TOUCH_MOVED, gfx::Point(21, 22), 0, Now()); | 822 ui::TouchEvent unsent_move(ui::ET_TOUCH_MOVED, gfx::Point(21, 22), 0, Now()); |
| 908 generator_->Dispatch(&unsent_move); | 823 generator_->Dispatch(&unsent_move); |
| 909 | 824 |
| 910 ui::TouchEvent first_touch_release( | 825 ui::TouchEvent first_touch_release( |
| 911 ui::ET_TOUCH_RELEASED, first_touch_move_location, 0, Now()); | 826 ui::ET_TOUCH_RELEASED, first_touch_move_location, 0, Now()); |
| 912 generator_->Dispatch(&first_touch_release); | 827 generator_->Dispatch(&first_touch_release); |
| 913 captured_events = GetCapturedLocatedEvents(); | 828 |
| 914 ASSERT_EQ(captured_events.size(), 0u); | 829 ASSERT_EQ(captured_events.size(), 0u); |
| 915 EXPECT_TRUE(IsInNoFingersDownState()); | 830 EXPECT_TRUE(IsInNoFingersDownState()); |
| 916 } | 831 } |
| 917 | 832 |
| 918 // The press should also be released if the first finger is lifted | 833 // The press should also be released if the first finger is lifted |
| 919 // in TwoToOneFinger. | 834 // in TwoToOneFinger. |
| 920 TEST_F(TouchExplorationTest, TwoToOneFingerRelaseFirst) { | 835 TEST_F(TouchExplorationTest, TwoToOneFingerRelaseFirst) { |
| 921 gfx::Point first_touch_location = gfx::Point(11,12); | 836 gfx::Point first_touch_location = gfx::Point(11,12); |
| 922 gfx::Point second_touch_location = gfx::Point(21, 22); | 837 gfx::Point second_touch_location = gfx::Point(21, 22); |
| 923 EnterTwoToOne(first_touch_location, second_touch_location); | 838 EnterTwoToOne(first_touch_location, second_touch_location); |
| 924 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 839 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 925 ASSERT_EQ(captured_events.size(), 1u); | 840 ASSERT_EQ(captured_events.size(), 1u); |
| 926 ClearCapturedEvents(); | 841 ClearCapturedEvents(); |
| 927 | 842 |
| 928 // Actions before release have already been tested in the previous test. | 843 // Actions before release have already been tested in the previous test. |
| 929 | 844 |
| 930 // A release of the first finger should send an event, as the state | 845 // A release of the first finger should send an event, as the state |
| 931 // changes to the wait state. | 846 // changes to the wait state. |
| 932 ui::TouchEvent first_touch_release( | 847 ui::TouchEvent first_touch_release( |
| 933 ui::ET_TOUCH_RELEASED, first_touch_location, 0, Now()); | 848 ui::ET_TOUCH_RELEASED, first_touch_location, 0, Now()); |
| 934 generator_->Dispatch(&first_touch_release); | 849 generator_->Dispatch(&first_touch_release); |
| 935 captured_events = GetCapturedLocatedEvents(); | |
| 936 ASSERT_EQ(captured_events.size(), 1u); | 850 ASSERT_EQ(captured_events.size(), 1u); |
| 937 ClearCapturedEvents(); | 851 ClearCapturedEvents(); |
| 938 | 852 |
| 939 // No events should be sent after the second finger is lifted. | 853 // No events should be sent after the second finger is lifted. |
| 940 | 854 |
| 941 ui::TouchEvent unsent_move(ui::ET_TOUCH_MOVED, gfx::Point(21, 22), 1, Now()); | 855 ui::TouchEvent unsent_move(ui::ET_TOUCH_MOVED, gfx::Point(21, 22), 1, Now()); |
| 942 generator_->Dispatch(&unsent_move); | 856 generator_->Dispatch(&unsent_move); |
| 943 | 857 |
| 944 ui::TouchEvent second_touch_release( | 858 ui::TouchEvent second_touch_release( |
| 945 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | 859 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); |
| 946 generator_->Dispatch(&second_touch_release); | 860 generator_->Dispatch(&second_touch_release); |
| 947 captured_events = GetCapturedLocatedEvents(); | 861 |
| 948 ASSERT_EQ(captured_events.size(), 0u); | 862 ASSERT_EQ(captured_events.size(), 0u); |
| 949 EXPECT_TRUE(IsInNoFingersDownState()); | 863 EXPECT_TRUE(IsInNoFingersDownState()); |
| 950 } | 864 } |
| 951 | 865 |
| 952 // Placing three fingers should start passthrough, and all fingers should | 866 // Placing three fingers should start passthrough, and all fingers should |
| 953 // continue to be passed through until the last one is released. | 867 // continue to be passed through until the last one is released. |
| 954 TEST_F(TouchExplorationTest, Passthrough) { | 868 TEST_F(TouchExplorationTest, Passthrough) { |
| 955 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 869 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 956 | 870 |
| 957 gfx::Point first_touch_location = gfx::Point(11,12); | 871 gfx::Point first_touch_location = gfx::Point(11,12); |
| 958 gfx::Point second_touch_location = gfx::Point(21, 22); | 872 gfx::Point second_touch_location = gfx::Point(21, 22); |
| 959 EnterTwoToOne(first_touch_location, second_touch_location); | 873 EnterTwoToOne(first_touch_location, second_touch_location); |
| 960 captured_events = GetCapturedLocatedEvents(); | |
| 961 ASSERT_EQ(captured_events.size(), 1u); | 874 ASSERT_EQ(captured_events.size(), 1u); |
| 962 | 875 |
| 963 gfx::Point third_touch_location = gfx::Point(31, 32); | 876 gfx::Point third_touch_location = gfx::Point(31, 32); |
| 964 ui::TouchEvent third_touch_press( | 877 ui::TouchEvent third_touch_press( |
| 965 ui::ET_TOUCH_PRESSED, third_touch_location, 2, Now()); | 878 ui::ET_TOUCH_PRESSED, third_touch_location, 2, Now()); |
| 966 generator_->Dispatch(&third_touch_press); | 879 generator_->Dispatch(&third_touch_press); |
| 967 captured_events = GetCapturedLocatedEvents(); | |
| 968 // Now all fingers are registered as pressed. | 880 // Now all fingers are registered as pressed. |
| 969 ASSERT_EQ(captured_events.size(), 3u); | 881 ASSERT_EQ(captured_events.size(), 3u); |
| 970 ClearCapturedEvents(); | 882 ClearCapturedEvents(); |
| 971 | 883 |
| 972 // All fingers should be passed through. | 884 // All fingers should be passed through. |
| 973 first_touch_location = gfx::Point(13, 14); | 885 first_touch_location = gfx::Point(13, 14); |
| 974 second_touch_location = gfx::Point(23, 24); | 886 second_touch_location = gfx::Point(23, 24); |
| 975 third_touch_location = gfx::Point(33, 34); | 887 third_touch_location = gfx::Point(33, 34); |
| 976 ui::TouchEvent first_touch_first_move( | 888 ui::TouchEvent first_touch_first_move( |
| 977 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); | 889 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); |
| 978 ui::TouchEvent second_touch_first_move( | 890 ui::TouchEvent second_touch_first_move( |
| 979 ui::ET_TOUCH_MOVED, second_touch_location, 1, Now()); | 891 ui::ET_TOUCH_MOVED, second_touch_location, 1, Now()); |
| 980 ui::TouchEvent third_touch_first_move( | 892 ui::TouchEvent third_touch_first_move( |
| 981 ui::ET_TOUCH_MOVED, third_touch_location, 2, Now()); | 893 ui::ET_TOUCH_MOVED, third_touch_location, 2, Now()); |
| 982 generator_->Dispatch(&first_touch_first_move); | 894 generator_->Dispatch(&first_touch_first_move); |
| 983 generator_->Dispatch(&second_touch_first_move); | 895 generator_->Dispatch(&second_touch_first_move); |
| 984 generator_->Dispatch(&third_touch_first_move); | 896 generator_->Dispatch(&third_touch_first_move); |
| 985 captured_events = GetCapturedLocatedEvents(); | |
| 986 ASSERT_EQ(captured_events.size(), 3u); | 897 ASSERT_EQ(captured_events.size(), 3u); |
| 987 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); | 898 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); |
| 988 EXPECT_EQ(first_touch_location, captured_events[0]->location()); | 899 EXPECT_EQ(first_touch_location, captured_events[0]->location()); |
| 989 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); | 900 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); |
| 990 EXPECT_EQ(second_touch_location, captured_events[1]->location()); | 901 EXPECT_EQ(second_touch_location, captured_events[1]->location()); |
| 991 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[2]->type()); | 902 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[2]->type()); |
| 992 EXPECT_EQ(third_touch_location, captured_events[2]->location()); | 903 EXPECT_EQ(third_touch_location, captured_events[2]->location()); |
| 993 ClearCapturedEvents(); | 904 ClearCapturedEvents(); |
| 994 | 905 |
| 995 // When we release the third finger, the other fingers should still be | 906 // When we release the third finger, the other fingers should still be |
| 996 // passed through. | 907 // passed through. |
| 997 ui::TouchEvent third_touch_release( | 908 ui::TouchEvent third_touch_release( |
| 998 ui::ET_TOUCH_RELEASED, third_touch_location, 2, Now()); | 909 ui::ET_TOUCH_RELEASED, third_touch_location, 2, Now()); |
| 999 generator_->Dispatch(&third_touch_release); | 910 generator_->Dispatch(&third_touch_release); |
| 1000 captured_events = GetCapturedLocatedEvents(); | |
| 1001 ASSERT_EQ(captured_events.size(), 1u); | 911 ASSERT_EQ(captured_events.size(), 1u); |
| 1002 ClearCapturedEvents(); | 912 ClearCapturedEvents(); |
| 1003 first_touch_location = gfx::Point(15, 16); | 913 first_touch_location = gfx::Point(15, 16); |
| 1004 second_touch_location = gfx::Point(25, 26); | 914 second_touch_location = gfx::Point(25, 26); |
| 1005 ui::TouchEvent first_touch_second_move( | 915 ui::TouchEvent first_touch_second_move( |
| 1006 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); | 916 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); |
| 1007 ui::TouchEvent second_touch_second_move( | 917 ui::TouchEvent second_touch_second_move( |
| 1008 ui::ET_TOUCH_MOVED, second_touch_location, 1, Now()); | 918 ui::ET_TOUCH_MOVED, second_touch_location, 1, Now()); |
| 1009 generator_->Dispatch(&first_touch_second_move); | 919 generator_->Dispatch(&first_touch_second_move); |
| 1010 generator_->Dispatch(&second_touch_second_move); | 920 generator_->Dispatch(&second_touch_second_move); |
| 1011 captured_events = GetCapturedLocatedEvents(); | |
| 1012 ASSERT_EQ(captured_events.size(), 2u); | 921 ASSERT_EQ(captured_events.size(), 2u); |
| 1013 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); | 922 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); |
| 1014 EXPECT_EQ(first_touch_location, captured_events[0]->location()); | 923 EXPECT_EQ(first_touch_location, captured_events[0]->location()); |
| 1015 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); | 924 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[1]->type()); |
| 1016 EXPECT_EQ(second_touch_location, captured_events[1]->location()); | 925 EXPECT_EQ(second_touch_location, captured_events[1]->location()); |
| 1017 ClearCapturedEvents(); | 926 ClearCapturedEvents(); |
| 1018 | 927 |
| 1019 // When we release the second finger, the first finger should still be | 928 // When we release the second finger, the first finger should still be |
| 1020 // passed through. | 929 // passed through. |
| 1021 ui::TouchEvent second_touch_release( | 930 ui::TouchEvent second_touch_release( |
| 1022 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | 931 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); |
| 1023 generator_->Dispatch(&second_touch_release); | 932 generator_->Dispatch(&second_touch_release); |
| 1024 captured_events = GetCapturedLocatedEvents(); | |
| 1025 ASSERT_EQ(captured_events.size(), 1u); | 933 ASSERT_EQ(captured_events.size(), 1u); |
| 1026 ClearCapturedEvents(); | 934 ClearCapturedEvents(); |
| 1027 first_touch_location = gfx::Point(17, 18); | 935 first_touch_location = gfx::Point(17, 18); |
| 1028 ui::TouchEvent first_touch_third_move( | 936 ui::TouchEvent first_touch_third_move( |
| 1029 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); | 937 ui::ET_TOUCH_MOVED, first_touch_location, 0, Now()); |
| 1030 generator_->Dispatch(&first_touch_third_move); | 938 generator_->Dispatch(&first_touch_third_move); |
| 1031 captured_events = GetCapturedLocatedEvents(); | |
| 1032 ASSERT_EQ(captured_events.size(), 1u); | 939 ASSERT_EQ(captured_events.size(), 1u); |
| 1033 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); | 940 EXPECT_EQ(ui::ET_TOUCH_MOVED, captured_events[0]->type()); |
| 1034 EXPECT_EQ(first_touch_location, captured_events[0]->location()); | 941 EXPECT_EQ(first_touch_location, captured_events[0]->location()); |
| 1035 ClearCapturedEvents(); | 942 ClearCapturedEvents(); |
| 1036 | 943 |
| 1037 ui::TouchEvent first_touch_release( | 944 ui::TouchEvent first_touch_release( |
| 1038 ui::ET_TOUCH_RELEASED, first_touch_location, 0, Now()); | 945 ui::ET_TOUCH_RELEASED, first_touch_location, 0, Now()); |
| 1039 generator_->Dispatch(&first_touch_release); | 946 generator_->Dispatch(&first_touch_release); |
| 1040 captured_events = GetCapturedLocatedEvents(); | |
| 1041 ASSERT_EQ(captured_events.size(), 1u); | 947 ASSERT_EQ(captured_events.size(), 1u); |
| 1042 EXPECT_TRUE(IsInNoFingersDownState()); | 948 EXPECT_TRUE(IsInNoFingersDownState()); |
| 1043 } | 949 } |
| 1044 | 950 |
| 1045 // Finger must have moved more than slop, faster than the minimum swipe | |
| 1046 // velocity, and before the tap timer fires in order to enter | |
| 1047 // GestureInProgress state. Otherwise, if the tap timer fires before the a | |
| 1048 // gesture is completed, enter touch exploration. | |
| 1049 TEST_F(TouchExplorationTest, EnterGestureInProgressState) { | |
| 1050 SwitchTouchExplorationMode(true); | |
| 1051 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1052 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1053 | |
| 1054 float distance = gesture_detector_config_.touch_slop + 1; | |
| 1055 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 1), 0, Now()); | |
| 1056 gfx::Point second_location(distance / 2, 1); | |
| 1057 gfx::Point third_location(distance, 1); | |
| 1058 | |
| 1059 generator_->Dispatch(&first_press); | |
| 1060 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 1061 // Since we are not out of the touch slop yet, we should not be in gesture in | |
| 1062 // progress. | |
| 1063 generator_->MoveTouch(second_location); | |
| 1064 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1065 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1066 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 1067 | |
| 1068 // Once we are out of slop, we should be in GestureInProgress. | |
| 1069 generator_->MoveTouch(third_location); | |
| 1070 EXPECT_TRUE(IsInGestureInProgressState()); | |
| 1071 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1072 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
| 1073 ASSERT_EQ(0U, captured_events.size()); | |
| 1074 | |
| 1075 // Exit out of gesture mode once grace period is over and enter touch | |
| 1076 // exploration. | |
| 1077 AdvanceSimulatedTimePastTapDelay(); | |
| 1078 ASSERT_EQ(1U, captured_events.size()); | |
| 1079 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); | |
| 1080 EXPECT_TRUE(IsInTouchToMouseMode()); | |
| 1081 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1082 } | |
| 1083 | |
| 1084 // A swipe+direction gesture should trigger a Shift+Search+Direction | |
| 1085 // keyboard event. | |
| 1086 TEST_F(TouchExplorationTest, GestureSwipe) { | |
| 1087 SwitchTouchExplorationMode(true); | |
| 1088 std::vector<ui::KeyboardCode> directions; | |
| 1089 directions.push_back(ui::VKEY_RIGHT); | |
| 1090 directions.push_back(ui::VKEY_LEFT); | |
| 1091 directions.push_back(ui::VKEY_UP); | |
| 1092 directions.push_back(ui::VKEY_DOWN); | |
| 1093 | |
| 1094 for (std::vector<ui::KeyboardCode>::const_iterator it = directions.begin(); | |
| 1095 it != directions.end(); | |
| 1096 ++it) { | |
| 1097 int x = 30; | |
| 1098 int y = 31; | |
| 1099 ui::TouchEvent origin(ui::ET_TOUCH_PRESSED, gfx::Point(x, y), 0, Now()); | |
| 1100 generator_->Dispatch(&origin); | |
| 1101 | |
| 1102 ui::KeyboardCode direction = *it; | |
| 1103 float distance = gesture_detector_config_.touch_slop + 1; | |
| 1104 scoped_ptr<gfx::Point> swipe; | |
| 1105 switch (direction) { | |
| 1106 case ui::VKEY_RIGHT: | |
| 1107 swipe.reset(new gfx::Point(x + distance, y)); | |
| 1108 break; | |
| 1109 case ui::VKEY_LEFT: | |
| 1110 swipe.reset(new gfx::Point(x - distance, y)); | |
| 1111 break; | |
| 1112 case ui::VKEY_UP: | |
| 1113 swipe.reset(new gfx::Point(x, y - distance)); | |
| 1114 break; | |
| 1115 case ui::VKEY_DOWN: | |
| 1116 swipe.reset(new gfx::Point(x, y + distance)); | |
| 1117 break; | |
| 1118 default: | |
| 1119 return; | |
| 1120 } | |
| 1121 | |
| 1122 // A swipe is made when a fling starts | |
| 1123 float delta_time = | |
| 1124 distance / gesture_detector_config_.maximum_fling_velocity; | |
| 1125 simulated_clock_->Advance(base::TimeDelta::FromSecondsD(delta_time)); | |
| 1126 generator_->MoveTouch(*swipe); | |
| 1127 EXPECT_TRUE(IsInGestureInProgressState()); | |
| 1128 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1129 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
| 1130 ASSERT_EQ(0U, captured_events.size()); | |
| 1131 generator_->ReleaseTouch(); | |
| 1132 | |
| 1133 // The swipe registered and sent the appropriate key events. | |
| 1134 AssertDirectionalNavigationEvents(captured_events, direction); | |
| 1135 EXPECT_TRUE(IsInNoFingersDownState()); | |
| 1136 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1137 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1138 ClearCapturedEvents(); | |
| 1139 } | |
| 1140 } | |
| 1141 | |
| 1142 // With the simple swipe gestures, if additional fingers are added, then the | |
| 1143 // state should change to passthrough. | |
| 1144 TEST_F(TouchExplorationTest, FromGestureToPassthrough) { | |
| 1145 SwitchTouchExplorationMode(true); | |
| 1146 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1147 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1148 | |
| 1149 float distance = gesture_detector_config_.touch_slop + 1; | |
| 1150 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 1), 0, Now()); | |
| 1151 generator_->Dispatch(&first_press); | |
| 1152 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 1153 gfx::Point second_location(distance, 1); | |
| 1154 generator_->MoveTouch(second_location); | |
| 1155 EXPECT_TRUE(IsInGestureInProgressState()); | |
| 1156 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1157 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
| 1158 ASSERT_EQ(0U, captured_events.size()); | |
| 1159 | |
| 1160 // Generate a second press that should go through as is. | |
| 1161 ui::TouchEvent second_press( | |
| 1162 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now()); | |
| 1163 generator_->Dispatch(&second_press); | |
| 1164 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1165 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1166 std::vector<ui::LocatedEvent*> captured_located_events = | |
| 1167 GetCapturedLocatedEvents(); | |
| 1168 ASSERT_EQ(1U, captured_events.size()); | |
| 1169 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_located_events[0], &second_press); | |
| 1170 ClearCapturedEvents(); | |
| 1171 | |
| 1172 // The rest of the events should occur in passthrough. | |
| 1173 generator_->ReleaseTouchId(0); | |
| 1174 ASSERT_EQ(1U, captured_events.size()); | |
| 1175 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); | |
| 1176 ClearCapturedEvents(); | |
| 1177 generator_->ReleaseTouchId(1); | |
| 1178 ASSERT_EQ(0U, captured_events.size()); | |
| 1179 } | |
| 1180 | |
| 1181 } // namespace ui | 951 } // namespace ui |
| OLD | NEW |