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

Side by Side Diff: ui/aura/gestures/gesture_recognizer_unittest.cc

Issue 9452024: Gestures are now possible using touch events with any ids (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Allow consecutive touch presses with the same touch-id. Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/timer.h" 5 #include "base/timer.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/aura/event.h" 7 #include "ui/aura/event.h"
8 #include "ui/aura/gestures/gesture_recognizer_aura.h" 8 #include "ui/aura/gestures/gesture_recognizer_aura.h"
9 #include "ui/aura/gestures/gesture_sequence.h" 9 #include "ui/aura/gestures/gesture_sequence.h"
10 #include "ui/aura/root_window.h" 10 #include "ui/aura/root_window.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 bool pinch_update() const { return pinch_update_; } 68 bool pinch_update() const { return pinch_update_; }
69 bool pinch_end() const { return pinch_end_; } 69 bool pinch_end() const { return pinch_end_; }
70 bool long_press() const { return long_press_; } 70 bool long_press() const { return long_press_; }
71 71
72 const gfx::Point scroll_begin_position() const { 72 const gfx::Point scroll_begin_position() const {
73 return scroll_begin_position_; 73 return scroll_begin_position_;
74 } 74 }
75 75
76 float scroll_x() const { return scroll_x_; } 76 float scroll_x() const { return scroll_x_; }
77 float scroll_y() const { return scroll_y_; } 77 float scroll_y() const { return scroll_y_; }
78 unsigned int touch_id() const { return touch_id_; } 78 int touch_id() const { return touch_id_; }
79 79
80 virtual ui::GestureStatus OnGestureEvent(GestureEvent* gesture) OVERRIDE { 80 virtual ui::GestureStatus OnGestureEvent(GestureEvent* gesture) OVERRIDE {
81 switch (gesture->type()) { 81 switch (gesture->type()) {
82 case ui::ET_GESTURE_TAP: 82 case ui::ET_GESTURE_TAP:
83 tap_ = true; 83 tap_ = true;
84 break; 84 break;
85 case ui::ET_GESTURE_TAP_DOWN: 85 case ui::ET_GESTURE_TAP_DOWN:
86 tap_down_ = true; 86 tap_down_ = true;
87 break; 87 break;
88 case ui::ET_GESTURE_DOUBLE_TAP: 88 case ui::ET_GESTURE_DOUBLE_TAP:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 bool scroll_end_; 128 bool scroll_end_;
129 bool pinch_begin_; 129 bool pinch_begin_;
130 bool pinch_update_; 130 bool pinch_update_;
131 bool pinch_end_; 131 bool pinch_end_;
132 bool long_press_; 132 bool long_press_;
133 133
134 gfx::Point scroll_begin_position_; 134 gfx::Point scroll_begin_position_;
135 135
136 float scroll_x_; 136 float scroll_x_;
137 float scroll_y_; 137 float scroll_y_;
138 unsigned int touch_id_; 138 int touch_id_;
139 139
140 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); 140 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate);
141 }; 141 };
142 142
143 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 143 class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
144 public: 144 public:
145 explicit QueueTouchEventDelegate(RootWindow* root_window) 145 explicit QueueTouchEventDelegate(RootWindow* root_window)
146 : window_(NULL), 146 : window_(NULL),
147 root_window_(root_window) { 147 root_window_(root_window) {
148 } 148 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 : public base::OneShotTimer<GestureSequence> { 234 : public base::OneShotTimer<GestureSequence> {
235 public: 235 public:
236 void ForceTimeout() { 236 void ForceTimeout() {
237 if (delayed_task_) 237 if (delayed_task_)
238 delayed_task_->Run(); 238 delayed_task_->Run();
239 } 239 }
240 }; 240 };
241 241
242 class TimerTestGestureSequence : public GestureSequence { 242 class TimerTestGestureSequence : public GestureSequence {
243 public: 243 public:
244 TimerTestGestureSequence(RootWindow* root_window) 244 explicit TimerTestGestureSequence(RootWindow* root_window)
245 : GestureSequence(root_window) { 245 : GestureSequence(root_window) {
246 } 246 }
247 247
248 void ForceTimeout() { 248 void ForceTimeout() {
249 static_cast<TestOneShotGestureSequenceTimer*>( 249 static_cast<TestOneShotGestureSequenceTimer*>(
250 long_press_timer())->ForceTimeout(); 250 long_press_timer())->ForceTimeout();
251 } 251 }
252 252
253 base::OneShotTimer<GestureSequence>* CreateTimer() { 253 base::OneShotTimer<GestureSequence>* CreateTimer() {
254 return new TestOneShotGestureSequenceTimer(); 254 return new TestOneShotGestureSequenceTimer();
255 } 255 }
256 }; 256 };
257 257
258 class TestGestureRecognizer : public GestureRecognizerAura { 258 class TestGestureRecognizer : public GestureRecognizerAura {
259 public: 259 public:
260 TestGestureRecognizer(RootWindow* root_window) 260 explicit TestGestureRecognizer(RootWindow* root_window)
261 : GestureRecognizerAura(root_window) { 261 : GestureRecognizerAura(root_window) {
262 } 262 }
263 263
264 GestureSequence* GetGestureSequenceForTesting() { 264 GestureSequence* GetGestureSequenceForTesting() {
265 return gesture_sequence(); 265 return gesture_sequence();
266 } 266 }
267 267
268 virtual GestureSequence* CreateSequence(RootWindow* root_window) OVERRIDE { 268 virtual GestureSequence* CreateSequence(RootWindow* root_window) OVERRIDE {
269 return new TimerTestGestureSequence(root_window); 269 return new TimerTestGestureSequence(root_window);
270 } 270 }
271 }; 271 };
272 272
273 void SendScrollEvents(RootWindow* root_window, 273 void SendScrollEvents(RootWindow* root_window,
274 int x_start, 274 int x_start,
275 int y_start, 275 int y_start,
276 base::TimeDelta time_start, 276 base::TimeDelta time_start,
277 int dx, 277 int dx,
278 int dy, 278 int dy,
279 int touch_id,
279 int time_step, 280 int time_step,
280 int num_steps, 281 int num_steps,
281 GestureEventConsumeDelegate* delegate) { 282 GestureEventConsumeDelegate* delegate) {
282 int x = x_start; 283 int x = x_start;
283 int y = y_start; 284 int y = y_start;
284 base::TimeDelta time = time_start; 285 base::TimeDelta time = time_start;
285 286
286 for (int i = 0; i < num_steps; i++) { 287 for (int i = 0; i < num_steps; i++) {
287 delegate->Reset(); 288 delegate->Reset();
288 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 0); 289 x += dx;
290 y += dy;
291 time = time + base::TimeDelta::FromMilliseconds(time_step);
292 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), touch_id);
289 Event::TestApi test_move(&move); 293 Event::TestApi test_move(&move);
290 test_move.set_time_stamp(time); 294 test_move.set_time_stamp(time);
291 root_window->DispatchTouchEvent(&move); 295 root_window->DispatchTouchEvent(&move);
292 x += dx;
293 y += dy;
294 time = time + base::TimeDelta::FromMilliseconds(time_step);
295 } 296 }
296 } 297 }
297 298
298 void SendScrollEvent(RootWindow* root_window, 299 void SendScrollEvent(RootWindow* root_window,
299 int x, 300 int x,
300 int y, 301 int y,
302 int touch_id,
301 GestureEventConsumeDelegate* delegate) { 303 GestureEventConsumeDelegate* delegate) {
302 delegate->Reset(); 304 delegate->Reset();
303 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 0); 305 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), touch_id);
304 root_window->DispatchTouchEvent(&move); 306 root_window->DispatchTouchEvent(&move);
305 } 307 }
306 308
307 const int kBufferedPoints = 10; 309 const int kBufferedPoints = 10;
308 310
309 } // namespace 311 } // namespace
310 312
311 typedef AuraTestBase GestureRecognizerTest; 313 typedef AuraTestBase GestureRecognizerTest;
312 314
313 // Check that appropriate touch events generate tap gesture events. 315 // Check that appropriate touch events generate tap gesture events.
314 TEST_F(GestureRecognizerTest, GestureEventTap) { 316 TEST_F(GestureRecognizerTest, GestureEventTap) {
315 scoped_ptr<GestureEventConsumeDelegate> delegate( 317 scoped_ptr<GestureEventConsumeDelegate> delegate(
316 new GestureEventConsumeDelegate()); 318 new GestureEventConsumeDelegate());
317 const int kWindowWidth = 123; 319 const int kWindowWidth = 123;
318 const int kWindowHeight = 45; 320 const int kWindowHeight = 45;
321 const int kTouchId = 2;
319 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 322 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
320 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 323 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
321 delegate.get(), -1234, bounds, NULL)); 324 delegate.get(), -1234, bounds, NULL));
322 325
323 delegate->Reset(); 326 delegate->Reset();
324 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 327 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId);
325 root_window()->DispatchTouchEvent(&press); 328 root_window()->DispatchTouchEvent(&press);
326 EXPECT_FALSE(delegate->tap()); 329 EXPECT_FALSE(delegate->tap());
327 EXPECT_TRUE(delegate->tap_down()); 330 EXPECT_TRUE(delegate->tap_down());
328 EXPECT_FALSE(delegate->double_tap()); 331 EXPECT_FALSE(delegate->double_tap());
329 EXPECT_FALSE(delegate->scroll_begin()); 332 EXPECT_FALSE(delegate->scroll_begin());
330 EXPECT_FALSE(delegate->scroll_update()); 333 EXPECT_FALSE(delegate->scroll_update());
331 EXPECT_FALSE(delegate->scroll_end()); 334 EXPECT_FALSE(delegate->scroll_end());
332 EXPECT_FALSE(delegate->long_press()); 335 EXPECT_FALSE(delegate->long_press());
333 336
334 // Make sure there is enough delay before the touch is released so that it is 337 // Make sure there is enough delay before the touch is released so that it is
335 // recognized as a tap. 338 // recognized as a tap.
336 delegate->Reset(); 339 delegate->Reset();
337 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 340 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId);
338 Event::TestApi test_release(&release); 341 Event::TestApi test_release(&release);
339 test_release.set_time_stamp(press.time_stamp() + 342 test_release.set_time_stamp(press.time_stamp() +
340 base::TimeDelta::FromMilliseconds(50)); 343 base::TimeDelta::FromMilliseconds(50));
341 root_window()->DispatchTouchEvent(&release); 344 root_window()->DispatchTouchEvent(&release);
342 EXPECT_TRUE(delegate->tap()); 345 EXPECT_TRUE(delegate->tap());
343 EXPECT_FALSE(delegate->tap_down()); 346 EXPECT_FALSE(delegate->tap_down());
344 EXPECT_FALSE(delegate->double_tap()); 347 EXPECT_FALSE(delegate->double_tap());
345 EXPECT_FALSE(delegate->scroll_begin()); 348 EXPECT_FALSE(delegate->scroll_begin());
346 EXPECT_FALSE(delegate->scroll_update()); 349 EXPECT_FALSE(delegate->scroll_update());
347 EXPECT_FALSE(delegate->scroll_end()); 350 EXPECT_FALSE(delegate->scroll_end());
348 } 351 }
349 352
350 // Check that appropriate touch events generate scroll gesture events. 353 // Check that appropriate touch events generate scroll gesture events.
351 TEST_F(GestureRecognizerTest, GestureEventScroll) { 354 TEST_F(GestureRecognizerTest, GestureEventScroll) {
352 scoped_ptr<GestureEventConsumeDelegate> delegate( 355 scoped_ptr<GestureEventConsumeDelegate> delegate(
353 new GestureEventConsumeDelegate()); 356 new GestureEventConsumeDelegate());
354 const int kWindowWidth = 123; 357 const int kWindowWidth = 123;
355 const int kWindowHeight = 45; 358 const int kWindowHeight = 45;
359 const int kTouchId = 5;
356 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 360 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
357 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 361 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
358 delegate.get(), -1234, bounds, NULL)); 362 delegate.get(), -1234, bounds, NULL));
359 363
360 delegate->Reset(); 364 delegate->Reset();
361 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 365 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId);
362 root_window()->DispatchTouchEvent(&press); 366 root_window()->DispatchTouchEvent(&press);
363 EXPECT_FALSE(delegate->tap()); 367 EXPECT_FALSE(delegate->tap());
364 EXPECT_TRUE(delegate->tap_down()); 368 EXPECT_TRUE(delegate->tap_down());
365 EXPECT_FALSE(delegate->double_tap()); 369 EXPECT_FALSE(delegate->double_tap());
366 EXPECT_FALSE(delegate->scroll_begin()); 370 EXPECT_FALSE(delegate->scroll_begin());
367 EXPECT_FALSE(delegate->scroll_update()); 371 EXPECT_FALSE(delegate->scroll_update());
368 EXPECT_FALSE(delegate->scroll_end()); 372 EXPECT_FALSE(delegate->scroll_end());
369 373
370 // Move the touch-point enough so that it is considered as a scroll. This 374 // Move the touch-point enough so that it is considered as a scroll. This
371 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 375 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
372 // The first movement is diagonal, to ensure that we have a free scroll, 376 // The first movement is diagonal, to ensure that we have a free scroll,
373 // and not a rail scroll. 377 // and not a rail scroll.
374 SendScrollEvent(root_window(), 130, 230, delegate.get()); 378 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get());
375 EXPECT_FALSE(delegate->tap()); 379 EXPECT_FALSE(delegate->tap());
376 EXPECT_FALSE(delegate->tap_down()); 380 EXPECT_FALSE(delegate->tap_down());
377 EXPECT_FALSE(delegate->double_tap()); 381 EXPECT_FALSE(delegate->double_tap());
378 EXPECT_TRUE(delegate->scroll_begin()); 382 EXPECT_TRUE(delegate->scroll_begin());
379 EXPECT_TRUE(delegate->scroll_update()); 383 EXPECT_TRUE(delegate->scroll_update());
380 EXPECT_FALSE(delegate->scroll_end()); 384 EXPECT_FALSE(delegate->scroll_end());
381 EXPECT_EQ(29, delegate->scroll_x()); 385 EXPECT_EQ(29, delegate->scroll_x());
382 EXPECT_EQ(29, delegate->scroll_y()); 386 EXPECT_EQ(29, delegate->scroll_y());
383 EXPECT_EQ(gfx::Point(1, 1).ToString(), 387 EXPECT_EQ(gfx::Point(1, 1).ToString(),
384 delegate->scroll_begin_position().ToString()); 388 delegate->scroll_begin_position().ToString());
385 389
386 // Move some more to generate a few more scroll updates. 390 // Move some more to generate a few more scroll updates.
387 SendScrollEvent(root_window(), 110, 211, delegate.get()); 391 SendScrollEvent(root_window(), 110, 211, kTouchId, delegate.get());
388 EXPECT_FALSE(delegate->tap()); 392 EXPECT_FALSE(delegate->tap());
389 EXPECT_FALSE(delegate->tap_down()); 393 EXPECT_FALSE(delegate->tap_down());
390 EXPECT_FALSE(delegate->double_tap()); 394 EXPECT_FALSE(delegate->double_tap());
391 EXPECT_FALSE(delegate->scroll_begin()); 395 EXPECT_FALSE(delegate->scroll_begin());
392 EXPECT_TRUE(delegate->scroll_update()); 396 EXPECT_TRUE(delegate->scroll_update());
393 EXPECT_FALSE(delegate->scroll_end()); 397 EXPECT_FALSE(delegate->scroll_end());
394 EXPECT_EQ(-20, delegate->scroll_x()); 398 EXPECT_EQ(-20, delegate->scroll_x());
395 EXPECT_EQ(-19, delegate->scroll_y()); 399 EXPECT_EQ(-19, delegate->scroll_y());
396 400
397 SendScrollEvent(root_window(), 140, 215, delegate.get()); 401 SendScrollEvent(root_window(), 140, 215, kTouchId, delegate.get());
398 EXPECT_FALSE(delegate->tap()); 402 EXPECT_FALSE(delegate->tap());
399 EXPECT_FALSE(delegate->tap_down()); 403 EXPECT_FALSE(delegate->tap_down());
400 EXPECT_FALSE(delegate->double_tap()); 404 EXPECT_FALSE(delegate->double_tap());
401 EXPECT_FALSE(delegate->scroll_begin()); 405 EXPECT_FALSE(delegate->scroll_begin());
402 EXPECT_TRUE(delegate->scroll_update()); 406 EXPECT_TRUE(delegate->scroll_update());
403 EXPECT_FALSE(delegate->scroll_end()); 407 EXPECT_FALSE(delegate->scroll_end());
404 EXPECT_EQ(30, delegate->scroll_x()); 408 EXPECT_EQ(30, delegate->scroll_x());
405 EXPECT_EQ(4, delegate->scroll_y()); 409 EXPECT_EQ(4, delegate->scroll_y());
406 410
407 // Release the touch. This should end the scroll. 411 // Release the touch. This should end the scroll.
408 delegate->Reset(); 412 delegate->Reset();
409 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 413 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId);
410 Event::TestApi test_release(&release); 414 Event::TestApi test_release(&release);
411 test_release.set_time_stamp(press.time_stamp() + 415 test_release.set_time_stamp(press.time_stamp() +
412 base::TimeDelta::FromMilliseconds(50)); 416 base::TimeDelta::FromMilliseconds(50));
413 root_window()->DispatchTouchEvent(&release); 417 root_window()->DispatchTouchEvent(&release);
414 EXPECT_FALSE(delegate->tap()); 418 EXPECT_FALSE(delegate->tap());
415 EXPECT_FALSE(delegate->tap_down()); 419 EXPECT_FALSE(delegate->tap_down());
416 EXPECT_FALSE(delegate->double_tap()); 420 EXPECT_FALSE(delegate->double_tap());
417 EXPECT_FALSE(delegate->scroll_begin()); 421 EXPECT_FALSE(delegate->scroll_begin());
418 EXPECT_FALSE(delegate->scroll_update()); 422 EXPECT_FALSE(delegate->scroll_update());
419 EXPECT_TRUE(delegate->scroll_end()); 423 EXPECT_TRUE(delegate->scroll_end());
420 } 424 }
421 425
422 // Check that appropriate touch events generate long press events 426 // Check that appropriate touch events generate long press events
423 TEST_F(GestureRecognizerTest, GestureEventLongPress) { 427 TEST_F(GestureRecognizerTest, GestureEventLongPress) {
424 scoped_ptr<GestureEventConsumeDelegate> delegate( 428 scoped_ptr<GestureEventConsumeDelegate> delegate(
425 new GestureEventConsumeDelegate()); 429 new GestureEventConsumeDelegate());
426 const int kWindowWidth = 123; 430 const int kWindowWidth = 123;
427 const int kWindowHeight = 45; 431 const int kWindowHeight = 45;
432 const int kTouchId = 2;
428 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 433 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
429 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 434 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
430 delegate.get(), -1234, bounds, NULL)); 435 delegate.get(), -1234, bounds, NULL));
431 436
432 delegate->Reset(); 437 delegate->Reset();
433 438
434 TestGestureRecognizer* gesture_recognizer = 439 TestGestureRecognizer* gesture_recognizer =
435 new TestGestureRecognizer(root_window()); 440 new TestGestureRecognizer(root_window());
436 TimerTestGestureSequence* gesture_sequence = 441 TimerTestGestureSequence* gesture_sequence =
437 static_cast<TimerTestGestureSequence*>( 442 static_cast<TimerTestGestureSequence*>(
438 gesture_recognizer->GetGestureSequenceForTesting()); 443 gesture_recognizer->GetGestureSequenceForTesting());
439 444
440 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 445 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
441 446
442 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 447 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId);
443 root_window()->DispatchTouchEvent(&press1); 448 root_window()->DispatchTouchEvent(&press1);
444 EXPECT_TRUE(delegate->tap_down()); 449 EXPECT_TRUE(delegate->tap_down());
445 450
446 // We haven't pressed long enough for a long press to occur 451 // We haven't pressed long enough for a long press to occur
447 EXPECT_FALSE(delegate->long_press()); 452 EXPECT_FALSE(delegate->long_press());
448 453
449 // Wait until the timer runs out 454 // Wait until the timer runs out
450 gesture_sequence->ForceTimeout(); 455 gesture_sequence->ForceTimeout();
451 EXPECT_TRUE(delegate->long_press()); 456 EXPECT_TRUE(delegate->long_press());
452 EXPECT_EQ(0u, delegate->touch_id()); 457 EXPECT_EQ(0, delegate->touch_id());
453 458
454 delegate->Reset(); 459 delegate->Reset();
455 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 460 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId);
456 root_window()->DispatchTouchEvent(&release1); 461 root_window()->DispatchTouchEvent(&release1);
457 EXPECT_FALSE(delegate->long_press()); 462 EXPECT_FALSE(delegate->long_press());
458 } 463 }
459 464
460 // Check that scrolling cancels a long press 465 // Check that scrolling cancels a long press
461 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { 466 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) {
462 scoped_ptr<GestureEventConsumeDelegate> delegate( 467 scoped_ptr<GestureEventConsumeDelegate> delegate(
463 new GestureEventConsumeDelegate()); 468 new GestureEventConsumeDelegate());
464 const int kWindowWidth = 123; 469 const int kWindowWidth = 123;
465 const int kWindowHeight = 45; 470 const int kWindowHeight = 45;
471 const int kTouchId = 6;
466 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 472 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
467 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 473 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
468 delegate.get(), -1234, bounds, NULL)); 474 delegate.get(), -1234, bounds, NULL));
469 475
470 delegate->Reset(); 476 delegate->Reset();
471 477
472 TestGestureRecognizer* gesture_recognizer = 478 TestGestureRecognizer* gesture_recognizer =
473 new TestGestureRecognizer(root_window()); 479 new TestGestureRecognizer(root_window());
474 TimerTestGestureSequence* gesture_sequence = 480 TimerTestGestureSequence* gesture_sequence =
475 static_cast<TimerTestGestureSequence*>( 481 static_cast<TimerTestGestureSequence*>(
476 gesture_recognizer->GetGestureSequenceForTesting()); 482 gesture_recognizer->GetGestureSequenceForTesting());
477 483
478 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 484 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
479 485
480 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 486 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId);
481 root_window()->DispatchTouchEvent(&press1); 487 root_window()->DispatchTouchEvent(&press1);
482 EXPECT_TRUE(delegate->tap_down()); 488 EXPECT_TRUE(delegate->tap_down());
483 489
484 // We haven't pressed long enough for a long press to occur 490 // We haven't pressed long enough for a long press to occur
485 EXPECT_FALSE(delegate->long_press()); 491 EXPECT_FALSE(delegate->long_press());
486 492
487 // Scroll around, to cancel the long press 493 // Scroll around, to cancel the long press
488 SendScrollEvent(root_window(), 130, 230, delegate.get()); 494 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get());
489 // Wait until the timer runs out 495 // Wait until the timer runs out
490 gesture_sequence->ForceTimeout(); 496 gesture_sequence->ForceTimeout();
491 EXPECT_FALSE(delegate->long_press()); 497 EXPECT_FALSE(delegate->long_press());
492 498
493 delegate->Reset(); 499 delegate->Reset();
494 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 500 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId);
495 root_window()->DispatchTouchEvent(&release1); 501 root_window()->DispatchTouchEvent(&release1);
496 EXPECT_FALSE(delegate->long_press()); 502 EXPECT_FALSE(delegate->long_press());
497 } 503 }
498 504
499 // Check that pinching cancels a long press 505 // Check that pinching cancels a long press
500 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByPinch) { 506 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByPinch) {
501 scoped_ptr<GestureEventConsumeDelegate> delegate( 507 scoped_ptr<GestureEventConsumeDelegate> delegate(
502 new GestureEventConsumeDelegate()); 508 new GestureEventConsumeDelegate());
503 const int kWindowWidth = 300; 509 const int kWindowWidth = 300;
504 const int kWindowHeight = 400; 510 const int kWindowHeight = 400;
511 const int kTouchId1 = 8;
512 const int kTouchId2 = 2;
505 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 513 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
506 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 514 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
507 delegate.get(), -1234, bounds, NULL)); 515 delegate.get(), -1234, bounds, NULL));
508 516
509 TestGestureRecognizer* gesture_recognizer = 517 TestGestureRecognizer* gesture_recognizer =
510 new TestGestureRecognizer(root_window()); 518 new TestGestureRecognizer(root_window());
511 TimerTestGestureSequence* gesture_sequence = 519 TimerTestGestureSequence* gesture_sequence =
512 static_cast<TimerTestGestureSequence*>( 520 static_cast<TimerTestGestureSequence*>(
513 gesture_recognizer->GetGestureSequenceForTesting()); 521 gesture_recognizer->GetGestureSequenceForTesting());
514 522
515 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 523 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
516 524
517 delegate->Reset(); 525 delegate->Reset();
518 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 526 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1);
519 root_window()->DispatchTouchEvent(&press); 527 root_window()->DispatchTouchEvent(&press);
520 EXPECT_TRUE(delegate->tap_down()); 528 EXPECT_TRUE(delegate->tap_down());
521 529
522 // We haven't pressed long enough for a long press to occur 530 // We haven't pressed long enough for a long press to occur
523 EXPECT_FALSE(delegate->long_press()); 531 EXPECT_FALSE(delegate->long_press());
524 532
525 // Pinch, to cancel the long press 533 // Pinch, to cancel the long press
526 delegate->Reset(); 534 delegate->Reset();
527 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1); 535 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), kTouchId2);
528 root_window()->DispatchTouchEvent(&press2); 536 root_window()->DispatchTouchEvent(&press2);
529 EXPECT_TRUE(delegate->tap_down()); 537 EXPECT_TRUE(delegate->tap_down());
530 EXPECT_TRUE(delegate->pinch_begin()); 538 EXPECT_TRUE(delegate->pinch_begin());
531 539
532 // Wait until the timer runs out 540 // Wait until the timer runs out
533 gesture_sequence->ForceTimeout(); 541 gesture_sequence->ForceTimeout();
534 542
535 // No long press occurred 543 // No long press occurred
536 EXPECT_FALSE(delegate->long_press()); 544 EXPECT_FALSE(delegate->long_press());
537 545
538 delegate->Reset(); 546 delegate->Reset();
539 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 547 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId1);
540 root_window()->DispatchTouchEvent(&release1); 548 root_window()->DispatchTouchEvent(&release1);
541 EXPECT_FALSE(delegate->long_press()); 549 EXPECT_FALSE(delegate->long_press());
542 } 550 }
543 551
544 // Check that horizontal scroll gestures cause scrolls on horizontal rails. 552 // Check that horizontal scroll gestures cause scrolls on horizontal rails.
545 // Also tests that horizontal rails can be broken. 553 // Also tests that horizontal rails can be broken.
546 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) { 554 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
547 scoped_ptr<GestureEventConsumeDelegate> delegate( 555 scoped_ptr<GestureEventConsumeDelegate> delegate(
548 new GestureEventConsumeDelegate()); 556 new GestureEventConsumeDelegate());
557 const int kTouchId = 7;
549 gfx::Rect bounds(0, 0, 1000, 1000); 558 gfx::Rect bounds(0, 0, 1000, 1000);
550 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 559 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
551 delegate.get(), -1234, bounds, NULL)); 560 delegate.get(), -1234, bounds, NULL));
552 561
553 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0); 562 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), kTouchId);
554 root_window()->DispatchTouchEvent(&press); 563 root_window()->DispatchTouchEvent(&press);
555 564
556 // Move the touch-point horizontally enough that it is considered a 565 // Move the touch-point horizontally enough that it is considered a
557 // horizontal scroll. 566 // horizontal scroll.
558 SendScrollEvent(root_window(), 20, 1, delegate.get()); 567 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get());
559 EXPECT_EQ(0, delegate->scroll_y()); 568 EXPECT_EQ(0, delegate->scroll_y());
560 EXPECT_EQ(20, delegate->scroll_x()); 569 EXPECT_EQ(20, delegate->scroll_x());
561 570
562 SendScrollEvent(root_window(), 25, 6, delegate.get()); 571 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get());
563 EXPECT_TRUE(delegate->scroll_update()); 572 EXPECT_TRUE(delegate->scroll_update());
564 EXPECT_EQ(5, delegate->scroll_x()); 573 EXPECT_EQ(5, delegate->scroll_x());
565 // y shouldn't change, as we're on a horizontal rail. 574 // y shouldn't change, as we're on a horizontal rail.
566 EXPECT_EQ(0, delegate->scroll_y()); 575 EXPECT_EQ(0, delegate->scroll_y());
567 576
568 // Send enough information that a velocity can be calculated for the gesture, 577 // Send enough information that a velocity can be calculated for the gesture,
569 // and we can break the rail 578 // and we can break the rail
570 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 579 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
571 1, 100, 1, kBufferedPoints, delegate.get()); 580 1, 100, kTouchId, 1, kBufferedPoints, delegate.get());
572 581
573 SendScrollEvent(root_window(), 0, 0, delegate.get()); 582 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get());
574 SendScrollEvent(root_window(), 5, 5, delegate.get()); 583 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get());
575 584
576 // The rail should be broken 585 // The rail should be broken
577 EXPECT_TRUE(delegate->scroll_update()); 586 EXPECT_TRUE(delegate->scroll_update());
578 EXPECT_EQ(5, delegate->scroll_x()); 587 EXPECT_EQ(5, delegate->scroll_x());
579 EXPECT_EQ(5, delegate->scroll_y()); 588 EXPECT_EQ(5, delegate->scroll_y());
580 } 589 }
581 590
582 // Check that vertical scroll gestures cause scrolls on vertical rails. 591 // Check that vertical scroll gestures cause scrolls on vertical rails.
583 // Also tests that vertical rails can be broken. 592 // Also tests that vertical rails can be broken.
584 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { 593 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
585 scoped_ptr<GestureEventConsumeDelegate> delegate( 594 scoped_ptr<GestureEventConsumeDelegate> delegate(
586 new GestureEventConsumeDelegate()); 595 new GestureEventConsumeDelegate());
596 const int kTouchId = 7;
587 gfx::Rect bounds(0, 0, 1000, 1000); 597 gfx::Rect bounds(0, 0, 1000, 1000);
588 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 598 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
589 delegate.get(), -1234, bounds, NULL)); 599 delegate.get(), -1234, bounds, NULL));
590 600
591 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0); 601 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), kTouchId);
592 root_window()->DispatchTouchEvent(&press); 602 root_window()->DispatchTouchEvent(&press);
593 603
594 // Move the touch-point vertically enough that it is considered a 604 // Move the touch-point vertically enough that it is considered a
595 // vertical scroll. 605 // vertical scroll.
596 SendScrollEvent(root_window(), 1, 20, delegate.get()); 606 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
597 EXPECT_EQ(0, delegate->scroll_x()); 607 EXPECT_EQ(0, delegate->scroll_x());
598 EXPECT_EQ(20, delegate->scroll_y()); 608 EXPECT_EQ(20, delegate->scroll_y());
599 609
600 SendScrollEvent(root_window(), 6, 25, delegate.get()); 610 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get());
601 EXPECT_TRUE(delegate->scroll_update()); 611 EXPECT_TRUE(delegate->scroll_update());
602 EXPECT_EQ(5, delegate->scroll_y()); 612 EXPECT_EQ(5, delegate->scroll_y());
603 // x shouldn't change, as we're on a vertical rail. 613 // x shouldn't change, as we're on a vertical rail.
604 EXPECT_EQ(0, delegate->scroll_x()); 614 EXPECT_EQ(0, delegate->scroll_x());
605 615
606 // Send enough information that a velocity can be calculated for the gesture, 616 // Send enough information that a velocity can be calculated for the gesture,
607 // and we can break the rail 617 // and we can break the rail
608 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 618 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
609 100, 1, 1, kBufferedPoints, delegate.get()); 619 100, 1, kTouchId, 1, kBufferedPoints, delegate.get());
610 620
611 SendScrollEvent(root_window(), 0, 0, delegate.get()); 621 SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get());
612 SendScrollEvent(root_window(), 5, 5, delegate.get()); 622 SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get());
613 623
614 // The rail should be broken 624 // The rail should be broken
615 EXPECT_TRUE(delegate->scroll_update()); 625 EXPECT_TRUE(delegate->scroll_update());
616 EXPECT_EQ(5, delegate->scroll_x()); 626 EXPECT_EQ(5, delegate->scroll_x());
617 EXPECT_EQ(5, delegate->scroll_y()); 627 EXPECT_EQ(5, delegate->scroll_y());
618 } 628 }
619 629
620 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { 630 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
621 // First, tap. Then, do a scroll using the same touch-id. 631 // First, tap. Then, do a scroll using the same touch-id.
622 scoped_ptr<GestureEventConsumeDelegate> delegate( 632 scoped_ptr<GestureEventConsumeDelegate> delegate(
623 new GestureEventConsumeDelegate()); 633 new GestureEventConsumeDelegate());
624 const int kWindowWidth = 123; 634 const int kWindowWidth = 123;
625 const int kWindowHeight = 45; 635 const int kWindowHeight = 45;
636 const int kTouchId = 3;
626 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 637 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
627 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 638 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
628 delegate.get(), -1234, bounds, NULL)); 639 delegate.get(), -1234, bounds, NULL));
629 640
630 delegate->Reset(); 641 delegate->Reset();
631 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 642 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId);
632 root_window()->DispatchTouchEvent(&press); 643 root_window()->DispatchTouchEvent(&press);
633 EXPECT_FALSE(delegate->tap()); 644 EXPECT_FALSE(delegate->tap());
634 EXPECT_TRUE(delegate->tap_down()); 645 EXPECT_TRUE(delegate->tap_down());
635 EXPECT_FALSE(delegate->double_tap()); 646 EXPECT_FALSE(delegate->double_tap());
636 EXPECT_FALSE(delegate->scroll_begin()); 647 EXPECT_FALSE(delegate->scroll_begin());
637 EXPECT_FALSE(delegate->scroll_update()); 648 EXPECT_FALSE(delegate->scroll_update());
638 EXPECT_FALSE(delegate->scroll_end()); 649 EXPECT_FALSE(delegate->scroll_end());
639 650
640 // Make sure there is enough delay before the touch is released so that it is 651 // Make sure there is enough delay before the touch is released so that it is
641 // recognized as a tap. 652 // recognized as a tap.
642 delegate->Reset(); 653 delegate->Reset();
643 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 654 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId);
644 Event::TestApi test_release(&release); 655 Event::TestApi test_release(&release);
645 test_release.set_time_stamp(press.time_stamp() + 656 test_release.set_time_stamp(press.time_stamp() +
646 base::TimeDelta::FromMilliseconds(50)); 657 base::TimeDelta::FromMilliseconds(50));
647 root_window()->DispatchTouchEvent(&release); 658 root_window()->DispatchTouchEvent(&release);
648 EXPECT_TRUE(delegate->tap()); 659 EXPECT_TRUE(delegate->tap());
649 EXPECT_FALSE(delegate->tap_down()); 660 EXPECT_FALSE(delegate->tap_down());
650 EXPECT_FALSE(delegate->double_tap()); 661 EXPECT_FALSE(delegate->double_tap());
651 EXPECT_FALSE(delegate->scroll_begin()); 662 EXPECT_FALSE(delegate->scroll_begin());
652 EXPECT_FALSE(delegate->scroll_update()); 663 EXPECT_FALSE(delegate->scroll_update());
653 EXPECT_FALSE(delegate->scroll_end()); 664 EXPECT_FALSE(delegate->scroll_end());
654 665
655 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger 666 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger
656 // a double-tap. 667 // a double-tap.
657 delegate->Reset(); 668 delegate->Reset();
658 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 669 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId);
659 Event::TestApi test_release1(&press1); 670 Event::TestApi test_release1(&press1);
660 test_release1.set_time_stamp(release.time_stamp() + 671 test_release1.set_time_stamp(release.time_stamp() +
661 base::TimeDelta::FromMilliseconds(1000)); 672 base::TimeDelta::FromMilliseconds(1000));
662 root_window()->DispatchTouchEvent(&press1); 673 root_window()->DispatchTouchEvent(&press1);
663 EXPECT_FALSE(delegate->tap()); 674 EXPECT_FALSE(delegate->tap());
664 EXPECT_TRUE(delegate->tap_down()); 675 EXPECT_TRUE(delegate->tap_down());
665 EXPECT_FALSE(delegate->double_tap()); 676 EXPECT_FALSE(delegate->double_tap());
666 EXPECT_FALSE(delegate->scroll_begin()); 677 EXPECT_FALSE(delegate->scroll_begin());
667 EXPECT_FALSE(delegate->scroll_update()); 678 EXPECT_FALSE(delegate->scroll_update());
668 EXPECT_FALSE(delegate->scroll_end()); 679 EXPECT_FALSE(delegate->scroll_end());
669 680
670 // Move the touch-point enough so that it is considered as a scroll. This 681 // Move the touch-point enough so that it is considered as a scroll. This
671 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 682 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
672 // The first movement is diagonal, to ensure that we have a free scroll, 683 // The first movement is diagonal, to ensure that we have a free scroll,
673 // and not a rail scroll. 684 // and not a rail scroll.
674 delegate->Reset(); 685 delegate->Reset();
675 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230), 0); 686 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230), kTouchId);
676 root_window()->DispatchTouchEvent(&move); 687 root_window()->DispatchTouchEvent(&move);
677 EXPECT_FALSE(delegate->tap()); 688 EXPECT_FALSE(delegate->tap());
678 EXPECT_FALSE(delegate->tap_down()); 689 EXPECT_FALSE(delegate->tap_down());
679 EXPECT_FALSE(delegate->double_tap()); 690 EXPECT_FALSE(delegate->double_tap());
680 EXPECT_TRUE(delegate->scroll_begin()); 691 EXPECT_TRUE(delegate->scroll_begin());
681 EXPECT_TRUE(delegate->scroll_update()); 692 EXPECT_TRUE(delegate->scroll_update());
682 EXPECT_FALSE(delegate->scroll_end()); 693 EXPECT_FALSE(delegate->scroll_end());
683 EXPECT_EQ(29, delegate->scroll_x()); 694 EXPECT_EQ(29, delegate->scroll_x());
684 EXPECT_EQ(29, delegate->scroll_y()); 695 EXPECT_EQ(29, delegate->scroll_y());
685 696
686 // Move some more to generate a few more scroll updates. 697 // Move some more to generate a few more scroll updates.
687 delegate->Reset(); 698 delegate->Reset();
688 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211), 0); 699 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211), kTouchId);
689 root_window()->DispatchTouchEvent(&move1); 700 root_window()->DispatchTouchEvent(&move1);
690 EXPECT_FALSE(delegate->tap()); 701 EXPECT_FALSE(delegate->tap());
691 EXPECT_FALSE(delegate->tap_down()); 702 EXPECT_FALSE(delegate->tap_down());
692 EXPECT_FALSE(delegate->double_tap()); 703 EXPECT_FALSE(delegate->double_tap());
693 EXPECT_FALSE(delegate->scroll_begin()); 704 EXPECT_FALSE(delegate->scroll_begin());
694 EXPECT_TRUE(delegate->scroll_update()); 705 EXPECT_TRUE(delegate->scroll_update());
695 EXPECT_FALSE(delegate->scroll_end()); 706 EXPECT_FALSE(delegate->scroll_end());
696 EXPECT_EQ(-20, delegate->scroll_x()); 707 EXPECT_EQ(-20, delegate->scroll_x());
697 EXPECT_EQ(-19, delegate->scroll_y()); 708 EXPECT_EQ(-19, delegate->scroll_y());
698 709
699 delegate->Reset(); 710 delegate->Reset();
700 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215), 0); 711 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215), kTouchId);
701 root_window()->DispatchTouchEvent(&move2); 712 root_window()->DispatchTouchEvent(&move2);
702 EXPECT_FALSE(delegate->tap()); 713 EXPECT_FALSE(delegate->tap());
703 EXPECT_FALSE(delegate->tap_down()); 714 EXPECT_FALSE(delegate->tap_down());
704 EXPECT_FALSE(delegate->double_tap()); 715 EXPECT_FALSE(delegate->double_tap());
705 EXPECT_FALSE(delegate->scroll_begin()); 716 EXPECT_FALSE(delegate->scroll_begin());
706 EXPECT_TRUE(delegate->scroll_update()); 717 EXPECT_TRUE(delegate->scroll_update());
707 EXPECT_FALSE(delegate->scroll_end()); 718 EXPECT_FALSE(delegate->scroll_end());
708 EXPECT_EQ(30, delegate->scroll_x()); 719 EXPECT_EQ(30, delegate->scroll_x());
709 EXPECT_EQ(4, delegate->scroll_y()); 720 EXPECT_EQ(4, delegate->scroll_y());
710 721
711 // Release the touch. This should end the scroll. 722 // Release the touch. This should end the scroll.
712 delegate->Reset(); 723 delegate->Reset();
713 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 724 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId);
714 root_window()->DispatchTouchEvent(&release1); 725 root_window()->DispatchTouchEvent(&release1);
715 EXPECT_FALSE(delegate->tap()); 726 EXPECT_FALSE(delegate->tap());
716 EXPECT_FALSE(delegate->tap_down()); 727 EXPECT_FALSE(delegate->tap_down());
717 EXPECT_FALSE(delegate->double_tap()); 728 EXPECT_FALSE(delegate->double_tap());
718 EXPECT_FALSE(delegate->scroll_begin()); 729 EXPECT_FALSE(delegate->scroll_begin());
719 EXPECT_FALSE(delegate->scroll_update()); 730 EXPECT_FALSE(delegate->scroll_update());
720 EXPECT_TRUE(delegate->scroll_end()); 731 EXPECT_TRUE(delegate->scroll_end());
721 } 732 }
722 733
723 // Check that unprocessed gesture events generate appropriate synthetic mouse 734 // Check that unprocessed gesture events generate appropriate synthetic mouse
724 // events. 735 // events.
725 TEST_F(GestureRecognizerTest, GestureTapSyntheticMouse) { 736 TEST_F(GestureRecognizerTest, GestureTapSyntheticMouse) {
726 scoped_ptr<GestureEventSynthDelegate> delegate( 737 scoped_ptr<GestureEventSynthDelegate> delegate(
727 new GestureEventSynthDelegate()); 738 new GestureEventSynthDelegate());
728 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, 739 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234,
729 gfx::Rect(0, 0, 123, 45), NULL)); 740 gfx::Rect(0, 0, 123, 45), NULL));
730 741
731 delegate->Reset(); 742 delegate->Reset();
732 GestureEvent tap(ui::ET_GESTURE_TAP, 20, 20, 0, base::Time::Now(), 0, 0); 743 GestureEvent tap(ui::ET_GESTURE_TAP, 20, 20, 0, base::Time::Now(), 0, 6);
733 root_window()->DispatchGestureEvent(&tap); 744 root_window()->DispatchGestureEvent(&tap);
734 EXPECT_TRUE(delegate->mouse_enter()); 745 EXPECT_TRUE(delegate->mouse_enter());
735 EXPECT_TRUE(delegate->mouse_press()); 746 EXPECT_TRUE(delegate->mouse_press());
736 EXPECT_TRUE(delegate->mouse_release()); 747 EXPECT_TRUE(delegate->mouse_release());
737 EXPECT_TRUE(delegate->mouse_exit()); 748 EXPECT_TRUE(delegate->mouse_exit());
738 EXPECT_FALSE(delegate->double_click()); 749 EXPECT_FALSE(delegate->double_click());
739 750
740 delegate->Reset(); 751 delegate->Reset();
741 GestureEvent tap2(ui::ET_GESTURE_DOUBLE_TAP, 20, 20, 0, 752 GestureEvent tap2(ui::ET_GESTURE_DOUBLE_TAP, 20, 20, 0,
742 base::Time::Now(), 0, 0); 753 base::Time::Now(), 0, 0);
743 root_window()->DispatchGestureEvent(&tap2); 754 root_window()->DispatchGestureEvent(&tap2);
744 EXPECT_TRUE(delegate->mouse_enter()); 755 EXPECT_TRUE(delegate->mouse_enter());
745 EXPECT_TRUE(delegate->mouse_press()); 756 EXPECT_TRUE(delegate->mouse_press());
746 EXPECT_TRUE(delegate->mouse_release()); 757 EXPECT_TRUE(delegate->mouse_release());
747 EXPECT_TRUE(delegate->mouse_exit()); 758 EXPECT_TRUE(delegate->mouse_exit());
748 EXPECT_TRUE(delegate->double_click()); 759 EXPECT_TRUE(delegate->double_click());
749 } 760 }
750 761
751 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) { 762 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
752 scoped_ptr<QueueTouchEventDelegate> queued_delegate( 763 scoped_ptr<QueueTouchEventDelegate> queued_delegate(
753 new QueueTouchEventDelegate(root_window())); 764 new QueueTouchEventDelegate(root_window()));
754 const int kWindowWidth = 123; 765 const int kWindowWidth = 123;
755 const int kWindowHeight = 45; 766 const int kWindowHeight = 45;
767 const int kTouchId1 = 6;
768 const int kTouchId2 = 4;
756 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 769 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
757 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( 770 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate(
758 queued_delegate.get(), -1234, bounds, NULL)); 771 queued_delegate.get(), -1234, bounds, NULL));
759 772
760 queued_delegate->set_window(queue.get()); 773 queued_delegate->set_window(queue.get());
761 774
762 // Touch down on the window. This should not generate any gesture event. 775 // Touch down on the window. This should not generate any gesture event.
763 queued_delegate->Reset(); 776 queued_delegate->Reset();
764 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 777 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1);
765 root_window()->DispatchTouchEvent(&press); 778 root_window()->DispatchTouchEvent(&press);
766 EXPECT_FALSE(queued_delegate->tap()); 779 EXPECT_FALSE(queued_delegate->tap());
767 EXPECT_FALSE(queued_delegate->tap_down()); 780 EXPECT_FALSE(queued_delegate->tap_down());
768 EXPECT_FALSE(queued_delegate->double_tap()); 781 EXPECT_FALSE(queued_delegate->double_tap());
769 EXPECT_FALSE(queued_delegate->scroll_begin()); 782 EXPECT_FALSE(queued_delegate->scroll_begin());
770 EXPECT_FALSE(queued_delegate->scroll_update()); 783 EXPECT_FALSE(queued_delegate->scroll_update());
771 EXPECT_FALSE(queued_delegate->scroll_end()); 784 EXPECT_FALSE(queued_delegate->scroll_end());
772 785
773 // Introduce some delay before the touch is released so that it is recognized 786 // Introduce some delay before the touch is released so that it is recognized
774 // as a tap. However, this still should not create any gesture events. 787 // as a tap. However, this still should not create any gesture events.
775 queued_delegate->Reset(); 788 queued_delegate->Reset();
776 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 789 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId1);
777 Event::TestApi test_release(&release); 790 Event::TestApi test_release(&release);
778 test_release.set_time_stamp(press.time_stamp() + 791 test_release.set_time_stamp(press.time_stamp() +
779 base::TimeDelta::FromMilliseconds(50)); 792 base::TimeDelta::FromMilliseconds(50));
780 root_window()->DispatchTouchEvent(&release); 793 root_window()->DispatchTouchEvent(&release);
781 EXPECT_FALSE(queued_delegate->tap()); 794 EXPECT_FALSE(queued_delegate->tap());
782 EXPECT_FALSE(queued_delegate->tap_down()); 795 EXPECT_FALSE(queued_delegate->tap_down());
783 EXPECT_FALSE(queued_delegate->double_tap()); 796 EXPECT_FALSE(queued_delegate->double_tap());
784 EXPECT_FALSE(queued_delegate->scroll_begin()); 797 EXPECT_FALSE(queued_delegate->scroll_begin());
785 EXPECT_FALSE(queued_delegate->scroll_update()); 798 EXPECT_FALSE(queued_delegate->scroll_update());
786 EXPECT_FALSE(queued_delegate->scroll_end()); 799 EXPECT_FALSE(queued_delegate->scroll_end());
787 800
788 // Create another window, and place a touch-down on it. This should create a 801 // Create another window, and place a touch-down on it. This should create a
789 // tap-down gesture. 802 // tap-down gesture.
790 scoped_ptr<GestureEventConsumeDelegate> delegate( 803 scoped_ptr<GestureEventConsumeDelegate> delegate(
791 new GestureEventConsumeDelegate()); 804 new GestureEventConsumeDelegate());
792 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 805 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
793 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL)); 806 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL));
794 delegate->Reset(); 807 delegate->Reset();
795 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), 0); 808 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), kTouchId2);
796 root_window()->DispatchTouchEvent(&press2); 809 root_window()->DispatchTouchEvent(&press2);
797 EXPECT_FALSE(delegate->tap()); 810 EXPECT_FALSE(delegate->tap());
798 EXPECT_TRUE(delegate->tap_down()); 811 EXPECT_TRUE(delegate->tap_down());
799 EXPECT_FALSE(delegate->double_tap()); 812 EXPECT_FALSE(delegate->double_tap());
800 EXPECT_FALSE(delegate->scroll_begin()); 813 EXPECT_FALSE(delegate->scroll_begin());
801 EXPECT_FALSE(delegate->scroll_update()); 814 EXPECT_FALSE(delegate->scroll_update());
802 EXPECT_FALSE(delegate->scroll_end()); 815 EXPECT_FALSE(delegate->scroll_end());
803 816
804 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 0); 817 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), kTouchId2);
805 root_window()->DispatchTouchEvent(&release2); 818 root_window()->DispatchTouchEvent(&release2);
806 819
807 // Process the first queued event. 820 // Process the first queued event.
808 queued_delegate->Reset(); 821 queued_delegate->Reset();
809 queued_delegate->ReceivedAck(); 822 queued_delegate->ReceivedAck();
810 EXPECT_FALSE(queued_delegate->tap()); 823 EXPECT_FALSE(queued_delegate->tap());
811 EXPECT_TRUE(queued_delegate->tap_down()); 824 EXPECT_TRUE(queued_delegate->tap_down());
812 EXPECT_FALSE(queued_delegate->double_tap()); 825 EXPECT_FALSE(queued_delegate->double_tap());
813 EXPECT_FALSE(queued_delegate->scroll_begin()); 826 EXPECT_FALSE(queued_delegate->scroll_begin());
814 EXPECT_FALSE(queued_delegate->scroll_update()); 827 EXPECT_FALSE(queued_delegate->scroll_update());
815 EXPECT_FALSE(queued_delegate->scroll_end()); 828 EXPECT_FALSE(queued_delegate->scroll_end());
816 829
817 // Now, process the second queued event. 830 // Now, process the second queued event.
818 queued_delegate->Reset(); 831 queued_delegate->Reset();
819 queued_delegate->ReceivedAck(); 832 queued_delegate->ReceivedAck();
820 EXPECT_TRUE(queued_delegate->tap()); 833 EXPECT_TRUE(queued_delegate->tap());
821 EXPECT_FALSE(queued_delegate->tap_down()); 834 EXPECT_FALSE(queued_delegate->tap_down());
822 EXPECT_FALSE(queued_delegate->double_tap()); 835 EXPECT_FALSE(queued_delegate->double_tap());
823 EXPECT_FALSE(queued_delegate->scroll_begin()); 836 EXPECT_FALSE(queued_delegate->scroll_begin());
824 EXPECT_FALSE(queued_delegate->scroll_update()); 837 EXPECT_FALSE(queued_delegate->scroll_update());
825 EXPECT_FALSE(queued_delegate->scroll_end()); 838 EXPECT_FALSE(queued_delegate->scroll_end());
826 839
827 // Start all over. Press on the first window, then press again on the second 840 // Start all over. Press on the first window, then press again on the second
828 // window. The second press should still go to the first window. 841 // window. The second press should still go to the first window.
829 queued_delegate->Reset(); 842 queued_delegate->Reset();
830 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 843 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1);
831 root_window()->DispatchTouchEvent(&press3); 844 root_window()->DispatchTouchEvent(&press3);
832 EXPECT_FALSE(queued_delegate->tap()); 845 EXPECT_FALSE(queued_delegate->tap());
833 EXPECT_FALSE(queued_delegate->tap_down()); 846 EXPECT_FALSE(queued_delegate->tap_down());
834 EXPECT_FALSE(queued_delegate->double_tap()); 847 EXPECT_FALSE(queued_delegate->double_tap());
835 EXPECT_FALSE(queued_delegate->scroll_begin()); 848 EXPECT_FALSE(queued_delegate->scroll_begin());
836 EXPECT_FALSE(queued_delegate->scroll_update()); 849 EXPECT_FALSE(queued_delegate->scroll_update());
837 EXPECT_FALSE(queued_delegate->scroll_end()); 850 EXPECT_FALSE(queued_delegate->scroll_end());
838 851
839 queued_delegate->Reset(); 852 queued_delegate->Reset();
840 delegate->Reset(); 853 delegate->Reset();
841 TouchEvent press4(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), 1); 854 TouchEvent press4(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), kTouchId2);
842 root_window()->DispatchTouchEvent(&press4); 855 root_window()->DispatchTouchEvent(&press4);
843 EXPECT_FALSE(delegate->tap()); 856 EXPECT_FALSE(delegate->tap());
844 EXPECT_FALSE(delegate->tap_down()); 857 EXPECT_FALSE(delegate->tap_down());
845 EXPECT_FALSE(delegate->double_tap()); 858 EXPECT_FALSE(delegate->double_tap());
846 EXPECT_FALSE(delegate->scroll_begin()); 859 EXPECT_FALSE(delegate->scroll_begin());
847 EXPECT_FALSE(delegate->scroll_update()); 860 EXPECT_FALSE(delegate->scroll_update());
848 EXPECT_FALSE(delegate->scroll_end()); 861 EXPECT_FALSE(delegate->scroll_end());
849 EXPECT_FALSE(queued_delegate->tap()); 862 EXPECT_FALSE(queued_delegate->tap());
850 EXPECT_FALSE(queued_delegate->tap_down()); 863 EXPECT_FALSE(queued_delegate->tap_down());
851 EXPECT_FALSE(queued_delegate->double_tap()); 864 EXPECT_FALSE(queued_delegate->double_tap());
(...skipping 22 matching lines...) Expand all
874 EXPECT_FALSE(queued_delegate->pinch_update()); 887 EXPECT_FALSE(queued_delegate->pinch_update());
875 EXPECT_FALSE(queued_delegate->pinch_end()); 888 EXPECT_FALSE(queued_delegate->pinch_end());
876 } 889 }
877 890
878 // Check that appropriate touch events generate pinch gesture events. 891 // Check that appropriate touch events generate pinch gesture events.
879 TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) { 892 TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) {
880 scoped_ptr<GestureEventConsumeDelegate> delegate( 893 scoped_ptr<GestureEventConsumeDelegate> delegate(
881 new GestureEventConsumeDelegate()); 894 new GestureEventConsumeDelegate());
882 const int kWindowWidth = 300; 895 const int kWindowWidth = 300;
883 const int kWindowHeight = 400; 896 const int kWindowHeight = 400;
897 const int kTouchId1 = 5;
898 const int kTouchId2 = 3;
884 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 899 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
885 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 900 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
886 delegate.get(), -1234, bounds, NULL)); 901 delegate.get(), -1234, bounds, NULL));
887 902
888 aura::RootWindow* root = root_window(); 903 aura::RootWindow* root = root_window();
889 904
890 delegate->Reset(); 905 delegate->Reset();
891 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 906 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1);
892 root->DispatchTouchEvent(&press); 907 root->DispatchTouchEvent(&press);
893 EXPECT_FALSE(delegate->tap()); 908 EXPECT_FALSE(delegate->tap());
894 EXPECT_TRUE(delegate->tap_down()); 909 EXPECT_TRUE(delegate->tap_down());
895 EXPECT_FALSE(delegate->double_tap()); 910 EXPECT_FALSE(delegate->double_tap());
896 EXPECT_FALSE(delegate->scroll_begin()); 911 EXPECT_FALSE(delegate->scroll_begin());
897 EXPECT_FALSE(delegate->scroll_update()); 912 EXPECT_FALSE(delegate->scroll_update());
898 EXPECT_FALSE(delegate->scroll_end()); 913 EXPECT_FALSE(delegate->scroll_end());
899 914
900 // Move the touch-point enough so that it is considered as a scroll. This 915 // Move the touch-point enough so that it is considered as a scroll. This
901 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 916 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
902 delegate->Reset(); 917 delegate->Reset();
903 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 201), 0); 918 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 201), kTouchId1);
904 root->DispatchTouchEvent(&move); 919 root->DispatchTouchEvent(&move);
905 EXPECT_FALSE(delegate->tap()); 920 EXPECT_FALSE(delegate->tap());
906 EXPECT_FALSE(delegate->tap_down()); 921 EXPECT_FALSE(delegate->tap_down());
907 EXPECT_FALSE(delegate->double_tap()); 922 EXPECT_FALSE(delegate->double_tap());
908 EXPECT_TRUE(delegate->scroll_begin()); 923 EXPECT_TRUE(delegate->scroll_begin());
909 EXPECT_TRUE(delegate->scroll_update()); 924 EXPECT_TRUE(delegate->scroll_update());
910 EXPECT_FALSE(delegate->scroll_end()); 925 EXPECT_FALSE(delegate->scroll_end());
911 926
912 // Press the second finger. It should cause both a tap-down and pinch-begin. 927 // Press the second finger. It should cause both a tap-down and pinch-begin.
913 delegate->Reset(); 928 delegate->Reset();
914 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1); 929 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), kTouchId2);
915 root->DispatchTouchEvent(&press2); 930 root->DispatchTouchEvent(&press2);
916 EXPECT_FALSE(delegate->tap()); 931 EXPECT_FALSE(delegate->tap());
917 EXPECT_TRUE(delegate->tap_down()); 932 EXPECT_TRUE(delegate->tap_down());
918 EXPECT_FALSE(delegate->double_tap()); 933 EXPECT_FALSE(delegate->double_tap());
919 EXPECT_FALSE(delegate->scroll_begin()); 934 EXPECT_FALSE(delegate->scroll_begin());
920 EXPECT_FALSE(delegate->scroll_update()); 935 EXPECT_FALSE(delegate->scroll_update());
921 EXPECT_FALSE(delegate->scroll_end()); 936 EXPECT_FALSE(delegate->scroll_end());
922 EXPECT_TRUE(delegate->pinch_begin()); 937 EXPECT_TRUE(delegate->pinch_begin());
923 938
924 // Move the first finger. 939 // Move the first finger.
925 delegate->Reset(); 940 delegate->Reset();
926 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(95, 201), 0); 941 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(95, 201), kTouchId1);
927 root->DispatchTouchEvent(&move3); 942 root->DispatchTouchEvent(&move3);
928 EXPECT_FALSE(delegate->tap()); 943 EXPECT_FALSE(delegate->tap());
929 EXPECT_FALSE(delegate->tap_down()); 944 EXPECT_FALSE(delegate->tap_down());
930 EXPECT_FALSE(delegate->double_tap()); 945 EXPECT_FALSE(delegate->double_tap());
931 EXPECT_FALSE(delegate->scroll_begin()); 946 EXPECT_FALSE(delegate->scroll_begin());
932 EXPECT_FALSE(delegate->scroll_update()); 947 EXPECT_FALSE(delegate->scroll_update());
933 EXPECT_FALSE(delegate->scroll_end()); 948 EXPECT_FALSE(delegate->scroll_end());
934 EXPECT_FALSE(delegate->pinch_begin()); 949 EXPECT_FALSE(delegate->pinch_begin());
935 EXPECT_TRUE(delegate->pinch_update()); 950 EXPECT_TRUE(delegate->pinch_update());
936 951
937 // Now move the second finger. 952 // Now move the second finger.
938 delegate->Reset(); 953 delegate->Reset();
939 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), 1); 954 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), kTouchId2);
940 root->DispatchTouchEvent(&move4); 955 root->DispatchTouchEvent(&move4);
941 EXPECT_FALSE(delegate->tap()); 956 EXPECT_FALSE(delegate->tap());
942 EXPECT_FALSE(delegate->tap_down()); 957 EXPECT_FALSE(delegate->tap_down());
943 EXPECT_FALSE(delegate->double_tap()); 958 EXPECT_FALSE(delegate->double_tap());
944 EXPECT_FALSE(delegate->scroll_begin()); 959 EXPECT_FALSE(delegate->scroll_begin());
945 EXPECT_FALSE(delegate->scroll_update()); 960 EXPECT_FALSE(delegate->scroll_update());
946 EXPECT_FALSE(delegate->scroll_end()); 961 EXPECT_FALSE(delegate->scroll_end());
947 EXPECT_FALSE(delegate->pinch_begin()); 962 EXPECT_FALSE(delegate->pinch_begin());
948 EXPECT_TRUE(delegate->pinch_update()); 963 EXPECT_TRUE(delegate->pinch_update());
949 964
950 // Release the first finger. This should end pinch. 965 // Release the first finger. This should end pinch.
951 delegate->Reset(); 966 delegate->Reset();
952 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 967 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId1);
953 Event::TestApi test_release(&release); 968 Event::TestApi test_release(&release);
954 test_release.set_time_stamp(press.time_stamp() + 969 test_release.set_time_stamp(press.time_stamp() +
955 base::TimeDelta::FromMilliseconds(50)); 970 base::TimeDelta::FromMilliseconds(50));
956 root->DispatchTouchEvent(&release); 971 root->DispatchTouchEvent(&release);
957 EXPECT_FALSE(delegate->tap()); 972 EXPECT_FALSE(delegate->tap());
958 EXPECT_FALSE(delegate->tap_down()); 973 EXPECT_FALSE(delegate->tap_down());
959 EXPECT_FALSE(delegate->double_tap()); 974 EXPECT_FALSE(delegate->double_tap());
960 EXPECT_FALSE(delegate->scroll_begin()); 975 EXPECT_FALSE(delegate->scroll_begin());
961 EXPECT_FALSE(delegate->scroll_update()); 976 EXPECT_FALSE(delegate->scroll_update());
962 EXPECT_FALSE(delegate->scroll_end()); 977 EXPECT_FALSE(delegate->scroll_end());
963 EXPECT_TRUE(delegate->pinch_end()); 978 EXPECT_TRUE(delegate->pinch_end());
964 979
965 // Move the second finger. This should still generate a scroll. 980 // Move the second finger. This should still generate a scroll.
966 delegate->Reset(); 981 delegate->Reset();
967 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 1); 982 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), kTouchId2);
968 root->DispatchTouchEvent(&move5); 983 root->DispatchTouchEvent(&move5);
969 EXPECT_FALSE(delegate->tap()); 984 EXPECT_FALSE(delegate->tap());
970 EXPECT_FALSE(delegate->tap_down()); 985 EXPECT_FALSE(delegate->tap_down());
971 EXPECT_FALSE(delegate->double_tap()); 986 EXPECT_FALSE(delegate->double_tap());
972 EXPECT_FALSE(delegate->scroll_begin()); 987 EXPECT_FALSE(delegate->scroll_begin());
973 EXPECT_TRUE(delegate->scroll_update()); 988 EXPECT_TRUE(delegate->scroll_update());
974 EXPECT_FALSE(delegate->scroll_end()); 989 EXPECT_FALSE(delegate->scroll_end());
975 EXPECT_FALSE(delegate->pinch_begin()); 990 EXPECT_FALSE(delegate->pinch_begin());
976 EXPECT_FALSE(delegate->pinch_update()); 991 EXPECT_FALSE(delegate->pinch_update());
977 } 992 }
978 993
994 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) {
995 scoped_ptr<GestureEventConsumeDelegate> delegate(
996 new GestureEventConsumeDelegate());
997 const int kWindowWidth = 300;
998 const int kWindowHeight = 400;
999 const int kTouchId1 = 5;
1000 const int kTouchId2 = 3;
1001 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1002 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1003 delegate.get(), -1234, bounds, NULL));
1004
1005 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1);
1006 root_window()->DispatchTouchEvent(&press);
1007 delegate->Reset();
1008 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), kTouchId2);
1009 root_window()->DispatchTouchEvent(&press2);
1010 EXPECT_TRUE(delegate->pinch_begin());
1011
1012 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get());
1013 EXPECT_TRUE(delegate->pinch_update());
1014
1015 // Pinch has started, now release the second finger
1016 delegate->Reset();
1017 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId1);
1018 root_window()->DispatchTouchEvent(&release);
1019 EXPECT_TRUE(delegate->pinch_end());
1020
1021 SendScrollEvent(root_window(), 130, 230, kTouchId2, delegate.get());
1022 EXPECT_TRUE(delegate->scroll_update());
1023
1024 // Pinch again
1025 delegate->Reset();
1026 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), kTouchId1);
1027 root_window()->DispatchTouchEvent(&press3);
1028 EXPECT_TRUE(delegate->pinch_begin());
1029
1030 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get());
1031 EXPECT_TRUE(delegate->pinch_update());
1032 }
1033
979 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) { 1034 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) {
980 scoped_ptr<GestureEventConsumeDelegate> delegate( 1035 scoped_ptr<GestureEventConsumeDelegate> delegate(
981 new GestureEventConsumeDelegate()); 1036 new GestureEventConsumeDelegate());
982 const int kWindowWidth = 300; 1037 const int kWindowWidth = 300;
983 const int kWindowHeight = 400; 1038 const int kWindowHeight = 400;
1039 const int kTouchId1 = 3;
1040 const int kTouchId2 = 5;
984 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1041 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
985 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1042 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
986 delegate.get(), -1234, bounds, NULL)); 1043 delegate.get(), -1234, bounds, NULL));
987 1044
988 aura::RootWindow* root = root_window(); 1045 aura::RootWindow* root = root_window();
989 1046
990 delegate->Reset(); 1047 delegate->Reset();
991 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 0); 1048 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1);
992 root->DispatchTouchEvent(&press); 1049 root->DispatchTouchEvent(&press);
993 EXPECT_FALSE(delegate->tap()); 1050 EXPECT_FALSE(delegate->tap());
994 EXPECT_TRUE(delegate->tap_down()); 1051 EXPECT_TRUE(delegate->tap_down());
995 EXPECT_FALSE(delegate->double_tap()); 1052 EXPECT_FALSE(delegate->double_tap());
996 EXPECT_FALSE(delegate->scroll_begin()); 1053 EXPECT_FALSE(delegate->scroll_begin());
997 EXPECT_FALSE(delegate->scroll_update()); 1054 EXPECT_FALSE(delegate->scroll_update());
998 EXPECT_FALSE(delegate->scroll_end()); 1055 EXPECT_FALSE(delegate->scroll_end());
999 1056
1000 // Press the second finger. It should cause a tap-down, scroll-begin and 1057 // Press the second finger. It should cause a tap-down, scroll-begin and
1001 // pinch-begin. 1058 // pinch-begin.
1002 delegate->Reset(); 1059 delegate->Reset();
1003 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1); 1060 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), kTouchId2);
1004 root->DispatchTouchEvent(&press2); 1061 root->DispatchTouchEvent(&press2);
1005 EXPECT_FALSE(delegate->tap()); 1062 EXPECT_FALSE(delegate->tap());
1006 EXPECT_TRUE(delegate->tap_down()); 1063 EXPECT_TRUE(delegate->tap_down());
1007 EXPECT_FALSE(delegate->double_tap()); 1064 EXPECT_FALSE(delegate->double_tap());
1008 EXPECT_TRUE(delegate->scroll_begin()); 1065 EXPECT_TRUE(delegate->scroll_begin());
1009 EXPECT_FALSE(delegate->scroll_update()); 1066 EXPECT_FALSE(delegate->scroll_update());
1010 EXPECT_FALSE(delegate->scroll_end()); 1067 EXPECT_FALSE(delegate->scroll_end());
1011 EXPECT_TRUE(delegate->pinch_begin()); 1068 EXPECT_TRUE(delegate->pinch_begin());
1012 1069
1013 // Move the first finger. 1070 // Move the first finger.
1014 delegate->Reset(); 1071 delegate->Reset();
1015 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201), 0); 1072 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201), kTouchId1);
1016 root->DispatchTouchEvent(&move3); 1073 root->DispatchTouchEvent(&move3);
1017 EXPECT_FALSE(delegate->tap()); 1074 EXPECT_FALSE(delegate->tap());
1018 EXPECT_FALSE(delegate->tap_down()); 1075 EXPECT_FALSE(delegate->tap_down());
1019 EXPECT_FALSE(delegate->double_tap()); 1076 EXPECT_FALSE(delegate->double_tap());
1020 EXPECT_FALSE(delegate->scroll_begin()); 1077 EXPECT_FALSE(delegate->scroll_begin());
1021 EXPECT_FALSE(delegate->scroll_update()); 1078 EXPECT_FALSE(delegate->scroll_update());
1022 EXPECT_FALSE(delegate->scroll_end()); 1079 EXPECT_FALSE(delegate->scroll_end());
1023 EXPECT_FALSE(delegate->pinch_begin()); 1080 EXPECT_FALSE(delegate->pinch_begin());
1024 EXPECT_TRUE(delegate->pinch_update()); 1081 EXPECT_TRUE(delegate->pinch_update());
1025 1082
1026 // Now move the second finger. 1083 // Now move the second finger.
1027 delegate->Reset(); 1084 delegate->Reset();
1028 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), 1); 1085 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), kTouchId2);
1029 root->DispatchTouchEvent(&move4); 1086 root->DispatchTouchEvent(&move4);
1030 EXPECT_FALSE(delegate->tap()); 1087 EXPECT_FALSE(delegate->tap());
1031 EXPECT_FALSE(delegate->tap_down()); 1088 EXPECT_FALSE(delegate->tap_down());
1032 EXPECT_FALSE(delegate->double_tap()); 1089 EXPECT_FALSE(delegate->double_tap());
1033 EXPECT_FALSE(delegate->scroll_begin()); 1090 EXPECT_FALSE(delegate->scroll_begin());
1034 EXPECT_FALSE(delegate->scroll_update()); 1091 EXPECT_FALSE(delegate->scroll_update());
1035 EXPECT_FALSE(delegate->scroll_end()); 1092 EXPECT_FALSE(delegate->scroll_end());
1036 EXPECT_FALSE(delegate->pinch_begin()); 1093 EXPECT_FALSE(delegate->pinch_begin());
1037 EXPECT_TRUE(delegate->pinch_update()); 1094 EXPECT_TRUE(delegate->pinch_update());
1038 1095
1039 // Release the first finger. This should end pinch. 1096 // Release the first finger. This should end pinch.
1040 delegate->Reset(); 1097 delegate->Reset();
1041 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 0); 1098 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), kTouchId1);
1042 Event::TestApi test_release(&release); 1099 Event::TestApi test_release(&release);
1043 test_release.set_time_stamp(press.time_stamp() + 1100 test_release.set_time_stamp(press.time_stamp() +
1044 base::TimeDelta::FromMilliseconds(50)); 1101 base::TimeDelta::FromMilliseconds(50));
1045 root->DispatchTouchEvent(&release); 1102 root->DispatchTouchEvent(&release);
1046 EXPECT_FALSE(delegate->tap()); 1103 EXPECT_FALSE(delegate->tap());
1047 EXPECT_FALSE(delegate->tap_down()); 1104 EXPECT_FALSE(delegate->tap_down());
1048 EXPECT_FALSE(delegate->double_tap()); 1105 EXPECT_FALSE(delegate->double_tap());
1049 EXPECT_FALSE(delegate->scroll_begin()); 1106 EXPECT_FALSE(delegate->scroll_begin());
1050 EXPECT_FALSE(delegate->scroll_update()); 1107 EXPECT_FALSE(delegate->scroll_update());
1051 EXPECT_FALSE(delegate->scroll_end()); 1108 EXPECT_FALSE(delegate->scroll_end());
1052 EXPECT_TRUE(delegate->pinch_end()); 1109 EXPECT_TRUE(delegate->pinch_end());
1053 1110
1054 // Move the second finger. This should still generate a scroll. 1111 // Move the second finger. This should still generate a scroll.
1055 delegate->Reset(); 1112 delegate->Reset();
1056 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 1); 1113 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), kTouchId2);
1057 root->DispatchTouchEvent(&move5); 1114 root->DispatchTouchEvent(&move5);
1058 EXPECT_FALSE(delegate->tap()); 1115 EXPECT_FALSE(delegate->tap());
1059 EXPECT_FALSE(delegate->tap_down()); 1116 EXPECT_FALSE(delegate->tap_down());
1060 EXPECT_FALSE(delegate->double_tap()); 1117 EXPECT_FALSE(delegate->double_tap());
1061 EXPECT_FALSE(delegate->scroll_begin()); 1118 EXPECT_FALSE(delegate->scroll_begin());
1062 EXPECT_TRUE(delegate->scroll_update()); 1119 EXPECT_TRUE(delegate->scroll_update());
1063 EXPECT_FALSE(delegate->scroll_end()); 1120 EXPECT_FALSE(delegate->scroll_end());
1064 EXPECT_FALSE(delegate->pinch_begin()); 1121 EXPECT_FALSE(delegate->pinch_begin());
1065 EXPECT_FALSE(delegate->pinch_update()); 1122 EXPECT_FALSE(delegate->pinch_update());
1066 } 1123 }
1067 1124
1125 TEST_F(GestureRecognizerTest, GestureEventPinchScrollOnlyWhenBothFingersMove) {
1126 scoped_ptr<GestureEventConsumeDelegate> delegate(
1127 new GestureEventConsumeDelegate());
1128 const int kWindowWidth = 1000;
1129 const int kWindowHeight = 1000;
1130 const int kTouchId1 = 3;
1131 const int kTouchId2 = 5;
1132 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
1133 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1134 delegate.get(), -1234, bounds, NULL));
1135
1136 delegate->Reset();
1137 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(100, 100), kTouchId1);
1138
1139 root_window()->DispatchTouchEvent(&press1);
1140
1141 delegate->Reset();
1142 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(110, 110), kTouchId2);
1143 root_window()->DispatchTouchEvent(&press2);
1144
1145 SendScrollEvents(root_window(), 100, 100, press1.time_stamp(),
1146 1, 10, kTouchId1, 1, kBufferedPoints, delegate.get());
1147
1148 SendScrollEvents(root_window(), 110, 110, press1.time_stamp() +
1149 base::TimeDelta::FromMilliseconds(1000),
1150 1, 10, kTouchId2, 1, kBufferedPoints, delegate.get());
1151 // At no point were both fingers moving at the same time,
1152 // so no scrolling should have occurred
1153
1154 EXPECT_EQ(0, delegate->scroll_x());
1155 EXPECT_EQ(0, delegate->scroll_y());
1156 }
1157
1158 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) {
1159 scoped_ptr<GestureEventConsumeDelegate> delegate(
1160 new GestureEventConsumeDelegate());
1161
1162 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 6);
1163 root_window()->DispatchTouchEvent(&release1);
1164 EXPECT_FALSE(delegate->tap());
1165 EXPECT_FALSE(delegate->tap_down());
1166 }
1167
1068 } // namespace test 1168 } // namespace test
1069 } // namespace aura 1169 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698