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