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

Side by Side Diff: ui/chromeos/touch_exploration_controller_unittest.cc

Issue 296403011: Support double-tap to click in touch accessibility controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix existing tests and add double-tap test Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
mfomitchev 2014/06/02 23:12:18 It would be good to do some controller state valid
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/time/time.h" 7 #include "base/time/time.h"
8 #include "ui/aura/client/cursor_client.h" 8 #include "ui/aura/client/cursor_client.h"
9 #include "ui/aura/test/aura_test_base.h" 9 #include "ui/aura/test/aura_test_base.h"
10 #include "ui/aura/test/event_generator.h" 10 #include "ui/aura/test/event_generator.h"
11 #include "ui/aura/test/test_cursor_client.h" 11 #include "ui/aura/test/test_cursor_client.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 public: 62 public:
63 TouchExplorationTest() {} 63 TouchExplorationTest() {}
64 virtual ~TouchExplorationTest() {} 64 virtual ~TouchExplorationTest() {}
65 65
66 virtual void SetUp() OVERRIDE { 66 virtual void SetUp() OVERRIDE {
67 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) 67 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone)
68 gfx::GLSurface::InitializeOneOffForTests(); 68 gfx::GLSurface::InitializeOneOffForTests();
69 aura::test::AuraTestBase::SetUp(); 69 aura::test::AuraTestBase::SetUp();
70 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); 70 cursor_client_.reset(new aura::test::TestCursorClient(root_window()));
71 root_window()->AddPreTargetHandler(&event_capturer_); 71 root_window()->AddPreTargetHandler(&event_capturer_);
72 generator_.reset(new aura::test::EventGenerator(root_window()));
73 simulated_time_ms_ = 1000;
mfomitchev 2014/06/02 23:12:18 Perhaps just get the time from the generator whene
dmazzoni 2014/06/03 07:46:51 Done.
74 generator_->set_simulated_time(
75 base::TimeDelta::FromMilliseconds(simulated_time_ms_));
76 cursor_client()->ShowCursor();
mfomitchev 2014/06/02 23:12:18 Do we need to do this here considering we do this
dmazzoni 2014/06/03 07:46:51 Done.
77 cursor_client()->DisableMouseEvents();
72 } 78 }
73 79
74 virtual void TearDown() OVERRIDE { 80 virtual void TearDown() OVERRIDE {
75 root_window()->RemovePreTargetHandler(&event_capturer_); 81 root_window()->RemovePreTargetHandler(&event_capturer_);
76 SwitchTouchExplorationMode(false); 82 SwitchTouchExplorationMode(false);
77 cursor_client_.reset(); 83 cursor_client_.reset();
78 aura::test::AuraTestBase::TearDown(); 84 aura::test::AuraTestBase::TearDown();
79 } 85 }
80 86
81 const ScopedVector<ui::LocatedEvent>& GetCapturedEvents() { 87 const ScopedVector<ui::LocatedEvent>& GetCapturedEvents() {
82 return event_capturer_.captured_events(); 88 return event_capturer_.captured_events();
83 } 89 }
84 90
91 std::vector<ui::LocatedEvent*> GetCapturedEventsOfType(int type) {
92 const ScopedVector<ui::LocatedEvent>& all_events = GetCapturedEvents();
93 std::vector<ui::LocatedEvent*> events;
94 for (size_t i = 0; i < all_events.size(); ++i) {
95 if (type == all_events[i]->type())
96 events.push_back(all_events[i]);
97 }
98 return events;
99 }
100
85 void ClearCapturedEvents() { 101 void ClearCapturedEvents() {
86 event_capturer_.Reset(); 102 event_capturer_.Reset();
87 } 103 }
88 104
105 void AdvanceSimulatedTimePastTapDelay() {
106 simulated_time_ms_ += 1000;
107 generator_->set_simulated_time(
108 base::TimeDelta::FromMilliseconds(simulated_time_ms_));
109 touch_exploration_controller_->CallTapTimerNowForTesting();
110 }
111
89 protected: 112 protected:
90 aura::client::CursorClient* cursor_client() { return cursor_client_.get(); } 113 aura::client::CursorClient* cursor_client() { return cursor_client_.get(); }
91 114
92 void SwitchTouchExplorationMode(bool on) { 115 void SwitchTouchExplorationMode(bool on) {
93 if (!on && touch_exploration_controller_.get()) 116 if (!on && touch_exploration_controller_.get()) {
94 touch_exploration_controller_.reset(); 117 touch_exploration_controller_.reset();
95 else if (on && !touch_exploration_controller_.get()) 118 } else if (on && !touch_exploration_controller_.get()) {
96 touch_exploration_controller_.reset( 119 touch_exploration_controller_.reset(
97 new ui::TouchExplorationController(root_window())); 120 new ui::TouchExplorationController(root_window()));
121 touch_exploration_controller_->SetEventHandlerForTesting(
122 &event_capturer_);
123 cursor_client()->ShowCursor();
124 cursor_client()->DisableMouseEvents();
125 }
98 } 126 }
99 127
100 bool IsInTouchToMouseMode() { 128 bool IsInTouchToMouseMode() {
101 aura::client::CursorClient* cursor_client = 129 aura::client::CursorClient* cursor_client =
102 aura::client::GetCursorClient(root_window()); 130 aura::client::GetCursorClient(root_window());
103 return cursor_client && 131 return cursor_client &&
104 cursor_client->IsMouseEventsEnabled() && 132 cursor_client->IsMouseEventsEnabled() &&
105 !cursor_client->IsCursorVisible(); 133 !cursor_client->IsCursorVisible();
106 } 134 }
107 135
136 protected:
137 scoped_ptr<aura::test::EventGenerator> generator_;
138 int simulated_time_ms_;
139
108 private: 140 private:
109 EventCapturer event_capturer_; 141 EventCapturer event_capturer_;
110 scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_; 142 scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_;
111 scoped_ptr<aura::test::TestCursorClient> cursor_client_; 143 scoped_ptr<aura::test::TestCursorClient> cursor_client_;
112 144
113 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); 145 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest);
114 }; 146 };
115 147
116 // Executes a number of assertions to confirm that |e1| and |e2| are touch 148 // Executes a number of assertions to confirm that |e1| and |e2| are touch
117 // events and are equal to each other. 149 // events and are equal to each other.
(...skipping 25 matching lines...) Expand all
143 #define CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(e1, e2) \ 175 #define CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(e1, e2) \
144 ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreTouchAndEqual(e1, e2)) 176 ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreTouchAndEqual(e1, e2))
145 177
146 #define CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(e1, e2) \ 178 #define CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(e1, e2) \
147 ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreMouseAndEqual(e1, e2)) 179 ASSERT_NO_FATAL_FAILURE(ConfirmEventsAreMouseAndEqual(e1, e2))
148 180
149 // TODO(mfomitchev): Need to investigate why we don't get mouse enter/exit 181 // TODO(mfomitchev): Need to investigate why we don't get mouse enter/exit
150 // events when running these tests as part of ui_unittests. We do get them when 182 // events when running these tests as part of ui_unittests. We do get them when
151 // the tests are run as part of ash unit tests. 183 // the tests are run as part of ash unit tests.
152 184
153 // Simple test to confirm one-finger touches are transformed into mouse moves. 185 TEST_F(TouchExplorationTest, EntersTouchToMouseModeAfterPressAndDelay) {
154 TEST_F(TouchExplorationTest, OneFingerTouch) {
155 SwitchTouchExplorationMode(true); 186 SwitchTouchExplorationMode(true);
156 cursor_client()->ShowCursor(); 187 EXPECT_FALSE(IsInTouchToMouseMode());
157 cursor_client()->DisableMouseEvents(); 188 generator_->PressTouch();
158 aura::test::EventGenerator generator(root_window()); 189 AdvanceSimulatedTimePastTapDelay();
159 gfx::Point location_start = generator.current_location();
160 gfx::Point location_end(11, 12);
161 generator.PressTouch();
162 EXPECT_TRUE(IsInTouchToMouseMode()); 190 EXPECT_TRUE(IsInTouchToMouseMode());
163 generator.MoveTouch(location_end); 191 }
164 // Confirm the actual mouse moves are unaffected. 192
193 TEST_F(TouchExplorationTest, EntersTouchToMouseModeAfterMoveOutsideSlop) {
194 SwitchTouchExplorationMode(true);
195 EXPECT_FALSE(IsInTouchToMouseMode());
196 generator_->set_current_location(gfx::Point(11, 12));
197 generator_->PressTouch();
198 generator_->MoveTouch(gfx::Point(18, 12));
199 EXPECT_FALSE(IsInTouchToMouseMode());
200 generator_->MoveTouch(gfx::Point(11, 19));
201 EXPECT_FALSE(IsInTouchToMouseMode());
mfomitchev 2014/06/02 23:12:18 Is there any way we can obtain the slop value from
dmazzoni 2014/06/03 07:46:51 Done.
202 generator_->MoveTouch(gfx::Point(18, 19));
203 EXPECT_TRUE(IsInTouchToMouseMode());
204 }
205
206 TEST_F(TouchExplorationTest, OneFingerTap) {
207 SwitchTouchExplorationMode(true);
208 gfx::Point location(11, 12);
209 generator_->set_current_location(location);
210 generator_->PressTouch();
211 generator_->ReleaseTouch();
212 AdvanceSimulatedTimePastTapDelay();
213
214 std::vector<ui::LocatedEvent*> events =
215 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
216 ASSERT_EQ(1U, events.size());
217
218 EXPECT_EQ(location, events[0]->location());
219 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
220 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
221 }
222
223 TEST_F(TouchExplorationTest, ActualMouseMovesUnaffected) {
224 SwitchTouchExplorationMode(true);
225
226 gfx::Point location_start(11, 12);
227 gfx::Point location_end(13, 14);
228 generator_->set_current_location(location_start);
229 generator_->PressTouch();
230 AdvanceSimulatedTimePastTapDelay();
231 generator_->MoveTouch(location_end);
232
233 gfx::Point location_real_mouse_move(15, 16);
165 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, 234 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED,
166 gfx::Point(13, 14), 235 location_real_mouse_move,
167 gfx::Point(13, 14), 236 location_real_mouse_move,
168 0, 237 0,
169 0); 238 0);
170 generator.Dispatch(&mouse_move); 239 generator_->Dispatch(&mouse_move);
171 generator.ReleaseTouch(); 240 generator_->ReleaseTouch();
172 241
173 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); 242 std::vector<ui::LocatedEvent*> events =
174 ScopedVector<ui::LocatedEvent>::const_iterator it; 243 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
175 // TODO(mfomitchev): mouse enter/exit events 244 ASSERT_EQ(4U, events.size());
176 int num_mouse_moves = 0; 245
177 for (it = captured_events.begin(); it != captured_events.end(); ++it) { 246 EXPECT_EQ(location_start, events[0]->location());
178 int type = (*it)->type(); 247 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
179 // Ignore enter and exit mouse events synthesized when the mouse cursor is 248 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
180 // shown or hidden. 249
181 if (type == ui::ET_MOUSE_ENTERED || type == ui::ET_MOUSE_EXITED) 250 EXPECT_EQ(location_end, events[1]->location());
182 continue; 251 EXPECT_TRUE(events[1]->flags() & ui::EF_IS_SYNTHESIZED);
183 EXPECT_EQ(ui::ET_MOUSE_MOVED, (*it)->type()); 252 EXPECT_TRUE(events[1]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
184 if (num_mouse_moves == 0) 253
185 EXPECT_EQ(location_start, (*it)->location()); 254 EXPECT_EQ(location_real_mouse_move, events[2]->location());
186 if (num_mouse_moves == 1 || num_mouse_moves == 3) 255 CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(events[2], &mouse_move);
187 EXPECT_EQ(location_end, (*it)->location()); 256 EXPECT_FALSE(events[2]->flags() & ui::EF_IS_SYNTHESIZED);
188 if (num_mouse_moves == 2) 257 EXPECT_FALSE(events[2]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
189 CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(*it, &mouse_move); 258
190 if (num_mouse_moves != 2) { 259 EXPECT_EQ(location_end, events[3]->location());
191 EXPECT_TRUE((*it)->flags() & ui::EF_IS_SYNTHESIZED); 260 EXPECT_TRUE(events[3]->flags() & ui::EF_IS_SYNTHESIZED);
192 EXPECT_TRUE((*it)->flags() & ui::EF_TOUCH_ACCESSIBILITY); 261 EXPECT_TRUE(events[3]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
193 }
194 num_mouse_moves++;
195 }
196 EXPECT_EQ(4, num_mouse_moves);
197 } 262 }
198 263
199 // Turn the touch exploration mode on in the middle of the touch gesture. 264 // Turn the touch exploration mode on in the middle of the touch gesture.
200 // Confirm that events from the finger which was touching when the mode was 265 // Confirm that events from the finger which was touching when the mode was
201 // turned on don't get rewritten. 266 // turned on don't get rewritten.
202 TEST_F(TouchExplorationTest, TurnOnMidTouch) { 267 TEST_F(TouchExplorationTest, TurnOnMidTouch) {
203 SwitchTouchExplorationMode(false); 268 SwitchTouchExplorationMode(false);
204 cursor_client()->ShowCursor(); 269 generator_->PressTouchId(1);
205 cursor_client()->DisableMouseEvents();
206 aura::test::EventGenerator generator(root_window());
207 generator.PressTouchId(1);
208 EXPECT_TRUE(cursor_client()->IsCursorVisible()); 270 EXPECT_TRUE(cursor_client()->IsCursorVisible());
209 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); 271 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled());
210 ClearCapturedEvents(); 272 ClearCapturedEvents();
211 273
212 // Enable touch exploration mode while the first finger is touching the 274 // Enable touch exploration mode while the first finger is touching the
213 // screen. Ensure that subsequent events from that first finger are not 275 // screen. Ensure that subsequent events from that first finger are not
214 // affected by the touch exploration mode, while the touch events from another 276 // affected by the touch exploration mode, while the touch events from another
215 // finger get rewritten. 277 // finger get rewritten.
216 SwitchTouchExplorationMode(true); 278 SwitchTouchExplorationMode(true);
217 ui::TouchEvent touch_move(ui::ET_TOUCH_MOVED, 279 ui::TouchEvent touch_move(ui::ET_TOUCH_MOVED,
218 gfx::Point(11, 12), 280 gfx::Point(11, 12),
219 1, 281 1,
220 ui::EventTimeForNow()); 282 ui::EventTimeForNow());
221 generator.Dispatch(&touch_move); 283 generator_->Dispatch(&touch_move);
222 EXPECT_TRUE(cursor_client()->IsCursorVisible()); 284 EXPECT_TRUE(cursor_client()->IsCursorVisible());
223 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); 285 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled());
224 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); 286 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
225 ASSERT_EQ(1u, captured_events.size()); 287 ASSERT_EQ(1u, captured_events.size());
226 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_move); 288 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_move);
227 ClearCapturedEvents(); 289 ClearCapturedEvents();
228 290
229 // The press from the second finger should get rewritten. 291 // The press from the second finger should get rewritten.
230 generator.PressTouchId(2); 292 generator_->PressTouchId(2);
293 AdvanceSimulatedTimePastTapDelay();
231 EXPECT_TRUE(IsInTouchToMouseMode()); 294 EXPECT_TRUE(IsInTouchToMouseMode());
232 // TODO(mfomitchev): mouse enter/exit events
233 ScopedVector<ui::LocatedEvent>::const_iterator it; 295 ScopedVector<ui::LocatedEvent>::const_iterator it;
234 for (it = captured_events.begin(); it != captured_events.end(); ++it) { 296 for (it = captured_events.begin(); it != captured_events.end(); ++it) {
235 if ((*it)->type() == ui::ET_MOUSE_MOVED) 297 if ((*it)->type() == ui::ET_MOUSE_MOVED)
236 break; 298 break;
237 } 299 }
238 EXPECT_NE(captured_events.end(), it); 300 EXPECT_NE(captured_events.end(), it);
239 ClearCapturedEvents(); 301 ClearCapturedEvents();
240 302
241 // The release of the first finger shouldn't be affected. 303 // The release of the first finger shouldn't be affected.
242 ui::TouchEvent touch_release(ui::ET_TOUCH_RELEASED, 304 ui::TouchEvent touch_release(ui::ET_TOUCH_RELEASED,
243 gfx::Point(11, 12), 305 gfx::Point(11, 12),
244 1, 306 1,
245 ui::EventTimeForNow()); 307 ui::EventTimeForNow());
246 generator.Dispatch(&touch_release); 308 generator_->Dispatch(&touch_release);
247 ASSERT_EQ(1u, captured_events.size()); 309 ASSERT_EQ(1u, captured_events.size());
248 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_release); 310 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_release);
249 ClearCapturedEvents(); 311 ClearCapturedEvents();
250 312
251 // The move and release from the second finger should get rewritten. 313 // The move and release from the second finger should get rewritten.
252 generator.MoveTouchId(gfx::Point(13, 14), 2); 314 generator_->MoveTouchId(gfx::Point(13, 14), 2);
253 generator.ReleaseTouchId(2); 315 generator_->ReleaseTouchId(2);
254 ASSERT_EQ(2u, captured_events.size()); 316 ASSERT_EQ(2u, captured_events.size());
255 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); 317 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type());
256 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); 318 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type());
257 } 319 }
258 320
259 TEST_F(TouchExplorationTest, TwoFingerTouch) { 321 TEST_F(TouchExplorationTest, TwoFingerTouch) {
260 SwitchTouchExplorationMode(true); 322 SwitchTouchExplorationMode(true);
261 aura::test::EventGenerator generator(root_window()); 323 generator_->PressTouchId(1);
262 generator.PressTouchId(1);
263 ClearCapturedEvents(); 324 ClearCapturedEvents();
264 325
265 // Confirm events from the second finger go through as is. 326 // Confirm events from the second finger go through as is.
266 cursor_client()->ShowCursor(); 327 ui::TouchEvent touch_press(
267 cursor_client()->DisableMouseEvents(); 328 ui::ET_TOUCH_PRESSED,
268 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, 329 gfx::Point(10, 11),
269 gfx::Point(10, 11), 330 2,
270 2, 331 base::TimeDelta::FromMilliseconds(simulated_time_ms_));
271 ui::EventTimeForNow()); 332 generator_->Dispatch(&touch_press);
272 generator.Dispatch(&touch_press);
273 EXPECT_TRUE(cursor_client()->IsCursorVisible()); 333 EXPECT_TRUE(cursor_client()->IsCursorVisible());
274 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); 334 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled());
275 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); 335 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
276 // TODO(mfomitchev): mouse enter/exit events 336 // TODO(mfomitchev): mouse enter/exit events
277 // There will be a ET_MOUSE_EXITED event synthesized when the mouse cursor is 337 // There will be a ET_MOUSE_EXITED event synthesized when the mouse cursor is
278 // hidden - ignore it. 338 // hidden - ignore it.
279 ScopedVector<ui::LocatedEvent>::const_iterator it; 339 ScopedVector<ui::LocatedEvent>::const_iterator it;
280 for (it = captured_events.begin(); it != captured_events.end(); ++it) { 340 for (it = captured_events.begin(); it != captured_events.end(); ++it) {
281 if ((*it)->type() == ui::ET_TOUCH_PRESSED) { 341 if ((*it)->type() == ui::ET_TOUCH_PRESSED) {
282 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(*it, &touch_press); 342 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(*it, &touch_press);
283 break; 343 break;
284 } 344 }
285 } 345 }
286 EXPECT_NE(captured_events.end(), it); 346 EXPECT_NE(captured_events.end(), it);
287 ClearCapturedEvents(); 347 ClearCapturedEvents();
288 ui::TouchEvent touch_move(ui::ET_TOUCH_MOVED, 348 ui::TouchEvent touch_move(
289 gfx::Point(20, 21), 349 ui::ET_TOUCH_MOVED,
290 2, 350 gfx::Point(20, 21),
291 ui::EventTimeForNow()); 351 2,
292 generator.Dispatch(&touch_move); 352 base::TimeDelta::FromMilliseconds(simulated_time_ms_));
353 generator_->Dispatch(&touch_move);
293 ASSERT_EQ(1u, captured_events.size()); 354 ASSERT_EQ(1u, captured_events.size());
294 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_move); 355 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_move);
295 ClearCapturedEvents(); 356 ClearCapturedEvents();
296 357
297 // Confirm mouse moves go through unaffected. 358 // Confirm mouse moves go through unaffected.
298 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, 359 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED,
299 gfx::Point(13, 14), 360 gfx::Point(13, 14),
300 gfx::Point(13, 14), 361 gfx::Point(13, 14),
301 0, 362 0,
302 0); 363 0);
303 generator.Dispatch(&mouse_move); 364 generator_->Dispatch(&mouse_move);
304 // TODO(mfomitchev): mouse enter/exit events 365 // TODO(mfomitchev): mouse enter/exit events
305 // Ignore synthesized ET_MOUSE_ENTERED/ET_MOUSE_EXITED 366 // Ignore synthesized ET_MOUSE_ENTERED/ET_MOUSE_EXITED
306 for (it = captured_events.begin(); it != captured_events.end(); ++it) { 367 for (it = captured_events.begin(); it != captured_events.end(); ++it) {
307 if ((*it)->type() == ui::ET_MOUSE_MOVED) { 368 if ((*it)->type() == ui::ET_MOUSE_MOVED) {
308 CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(*it, &mouse_move); 369 CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(*it, &mouse_move);
309 break; 370 break;
310 } 371 }
311 } 372 }
312 EXPECT_NE(captured_events.end(), it); 373 EXPECT_NE(captured_events.end(), it);
313 ClearCapturedEvents(); 374 ClearCapturedEvents();
314 375
315 // Have some other fingers touch/move/release 376 // Have some other fingers touch/move/release
316 generator.PressTouchId(3); 377 generator_->PressTouchId(3);
317 generator.PressTouchId(4); 378 generator_->PressTouchId(4);
318 generator.MoveTouchId(gfx::Point(30, 31), 3); 379 generator_->MoveTouchId(gfx::Point(30, 31), 3);
319 generator.ReleaseTouchId(3); 380 generator_->ReleaseTouchId(3);
320 generator.ReleaseTouchId(4); 381 generator_->ReleaseTouchId(4);
321 ClearCapturedEvents(); 382 ClearCapturedEvents();
322 383
323 // Events from the first finger should not go through while the second finger 384 // Events from the first finger should not go through while the second finger
324 // is touching. 385 // is touching.
325 gfx::Point touch1_location = gfx::Point(15, 16); 386 gfx::Point touch1_location = gfx::Point(15, 16);
326 generator.MoveTouchId(touch1_location, 1); 387 generator_->MoveTouchId(touch1_location, 1);
327 EXPECT_EQ(0u, GetCapturedEvents().size()); 388 EXPECT_EQ(0u, GetCapturedEvents().size());
328 389
329 EXPECT_TRUE(cursor_client()->IsCursorVisible()); 390 EXPECT_TRUE(cursor_client()->IsCursorVisible());
330 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled()); 391 EXPECT_FALSE(cursor_client()->IsMouseEventsEnabled());
331 392
332 // A release of the second finger should go through, plus there should be a 393 // A release of the second finger should be rewritten as a mouse move
333 // mouse move at |touch1_location| generated. 394 // of that finger to the |touch1_location| and we stay in passthrough
334 ui::TouchEvent touch_release(ui::ET_TOUCH_RELEASED, 395 // mode.
335 gfx::Point(25, 26), 396 ui::TouchEvent touch_release(
336 2, 397 ui::ET_TOUCH_RELEASED,
337 ui::EventTimeForNow()); 398 gfx::Point(25, 26),
338 generator.Dispatch(&touch_release); 399 2,
339 EXPECT_TRUE(IsInTouchToMouseMode()); 400 base::TimeDelta::FromMilliseconds(simulated_time_ms_));
340 ASSERT_GE(captured_events.size(), 2u); 401 generator_->Dispatch(&touch_release);
341 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch_release); 402 EXPECT_FALSE(IsInTouchToMouseMode());
342 // TODO(mfomitchev): mouse enter/exit events 403 ASSERT_EQ(captured_events.size(), 1u);
343 // Ignore synthesized ET_MOUSE_ENTERED/ET_MOUSE_EXITED 404 EXPECT_EQ(touch1_location, captured_events[0]->location());
344 for (it = captured_events.begin(); it != captured_events.end(); ++it) {
345 if ((*it)->type() == ui::ET_MOUSE_MOVED) {
346 EXPECT_EQ(touch1_location, (*it)->location());
347 break;
348 }
349 }
350 EXPECT_NE(captured_events.end(), it);
351 } 405 }
352 406
353 TEST_F(TouchExplorationTest, MultiFingerTouch) { 407 TEST_F(TouchExplorationTest, MultiFingerTouch) {
354 SwitchTouchExplorationMode(true); 408 SwitchTouchExplorationMode(true);
355 aura::test::EventGenerator generator(root_window()); 409 generator_->PressTouchId(1);
356 generator.PressTouchId(1); 410 generator_->PressTouchId(2);
357 generator.PressTouchId(2);
358 ClearCapturedEvents(); 411 ClearCapturedEvents();
359 412
360 // Confirm events from other fingers go through as is. 413 // Confirm events from other fingers go through as is.
414 base::TimeDelta now = base::TimeDelta::FromMilliseconds(simulated_time_ms_);
361 ui::TouchEvent touch3_press(ui::ET_TOUCH_PRESSED, 415 ui::TouchEvent touch3_press(ui::ET_TOUCH_PRESSED,
362 gfx::Point(10, 11), 416 gfx::Point(10, 11),
363 3, 417 3,
364 ui::EventTimeForNow()); 418 now);
365 ui::TouchEvent touch3_move1(ui::ET_TOUCH_MOVED, 419 ui::TouchEvent touch3_move1(ui::ET_TOUCH_MOVED,
366 gfx::Point(12, 13), 420 gfx::Point(12, 13),
367 3, 421 3,
368 ui::EventTimeForNow()); 422 now);
369 ui::TouchEvent touch4_press(ui::ET_TOUCH_PRESSED, 423 ui::TouchEvent touch4_press(ui::ET_TOUCH_PRESSED,
370 gfx::Point(20, 21), 424 gfx::Point(20, 21),
371 4, 425 4,
372 ui::EventTimeForNow()); 426 now);
373 ui::TouchEvent touch3_move2(ui::ET_TOUCH_MOVED, 427 ui::TouchEvent touch3_move2(ui::ET_TOUCH_MOVED,
374 gfx::Point(14, 15), 428 gfx::Point(14, 15),
375 3, 429 3,
376 ui::EventTimeForNow()); 430 now);
377 ui::TouchEvent touch4_move(ui::ET_TOUCH_MOVED, 431 ui::TouchEvent touch4_move(ui::ET_TOUCH_MOVED,
378 gfx::Point(22, 23), 432 gfx::Point(22, 23),
379 4, 433 4,
380 ui::EventTimeForNow()); 434 now);
381 ui::TouchEvent touch3_release(ui::ET_TOUCH_RELEASED, 435 ui::TouchEvent touch3_release(ui::ET_TOUCH_RELEASED,
382 gfx::Point(14, 15), 436 gfx::Point(14, 15),
383 3, 437 3,
384 ui::EventTimeForNow()); 438 now);
385 ui::TouchEvent touch4_release(ui::ET_TOUCH_RELEASED, 439 ui::TouchEvent touch4_release(ui::ET_TOUCH_RELEASED,
386 gfx::Point(22, 23), 440 gfx::Point(22, 23),
387 4, 441 4,
388 ui::EventTimeForNow()); 442 now);
389 generator.Dispatch(&touch3_press); 443 generator_->Dispatch(&touch3_press);
390 generator.Dispatch(&touch3_move1); 444 generator_->Dispatch(&touch3_move1);
391 generator.Dispatch(&touch4_press); 445 generator_->Dispatch(&touch4_press);
392 generator.Dispatch(&touch3_move2); 446 generator_->Dispatch(&touch3_move2);
393 generator.Dispatch(&touch4_move); 447 generator_->Dispatch(&touch4_move);
394 generator.Dispatch(&touch3_release); 448 generator_->Dispatch(&touch3_release);
395 generator.Dispatch(&touch4_release); 449 generator_->Dispatch(&touch4_release);
396 450
397 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); 451 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
398 ASSERT_EQ(7u, captured_events.size()); 452 ASSERT_EQ(7u, captured_events.size());
399 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch3_press); 453 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch3_press);
400 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[1], &touch3_move1); 454 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[1], &touch3_move1);
401 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[2], &touch4_press); 455 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[2], &touch4_press);
402 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[3], &touch3_move2); 456 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[3], &touch3_move2);
403 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[4], &touch4_move); 457 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[4], &touch4_move);
404 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[5], &touch3_release); 458 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[5], &touch3_release);
405 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[6], &touch4_release); 459 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[6], &touch4_release);
406 } 460 }
407 461
408 // Test the case when there are multiple fingers on the screen and the first 462 // Test the case when there are multiple fingers on the screen and the first
409 // finger is released. This should be rewritten as a release of the second 463 // finger is released. This should be ignored. Additionally, if the second
410 // finger. Additionally, if the second finger is the only finger left touching, 464 // finger is the only finger left touching, we should enter a mouse move mode,
mfomitchev 2014/06/02 23:12:18 This comment seems wrong - we won't enter the mous
dmazzoni 2014/06/03 07:46:51 Done.
411 // we should enter a mouse move mode, and a mouse move event should be 465 // and a mouse move event should be dispatched.
412 // dispatched.
413 TEST_F(TouchExplorationTest, FirstFingerLifted) { 466 TEST_F(TouchExplorationTest, FirstFingerLifted) {
414 SwitchTouchExplorationMode(true); 467 SwitchTouchExplorationMode(true);
415 aura::test::EventGenerator generator(root_window()); 468 generator_->PressTouchId(1);
416 generator.PressTouchId(1); 469 generator_->PressTouchId(2);
417 generator.PressTouchId(2);
418 gfx::Point touch2_location(10, 11); 470 gfx::Point touch2_location(10, 11);
419 generator.MoveTouchId(touch2_location, 2); 471 generator_->MoveTouchId(touch2_location, 2);
420 generator.PressTouchId(3); 472 generator_->PressTouchId(3);
421 gfx::Point touch3_location(20, 21); 473 gfx::Point touch3_location(20, 21);
422 generator.MoveTouchId(touch3_location, 3); 474 generator_->MoveTouchId(touch3_location, 3);
423 ClearCapturedEvents(); 475 ClearCapturedEvents();
424 476
425 // Release of finger 1 should be rewritten as a release of finger 2. 477 // Release of finger 1 should be ignored.
mfomitchev 2014/06/02 23:12:18 Would be good to have another test where we are re
dmazzoni 2014/06/03 07:46:51 This is already covered a bit by TwoFingerTouch, b
426 generator.ReleaseTouchId(1); 478 generator_->ReleaseTouchId(1);
427 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); 479 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
480 ASSERT_EQ(0u, captured_events.size());
481
482 // Release of finger 2 should be passed through.
mfomitchev 2014/06/02 23:12:18 Might be worth doing a move, etc. before the relea
dmazzoni 2014/06/03 07:46:51 Done.
483 ui::TouchEvent touch2_release(
484 ui::ET_TOUCH_RELEASED,
485 gfx::Point(14, 15),
486 2,
487 base::TimeDelta::FromMilliseconds(simulated_time_ms_));
488 generator_->Dispatch(&touch2_release);
428 ASSERT_EQ(1u, captured_events.size()); 489 ASSERT_EQ(1u, captured_events.size());
429 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); 490 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_events[0], &touch2_release);
430 ui::TouchEvent* touch_event = 491 }
431 static_cast<ui::TouchEvent*>(captured_events[0]); 492
432 EXPECT_EQ(2, touch_event->touch_id()); 493 // Double-tapping should send a touch press and release through to the location
433 EXPECT_EQ(touch2_location, touch_event->location()); 494 // of the last successful touch exploration.
495 TEST_F(TouchExplorationTest, DoubleTap) {
496 SwitchTouchExplorationMode(true);
497
498 // Tap at one location, and get a mouse move event.
499 gfx::Point tap_location(11, 12);
500 generator_->set_current_location(tap_location);
501 generator_->PressTouch();
502 generator_->ReleaseTouch();
503 AdvanceSimulatedTimePastTapDelay();
504
505 std::vector<ui::LocatedEvent*> events =
506 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED);
507 ASSERT_EQ(1U, events.size());
508
509 EXPECT_EQ(tap_location, events[0]->location());
510 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED);
511 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY);
434 ClearCapturedEvents(); 512 ClearCapturedEvents();
435 513
436 // Release of finger 2 should be rewritten as a release of finger 3, plus 514 // Now double-tap at a different location. This should result in
437 // we should enter the mouse move mode and a mouse move event should be 515 // a single touch press and release at the location of the tap,
438 // dispatched. 516 // not at the location of the double-tap.
439 cursor_client()->ShowCursor(); 517 gfx::Point double_tap_location(33, 34);
440 cursor_client()->DisableMouseEvents(); 518 generator_->set_current_location(double_tap_location);
441 generator.ReleaseTouchId(2); 519 generator_->PressTouch();
442 EXPECT_TRUE(IsInTouchToMouseMode()); 520 generator_->ReleaseTouch();
443 ASSERT_GE(2u, captured_events.size()); 521 generator_->PressTouch();
444 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); 522 generator_->ReleaseTouch();
445 touch_event = static_cast<ui::TouchEvent*>(captured_events[0]); 523
446 EXPECT_EQ(3, touch_event->touch_id()); 524 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents();
447 EXPECT_EQ(touch3_location, touch_event->location()); 525 ASSERT_EQ(2U, captured_events.size());
448 // TODO(mfomitchev): mouse enter/exit events 526 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
449 ScopedVector<ui::LocatedEvent>::const_iterator it; 527 EXPECT_EQ(tap_location, captured_events[0]->location());
450 for (it = captured_events.begin(); it != captured_events.end(); ++it) { 528 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
451 if ((*it)->type() == ui::ET_MOUSE_MOVED) { 529 EXPECT_EQ(tap_location, captured_events[1]->location());
452 EXPECT_EQ(touch3_location, (*it)->location());
453 break;
454 }
455 }
456 EXPECT_NE(captured_events.end(), it);
457 } 530 }
458 531
459 } // namespace ui 532 } // namespace ui
OLDNEW
« ui/chromeos/touch_exploration_controller.cc ('K') | « ui/chromeos/touch_exploration_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698