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