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

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

Issue 10827145: Convert Aura to use ui::Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « ui/aura/focus_manager.cc ('k') | ui/aura/root_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/string_number_conversions.h" 6 #include "base/string_number_conversions.h"
7 #include "base/timer.h" 7 #include "base/timer.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/aura/event.h"
10 #include "ui/aura/root_window.h" 9 #include "ui/aura/root_window.h"
11 #include "ui/aura/test/aura_test_base.h" 10 #include "ui/aura/test/aura_test_base.h"
12 #include "ui/aura/test/event_generator.h" 11 #include "ui/aura/test/event_generator.h"
13 #include "ui/aura/test/test_window_delegate.h" 12 #include "ui/aura/test/test_window_delegate.h"
14 #include "ui/aura/test/test_windows.h" 13 #include "ui/aura/test/test_windows.h"
14 #include "ui/base/event.h"
15 #include "ui/base/gestures/gesture_configuration.h" 15 #include "ui/base/gestures/gesture_configuration.h"
16 #include "ui/base/gestures/gesture_recognizer_impl.h" 16 #include "ui/base/gestures/gesture_recognizer_impl.h"
17 #include "ui/base/gestures/gesture_sequence.h" 17 #include "ui/base/gestures/gesture_sequence.h"
18 #include "ui/base/gestures/gesture_types.h" 18 #include "ui/base/gestures/gesture_types.h"
19 #include "ui/base/hit_test.h" 19 #include "ui/base/hit_test.h"
20 #include "ui/gfx/point.h" 20 #include "ui/gfx/point.h"
21 #include "ui/gfx/rect.h" 21 #include "ui/gfx/rect.h"
22 22
23 namespace aura { 23 namespace aura {
24 namespace test { 24 namespace test {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 108
109 float scroll_x() const { return scroll_x_; } 109 float scroll_x() const { return scroll_x_; }
110 float scroll_y() const { return scroll_y_; } 110 float scroll_y() const { return scroll_y_; }
111 int touch_id() const { return touch_id_; } 111 int touch_id() const { return touch_id_; }
112 float velocity_x() const { return velocity_x_; } 112 float velocity_x() const { return velocity_x_; }
113 float velocity_y() const { return velocity_y_; } 113 float velocity_y() const { return velocity_y_; }
114 const gfx::Rect& bounding_box() const { return bounding_box_; } 114 const gfx::Rect& bounding_box() const { return bounding_box_; }
115 int tap_count() const { return tap_count_; } 115 int tap_count() const { return tap_count_; }
116 116
117 virtual ui::GestureStatus OnGestureEvent(GestureEvent* gesture) OVERRIDE { 117 virtual ui::GestureStatus OnGestureEvent(
118 ui::GestureEventImpl* gesture) OVERRIDE {
118 bounding_box_ = gesture->details().bounding_box(); 119 bounding_box_ = gesture->details().bounding_box();
119 switch (gesture->type()) { 120 switch (gesture->type()) {
120 case ui::ET_GESTURE_TAP: 121 case ui::ET_GESTURE_TAP:
121 tap_location_ = gesture->location(); 122 tap_location_ = gesture->location();
122 tap_count_ = gesture->details().tap_count(); 123 tap_count_ = gesture->details().tap_count();
123 tap_ = true; 124 tap_ = true;
124 break; 125 break;
125 case ui::ET_GESTURE_TAP_DOWN: 126 case ui::ET_GESTURE_TAP_DOWN:
126 tap_down_ = true; 127 tap_down_ = true;
127 break; 128 break;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 }; 207 };
207 208
208 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 209 class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
209 public: 210 public:
210 explicit QueueTouchEventDelegate(RootWindow* root_window) 211 explicit QueueTouchEventDelegate(RootWindow* root_window)
211 : window_(NULL), 212 : window_(NULL),
212 root_window_(root_window) { 213 root_window_(root_window) {
213 } 214 }
214 virtual ~QueueTouchEventDelegate() {} 215 virtual ~QueueTouchEventDelegate() {}
215 216
216 virtual ui::TouchStatus OnTouchEvent(TouchEvent* event) OVERRIDE { 217 virtual ui::TouchStatus OnTouchEvent(ui::TouchEventImpl* event) OVERRIDE {
217 return event->type() == ui::ET_TOUCH_RELEASED ? 218 return event->type() == ui::ET_TOUCH_RELEASED ?
218 ui::TOUCH_STATUS_QUEUED_END : ui::TOUCH_STATUS_QUEUED; 219 ui::TOUCH_STATUS_QUEUED_END : ui::TOUCH_STATUS_QUEUED;
219 } 220 }
220 221
221 void ReceivedAck() { 222 void ReceivedAck() {
222 root_window_->AdvanceQueuedTouchEvent(window_, false); 223 root_window_->AdvanceQueuedTouchEvent(window_, false);
223 } 224 }
224 225
225 void ReceivedAckPreventDefaulted() { 226 void ReceivedAckPreventDefaulted() {
226 root_window_->AdvanceQueuedTouchEvent(window_, true); 227 root_window_->AdvanceQueuedTouchEvent(window_, true);
(...skipping 30 matching lines...) Expand all
257 double_click_ = false; 258 double_click_ = false;
258 } 259 }
259 260
260 bool mouse_enter() const { return mouse_enter_; } 261 bool mouse_enter() const { return mouse_enter_; }
261 bool mouse_exit() const { return mouse_exit_; } 262 bool mouse_exit() const { return mouse_exit_; }
262 bool mouse_press() const { return mouse_press_; } 263 bool mouse_press() const { return mouse_press_; }
263 bool mouse_move() const { return mouse_move_; } 264 bool mouse_move() const { return mouse_move_; }
264 bool mouse_release() const { return mouse_release_; } 265 bool mouse_release() const { return mouse_release_; }
265 bool double_click() const { return double_click_; } 266 bool double_click() const { return double_click_; }
266 267
267 virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { 268 virtual bool OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
268 switch (event->type()) { 269 switch (event->type()) {
269 case ui::ET_MOUSE_PRESSED: 270 case ui::ET_MOUSE_PRESSED:
270 double_click_ = event->flags() & ui::EF_IS_DOUBLE_CLICK; 271 double_click_ = event->flags() & ui::EF_IS_DOUBLE_CLICK;
271 mouse_press_ = true; 272 mouse_press_ = true;
272 break; 273 break;
273 case ui::ET_MOUSE_RELEASED: 274 case ui::ET_MOUSE_RELEASED:
274 mouse_release_ = true; 275 mouse_release_ = true;
275 break; 276 break;
276 case ui::ET_MOUSE_MOVED: 277 case ui::ET_MOUSE_MOVED:
277 mouse_move_ = true; 278 mouse_move_ = true;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 int num_steps, 369 int num_steps,
369 GestureEventConsumeDelegate* delegate) { 370 GestureEventConsumeDelegate* delegate) {
370 int x = x_start; 371 int x = x_start;
371 int y = y_start; 372 int y = y_start;
372 base::TimeDelta time = time_start; 373 base::TimeDelta time = time_start;
373 374
374 for (int i = 0; i < num_steps; i++) { 375 for (int i = 0; i < num_steps; i++) {
375 x += dx; 376 x += dx;
376 y += dy; 377 y += dy;
377 time = time + base::TimeDelta::FromMilliseconds(time_step); 378 time = time + base::TimeDelta::FromMilliseconds(time_step);
378 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 379 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(x, y),
379 touch_id, time); 380 touch_id, time);
380 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 381 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
381 } 382 }
382 } 383 }
383 384
384 void SendScrollEvent(RootWindow* root_window, 385 void SendScrollEvent(RootWindow* root_window,
385 int x, 386 int x,
386 int y, 387 int y,
387 int touch_id, 388 int touch_id,
388 GestureEventConsumeDelegate* delegate) { 389 GestureEventConsumeDelegate* delegate) {
389 delegate->Reset(); 390 delegate->Reset();
390 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 391 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(x, y),
391 touch_id, GetTime()); 392 touch_id, GetTime());
392 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 393 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
393 } 394 }
394 395
395 } // namespace 396 } // namespace
396 397
397 typedef AuraTestBase GestureRecognizerTest; 398 typedef AuraTestBase GestureRecognizerTest;
398 399
399 // Check that appropriate touch events generate tap gesture events. 400 // Check that appropriate touch events generate tap gesture events.
400 TEST_F(GestureRecognizerTest, GestureEventTap) { 401 TEST_F(GestureRecognizerTest, GestureEventTap) {
401 scoped_ptr<GestureEventConsumeDelegate> delegate( 402 scoped_ptr<GestureEventConsumeDelegate> delegate(
402 new GestureEventConsumeDelegate()); 403 new GestureEventConsumeDelegate());
403 const int kWindowWidth = 123; 404 const int kWindowWidth = 123;
404 const int kWindowHeight = 45; 405 const int kWindowHeight = 45;
405 const int kTouchId = 2; 406 const int kTouchId = 2;
406 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 407 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
407 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 408 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
408 delegate.get(), -1234, bounds, NULL)); 409 delegate.get(), -1234, bounds, NULL));
409 410
410 delegate->Reset(); 411 delegate->Reset();
411 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 412 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
412 kTouchId, GetTime()); 413 kTouchId, GetTime());
413 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 414 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
414 EXPECT_FALSE(delegate->tap()); 415 EXPECT_FALSE(delegate->tap());
415 EXPECT_TRUE(delegate->tap_down()); 416 EXPECT_TRUE(delegate->tap_down());
416 EXPECT_TRUE(delegate->begin()); 417 EXPECT_TRUE(delegate->begin());
417 EXPECT_FALSE(delegate->double_tap()); 418 EXPECT_FALSE(delegate->double_tap());
418 EXPECT_FALSE(delegate->scroll_begin()); 419 EXPECT_FALSE(delegate->scroll_begin());
419 EXPECT_FALSE(delegate->scroll_update()); 420 EXPECT_FALSE(delegate->scroll_update());
420 EXPECT_FALSE(delegate->scroll_end()); 421 EXPECT_FALSE(delegate->scroll_end());
421 EXPECT_FALSE(delegate->long_press()); 422 EXPECT_FALSE(delegate->long_press());
422 423
423 // Make sure there is enough delay before the touch is released so that it is 424 // Make sure there is enough delay before the touch is released so that it is
424 // recognized as a tap. 425 // recognized as a tap.
425 delegate->Reset(); 426 delegate->Reset();
426 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 427 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
427 kTouchId, press.time_stamp() + 428 kTouchId, press.time_stamp() +
428 base::TimeDelta::FromMilliseconds(50)); 429 base::TimeDelta::FromMilliseconds(50));
429 430
430 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 431 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
431 EXPECT_TRUE(delegate->tap()); 432 EXPECT_TRUE(delegate->tap());
432 EXPECT_FALSE(delegate->tap_down()); 433 EXPECT_FALSE(delegate->tap_down());
433 EXPECT_FALSE(delegate->begin()); 434 EXPECT_FALSE(delegate->begin());
434 EXPECT_TRUE(delegate->end()); 435 EXPECT_TRUE(delegate->end());
435 EXPECT_FALSE(delegate->double_tap()); 436 EXPECT_FALSE(delegate->double_tap());
436 EXPECT_FALSE(delegate->scroll_begin()); 437 EXPECT_FALSE(delegate->scroll_begin());
437 EXPECT_FALSE(delegate->scroll_update()); 438 EXPECT_FALSE(delegate->scroll_update());
438 EXPECT_FALSE(delegate->scroll_end()); 439 EXPECT_FALSE(delegate->scroll_end());
439 440
440 EXPECT_EQ(1, delegate->tap_count()); 441 EXPECT_EQ(1, delegate->tap_count());
441 } 442 }
442 443
443 // Check that appropriate touch events generate tap gesture events 444 // Check that appropriate touch events generate tap gesture events
444 // when information about the touch radii are provided. 445 // when information about the touch radii are provided.
445 TEST_F(GestureRecognizerTest, GestureEventTapRegion) { 446 TEST_F(GestureRecognizerTest, GestureEventTapRegion) {
446 scoped_ptr<GestureEventConsumeDelegate> delegate( 447 scoped_ptr<GestureEventConsumeDelegate> delegate(
447 new GestureEventConsumeDelegate()); 448 new GestureEventConsumeDelegate());
448 const int kWindowWidth = 800; 449 const int kWindowWidth = 800;
449 const int kWindowHeight = 600; 450 const int kWindowHeight = 600;
450 const int kTouchId = 2; 451 const int kTouchId = 2;
451 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 452 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
452 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 453 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
453 delegate.get(), -1234, bounds, NULL)); 454 delegate.get(), -1234, bounds, NULL));
454 455
455 // Test with no ET_TOUCH_MOVED events. 456 // Test with no ET_TOUCH_MOVED events.
456 { 457 {
457 delegate->Reset(); 458 delegate->Reset();
458 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 459 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
459 kTouchId, GetTime()); 460 kTouchId, GetTime());
460 press.set_radius_x(5); 461 press.set_radius_x(5);
461 press.set_radius_y(12); 462 press.set_radius_y(12);
462 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 463 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
463 EXPECT_FALSE(delegate->tap()); 464 EXPECT_FALSE(delegate->tap());
464 EXPECT_TRUE(delegate->tap_down()); 465 EXPECT_TRUE(delegate->tap_down());
465 EXPECT_TRUE(delegate->begin()); 466 EXPECT_TRUE(delegate->begin());
466 EXPECT_FALSE(delegate->double_tap()); 467 EXPECT_FALSE(delegate->double_tap());
467 EXPECT_FALSE(delegate->scroll_begin()); 468 EXPECT_FALSE(delegate->scroll_begin());
468 EXPECT_FALSE(delegate->scroll_update()); 469 EXPECT_FALSE(delegate->scroll_update());
469 EXPECT_FALSE(delegate->scroll_end()); 470 EXPECT_FALSE(delegate->scroll_end());
470 EXPECT_FALSE(delegate->long_press()); 471 EXPECT_FALSE(delegate->long_press());
471 472
472 // Make sure there is enough delay before the touch is released so that it 473 // Make sure there is enough delay before the touch is released so that it
473 // is recognized as a tap. 474 // is recognized as a tap.
474 delegate->Reset(); 475 delegate->Reset();
475 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 476 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
476 kTouchId, press.time_stamp() + 477 kTouchId, press.time_stamp() +
477 base::TimeDelta::FromMilliseconds(50)); 478 base::TimeDelta::FromMilliseconds(50));
478 release.set_radius_x(5); 479 release.set_radius_x(5);
479 release.set_radius_y(12); 480 release.set_radius_y(12);
480 481
481 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 482 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
482 EXPECT_TRUE(delegate->tap()); 483 EXPECT_TRUE(delegate->tap());
483 EXPECT_FALSE(delegate->tap_down()); 484 EXPECT_FALSE(delegate->tap_down());
484 EXPECT_FALSE(delegate->begin()); 485 EXPECT_FALSE(delegate->begin());
485 EXPECT_TRUE(delegate->end()); 486 EXPECT_TRUE(delegate->end());
486 EXPECT_FALSE(delegate->double_tap()); 487 EXPECT_FALSE(delegate->double_tap());
487 EXPECT_FALSE(delegate->scroll_begin()); 488 EXPECT_FALSE(delegate->scroll_begin());
488 EXPECT_FALSE(delegate->scroll_update()); 489 EXPECT_FALSE(delegate->scroll_update());
489 EXPECT_FALSE(delegate->scroll_end()); 490 EXPECT_FALSE(delegate->scroll_end());
490 491
491 EXPECT_EQ(1, delegate->tap_count()); 492 EXPECT_EQ(1, delegate->tap_count());
492 gfx::Point actual_point(delegate->tap_location()); 493 gfx::Point actual_point(delegate->tap_location());
493 EXPECT_EQ(24, delegate->bounding_box().width()); 494 EXPECT_EQ(24, delegate->bounding_box().width());
494 EXPECT_EQ(24, delegate->bounding_box().height()); 495 EXPECT_EQ(24, delegate->bounding_box().height());
495 EXPECT_EQ(100, actual_point.x()); 496 EXPECT_EQ(100, actual_point.x());
496 EXPECT_EQ(200, actual_point.y()); 497 EXPECT_EQ(200, actual_point.y());
497 } 498 }
498 499
499 // Test with no ET_TOUCH_MOVED events but different touch points and radii. 500 // Test with no ET_TOUCH_MOVED events but different touch points and radii.
500 { 501 {
501 delegate->Reset(); 502 delegate->Reset();
502 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(365, 290), 503 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(365, 290),
503 kTouchId, GetTime()); 504 kTouchId, GetTime());
504 press.set_radius_x(8); 505 press.set_radius_x(8);
505 press.set_radius_y(14); 506 press.set_radius_y(14);
506 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 507 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
507 EXPECT_FALSE(delegate->tap()); 508 EXPECT_FALSE(delegate->tap());
508 EXPECT_TRUE(delegate->tap_down()); 509 EXPECT_TRUE(delegate->tap_down());
509 EXPECT_TRUE(delegate->begin()); 510 EXPECT_TRUE(delegate->begin());
510 EXPECT_FALSE(delegate->double_tap()); 511 EXPECT_FALSE(delegate->double_tap());
511 EXPECT_FALSE(delegate->scroll_begin()); 512 EXPECT_FALSE(delegate->scroll_begin());
512 EXPECT_FALSE(delegate->scroll_update()); 513 EXPECT_FALSE(delegate->scroll_update());
513 EXPECT_FALSE(delegate->scroll_end()); 514 EXPECT_FALSE(delegate->scroll_end());
514 EXPECT_FALSE(delegate->long_press()); 515 EXPECT_FALSE(delegate->long_press());
515 516
516 delegate->Reset(); 517 delegate->Reset();
517 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(377, 291), 518 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(377, 291),
518 kTouchId, press.time_stamp() + 519 kTouchId, press.time_stamp() +
519 base::TimeDelta::FromMilliseconds(50)); 520 base::TimeDelta::FromMilliseconds(50));
520 release.set_radius_x(20); 521 release.set_radius_x(20);
521 release.set_radius_y(13); 522 release.set_radius_y(13);
522 523
523 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 524 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
524 EXPECT_TRUE(delegate->tap()); 525 EXPECT_TRUE(delegate->tap());
525 EXPECT_FALSE(delegate->tap_down()); 526 EXPECT_FALSE(delegate->tap_down());
526 EXPECT_FALSE(delegate->begin()); 527 EXPECT_FALSE(delegate->begin());
527 EXPECT_TRUE(delegate->end()); 528 EXPECT_TRUE(delegate->end());
528 EXPECT_FALSE(delegate->double_tap()); 529 EXPECT_FALSE(delegate->double_tap());
529 EXPECT_FALSE(delegate->scroll_begin()); 530 EXPECT_FALSE(delegate->scroll_begin());
530 EXPECT_FALSE(delegate->scroll_update()); 531 EXPECT_FALSE(delegate->scroll_update());
531 EXPECT_FALSE(delegate->scroll_end()); 532 EXPECT_FALSE(delegate->scroll_end());
532 533
533 EXPECT_EQ(1, delegate->tap_count()); 534 EXPECT_EQ(1, delegate->tap_count());
534 gfx::Point actual_point(delegate->tap_location()); 535 gfx::Point actual_point(delegate->tap_location());
535 EXPECT_EQ(46, delegate->bounding_box().width()); 536 EXPECT_EQ(46, delegate->bounding_box().width());
536 EXPECT_EQ(40, delegate->bounding_box().height()); 537 EXPECT_EQ(40, delegate->bounding_box().height());
537 EXPECT_EQ(373, actual_point.x()); 538 EXPECT_EQ(373, actual_point.x());
538 EXPECT_EQ(290, actual_point.y()); 539 EXPECT_EQ(290, actual_point.y());
539 } 540 }
540 541
541 // Test with a single ET_TOUCH_MOVED event. 542 // Test with a single ET_TOUCH_MOVED event.
542 { 543 {
543 delegate->Reset(); 544 delegate->Reset();
544 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(46, 205), 545 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(46, 205),
545 kTouchId, GetTime()); 546 kTouchId, GetTime());
546 press.set_radius_x(6); 547 press.set_radius_x(6);
547 press.set_radius_y(10); 548 press.set_radius_y(10);
548 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 549 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
549 EXPECT_FALSE(delegate->tap()); 550 EXPECT_FALSE(delegate->tap());
550 EXPECT_TRUE(delegate->tap_down()); 551 EXPECT_TRUE(delegate->tap_down());
551 EXPECT_TRUE(delegate->begin()); 552 EXPECT_TRUE(delegate->begin());
552 EXPECT_FALSE(delegate->double_tap()); 553 EXPECT_FALSE(delegate->double_tap());
553 EXPECT_FALSE(delegate->scroll_begin()); 554 EXPECT_FALSE(delegate->scroll_begin());
554 EXPECT_FALSE(delegate->scroll_update()); 555 EXPECT_FALSE(delegate->scroll_update());
555 EXPECT_FALSE(delegate->scroll_end()); 556 EXPECT_FALSE(delegate->scroll_end());
556 EXPECT_FALSE(delegate->long_press()); 557 EXPECT_FALSE(delegate->long_press());
557 558
558 delegate->Reset(); 559 delegate->Reset();
559 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(52, 200), 560 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(52, 200),
560 kTouchId, press.time_stamp() + 561 kTouchId, press.time_stamp() +
561 base::TimeDelta::FromMilliseconds(50)); 562 base::TimeDelta::FromMilliseconds(50));
562 move.set_radius_x(8); 563 move.set_radius_x(8);
563 move.set_radius_y(12); 564 move.set_radius_y(12);
564 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 565 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
565 EXPECT_FALSE(delegate->tap()); 566 EXPECT_FALSE(delegate->tap());
566 EXPECT_FALSE(delegate->tap_down()); 567 EXPECT_FALSE(delegate->tap_down());
567 EXPECT_FALSE(delegate->begin()); 568 EXPECT_FALSE(delegate->begin());
568 EXPECT_FALSE(delegate->double_tap()); 569 EXPECT_FALSE(delegate->double_tap());
569 EXPECT_FALSE(delegate->scroll_begin()); 570 EXPECT_FALSE(delegate->scroll_begin());
570 EXPECT_FALSE(delegate->scroll_update()); 571 EXPECT_FALSE(delegate->scroll_update());
571 EXPECT_FALSE(delegate->scroll_end()); 572 EXPECT_FALSE(delegate->scroll_end());
572 EXPECT_FALSE(delegate->long_press()); 573 EXPECT_FALSE(delegate->long_press());
573 574
574 delegate->Reset(); 575 delegate->Reset();
575 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(50, 195), 576 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(50, 195),
576 kTouchId, press.time_stamp() + 577 kTouchId, press.time_stamp() +
577 base::TimeDelta::FromMilliseconds(50)); 578 base::TimeDelta::FromMilliseconds(50));
578 release.set_radius_x(4); 579 release.set_radius_x(4);
579 release.set_radius_y(8); 580 release.set_radius_y(8);
580 581
581 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 582 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
582 EXPECT_TRUE(delegate->tap()); 583 EXPECT_TRUE(delegate->tap());
583 EXPECT_FALSE(delegate->tap_down()); 584 EXPECT_FALSE(delegate->tap_down());
584 EXPECT_FALSE(delegate->begin()); 585 EXPECT_FALSE(delegate->begin());
585 EXPECT_TRUE(delegate->end()); 586 EXPECT_TRUE(delegate->end());
586 EXPECT_FALSE(delegate->double_tap()); 587 EXPECT_FALSE(delegate->double_tap());
587 EXPECT_FALSE(delegate->scroll_begin()); 588 EXPECT_FALSE(delegate->scroll_begin());
588 EXPECT_FALSE(delegate->scroll_update()); 589 EXPECT_FALSE(delegate->scroll_update());
589 EXPECT_FALSE(delegate->scroll_end()); 590 EXPECT_FALSE(delegate->scroll_end());
590 591
591 EXPECT_EQ(1, delegate->tap_count()); 592 EXPECT_EQ(1, delegate->tap_count());
592 gfx::Point actual_point(delegate->tap_location()); 593 gfx::Point actual_point(delegate->tap_location());
593 EXPECT_EQ(28, delegate->bounding_box().width()); 594 EXPECT_EQ(28, delegate->bounding_box().width());
594 EXPECT_EQ(28, delegate->bounding_box().height()); 595 EXPECT_EQ(28, delegate->bounding_box().height());
595 EXPECT_EQ(49, actual_point.x()); 596 EXPECT_EQ(49, actual_point.x());
596 EXPECT_EQ(200, actual_point.y()); 597 EXPECT_EQ(200, actual_point.y());
597 } 598 }
598 599
599 // Test with a few ET_TOUCH_MOVED events. 600 // Test with a few ET_TOUCH_MOVED events.
600 { 601 {
601 delegate->Reset(); 602 delegate->Reset();
602 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(400, 150), 603 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(400, 150),
603 kTouchId, GetTime()); 604 kTouchId, GetTime());
604 press.set_radius_x(7); 605 press.set_radius_x(7);
605 press.set_radius_y(10); 606 press.set_radius_y(10);
606 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 607 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
607 EXPECT_FALSE(delegate->tap()); 608 EXPECT_FALSE(delegate->tap());
608 EXPECT_TRUE(delegate->tap_down()); 609 EXPECT_TRUE(delegate->tap_down());
609 EXPECT_TRUE(delegate->begin()); 610 EXPECT_TRUE(delegate->begin());
610 EXPECT_FALSE(delegate->double_tap()); 611 EXPECT_FALSE(delegate->double_tap());
611 EXPECT_FALSE(delegate->scroll_begin()); 612 EXPECT_FALSE(delegate->scroll_begin());
612 EXPECT_FALSE(delegate->scroll_update()); 613 EXPECT_FALSE(delegate->scroll_update());
613 EXPECT_FALSE(delegate->scroll_end()); 614 EXPECT_FALSE(delegate->scroll_end());
614 EXPECT_FALSE(delegate->long_press()); 615 EXPECT_FALSE(delegate->long_press());
615 616
616 delegate->Reset(); 617 delegate->Reset();
617 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(397, 155), 618 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(397, 155),
618 kTouchId, press.time_stamp() + 619 kTouchId, press.time_stamp() +
619 base::TimeDelta::FromMilliseconds(50)); 620 base::TimeDelta::FromMilliseconds(50));
620 move.set_radius_x(13); 621 move.set_radius_x(13);
621 move.set_radius_y(12); 622 move.set_radius_y(12);
622 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 623 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
623 EXPECT_FALSE(delegate->tap()); 624 EXPECT_FALSE(delegate->tap());
624 EXPECT_FALSE(delegate->tap_down()); 625 EXPECT_FALSE(delegate->tap_down());
625 EXPECT_FALSE(delegate->begin()); 626 EXPECT_FALSE(delegate->begin());
626 EXPECT_FALSE(delegate->double_tap()); 627 EXPECT_FALSE(delegate->double_tap());
627 EXPECT_FALSE(delegate->scroll_begin()); 628 EXPECT_FALSE(delegate->scroll_begin());
628 EXPECT_FALSE(delegate->scroll_update()); 629 EXPECT_FALSE(delegate->scroll_update());
629 EXPECT_FALSE(delegate->scroll_end()); 630 EXPECT_FALSE(delegate->scroll_end());
630 EXPECT_FALSE(delegate->long_press()); 631 EXPECT_FALSE(delegate->long_press());
631 632
632 delegate->Reset(); 633 delegate->Reset();
633 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(395, 148), 634 ui::TouchEventImpl move1(ui::ET_TOUCH_MOVED, gfx::Point(395, 148),
634 kTouchId, move.time_stamp() + 635 kTouchId, move.time_stamp() +
635 base::TimeDelta::FromMilliseconds(50)); 636 base::TimeDelta::FromMilliseconds(50));
636 move1.set_radius_x(16); 637 move1.set_radius_x(16);
637 move1.set_radius_y(16); 638 move1.set_radius_y(16);
638 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 639 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
639 EXPECT_FALSE(delegate->tap()); 640 EXPECT_FALSE(delegate->tap());
640 EXPECT_FALSE(delegate->tap_down()); 641 EXPECT_FALSE(delegate->tap_down());
641 EXPECT_FALSE(delegate->begin()); 642 EXPECT_FALSE(delegate->begin());
642 EXPECT_FALSE(delegate->double_tap()); 643 EXPECT_FALSE(delegate->double_tap());
643 EXPECT_FALSE(delegate->scroll_begin()); 644 EXPECT_FALSE(delegate->scroll_begin());
644 EXPECT_FALSE(delegate->scroll_update()); 645 EXPECT_FALSE(delegate->scroll_update());
645 EXPECT_FALSE(delegate->scroll_end()); 646 EXPECT_FALSE(delegate->scroll_end());
646 EXPECT_FALSE(delegate->long_press()); 647 EXPECT_FALSE(delegate->long_press());
647 648
648 delegate->Reset(); 649 delegate->Reset();
649 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(400, 150), 650 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(400, 150),
650 kTouchId, move1.time_stamp() + 651 kTouchId, move1.time_stamp() +
651 base::TimeDelta::FromMilliseconds(50)); 652 base::TimeDelta::FromMilliseconds(50));
652 move2.set_radius_x(14); 653 move2.set_radius_x(14);
653 move2.set_radius_y(10); 654 move2.set_radius_y(10);
654 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 655 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
655 EXPECT_FALSE(delegate->tap()); 656 EXPECT_FALSE(delegate->tap());
656 EXPECT_FALSE(delegate->tap_down()); 657 EXPECT_FALSE(delegate->tap_down());
657 EXPECT_FALSE(delegate->begin()); 658 EXPECT_FALSE(delegate->begin());
658 EXPECT_FALSE(delegate->double_tap()); 659 EXPECT_FALSE(delegate->double_tap());
659 EXPECT_FALSE(delegate->scroll_begin()); 660 EXPECT_FALSE(delegate->scroll_begin());
660 EXPECT_FALSE(delegate->scroll_update()); 661 EXPECT_FALSE(delegate->scroll_update());
661 EXPECT_FALSE(delegate->scroll_end()); 662 EXPECT_FALSE(delegate->scroll_end());
662 EXPECT_FALSE(delegate->long_press()); 663 EXPECT_FALSE(delegate->long_press());
663 664
664 delegate->Reset(); 665 delegate->Reset();
665 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(401, 149), 666 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(401, 149),
666 kTouchId, press.time_stamp() + 667 kTouchId, press.time_stamp() +
667 base::TimeDelta::FromMilliseconds(50)); 668 base::TimeDelta::FromMilliseconds(50));
668 release.set_radius_x(8); 669 release.set_radius_x(8);
669 release.set_radius_y(9); 670 release.set_radius_y(9);
670 671
671 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 672 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
672 EXPECT_TRUE(delegate->tap()); 673 EXPECT_TRUE(delegate->tap());
673 EXPECT_FALSE(delegate->tap_down()); 674 EXPECT_FALSE(delegate->tap_down());
674 EXPECT_FALSE(delegate->begin()); 675 EXPECT_FALSE(delegate->begin());
675 EXPECT_TRUE(delegate->end()); 676 EXPECT_TRUE(delegate->end());
676 EXPECT_FALSE(delegate->double_tap()); 677 EXPECT_FALSE(delegate->double_tap());
677 EXPECT_FALSE(delegate->scroll_begin()); 678 EXPECT_FALSE(delegate->scroll_begin());
(...skipping 14 matching lines...) Expand all
692 scoped_ptr<GestureEventConsumeDelegate> delegate( 693 scoped_ptr<GestureEventConsumeDelegate> delegate(
693 new GestureEventConsumeDelegate()); 694 new GestureEventConsumeDelegate());
694 const int kWindowWidth = 123; 695 const int kWindowWidth = 123;
695 const int kWindowHeight = 45; 696 const int kWindowHeight = 45;
696 const int kTouchId = 5; 697 const int kTouchId = 5;
697 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 698 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
698 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 699 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
699 delegate.get(), -1234, bounds, NULL)); 700 delegate.get(), -1234, bounds, NULL));
700 701
701 delegate->Reset(); 702 delegate->Reset();
702 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 703 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
703 kTouchId, GetTime()); 704 kTouchId, GetTime());
704 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 705 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
705 EXPECT_FALSE(delegate->tap()); 706 EXPECT_FALSE(delegate->tap());
706 EXPECT_TRUE(delegate->tap_down()); 707 EXPECT_TRUE(delegate->tap_down());
707 EXPECT_TRUE(delegate->begin()); 708 EXPECT_TRUE(delegate->begin());
708 EXPECT_FALSE(delegate->double_tap()); 709 EXPECT_FALSE(delegate->double_tap());
709 EXPECT_FALSE(delegate->scroll_begin()); 710 EXPECT_FALSE(delegate->scroll_begin());
710 EXPECT_FALSE(delegate->scroll_update()); 711 EXPECT_FALSE(delegate->scroll_update());
711 EXPECT_FALSE(delegate->scroll_end()); 712 EXPECT_FALSE(delegate->scroll_end());
712 713
713 // Move the touch-point enough so that it is considered as a scroll. This 714 // Move the touch-point enough so that it is considered as a scroll. This
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 EXPECT_FALSE(delegate->double_tap()); 752 EXPECT_FALSE(delegate->double_tap());
752 EXPECT_FALSE(delegate->scroll_begin()); 753 EXPECT_FALSE(delegate->scroll_begin());
753 EXPECT_TRUE(delegate->scroll_update()); 754 EXPECT_TRUE(delegate->scroll_update());
754 EXPECT_FALSE(delegate->scroll_end()); 755 EXPECT_FALSE(delegate->scroll_end());
755 EXPECT_EQ(30, delegate->scroll_x()); 756 EXPECT_EQ(30, delegate->scroll_x());
756 EXPECT_EQ(4, delegate->scroll_y()); 757 EXPECT_EQ(4, delegate->scroll_y());
757 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 758 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
758 759
759 // Release the touch. This should end the scroll. 760 // Release the touch. This should end the scroll.
760 delegate->Reset(); 761 delegate->Reset();
761 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 762 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
762 kTouchId, press.time_stamp() + 763 kTouchId, press.time_stamp() +
763 base::TimeDelta::FromMilliseconds(50)); 764 base::TimeDelta::FromMilliseconds(50));
764 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 765 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
765 EXPECT_FALSE(delegate->tap()); 766 EXPECT_FALSE(delegate->tap());
766 EXPECT_FALSE(delegate->tap_down()); 767 EXPECT_FALSE(delegate->tap_down());
767 EXPECT_FALSE(delegate->begin()); 768 EXPECT_FALSE(delegate->begin());
768 EXPECT_TRUE(delegate->end()); 769 EXPECT_TRUE(delegate->end());
769 EXPECT_FALSE(delegate->double_tap()); 770 EXPECT_FALSE(delegate->double_tap());
770 EXPECT_FALSE(delegate->scroll_begin()); 771 EXPECT_FALSE(delegate->scroll_begin());
771 EXPECT_FALSE(delegate->scroll_update()); 772 EXPECT_FALSE(delegate->scroll_update());
772 EXPECT_TRUE(delegate->scroll_end()); 773 EXPECT_TRUE(delegate->scroll_end());
773 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 774 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
774 } 775 }
775 776
776 // Check that the bounding box during a scroll event is correct. 777 // Check that the bounding box during a scroll event is correct.
777 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { 778 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) {
778 for (int radius = 1; radius <= 10; ++radius) { 779 for (int radius = 1; radius <= 10; ++radius) {
779 ui::GestureConfiguration::set_default_radius(radius); 780 ui::GestureConfiguration::set_default_radius(radius);
780 scoped_ptr<GestureEventConsumeDelegate> delegate( 781 scoped_ptr<GestureEventConsumeDelegate> delegate(
781 new GestureEventConsumeDelegate()); 782 new GestureEventConsumeDelegate());
782 const int kWindowWidth = 123; 783 const int kWindowWidth = 123;
783 const int kWindowHeight = 45; 784 const int kWindowHeight = 45;
784 const int kTouchId = 5; 785 const int kTouchId = 5;
785 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 786 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
786 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 787 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
787 delegate.get(), -1234, bounds, NULL)); 788 delegate.get(), -1234, bounds, NULL));
788 789
789 const int kPositionX = 101; 790 const int kPositionX = 101;
790 const int kPositionY = 201; 791 const int kPositionY = 201;
791 delegate->Reset(); 792 delegate->Reset();
792 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(kPositionX, kPositionY), 793 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED,
793 kTouchId, GetTime()); 794 gfx::Point(kPositionX, kPositionY),
795 kTouchId,
796 GetTime());
794 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 797 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
795 EXPECT_EQ(gfx::Rect(kPositionX - radius, 798 EXPECT_EQ(gfx::Rect(kPositionX - radius,
796 kPositionY - radius, 799 kPositionY - radius,
797 radius * 2, 800 radius * 2,
798 radius * 2).ToString(), 801 radius * 2).ToString(),
799 delegate->bounding_box().ToString()); 802 delegate->bounding_box().ToString());
800 803
801 const int kScrollAmount = 50; 804 const int kScrollAmount = 50;
802 SendScrollEvents(root_window(), kPositionX, kPositionY, GetTime(), 805 SendScrollEvents(root_window(), kPositionX, kPositionY, GetTime(),
803 1, 1, kTouchId, 1, kScrollAmount, delegate.get()); 806 1, 1, kTouchId, 1, kScrollAmount, delegate.get());
804 EXPECT_EQ(gfx::Point(1, 1).ToString(), 807 EXPECT_EQ(gfx::Point(1, 1).ToString(),
805 delegate->scroll_begin_position().ToString()); 808 delegate->scroll_begin_position().ToString());
806 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, 809 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius,
807 kPositionY + kScrollAmount - radius, 810 kPositionY + kScrollAmount - radius,
808 radius * 2, 811 radius * 2,
809 radius * 2).ToString(), 812 radius * 2).ToString(),
810 delegate->bounding_box().ToString()); 813 delegate->bounding_box().ToString());
811 814
812 // Release the touch. This should end the scroll. 815 // Release the touch. This should end the scroll.
813 delegate->Reset(); 816 delegate->Reset();
814 TouchEvent release(ui::ET_TOUCH_RELEASED, 817 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED,
815 gfx::Point(kPositionX, kPositionY), 818 gfx::Point(kPositionX, kPositionY),
816 kTouchId, press.time_stamp() + 819 kTouchId, press.time_stamp() +
817 base::TimeDelta::FromMilliseconds(50)); 820 base::TimeDelta::FromMilliseconds(50));
818 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 821 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
819 EXPECT_EQ(gfx::Rect(kPositionX - radius, 822 EXPECT_EQ(gfx::Rect(kPositionX - radius,
820 kPositionY - radius, 823 kPositionY - radius,
821 radius * 2, 824 radius * 2,
822 radius * 2).ToString(), 825 radius * 2).ToString(),
823 delegate->bounding_box().ToString()); 826 delegate->bounding_box().ToString());
824 } 827 }
825 ui::GestureConfiguration::set_default_radius(0); 828 ui::GestureConfiguration::set_default_radius(0);
826 } 829 }
827 830
828 // Check Scroll End Events report correct velocities 831 // Check Scroll End Events report correct velocities
829 // if the user was on a horizontal rail 832 // if the user was on a horizontal rail
830 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { 833 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) {
831 scoped_ptr<GestureEventConsumeDelegate> delegate( 834 scoped_ptr<GestureEventConsumeDelegate> delegate(
832 new GestureEventConsumeDelegate()); 835 new GestureEventConsumeDelegate());
833 const int kTouchId = 7; 836 const int kTouchId = 7;
834 gfx::Rect bounds(0, 0, 1000, 1000); 837 gfx::Rect bounds(0, 0, 1000, 1000);
835 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 838 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
836 delegate.get(), -1234, bounds, NULL)); 839 delegate.get(), -1234, bounds, NULL));
837 840
838 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 841 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
839 kTouchId, GetTime()); 842 kTouchId, GetTime());
840 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 843 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
841 844
842 // Move the touch-point horizontally enough that it is considered a 845 // Move the touch-point horizontally enough that it is considered a
843 // horizontal scroll. 846 // horizontal scroll.
844 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 847 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get());
845 EXPECT_EQ(0, delegate->scroll_y()); 848 EXPECT_EQ(0, delegate->scroll_y());
846 EXPECT_EQ(20, delegate->scroll_x()); 849 EXPECT_EQ(20, delegate->scroll_x());
847 850
848 // Get a high x velocity, while still staying on the rail 851 // Get a high x velocity, while still staying on the rail
849 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 852 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
850 100, 10, kTouchId, 1, 853 100, 10, kTouchId, 1,
851 ui::GestureConfiguration::points_buffered_for_velocity(), 854 ui::GestureConfiguration::points_buffered_for_velocity(),
852 delegate.get()); 855 delegate.get());
853 856
854 delegate->Reset(); 857 delegate->Reset();
855 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 858 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
856 kTouchId, GetTime()); 859 kTouchId, GetTime());
857 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 860 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
858 861
859 EXPECT_TRUE(delegate->scroll_end()); 862 EXPECT_TRUE(delegate->scroll_end());
860 EXPECT_EQ(0, delegate->velocity_x()); 863 EXPECT_EQ(0, delegate->velocity_x());
861 EXPECT_EQ(0, delegate->velocity_y()); 864 EXPECT_EQ(0, delegate->velocity_y());
862 } 865 }
863 866
864 // Check Scroll End Events report correct velocities 867 // Check Scroll End Events report correct velocities
865 // if the user was on a vertical rail 868 // if the user was on a vertical rail
866 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { 869 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) {
867 scoped_ptr<GestureEventConsumeDelegate> delegate( 870 scoped_ptr<GestureEventConsumeDelegate> delegate(
868 new GestureEventConsumeDelegate()); 871 new GestureEventConsumeDelegate());
869 const int kTouchId = 7; 872 const int kTouchId = 7;
870 gfx::Rect bounds(0, 0, 1000, 1000); 873 gfx::Rect bounds(0, 0, 1000, 1000);
871 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 874 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
872 delegate.get(), -1234, bounds, NULL)); 875 delegate.get(), -1234, bounds, NULL));
873 876
874 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 877 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
875 kTouchId, GetTime()); 878 kTouchId, GetTime());
876 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 879 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
877 880
878 // Move the touch-point vertically enough that it is considered a 881 // Move the touch-point vertically enough that it is considered a
879 // vertical scroll. 882 // vertical scroll.
880 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 883 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
881 EXPECT_EQ(20, delegate->scroll_y()); 884 EXPECT_EQ(20, delegate->scroll_y());
882 EXPECT_EQ(0, delegate->scroll_x()); 885 EXPECT_EQ(0, delegate->scroll_x());
883 886
884 // Get a high y velocity, while still staying on the rail 887 // Get a high y velocity, while still staying on the rail
885 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 888 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
886 10, 100, kTouchId, 1, 889 10, 100, kTouchId, 1,
887 ui::GestureConfiguration::points_buffered_for_velocity(), 890 ui::GestureConfiguration::points_buffered_for_velocity(),
888 delegate.get()); 891 delegate.get());
889 892
890 delegate->Reset(); 893 delegate->Reset();
891 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 894 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
892 kTouchId, GetTime()); 895 kTouchId, GetTime());
893 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 896 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
894 897
895 EXPECT_TRUE(delegate->scroll_end()); 898 EXPECT_TRUE(delegate->scroll_end());
896 EXPECT_EQ(0, delegate->velocity_x()); 899 EXPECT_EQ(0, delegate->velocity_x());
897 EXPECT_EQ(0, delegate->velocity_y()); 900 EXPECT_EQ(0, delegate->velocity_y());
898 } 901 }
899 902
900 // Check Scroll End Events reports zero velocities 903 // Check Scroll End Events reports zero velocities
901 // if the user is not on a rail 904 // if the user is not on a rail
902 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { 905 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) {
903 scoped_ptr<GestureEventConsumeDelegate> delegate( 906 scoped_ptr<GestureEventConsumeDelegate> delegate(
904 new GestureEventConsumeDelegate()); 907 new GestureEventConsumeDelegate());
905 const int kTouchId = 7; 908 const int kTouchId = 7;
906 gfx::Rect bounds(0, 0, 1000, 1000); 909 gfx::Rect bounds(0, 0, 1000, 1000);
907 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 910 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
908 delegate.get(), -1234, bounds, NULL)); 911 delegate.get(), -1234, bounds, NULL));
909 912
910 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 913 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
911 kTouchId, GetTime()); 914 kTouchId, GetTime());
912 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 915 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
913 916
914 // Move the touch-point such that a non-rail scroll begins 917 // Move the touch-point such that a non-rail scroll begins
915 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get()); 918 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get());
916 EXPECT_EQ(20, delegate->scroll_y()); 919 EXPECT_EQ(20, delegate->scroll_y());
917 EXPECT_EQ(20, delegate->scroll_x()); 920 EXPECT_EQ(20, delegate->scroll_x());
918 921
919 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 922 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
920 10, 100, kTouchId, 1, 923 10, 100, kTouchId, 1,
921 ui::GestureConfiguration::points_buffered_for_velocity(), 924 ui::GestureConfiguration::points_buffered_for_velocity(),
922 delegate.get()); 925 delegate.get());
923 926
924 delegate->Reset(); 927 delegate->Reset();
925 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 928 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
926 kTouchId, GetTime()); 929 kTouchId, GetTime());
927 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 930 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
928 931
929 EXPECT_TRUE(delegate->scroll_end()); 932 EXPECT_TRUE(delegate->scroll_end());
930 EXPECT_EQ(0, delegate->velocity_x()); 933 EXPECT_EQ(0, delegate->velocity_x());
931 EXPECT_EQ(0, delegate->velocity_y()); 934 EXPECT_EQ(0, delegate->velocity_y());
932 } 935 }
933 936
934 // Check that appropriate touch events generate long press events 937 // Check that appropriate touch events generate long press events
935 TEST_F(GestureRecognizerTest, GestureEventLongPress) { 938 TEST_F(GestureRecognizerTest, GestureEventLongPress) {
936 scoped_ptr<GestureEventConsumeDelegate> delegate( 939 scoped_ptr<GestureEventConsumeDelegate> delegate(
937 new GestureEventConsumeDelegate()); 940 new GestureEventConsumeDelegate());
938 const int kWindowWidth = 123; 941 const int kWindowWidth = 123;
939 const int kWindowHeight = 45; 942 const int kWindowHeight = 45;
940 const int kTouchId = 2; 943 const int kTouchId = 2;
941 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 944 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
942 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 945 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
943 delegate.get(), -1234, bounds, NULL)); 946 delegate.get(), -1234, bounds, NULL));
944 947
945 delegate->Reset(); 948 delegate->Reset();
946 949
947 TimerTestGestureRecognizer* gesture_recognizer = 950 TimerTestGestureRecognizer* gesture_recognizer =
948 new TimerTestGestureRecognizer(root_window()); 951 new TimerTestGestureRecognizer(root_window());
949 TimerTestGestureSequence* gesture_sequence = 952 TimerTestGestureSequence* gesture_sequence =
950 static_cast<TimerTestGestureSequence*>( 953 static_cast<TimerTestGestureSequence*>(
951 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 954 gesture_recognizer->GetGestureSequenceForTesting(window.get()));
952 955
953 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 956 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
954 957
955 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 958 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
956 kTouchId, GetTime()); 959 kTouchId, GetTime());
957 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 960 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
958 EXPECT_TRUE(delegate->tap_down()); 961 EXPECT_TRUE(delegate->tap_down());
959 EXPECT_TRUE(delegate->begin()); 962 EXPECT_TRUE(delegate->begin());
960 963
961 // We haven't pressed long enough for a long press to occur 964 // We haven't pressed long enough for a long press to occur
962 EXPECT_FALSE(delegate->long_press()); 965 EXPECT_FALSE(delegate->long_press());
963 966
964 // Wait until the timer runs out 967 // Wait until the timer runs out
965 gesture_sequence->ForceTimeout(); 968 gesture_sequence->ForceTimeout();
966 EXPECT_TRUE(delegate->long_press()); 969 EXPECT_TRUE(delegate->long_press());
967 EXPECT_EQ(0, delegate->touch_id()); 970 EXPECT_EQ(0, delegate->touch_id());
968 971
969 delegate->Reset(); 972 delegate->Reset();
970 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 973 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
971 kTouchId, GetTime()); 974 kTouchId, GetTime());
972 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 975 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
973 EXPECT_FALSE(delegate->long_press()); 976 EXPECT_FALSE(delegate->long_press());
974 } 977 }
975 978
976 // Check that scrolling cancels a long press 979 // Check that scrolling cancels a long press
977 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { 980 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) {
978 scoped_ptr<GestureEventConsumeDelegate> delegate( 981 scoped_ptr<GestureEventConsumeDelegate> delegate(
979 new GestureEventConsumeDelegate()); 982 new GestureEventConsumeDelegate());
980 const int kWindowWidth = 123; 983 const int kWindowWidth = 123;
981 const int kWindowHeight = 45; 984 const int kWindowHeight = 45;
982 const int kTouchId = 6; 985 const int kTouchId = 6;
983 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 986 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
984 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 987 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
985 delegate.get(), -1234, bounds, NULL)); 988 delegate.get(), -1234, bounds, NULL));
986 989
987 delegate->Reset(); 990 delegate->Reset();
988 991
989 TimerTestGestureRecognizer* gesture_recognizer = 992 TimerTestGestureRecognizer* gesture_recognizer =
990 new TimerTestGestureRecognizer(root_window()); 993 new TimerTestGestureRecognizer(root_window());
991 TimerTestGestureSequence* gesture_sequence = 994 TimerTestGestureSequence* gesture_sequence =
992 static_cast<TimerTestGestureSequence*>( 995 static_cast<TimerTestGestureSequence*>(
993 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 996 gesture_recognizer->GetGestureSequenceForTesting(window.get()));
994 997
995 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 998 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
996 999
997 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1000 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
998 kTouchId, GetTime()); 1001 kTouchId, GetTime());
999 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1002 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
1000 EXPECT_TRUE(delegate->tap_down()); 1003 EXPECT_TRUE(delegate->tap_down());
1001 1004
1002 // We haven't pressed long enough for a long press to occur 1005 // We haven't pressed long enough for a long press to occur
1003 EXPECT_FALSE(delegate->long_press()); 1006 EXPECT_FALSE(delegate->long_press());
1004 1007
1005 // Scroll around, to cancel the long press 1008 // Scroll around, to cancel the long press
1006 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 1009 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get());
1007 // Wait until the timer runs out 1010 // Wait until the timer runs out
1008 gesture_sequence->ForceTimeout(); 1011 gesture_sequence->ForceTimeout();
1009 EXPECT_FALSE(delegate->long_press()); 1012 EXPECT_FALSE(delegate->long_press());
1010 1013
1011 delegate->Reset(); 1014 delegate->Reset();
1012 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1015 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1013 kTouchId, GetTime()); 1016 kTouchId, GetTime());
1014 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1017 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1015 EXPECT_FALSE(delegate->long_press()); 1018 EXPECT_FALSE(delegate->long_press());
1016 } 1019 }
1017 1020
1018 // Check that second tap cancels a long press 1021 // Check that second tap cancels a long press
1019 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { 1022 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) {
1020 scoped_ptr<GestureEventConsumeDelegate> delegate( 1023 scoped_ptr<GestureEventConsumeDelegate> delegate(
1021 new GestureEventConsumeDelegate()); 1024 new GestureEventConsumeDelegate());
1022 const int kWindowWidth = 300; 1025 const int kWindowWidth = 300;
1023 const int kWindowHeight = 400; 1026 const int kWindowHeight = 400;
1024 const int kTouchId1 = 8; 1027 const int kTouchId1 = 8;
1025 const int kTouchId2 = 2; 1028 const int kTouchId2 = 2;
1026 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1029 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1027 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1030 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1028 delegate.get(), -1234, bounds, NULL)); 1031 delegate.get(), -1234, bounds, NULL));
1029 1032
1030 TimerTestGestureRecognizer* gesture_recognizer = 1033 TimerTestGestureRecognizer* gesture_recognizer =
1031 new TimerTestGestureRecognizer(root_window()); 1034 new TimerTestGestureRecognizer(root_window());
1032 TimerTestGestureSequence* gesture_sequence = 1035 TimerTestGestureSequence* gesture_sequence =
1033 static_cast<TimerTestGestureSequence*>( 1036 static_cast<TimerTestGestureSequence*>(
1034 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 1037 gesture_recognizer->GetGestureSequenceForTesting(window.get()));
1035 1038
1036 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 1039 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
1037 1040
1038 delegate->Reset(); 1041 delegate->Reset();
1039 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1042 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1040 kTouchId1, GetTime()); 1043 kTouchId1, GetTime());
1041 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1044 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1042 EXPECT_TRUE(delegate->tap_down()); 1045 EXPECT_TRUE(delegate->tap_down());
1043 EXPECT_TRUE(delegate->begin()); 1046 EXPECT_TRUE(delegate->begin());
1044 1047
1045 // We haven't pressed long enough for a long press to occur 1048 // We haven't pressed long enough for a long press to occur
1046 EXPECT_FALSE(delegate->long_press()); 1049 EXPECT_FALSE(delegate->long_press());
1047 1050
1048 // Second tap, to cancel the long press 1051 // Second tap, to cancel the long press
1049 delegate->Reset(); 1052 delegate->Reset();
1050 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1053 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1051 kTouchId2, GetTime()); 1054 kTouchId2, GetTime());
1052 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1055 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1053 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 1056 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
1054 EXPECT_TRUE(delegate->begin()); 1057 EXPECT_TRUE(delegate->begin());
1055 1058
1056 // Wait until the timer runs out 1059 // Wait until the timer runs out
1057 gesture_sequence->ForceTimeout(); 1060 gesture_sequence->ForceTimeout();
1058 1061
1059 // No long press occurred 1062 // No long press occurred
1060 EXPECT_FALSE(delegate->long_press()); 1063 EXPECT_FALSE(delegate->long_press());
1061 1064
1062 delegate->Reset(); 1065 delegate->Reset();
1063 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1066 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1064 kTouchId1, GetTime()); 1067 kTouchId1, GetTime());
1065 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1068 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1066 EXPECT_FALSE(delegate->long_press()); 1069 EXPECT_FALSE(delegate->long_press());
1067 EXPECT_TRUE(delegate->two_finger_tap()); 1070 EXPECT_TRUE(delegate->two_finger_tap());
1068 } 1071 }
1069 1072
1070 // Check that horizontal scroll gestures cause scrolls on horizontal rails. 1073 // Check that horizontal scroll gestures cause scrolls on horizontal rails.
1071 // Also tests that horizontal rails can be broken. 1074 // Also tests that horizontal rails can be broken.
1072 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) { 1075 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
1073 scoped_ptr<GestureEventConsumeDelegate> delegate( 1076 scoped_ptr<GestureEventConsumeDelegate> delegate(
1074 new GestureEventConsumeDelegate()); 1077 new GestureEventConsumeDelegate());
1075 const int kTouchId = 7; 1078 const int kTouchId = 7;
1076 gfx::Rect bounds(0, 0, 1000, 1000); 1079 gfx::Rect bounds(0, 0, 1000, 1000);
1077 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1080 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1078 delegate.get(), -1234, bounds, NULL)); 1081 delegate.get(), -1234, bounds, NULL));
1079 1082
1080 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1083 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1081 kTouchId, GetTime()); 1084 kTouchId, GetTime());
1082 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1085 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1083 1086
1084 // Move the touch-point horizontally enough that it is considered a 1087 // Move the touch-point horizontally enough that it is considered a
1085 // horizontal scroll. 1088 // horizontal scroll.
1086 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 1089 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get());
1087 EXPECT_EQ(0, delegate->scroll_y()); 1090 EXPECT_EQ(0, delegate->scroll_y());
1088 EXPECT_EQ(20, delegate->scroll_x()); 1091 EXPECT_EQ(20, delegate->scroll_x());
1089 1092
1090 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get()); 1093 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get());
1091 EXPECT_TRUE(delegate->scroll_update()); 1094 EXPECT_TRUE(delegate->scroll_update());
(...skipping 20 matching lines...) Expand all
1112 // Check that vertical scroll gestures cause scrolls on vertical rails. 1115 // Check that vertical scroll gestures cause scrolls on vertical rails.
1113 // Also tests that vertical rails can be broken. 1116 // Also tests that vertical rails can be broken.
1114 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { 1117 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
1115 scoped_ptr<GestureEventConsumeDelegate> delegate( 1118 scoped_ptr<GestureEventConsumeDelegate> delegate(
1116 new GestureEventConsumeDelegate()); 1119 new GestureEventConsumeDelegate());
1117 const int kTouchId = 7; 1120 const int kTouchId = 7;
1118 gfx::Rect bounds(0, 0, 1000, 1000); 1121 gfx::Rect bounds(0, 0, 1000, 1000);
1119 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1122 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1120 delegate.get(), -1234, bounds, NULL)); 1123 delegate.get(), -1234, bounds, NULL));
1121 1124
1122 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1125 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1123 kTouchId, GetTime()); 1126 kTouchId, GetTime());
1124 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1127 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1125 1128
1126 // Move the touch-point vertically enough that it is considered a 1129 // Move the touch-point vertically enough that it is considered a
1127 // vertical scroll. 1130 // vertical scroll.
1128 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 1131 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
1129 EXPECT_EQ(0, delegate->scroll_x()); 1132 EXPECT_EQ(0, delegate->scroll_x());
1130 EXPECT_EQ(20, delegate->scroll_y()); 1133 EXPECT_EQ(20, delegate->scroll_y());
1131 1134
1132 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get()); 1135 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get());
1133 EXPECT_TRUE(delegate->scroll_update()); 1136 EXPECT_TRUE(delegate->scroll_update());
(...skipping 22 matching lines...) Expand all
1156 scoped_ptr<GestureEventConsumeDelegate> delegate( 1159 scoped_ptr<GestureEventConsumeDelegate> delegate(
1157 new GestureEventConsumeDelegate()); 1160 new GestureEventConsumeDelegate());
1158 const int kWindowWidth = 123; 1161 const int kWindowWidth = 123;
1159 const int kWindowHeight = 45; 1162 const int kWindowHeight = 45;
1160 const int kTouchId = 3; 1163 const int kTouchId = 3;
1161 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1164 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1162 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1165 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1163 delegate.get(), -1234, bounds, NULL)); 1166 delegate.get(), -1234, bounds, NULL));
1164 1167
1165 delegate->Reset(); 1168 delegate->Reset();
1166 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1169 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1167 kTouchId, GetTime()); 1170 kTouchId, GetTime());
1168 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1171 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1169 EXPECT_FALSE(delegate->tap()); 1172 EXPECT_FALSE(delegate->tap());
1170 EXPECT_TRUE(delegate->tap_down()); 1173 EXPECT_TRUE(delegate->tap_down());
1171 EXPECT_FALSE(delegate->double_tap()); 1174 EXPECT_FALSE(delegate->double_tap());
1172 EXPECT_FALSE(delegate->scroll_begin()); 1175 EXPECT_FALSE(delegate->scroll_begin());
1173 EXPECT_FALSE(delegate->scroll_update()); 1176 EXPECT_FALSE(delegate->scroll_update());
1174 EXPECT_FALSE(delegate->scroll_end()); 1177 EXPECT_FALSE(delegate->scroll_end());
1175 1178
1176 // Make sure there is enough delay before the touch is released so that it is 1179 // Make sure there is enough delay before the touch is released so that it is
1177 // recognized as a tap. 1180 // recognized as a tap.
1178 delegate->Reset(); 1181 delegate->Reset();
1179 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1182 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1180 kTouchId, press.time_stamp() + 1183 kTouchId, press.time_stamp() +
1181 base::TimeDelta::FromMilliseconds(50)); 1184 base::TimeDelta::FromMilliseconds(50));
1182 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1185 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1183 EXPECT_TRUE(delegate->tap()); 1186 EXPECT_TRUE(delegate->tap());
1184 EXPECT_FALSE(delegate->tap_down()); 1187 EXPECT_FALSE(delegate->tap_down());
1185 EXPECT_FALSE(delegate->double_tap()); 1188 EXPECT_FALSE(delegate->double_tap());
1186 EXPECT_FALSE(delegate->scroll_begin()); 1189 EXPECT_FALSE(delegate->scroll_begin());
1187 EXPECT_FALSE(delegate->scroll_update()); 1190 EXPECT_FALSE(delegate->scroll_update());
1188 EXPECT_FALSE(delegate->scroll_end()); 1191 EXPECT_FALSE(delegate->scroll_end());
1189 1192
1190 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger 1193 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger
1191 // a double-tap. 1194 // a double-tap.
1192 delegate->Reset(); 1195 delegate->Reset();
1193 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1196 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1194 kTouchId, release.time_stamp() + 1197 kTouchId, release.time_stamp() +
1195 base::TimeDelta::FromMilliseconds(1000)); 1198 base::TimeDelta::FromMilliseconds(1000));
1196 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1199 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
1197 EXPECT_FALSE(delegate->tap()); 1200 EXPECT_FALSE(delegate->tap());
1198 EXPECT_TRUE(delegate->tap_down()); 1201 EXPECT_TRUE(delegate->tap_down());
1199 EXPECT_FALSE(delegate->double_tap()); 1202 EXPECT_FALSE(delegate->double_tap());
1200 EXPECT_FALSE(delegate->scroll_begin()); 1203 EXPECT_FALSE(delegate->scroll_begin());
1201 EXPECT_FALSE(delegate->scroll_update()); 1204 EXPECT_FALSE(delegate->scroll_update());
1202 EXPECT_FALSE(delegate->scroll_end()); 1205 EXPECT_FALSE(delegate->scroll_end());
1203 1206
1204 // Move the touch-point enough so that it is considered as a scroll. This 1207 // Move the touch-point enough so that it is considered as a scroll. This
1205 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 1208 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1206 // The first movement is diagonal, to ensure that we have a free scroll, 1209 // The first movement is diagonal, to ensure that we have a free scroll,
1207 // and not a rail scroll. 1210 // and not a rail scroll.
1208 delegate->Reset(); 1211 delegate->Reset();
1209 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230), 1212 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230),
1210 kTouchId, GetTime()); 1213 kTouchId, GetTime());
1211 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1214 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
1212 EXPECT_FALSE(delegate->tap()); 1215 EXPECT_FALSE(delegate->tap());
1213 EXPECT_FALSE(delegate->tap_down()); 1216 EXPECT_FALSE(delegate->tap_down());
1214 EXPECT_FALSE(delegate->double_tap()); 1217 EXPECT_FALSE(delegate->double_tap());
1215 EXPECT_TRUE(delegate->scroll_begin()); 1218 EXPECT_TRUE(delegate->scroll_begin());
1216 EXPECT_TRUE(delegate->scroll_update()); 1219 EXPECT_TRUE(delegate->scroll_update());
1217 EXPECT_FALSE(delegate->scroll_end()); 1220 EXPECT_FALSE(delegate->scroll_end());
1218 EXPECT_EQ(29, delegate->scroll_x()); 1221 EXPECT_EQ(29, delegate->scroll_x());
1219 EXPECT_EQ(29, delegate->scroll_y()); 1222 EXPECT_EQ(29, delegate->scroll_y());
1220 1223
1221 // Move some more to generate a few more scroll updates. 1224 // Move some more to generate a few more scroll updates.
1222 delegate->Reset(); 1225 delegate->Reset();
1223 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211), 1226 ui::TouchEventImpl move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211),
1224 kTouchId, GetTime()); 1227 kTouchId, GetTime());
1225 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 1228 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
1226 EXPECT_FALSE(delegate->tap()); 1229 EXPECT_FALSE(delegate->tap());
1227 EXPECT_FALSE(delegate->tap_down()); 1230 EXPECT_FALSE(delegate->tap_down());
1228 EXPECT_FALSE(delegate->double_tap()); 1231 EXPECT_FALSE(delegate->double_tap());
1229 EXPECT_FALSE(delegate->scroll_begin()); 1232 EXPECT_FALSE(delegate->scroll_begin());
1230 EXPECT_TRUE(delegate->scroll_update()); 1233 EXPECT_TRUE(delegate->scroll_update());
1231 EXPECT_FALSE(delegate->scroll_end()); 1234 EXPECT_FALSE(delegate->scroll_end());
1232 EXPECT_EQ(-20, delegate->scroll_x()); 1235 EXPECT_EQ(-20, delegate->scroll_x());
1233 EXPECT_EQ(-19, delegate->scroll_y()); 1236 EXPECT_EQ(-19, delegate->scroll_y());
1234 1237
1235 delegate->Reset(); 1238 delegate->Reset();
1236 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215), 1239 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215),
1237 kTouchId, GetTime()); 1240 kTouchId, GetTime());
1238 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1241 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
1239 EXPECT_FALSE(delegate->tap()); 1242 EXPECT_FALSE(delegate->tap());
1240 EXPECT_FALSE(delegate->tap_down()); 1243 EXPECT_FALSE(delegate->tap_down());
1241 EXPECT_FALSE(delegate->double_tap()); 1244 EXPECT_FALSE(delegate->double_tap());
1242 EXPECT_FALSE(delegate->scroll_begin()); 1245 EXPECT_FALSE(delegate->scroll_begin());
1243 EXPECT_TRUE(delegate->scroll_update()); 1246 EXPECT_TRUE(delegate->scroll_update());
1244 EXPECT_FALSE(delegate->scroll_end()); 1247 EXPECT_FALSE(delegate->scroll_end());
1245 EXPECT_EQ(30, delegate->scroll_x()); 1248 EXPECT_EQ(30, delegate->scroll_x());
1246 EXPECT_EQ(4, delegate->scroll_y()); 1249 EXPECT_EQ(4, delegate->scroll_y());
1247 1250
1248 // Release the touch. This should end the scroll. 1251 // Release the touch. This should end the scroll.
1249 delegate->Reset(); 1252 delegate->Reset();
1250 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1253 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1251 kTouchId, GetTime()); 1254 kTouchId, GetTime());
1252 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1255 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1253 EXPECT_FALSE(delegate->tap()); 1256 EXPECT_FALSE(delegate->tap());
1254 EXPECT_FALSE(delegate->tap_down()); 1257 EXPECT_FALSE(delegate->tap_down());
1255 EXPECT_FALSE(delegate->double_tap()); 1258 EXPECT_FALSE(delegate->double_tap());
1256 EXPECT_FALSE(delegate->scroll_begin()); 1259 EXPECT_FALSE(delegate->scroll_begin());
1257 EXPECT_FALSE(delegate->scroll_update()); 1260 EXPECT_FALSE(delegate->scroll_update());
1258 EXPECT_TRUE(delegate->scroll_end()); 1261 EXPECT_TRUE(delegate->scroll_end());
1259 } 1262 }
1260 1263
1261 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) { 1264 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
1262 scoped_ptr<QueueTouchEventDelegate> queued_delegate( 1265 scoped_ptr<QueueTouchEventDelegate> queued_delegate(
1263 new QueueTouchEventDelegate(root_window())); 1266 new QueueTouchEventDelegate(root_window()));
1264 const int kWindowWidth = 123; 1267 const int kWindowWidth = 123;
1265 const int kWindowHeight = 45; 1268 const int kWindowHeight = 45;
1266 const int kTouchId1 = 6; 1269 const int kTouchId1 = 6;
1267 const int kTouchId2 = 4; 1270 const int kTouchId2 = 4;
1268 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1271 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1269 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( 1272 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate(
1270 queued_delegate.get(), -1234, bounds, NULL)); 1273 queued_delegate.get(), -1234, bounds, NULL));
1271 1274
1272 queued_delegate->set_window(queue.get()); 1275 queued_delegate->set_window(queue.get());
1273 1276
1274 // Touch down on the window. This should not generate any gesture event. 1277 // Touch down on the window. This should not generate any gesture event.
1275 queued_delegate->Reset(); 1278 queued_delegate->Reset();
1276 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1279 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1277 kTouchId1, GetTime()); 1280 kTouchId1, GetTime());
1278 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1281 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1279 EXPECT_FALSE(queued_delegate->tap()); 1282 EXPECT_FALSE(queued_delegate->tap());
1280 EXPECT_FALSE(queued_delegate->tap_down()); 1283 EXPECT_FALSE(queued_delegate->tap_down());
1281 EXPECT_FALSE(queued_delegate->begin()); 1284 EXPECT_FALSE(queued_delegate->begin());
1282 EXPECT_FALSE(queued_delegate->double_tap()); 1285 EXPECT_FALSE(queued_delegate->double_tap());
1283 EXPECT_FALSE(queued_delegate->scroll_begin()); 1286 EXPECT_FALSE(queued_delegate->scroll_begin());
1284 EXPECT_FALSE(queued_delegate->scroll_update()); 1287 EXPECT_FALSE(queued_delegate->scroll_update());
1285 EXPECT_FALSE(queued_delegate->scroll_end()); 1288 EXPECT_FALSE(queued_delegate->scroll_end());
1286 1289
1287 // Introduce some delay before the touch is released so that it is recognized 1290 // Introduce some delay before the touch is released so that it is recognized
1288 // as a tap. However, this still should not create any gesture events. 1291 // as a tap. However, this still should not create any gesture events.
1289 queued_delegate->Reset(); 1292 queued_delegate->Reset();
1290 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1293 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1291 kTouchId1, press.time_stamp() + 1294 kTouchId1, press.time_stamp() +
1292 base::TimeDelta::FromMilliseconds(50)); 1295 base::TimeDelta::FromMilliseconds(50));
1293 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1296 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1294 EXPECT_FALSE(queued_delegate->tap()); 1297 EXPECT_FALSE(queued_delegate->tap());
1295 EXPECT_FALSE(queued_delegate->tap_down()); 1298 EXPECT_FALSE(queued_delegate->tap_down());
1296 EXPECT_FALSE(queued_delegate->begin()); 1299 EXPECT_FALSE(queued_delegate->begin());
1297 EXPECT_FALSE(queued_delegate->end()); 1300 EXPECT_FALSE(queued_delegate->end());
1298 EXPECT_FALSE(queued_delegate->double_tap()); 1301 EXPECT_FALSE(queued_delegate->double_tap());
1299 EXPECT_FALSE(queued_delegate->scroll_begin()); 1302 EXPECT_FALSE(queued_delegate->scroll_begin());
1300 EXPECT_FALSE(queued_delegate->scroll_update()); 1303 EXPECT_FALSE(queued_delegate->scroll_update());
1301 EXPECT_FALSE(queued_delegate->scroll_end()); 1304 EXPECT_FALSE(queued_delegate->scroll_end());
1302 1305
1303 // Create another window, and place a touch-down on it. This should create a 1306 // Create another window, and place a touch-down on it. This should create a
1304 // tap-down gesture. 1307 // tap-down gesture.
1305 scoped_ptr<GestureEventConsumeDelegate> delegate( 1308 scoped_ptr<GestureEventConsumeDelegate> delegate(
1306 new GestureEventConsumeDelegate()); 1309 new GestureEventConsumeDelegate());
1307 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1310 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1308 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL)); 1311 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL));
1309 delegate->Reset(); 1312 delegate->Reset();
1310 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), 1313 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20),
1311 kTouchId2, GetTime()); 1314 kTouchId2, GetTime());
1312 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1315 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1313 EXPECT_FALSE(delegate->tap()); 1316 EXPECT_FALSE(delegate->tap());
1314 EXPECT_TRUE(delegate->tap_down()); 1317 EXPECT_TRUE(delegate->tap_down());
1315 EXPECT_FALSE(queued_delegate->begin()); 1318 EXPECT_FALSE(queued_delegate->begin());
1316 EXPECT_FALSE(queued_delegate->end()); 1319 EXPECT_FALSE(queued_delegate->end());
1317 EXPECT_FALSE(delegate->double_tap()); 1320 EXPECT_FALSE(delegate->double_tap());
1318 EXPECT_FALSE(delegate->scroll_begin()); 1321 EXPECT_FALSE(delegate->scroll_begin());
1319 EXPECT_FALSE(delegate->scroll_update()); 1322 EXPECT_FALSE(delegate->scroll_update());
1320 EXPECT_FALSE(delegate->scroll_end()); 1323 EXPECT_FALSE(delegate->scroll_end());
1321 1324
1322 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 1325 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20),
1323 kTouchId2, GetTime()); 1326 kTouchId2, GetTime());
1324 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 1327 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
1325 1328
1326 // Process the first queued event. 1329 // Process the first queued event.
1327 queued_delegate->Reset(); 1330 queued_delegate->Reset();
1328 queued_delegate->ReceivedAck(); 1331 queued_delegate->ReceivedAck();
1329 EXPECT_FALSE(queued_delegate->tap()); 1332 EXPECT_FALSE(queued_delegate->tap());
1330 EXPECT_TRUE(queued_delegate->tap_down()); 1333 EXPECT_TRUE(queued_delegate->tap_down());
1331 EXPECT_TRUE(queued_delegate->begin()); 1334 EXPECT_TRUE(queued_delegate->begin());
1332 EXPECT_FALSE(queued_delegate->end()); 1335 EXPECT_FALSE(queued_delegate->end());
1333 EXPECT_FALSE(queued_delegate->double_tap()); 1336 EXPECT_FALSE(queued_delegate->double_tap());
1334 EXPECT_FALSE(queued_delegate->scroll_begin()); 1337 EXPECT_FALSE(queued_delegate->scroll_begin());
1335 EXPECT_FALSE(queued_delegate->scroll_update()); 1338 EXPECT_FALSE(queued_delegate->scroll_update());
1336 EXPECT_FALSE(queued_delegate->scroll_end()); 1339 EXPECT_FALSE(queued_delegate->scroll_end());
1337 1340
1338 // Now, process the second queued event. 1341 // Now, process the second queued event.
1339 queued_delegate->Reset(); 1342 queued_delegate->Reset();
1340 queued_delegate->ReceivedAck(); 1343 queued_delegate->ReceivedAck();
1341 EXPECT_TRUE(queued_delegate->tap()); 1344 EXPECT_TRUE(queued_delegate->tap());
1342 EXPECT_FALSE(queued_delegate->tap_down()); 1345 EXPECT_FALSE(queued_delegate->tap_down());
1343 EXPECT_FALSE(queued_delegate->begin()); 1346 EXPECT_FALSE(queued_delegate->begin());
1344 EXPECT_TRUE(queued_delegate->end()); 1347 EXPECT_TRUE(queued_delegate->end());
1345 EXPECT_FALSE(queued_delegate->double_tap()); 1348 EXPECT_FALSE(queued_delegate->double_tap());
1346 EXPECT_FALSE(queued_delegate->scroll_begin()); 1349 EXPECT_FALSE(queued_delegate->scroll_begin());
1347 EXPECT_FALSE(queued_delegate->scroll_update()); 1350 EXPECT_FALSE(queued_delegate->scroll_update());
1348 EXPECT_FALSE(queued_delegate->scroll_end()); 1351 EXPECT_FALSE(queued_delegate->scroll_end());
1349 1352
1350 // Start all over. Press on the first window, then press again on the second 1353 // Start all over. Press on the first window, then press again on the second
1351 // window. The second press should still go to the first window. 1354 // window. The second press should still go to the first window.
1352 queued_delegate->Reset(); 1355 queued_delegate->Reset();
1353 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1356 ui::TouchEventImpl press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1354 kTouchId1, GetTime()); 1357 kTouchId1, GetTime());
1355 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3); 1358 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3);
1356 EXPECT_FALSE(queued_delegate->tap()); 1359 EXPECT_FALSE(queued_delegate->tap());
1357 EXPECT_FALSE(queued_delegate->tap_down()); 1360 EXPECT_FALSE(queued_delegate->tap_down());
1358 EXPECT_FALSE(queued_delegate->begin()); 1361 EXPECT_FALSE(queued_delegate->begin());
1359 EXPECT_FALSE(queued_delegate->end()); 1362 EXPECT_FALSE(queued_delegate->end());
1360 EXPECT_FALSE(queued_delegate->begin()); 1363 EXPECT_FALSE(queued_delegate->begin());
1361 EXPECT_FALSE(queued_delegate->end()); 1364 EXPECT_FALSE(queued_delegate->end());
1362 EXPECT_FALSE(queued_delegate->double_tap()); 1365 EXPECT_FALSE(queued_delegate->double_tap());
1363 EXPECT_FALSE(queued_delegate->scroll_begin()); 1366 EXPECT_FALSE(queued_delegate->scroll_begin());
1364 EXPECT_FALSE(queued_delegate->scroll_update()); 1367 EXPECT_FALSE(queued_delegate->scroll_update());
1365 EXPECT_FALSE(queued_delegate->scroll_end()); 1368 EXPECT_FALSE(queued_delegate->scroll_end());
1366 1369
1367 queued_delegate->Reset(); 1370 queued_delegate->Reset();
1368 delegate->Reset(); 1371 delegate->Reset();
1369 TouchEvent press4(ui::ET_TOUCH_PRESSED, gfx::Point(103, 203), 1372 ui::TouchEventImpl press4(ui::ET_TOUCH_PRESSED, gfx::Point(103, 203),
1370 kTouchId2, GetTime()); 1373 kTouchId2, GetTime());
1371 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press4); 1374 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press4);
1372 EXPECT_FALSE(delegate->tap()); 1375 EXPECT_FALSE(delegate->tap());
1373 EXPECT_FALSE(delegate->tap_down()); 1376 EXPECT_FALSE(delegate->tap_down());
1374 EXPECT_FALSE(delegate->begin()); 1377 EXPECT_FALSE(delegate->begin());
1375 EXPECT_FALSE(delegate->end()); 1378 EXPECT_FALSE(delegate->end());
1376 EXPECT_FALSE(delegate->double_tap()); 1379 EXPECT_FALSE(delegate->double_tap());
1377 EXPECT_FALSE(delegate->scroll_begin()); 1380 EXPECT_FALSE(delegate->scroll_begin());
1378 EXPECT_FALSE(delegate->scroll_update()); 1381 EXPECT_FALSE(delegate->scroll_update());
1379 EXPECT_FALSE(delegate->scroll_end()); 1382 EXPECT_FALSE(delegate->scroll_end());
1380 EXPECT_FALSE(queued_delegate->tap()); 1383 EXPECT_FALSE(queued_delegate->tap());
1381 EXPECT_FALSE(queued_delegate->tap_down()); 1384 EXPECT_FALSE(queued_delegate->tap_down());
1382 EXPECT_FALSE(queued_delegate->begin()); 1385 EXPECT_FALSE(queued_delegate->begin());
1383 EXPECT_FALSE(queued_delegate->end()); 1386 EXPECT_FALSE(queued_delegate->end());
1384 EXPECT_FALSE(queued_delegate->double_tap()); 1387 EXPECT_FALSE(queued_delegate->double_tap());
1385 EXPECT_FALSE(queued_delegate->scroll_begin()); 1388 EXPECT_FALSE(queued_delegate->scroll_begin());
1386 EXPECT_FALSE(queued_delegate->scroll_update()); 1389 EXPECT_FALSE(queued_delegate->scroll_update());
1387 EXPECT_FALSE(queued_delegate->scroll_end()); 1390 EXPECT_FALSE(queued_delegate->scroll_end());
1388 1391
1389 // Move the second touch-point enough so that it is considered a pinch. This 1392 // Move the second touch-point enough so that it is considered a pinch. This
1390 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. 1393 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures.
1391 queued_delegate->Reset(); 1394 queued_delegate->Reset();
1392 delegate->Reset(); 1395 delegate->Reset();
1393 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); 1396 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click();
1394 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(103 + x_move, 203), 1397 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(103 + x_move, 203),
1395 kTouchId2, GetTime()); 1398 kTouchId2, GetTime());
1396 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1399 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
1397 EXPECT_FALSE(delegate->tap()); 1400 EXPECT_FALSE(delegate->tap());
1398 EXPECT_FALSE(delegate->tap_down()); 1401 EXPECT_FALSE(delegate->tap_down());
1399 EXPECT_FALSE(delegate->begin()); 1402 EXPECT_FALSE(delegate->begin());
1400 EXPECT_FALSE(delegate->double_tap()); 1403 EXPECT_FALSE(delegate->double_tap());
1401 EXPECT_FALSE(delegate->scroll_begin()); 1404 EXPECT_FALSE(delegate->scroll_begin());
1402 EXPECT_FALSE(delegate->scroll_update()); 1405 EXPECT_FALSE(delegate->scroll_update());
1403 EXPECT_FALSE(delegate->scroll_end()); 1406 EXPECT_FALSE(delegate->scroll_end());
1404 EXPECT_FALSE(queued_delegate->tap()); 1407 EXPECT_FALSE(queued_delegate->tap());
1405 EXPECT_FALSE(queued_delegate->tap_down()); 1408 EXPECT_FALSE(queued_delegate->tap_down());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 const int kWindowHeight = 400; 1460 const int kWindowHeight = 400;
1458 const int kTouchId1 = 5; 1461 const int kTouchId1 = 5;
1459 const int kTouchId2 = 3; 1462 const int kTouchId2 = 3;
1460 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1463 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1461 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1464 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1462 delegate.get(), -1234, bounds, NULL)); 1465 delegate.get(), -1234, bounds, NULL));
1463 1466
1464 aura::RootWindow* root = root_window(); 1467 aura::RootWindow* root = root_window();
1465 1468
1466 delegate->Reset(); 1469 delegate->Reset();
1467 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1470 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1468 kTouchId1, GetTime()); 1471 kTouchId1, GetTime());
1469 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1472 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1470 EXPECT_FALSE(delegate->tap()); 1473 EXPECT_FALSE(delegate->tap());
1471 EXPECT_TRUE(delegate->tap_down()); 1474 EXPECT_TRUE(delegate->tap_down());
1472 EXPECT_FALSE(delegate->double_tap()); 1475 EXPECT_FALSE(delegate->double_tap());
1473 EXPECT_FALSE(delegate->scroll_begin()); 1476 EXPECT_FALSE(delegate->scroll_begin());
1474 EXPECT_FALSE(delegate->scroll_update()); 1477 EXPECT_FALSE(delegate->scroll_update());
1475 EXPECT_FALSE(delegate->scroll_end()); 1478 EXPECT_FALSE(delegate->scroll_end());
1476 1479
1477 // Move the touch-point enough so that it is considered as a scroll. This 1480 // Move the touch-point enough so that it is considered as a scroll. This
1478 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 1481 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1479 delegate->Reset(); 1482 delegate->Reset();
1480 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 301), 1483 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(130, 301),
1481 kTouchId1, GetTime()); 1484 kTouchId1, GetTime());
1482 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1485 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
1483 EXPECT_FALSE(delegate->tap()); 1486 EXPECT_FALSE(delegate->tap());
1484 EXPECT_FALSE(delegate->tap_down()); 1487 EXPECT_FALSE(delegate->tap_down());
1485 EXPECT_FALSE(delegate->double_tap()); 1488 EXPECT_FALSE(delegate->double_tap());
1486 EXPECT_TRUE(delegate->scroll_begin()); 1489 EXPECT_TRUE(delegate->scroll_begin());
1487 EXPECT_TRUE(delegate->scroll_update()); 1490 EXPECT_TRUE(delegate->scroll_update());
1488 EXPECT_FALSE(delegate->scroll_end()); 1491 EXPECT_FALSE(delegate->scroll_end());
1489 1492
1490 // Press the second finger. It should cause pinch-begin. Note that we will not 1493 // Press the second finger. It should cause pinch-begin. Note that we will not
1491 // transition to two finger tap here because the touch points are far enough. 1494 // transition to two finger tap here because the touch points are far enough.
1492 delegate->Reset(); 1495 delegate->Reset();
1493 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1496 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1494 kTouchId2, GetTime()); 1497 kTouchId2, GetTime());
1495 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1498 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1496 EXPECT_FALSE(delegate->tap()); 1499 EXPECT_FALSE(delegate->tap());
1497 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 1500 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
1498 EXPECT_FALSE(delegate->double_tap()); 1501 EXPECT_FALSE(delegate->double_tap());
1499 EXPECT_FALSE(delegate->scroll_begin()); 1502 EXPECT_FALSE(delegate->scroll_begin());
1500 EXPECT_FALSE(delegate->scroll_update()); 1503 EXPECT_FALSE(delegate->scroll_update());
1501 EXPECT_FALSE(delegate->scroll_end()); 1504 EXPECT_FALSE(delegate->scroll_end());
1502 EXPECT_TRUE(delegate->pinch_begin()); 1505 EXPECT_TRUE(delegate->pinch_begin());
1503 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(), 1506 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(),
1504 delegate->bounding_box().ToString()); 1507 delegate->bounding_box().ToString());
1505 1508
1506 // Move the first finger. 1509 // Move the first finger.
1507 delegate->Reset(); 1510 delegate->Reset();
1508 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(95, 201), 1511 ui::TouchEventImpl move3(ui::ET_TOUCH_MOVED, gfx::Point(95, 201),
1509 kTouchId1, GetTime()); 1512 kTouchId1, GetTime());
1510 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3); 1513 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3);
1511 EXPECT_FALSE(delegate->tap()); 1514 EXPECT_FALSE(delegate->tap());
1512 EXPECT_FALSE(delegate->tap_down()); 1515 EXPECT_FALSE(delegate->tap_down());
1513 EXPECT_FALSE(delegate->double_tap()); 1516 EXPECT_FALSE(delegate->double_tap());
1514 EXPECT_FALSE(delegate->scroll_begin()); 1517 EXPECT_FALSE(delegate->scroll_begin());
1515 EXPECT_FALSE(delegate->scroll_update()); 1518 EXPECT_FALSE(delegate->scroll_update());
1516 EXPECT_FALSE(delegate->scroll_end()); 1519 EXPECT_FALSE(delegate->scroll_end());
1517 EXPECT_FALSE(delegate->pinch_begin()); 1520 EXPECT_FALSE(delegate->pinch_begin());
1518 EXPECT_TRUE(delegate->pinch_update()); 1521 EXPECT_TRUE(delegate->pinch_update());
1519 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(), 1522 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(),
1520 delegate->bounding_box().ToString()); 1523 delegate->bounding_box().ToString());
1521 1524
1522 // Now move the second finger. 1525 // Now move the second finger.
1523 delegate->Reset(); 1526 delegate->Reset();
1524 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), 1527 ui::TouchEventImpl move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15),
1525 kTouchId2, GetTime()); 1528 kTouchId2, GetTime());
1526 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); 1529 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4);
1527 EXPECT_FALSE(delegate->tap()); 1530 EXPECT_FALSE(delegate->tap());
1528 EXPECT_FALSE(delegate->tap_down()); 1531 EXPECT_FALSE(delegate->tap_down());
1529 EXPECT_FALSE(delegate->double_tap()); 1532 EXPECT_FALSE(delegate->double_tap());
1530 EXPECT_FALSE(delegate->scroll_begin()); 1533 EXPECT_FALSE(delegate->scroll_begin());
1531 EXPECT_FALSE(delegate->scroll_update()); 1534 EXPECT_FALSE(delegate->scroll_update());
1532 EXPECT_FALSE(delegate->scroll_end()); 1535 EXPECT_FALSE(delegate->scroll_end());
1533 EXPECT_FALSE(delegate->pinch_begin()); 1536 EXPECT_FALSE(delegate->pinch_begin());
1534 EXPECT_TRUE(delegate->pinch_update()); 1537 EXPECT_TRUE(delegate->pinch_update());
1535 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(), 1538 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(),
1536 delegate->bounding_box().ToString()); 1539 delegate->bounding_box().ToString());
1537 1540
1538 // Release the first finger. This should end pinch. 1541 // Release the first finger. This should end pinch.
1539 delegate->Reset(); 1542 delegate->Reset();
1540 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1543 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1541 kTouchId1, press.time_stamp() + 1544 kTouchId1, press.time_stamp() +
1542 base::TimeDelta::FromMilliseconds(50)); 1545 base::TimeDelta::FromMilliseconds(50));
1543 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1546 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1544 EXPECT_FALSE(delegate->tap()); 1547 EXPECT_FALSE(delegate->tap());
1545 EXPECT_FALSE(delegate->tap_down()); 1548 EXPECT_FALSE(delegate->tap_down());
1546 EXPECT_FALSE(delegate->double_tap()); 1549 EXPECT_FALSE(delegate->double_tap());
1547 EXPECT_FALSE(delegate->scroll_begin()); 1550 EXPECT_FALSE(delegate->scroll_begin());
1548 EXPECT_FALSE(delegate->scroll_update()); 1551 EXPECT_FALSE(delegate->scroll_update());
1549 EXPECT_FALSE(delegate->scroll_end()); 1552 EXPECT_FALSE(delegate->scroll_end());
1550 EXPECT_TRUE(delegate->pinch_end()); 1553 EXPECT_TRUE(delegate->pinch_end());
1551 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), 1554 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
1552 delegate->bounding_box().ToString()); 1555 delegate->bounding_box().ToString());
1553 1556
1554 // Move the second finger. This should still generate a scroll. 1557 // Move the second finger. This should still generate a scroll.
1555 delegate->Reset(); 1558 delegate->Reset();
1556 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 1559 ui::TouchEventImpl move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
1557 kTouchId2, GetTime()); 1560 kTouchId2, GetTime());
1558 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5); 1561 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5);
1559 EXPECT_FALSE(delegate->tap()); 1562 EXPECT_FALSE(delegate->tap());
1560 EXPECT_FALSE(delegate->tap_down()); 1563 EXPECT_FALSE(delegate->tap_down());
1561 EXPECT_FALSE(delegate->double_tap()); 1564 EXPECT_FALSE(delegate->double_tap());
1562 EXPECT_FALSE(delegate->scroll_begin()); 1565 EXPECT_FALSE(delegate->scroll_begin());
1563 EXPECT_TRUE(delegate->scroll_update()); 1566 EXPECT_TRUE(delegate->scroll_update());
1564 EXPECT_FALSE(delegate->scroll_end()); 1567 EXPECT_FALSE(delegate->scroll_end());
1565 EXPECT_FALSE(delegate->pinch_begin()); 1568 EXPECT_FALSE(delegate->pinch_begin());
1566 EXPECT_FALSE(delegate->pinch_update()); 1569 EXPECT_FALSE(delegate->pinch_update());
1567 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1570 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1568 } 1571 }
1569 1572
1570 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) { 1573 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) {
1571 scoped_ptr<GestureEventConsumeDelegate> delegate( 1574 scoped_ptr<GestureEventConsumeDelegate> delegate(
1572 new GestureEventConsumeDelegate()); 1575 new GestureEventConsumeDelegate());
1573 const int kWindowWidth = 300; 1576 const int kWindowWidth = 300;
1574 const int kWindowHeight = 400; 1577 const int kWindowHeight = 400;
1575 const int kTouchId1 = 5; 1578 const int kTouchId1 = 5;
1576 const int kTouchId2 = 3; 1579 const int kTouchId2 = 3;
1577 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1580 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1578 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1581 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1579 delegate.get(), -1234, bounds, NULL)); 1582 delegate.get(), -1234, bounds, NULL));
1580 1583
1581 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 1584 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301),
1582 kTouchId1, GetTime()); 1585 kTouchId1, GetTime());
1583 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1586 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1584 delegate->Reset(); 1587 delegate->Reset();
1585 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1588 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1586 kTouchId2, GetTime()); 1589 kTouchId2, GetTime());
1587 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1590 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1588 // Since the touch points are far enough we will go to pinch rather than two 1591 // Since the touch points are far enough we will go to pinch rather than two
1589 // finger tap. 1592 // finger tap.
1590 EXPECT_TRUE(delegate->pinch_begin()); 1593 EXPECT_TRUE(delegate->pinch_begin());
1591 1594
1592 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 1595 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get());
1593 EXPECT_TRUE(delegate->pinch_update()); 1596 EXPECT_TRUE(delegate->pinch_update());
1594 1597
1595 // Pinch has started, now release the second finger 1598 // Pinch has started, now release the second finger
1596 delegate->Reset(); 1599 delegate->Reset();
1597 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1600 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1598 kTouchId1, GetTime()); 1601 kTouchId1, GetTime());
1599 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1602 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1600 EXPECT_TRUE(delegate->pinch_end()); 1603 EXPECT_TRUE(delegate->pinch_end());
1601 1604
1602 SendScrollEvent(root_window(), 130, 230, kTouchId2, delegate.get()); 1605 SendScrollEvent(root_window(), 130, 230, kTouchId2, delegate.get());
1603 EXPECT_TRUE(delegate->scroll_update()); 1606 EXPECT_TRUE(delegate->scroll_update());
1604 1607
1605 // Pinch again 1608 // Pinch again
1606 delegate->Reset(); 1609 delegate->Reset();
1607 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1610 ui::TouchEventImpl press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1608 kTouchId1, GetTime()); 1611 kTouchId1, GetTime());
1609 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3); 1612 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3);
1610 // Now the touch points are close. So we will go into two finger tap. 1613 // Now the touch points are close. So we will go into two finger tap.
1611 // Move the touch-point enough to break two-finger-tap and enter pinch. 1614 // Move the touch-point enough to break two-finger-tap and enter pinch.
1612 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 202), 1615 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 202),
1613 kTouchId1, GetTime()); 1616 kTouchId1, GetTime());
1614 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1617 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
1615 EXPECT_TRUE(delegate->pinch_begin()); 1618 EXPECT_TRUE(delegate->pinch_begin());
1616 1619
1617 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 1620 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get());
1618 EXPECT_TRUE(delegate->pinch_update()); 1621 EXPECT_TRUE(delegate->pinch_update());
1619 } 1622 }
1620 1623
1621 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) { 1624 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) {
1622 scoped_ptr<GestureEventConsumeDelegate> delegate( 1625 scoped_ptr<GestureEventConsumeDelegate> delegate(
1623 new GestureEventConsumeDelegate()); 1626 new GestureEventConsumeDelegate());
1624 const int kWindowWidth = 300; 1627 const int kWindowWidth = 300;
1625 const int kWindowHeight = 400; 1628 const int kWindowHeight = 400;
1626 const int kTouchId1 = 3; 1629 const int kTouchId1 = 3;
1627 const int kTouchId2 = 5; 1630 const int kTouchId2 = 5;
1628 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1631 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1629 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1632 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1630 delegate.get(), -1234, bounds, NULL)); 1633 delegate.get(), -1234, bounds, NULL));
1631 1634
1632 aura::RootWindow* root = root_window(); 1635 aura::RootWindow* root = root_window();
1633 1636
1634 delegate->Reset(); 1637 delegate->Reset();
1635 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 1638 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301),
1636 kTouchId1, GetTime()); 1639 kTouchId1, GetTime());
1637 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1640 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1638 EXPECT_FALSE(delegate->tap()); 1641 EXPECT_FALSE(delegate->tap());
1639 EXPECT_TRUE(delegate->tap_down()); 1642 EXPECT_TRUE(delegate->tap_down());
1640 EXPECT_FALSE(delegate->double_tap()); 1643 EXPECT_FALSE(delegate->double_tap());
1641 EXPECT_FALSE(delegate->scroll_begin()); 1644 EXPECT_FALSE(delegate->scroll_begin());
1642 EXPECT_FALSE(delegate->scroll_update()); 1645 EXPECT_FALSE(delegate->scroll_update());
1643 EXPECT_FALSE(delegate->scroll_end()); 1646 EXPECT_FALSE(delegate->scroll_end());
1644 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1647 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1645 1648
1646 // Press the second finger far enough to break two finger tap. It should 1649 // Press the second finger far enough to break two finger tap. It should
1647 // instead cause a scroll-begin and pinch-begin. 1650 // instead cause a scroll-begin and pinch-begin.
1648 delegate->Reset(); 1651 delegate->Reset();
1649 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1652 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1650 kTouchId2, GetTime()); 1653 kTouchId2, GetTime());
1651 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1654 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1652 EXPECT_FALSE(delegate->tap()); 1655 EXPECT_FALSE(delegate->tap());
1653 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 1656 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
1654 EXPECT_FALSE(delegate->double_tap()); 1657 EXPECT_FALSE(delegate->double_tap());
1655 EXPECT_TRUE(delegate->scroll_begin()); 1658 EXPECT_TRUE(delegate->scroll_begin());
1656 EXPECT_FALSE(delegate->scroll_update()); 1659 EXPECT_FALSE(delegate->scroll_update());
1657 EXPECT_FALSE(delegate->scroll_end()); 1660 EXPECT_FALSE(delegate->scroll_end());
1658 EXPECT_TRUE(delegate->pinch_begin()); 1661 EXPECT_TRUE(delegate->pinch_begin());
1659 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(), 1662 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(),
1660 delegate->bounding_box().ToString()); 1663 delegate->bounding_box().ToString());
1661 1664
1662 // Move the first finger. 1665 // Move the first finger.
1663 delegate->Reset(); 1666 delegate->Reset();
1664 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201), 1667 ui::TouchEventImpl move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201),
1665 kTouchId1, GetTime()); 1668 kTouchId1, GetTime());
1666 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3); 1669 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3);
1667 EXPECT_FALSE(delegate->tap()); 1670 EXPECT_FALSE(delegate->tap());
1668 EXPECT_FALSE(delegate->tap_down()); 1671 EXPECT_FALSE(delegate->tap_down());
1669 EXPECT_FALSE(delegate->double_tap()); 1672 EXPECT_FALSE(delegate->double_tap());
1670 EXPECT_FALSE(delegate->scroll_begin()); 1673 EXPECT_FALSE(delegate->scroll_begin());
1671 EXPECT_FALSE(delegate->scroll_update()); 1674 EXPECT_FALSE(delegate->scroll_update());
1672 EXPECT_FALSE(delegate->scroll_end()); 1675 EXPECT_FALSE(delegate->scroll_end());
1673 EXPECT_FALSE(delegate->pinch_begin()); 1676 EXPECT_FALSE(delegate->pinch_begin());
1674 EXPECT_TRUE(delegate->pinch_update()); 1677 EXPECT_TRUE(delegate->pinch_update());
1675 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(), 1678 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(),
1676 delegate->bounding_box().ToString()); 1679 delegate->bounding_box().ToString());
1677 1680
1678 // Now move the second finger. 1681 // Now move the second finger.
1679 delegate->Reset(); 1682 delegate->Reset();
1680 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), 1683 ui::TouchEventImpl move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15),
1681 kTouchId2, GetTime()); 1684 kTouchId2, GetTime());
1682 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); 1685 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4);
1683 EXPECT_FALSE(delegate->tap()); 1686 EXPECT_FALSE(delegate->tap());
1684 EXPECT_FALSE(delegate->tap_down()); 1687 EXPECT_FALSE(delegate->tap_down());
1685 EXPECT_FALSE(delegate->double_tap()); 1688 EXPECT_FALSE(delegate->double_tap());
1686 EXPECT_FALSE(delegate->scroll_begin()); 1689 EXPECT_FALSE(delegate->scroll_begin());
1687 EXPECT_FALSE(delegate->scroll_update()); 1690 EXPECT_FALSE(delegate->scroll_update());
1688 EXPECT_FALSE(delegate->scroll_end()); 1691 EXPECT_FALSE(delegate->scroll_end());
1689 EXPECT_FALSE(delegate->pinch_begin()); 1692 EXPECT_FALSE(delegate->pinch_begin());
1690 EXPECT_TRUE(delegate->pinch_update()); 1693 EXPECT_TRUE(delegate->pinch_update());
1691 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(), 1694 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(),
1692 delegate->bounding_box().ToString()); 1695 delegate->bounding_box().ToString());
1693 1696
1694 // Release the first finger. This should end pinch. 1697 // Release the first finger. This should end pinch.
1695 delegate->Reset(); 1698 delegate->Reset();
1696 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1699 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1697 kTouchId1, press.time_stamp() + 1700 kTouchId1, press.time_stamp() +
1698 base::TimeDelta::FromMilliseconds(50)); 1701 base::TimeDelta::FromMilliseconds(50));
1699 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1702 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1700 EXPECT_FALSE(delegate->tap()); 1703 EXPECT_FALSE(delegate->tap());
1701 EXPECT_FALSE(delegate->tap_down()); 1704 EXPECT_FALSE(delegate->tap_down());
1702 EXPECT_FALSE(delegate->double_tap()); 1705 EXPECT_FALSE(delegate->double_tap());
1703 EXPECT_FALSE(delegate->scroll_begin()); 1706 EXPECT_FALSE(delegate->scroll_begin());
1704 EXPECT_FALSE(delegate->scroll_update()); 1707 EXPECT_FALSE(delegate->scroll_update());
1705 EXPECT_FALSE(delegate->scroll_end()); 1708 EXPECT_FALSE(delegate->scroll_end());
1706 EXPECT_TRUE(delegate->pinch_end()); 1709 EXPECT_TRUE(delegate->pinch_end());
1707 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), 1710 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
1708 delegate->bounding_box().ToString()); 1711 delegate->bounding_box().ToString());
1709 1712
1710 // Move the second finger. This should still generate a scroll. 1713 // Move the second finger. This should still generate a scroll.
1711 delegate->Reset(); 1714 delegate->Reset();
1712 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 1715 ui::TouchEventImpl move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
1713 kTouchId2, GetTime()); 1716 kTouchId2, GetTime());
1714 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5); 1717 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5);
1715 EXPECT_FALSE(delegate->tap()); 1718 EXPECT_FALSE(delegate->tap());
1716 EXPECT_FALSE(delegate->tap_down()); 1719 EXPECT_FALSE(delegate->tap_down());
1717 EXPECT_FALSE(delegate->double_tap()); 1720 EXPECT_FALSE(delegate->double_tap());
1718 EXPECT_FALSE(delegate->scroll_begin()); 1721 EXPECT_FALSE(delegate->scroll_begin());
1719 EXPECT_TRUE(delegate->scroll_update()); 1722 EXPECT_TRUE(delegate->scroll_update());
1720 EXPECT_FALSE(delegate->scroll_end()); 1723 EXPECT_FALSE(delegate->scroll_end());
1721 EXPECT_FALSE(delegate->pinch_begin()); 1724 EXPECT_FALSE(delegate->pinch_begin());
1722 EXPECT_FALSE(delegate->pinch_update()); 1725 EXPECT_FALSE(delegate->pinch_update());
1723 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1726 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1724 } 1727 }
1725 1728
1726 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { 1729 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) {
1727 scoped_ptr<GestureEventConsumeDelegate> delegate( 1730 scoped_ptr<GestureEventConsumeDelegate> delegate(
1728 new GestureEventConsumeDelegate()); 1731 new GestureEventConsumeDelegate());
1729 1732
1730 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1733 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1731 6, GetTime()); 1734 6, GetTime());
1732 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1735 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1733 EXPECT_FALSE(delegate->tap()); 1736 EXPECT_FALSE(delegate->tap());
1734 EXPECT_FALSE(delegate->tap_down()); 1737 EXPECT_FALSE(delegate->tap_down());
1735 } 1738 }
1736 1739
1737 // Check that a touch is locked to the window of the closest current touch 1740 // Check that a touch is locked to the window of the closest current touch
1738 // within max_separation_for_gesture_touches_in_pixels 1741 // within max_separation_for_gesture_touches_in_pixels
1739 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) { 1742 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) {
1740 ui::GestureRecognizer* gesture_recognizer = 1743 ui::GestureRecognizer* gesture_recognizer =
1741 new ui::GestureRecognizerImpl(root_window()); 1744 new ui::GestureRecognizerImpl(root_window());
(...skipping 16 matching lines...) Expand all
1758 1761
1759 scoped_array<aura::Window*> windows(new aura::Window*[kNumWindows]); 1762 scoped_array<aura::Window*> windows(new aura::Window*[kNumWindows]);
1760 1763
1761 // Instantiate windows with |window_bounds| and touch each window at 1764 // Instantiate windows with |window_bounds| and touch each window at
1762 // its origin. 1765 // its origin.
1763 for (int i = 0; i < kNumWindows; ++i) { 1766 for (int i = 0; i < kNumWindows; ++i) {
1764 delegates[i] = new GestureEventConsumeDelegate(); 1767 delegates[i] = new GestureEventConsumeDelegate();
1765 windows[i] = CreateTestWindowWithDelegate( 1768 windows[i] = CreateTestWindowWithDelegate(
1766 delegates[i], i, *window_bounds[i], NULL); 1769 delegates[i], i, *window_bounds[i], NULL);
1767 windows[i]->set_id(i); 1770 windows[i]->set_id(i);
1768 TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i]->origin(), 1771 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, window_bounds[i]->origin(),
1769 i, GetTime()); 1772 i, GetTime());
1770 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1773 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1771 } 1774 }
1772 1775
1773 // Touches should now be associated with the closest touch within 1776 // Touches should now be associated with the closest touch within
1774 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels 1777 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels
1775 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11)); 1778 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11));
1776 EXPECT_EQ("0", WindowIDAsString(target)); 1779 EXPECT_EQ("0", WindowIDAsString(target));
1777 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11)); 1780 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11));
1778 EXPECT_EQ("1", WindowIDAsString(target)); 1781 EXPECT_EQ("1", WindowIDAsString(target));
1779 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511)); 1782 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511));
1780 EXPECT_EQ("2", WindowIDAsString(target)); 1783 EXPECT_EQ("2", WindowIDAsString(target));
1781 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511)); 1784 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511));
1782 EXPECT_EQ("3", WindowIDAsString(target)); 1785 EXPECT_EQ("3", WindowIDAsString(target));
1783 1786
1784 // Add a touch in the middle associated with windows[2] 1787 // Add a touch in the middle associated with windows[2]
1785 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500), 1788 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500),
1786 kNumWindows, GetTime()); 1789 kNumWindows, GetTime());
1787 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1790 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1788 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250), 1791 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250),
1789 kNumWindows, GetTime()); 1792 kNumWindows, GetTime());
1790 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1793 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
1791 1794
1792 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250)); 1795 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250));
1793 EXPECT_EQ("2", WindowIDAsString(target)); 1796 EXPECT_EQ("2", WindowIDAsString(target));
1794 1797
1795 // Make sure that ties are broken by distance to a current touch 1798 // Make sure that ties are broken by distance to a current touch
1796 // Closer to the point in the bottom right. 1799 // Closer to the point in the bottom right.
1797 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380)); 1800 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380));
1798 EXPECT_EQ("3", WindowIDAsString(target)); 1801 EXPECT_EQ("3", WindowIDAsString(target));
1799 1802
1800 // This touch is closer to the point in the middle 1803 // This touch is closer to the point in the middle
1801 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300)); 1804 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300));
1802 EXPECT_EQ("2", WindowIDAsString(target)); 1805 EXPECT_EQ("2", WindowIDAsString(target));
1803 1806
1804 // A touch too far from other touches won't be locked to anything 1807 // A touch too far from other touches won't be locked to anything
1805 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); 1808 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000));
1806 EXPECT_TRUE(target == NULL); 1809 EXPECT_TRUE(target == NULL);
1807 1810
1808 // Move a touch associated with windows[2] to 1000, 1000 1811 // Move a touch associated with windows[2] to 1000, 1000
1809 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), 1812 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000),
1810 kNumWindows, GetTime()); 1813 kNumWindows, GetTime());
1811 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1814 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
1812 1815
1813 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); 1816 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000));
1814 EXPECT_EQ("2", WindowIDAsString(target)); 1817 EXPECT_EQ("2", WindowIDAsString(target));
1815 } 1818 }
1816 1819
1817 // Check that touch events outside the root window are still handled 1820 // Check that touch events outside the root window are still handled
1818 // by the root window's gesture sequence. 1821 // by the root window's gesture sequence.
1819 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { 1822 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) {
1820 TestGestureRecognizer* gesture_recognizer = 1823 TestGestureRecognizer* gesture_recognizer =
1821 new TestGestureRecognizer(root_window()); 1824 new TestGestureRecognizer(root_window());
1822 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 1825 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
1823 1826
1824 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( 1827 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds(
1825 gfx::Rect(-100, -100, 2000, 2000), NULL)); 1828 gfx::Rect(-100, -100, 2000, 2000), NULL));
1826 1829
1827 ui::GestureSequence* window_gesture_sequence = 1830 ui::GestureSequence* window_gesture_sequence =
1828 gesture_recognizer->GetGestureSequenceForTesting(window.get()); 1831 gesture_recognizer->GetGestureSequenceForTesting(window.get());
1829 1832
1830 ui::GestureSequence* root_window_gesture_sequence = 1833 ui::GestureSequence* root_window_gesture_sequence =
1831 gesture_recognizer->GetGestureSequenceForTesting(root_window()); 1834 gesture_recognizer->GetGestureSequenceForTesting(root_window());
1832 1835
1833 gfx::Point pos1(-10, -10); 1836 gfx::Point pos1(-10, -10);
1834 TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, GetTime()); 1837 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, pos1, 0, GetTime());
1835 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1838 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
1836 1839
1837 gfx::Point pos2(1000, 1000); 1840 gfx::Point pos2(1000, 1000);
1838 TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, GetTime()); 1841 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, pos2, 1, GetTime());
1839 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1842 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1840 1843
1841 // As these presses were outside the root window, they should be 1844 // As these presses were outside the root window, they should be
1842 // associated with the root window. 1845 // associated with the root window.
1843 EXPECT_EQ(0, window_gesture_sequence->point_count()); 1846 EXPECT_EQ(0, window_gesture_sequence->point_count());
1844 EXPECT_EQ(2, root_window_gesture_sequence->point_count()); 1847 EXPECT_EQ(2, root_window_gesture_sequence->point_count());
1845 } 1848 }
1846 1849
1847 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) { 1850 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) {
1848 scoped_ptr<QueueTouchEventDelegate> delegate( 1851 scoped_ptr<QueueTouchEventDelegate> delegate(
1849 new QueueTouchEventDelegate(root_window())); 1852 new QueueTouchEventDelegate(root_window()));
1850 const int kTouchId = 2; 1853 const int kTouchId = 2;
1851 gfx::Rect bounds(100, 200, 100, 100); 1854 gfx::Rect bounds(100, 200, 100, 100);
1852 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1855 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1853 delegate.get(), -1234, bounds, NULL)); 1856 delegate.get(), -1234, bounds, NULL));
1854 delegate->set_window(window.get()); 1857 delegate->set_window(window.get());
1855 1858
1856 delegate->Reset(); 1859 delegate->Reset();
1857 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1860 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1858 kTouchId, GetTime()); 1861 kTouchId, GetTime());
1859 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1862 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1860 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1863 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1861 kTouchId, press.time_stamp() + 1864 kTouchId, press.time_stamp() +
1862 base::TimeDelta::FromMilliseconds(50)); 1865 base::TimeDelta::FromMilliseconds(50));
1863 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1866 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1864 1867
1865 delegate->Reset(); 1868 delegate->Reset();
1866 delegate->ReceivedAck(); 1869 delegate->ReceivedAck();
1867 EXPECT_TRUE(delegate->tap_down()); 1870 EXPECT_TRUE(delegate->tap_down());
1868 delegate->Reset(); 1871 delegate->Reset();
1869 delegate->ReceivedAckPreventDefaulted(); 1872 delegate->ReceivedAckPreventDefaulted();
1870 EXPECT_FALSE(delegate->tap()); 1873 EXPECT_FALSE(delegate->tap());
1871 } 1874 }
1872 1875
(...skipping 27 matching lines...) Expand all
1900 new GestureEventConsumeDelegate()); 1903 new GestureEventConsumeDelegate());
1901 const int kWindowWidth = 123; 1904 const int kWindowWidth = 123;
1902 const int kWindowHeight = 45; 1905 const int kWindowHeight = 45;
1903 const int kTouchId1 = 2; 1906 const int kTouchId1 = 2;
1904 const int kTouchId2 = 3; 1907 const int kTouchId2 = 3;
1905 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1908 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1906 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1909 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1907 delegate.get(), -1234, bounds, NULL)); 1910 delegate.get(), -1234, bounds, NULL));
1908 1911
1909 delegate->Reset(); 1912 delegate->Reset();
1910 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1913 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1911 kTouchId1, GetTime()); 1914 kTouchId1, GetTime());
1912 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1915 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
1913 EXPECT_FALSE(delegate->tap()); 1916 EXPECT_FALSE(delegate->tap());
1914 EXPECT_TRUE(delegate->tap_down()); 1917 EXPECT_TRUE(delegate->tap_down());
1915 EXPECT_FALSE(delegate->double_tap()); 1918 EXPECT_FALSE(delegate->double_tap());
1916 EXPECT_FALSE(delegate->scroll_begin()); 1919 EXPECT_FALSE(delegate->scroll_begin());
1917 EXPECT_FALSE(delegate->scroll_update()); 1920 EXPECT_FALSE(delegate->scroll_update());
1918 EXPECT_FALSE(delegate->scroll_end()); 1921 EXPECT_FALSE(delegate->scroll_end());
1919 EXPECT_FALSE(delegate->long_press()); 1922 EXPECT_FALSE(delegate->long_press());
1920 EXPECT_FALSE(delegate->two_finger_tap()); 1923 EXPECT_FALSE(delegate->two_finger_tap());
1921 1924
1922 delegate->Reset(); 1925 delegate->Reset();
1923 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 1926 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
1924 kTouchId2, GetTime()); 1927 kTouchId2, GetTime());
1925 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1928 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1926 EXPECT_FALSE(delegate->tap()); 1929 EXPECT_FALSE(delegate->tap());
1927 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 1930 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
1928 EXPECT_FALSE(delegate->double_tap()); 1931 EXPECT_FALSE(delegate->double_tap());
1929 EXPECT_FALSE(delegate->scroll_begin()); 1932 EXPECT_FALSE(delegate->scroll_begin());
1930 EXPECT_FALSE(delegate->scroll_update()); 1933 EXPECT_FALSE(delegate->scroll_update());
1931 EXPECT_FALSE(delegate->scroll_end()); 1934 EXPECT_FALSE(delegate->scroll_end());
1932 EXPECT_FALSE(delegate->long_press()); 1935 EXPECT_FALSE(delegate->long_press());
1933 EXPECT_FALSE(delegate->two_finger_tap()); 1936 EXPECT_FALSE(delegate->two_finger_tap());
1934 1937
1935 // Little bit of touch move should not affect our state. 1938 // Little bit of touch move should not affect our state.
1936 delegate->Reset(); 1939 delegate->Reset();
1937 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(102, 202), 1940 ui::TouchEventImpl move1(ui::ET_TOUCH_MOVED, gfx::Point(102, 202),
1938 kTouchId1, GetTime()); 1941 kTouchId1, GetTime());
1939 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 1942 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
1940 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(131, 202), 1943 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(131, 202),
1941 kTouchId2, GetTime()); 1944 kTouchId2, GetTime());
1942 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1945 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
1943 EXPECT_FALSE(delegate->tap()); 1946 EXPECT_FALSE(delegate->tap());
1944 EXPECT_FALSE(delegate->tap_down()); 1947 EXPECT_FALSE(delegate->tap_down());
1945 EXPECT_FALSE(delegate->double_tap()); 1948 EXPECT_FALSE(delegate->double_tap());
1946 EXPECT_FALSE(delegate->scroll_begin()); 1949 EXPECT_FALSE(delegate->scroll_begin());
1947 EXPECT_FALSE(delegate->scroll_update()); 1950 EXPECT_FALSE(delegate->scroll_update());
1948 EXPECT_FALSE(delegate->scroll_end()); 1951 EXPECT_FALSE(delegate->scroll_end());
1949 EXPECT_FALSE(delegate->long_press()); 1952 EXPECT_FALSE(delegate->long_press());
1950 EXPECT_FALSE(delegate->two_finger_tap()); 1953 EXPECT_FALSE(delegate->two_finger_tap());
1951 1954
1952 // Make sure there is enough delay before the touch is released so that it is 1955 // Make sure there is enough delay before the touch is released so that it is
1953 // recognized as a tap. 1956 // recognized as a tap.
1954 delegate->Reset(); 1957 delegate->Reset();
1955 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1958 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1956 kTouchId1, press1.time_stamp() + 1959 kTouchId1, press1.time_stamp() +
1957 base::TimeDelta::FromMilliseconds(50)); 1960 base::TimeDelta::FromMilliseconds(50));
1958 1961
1959 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1962 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1960 EXPECT_FALSE(delegate->tap()); 1963 EXPECT_FALSE(delegate->tap());
1961 EXPECT_FALSE(delegate->tap_down()); 1964 EXPECT_FALSE(delegate->tap_down());
1962 EXPECT_FALSE(delegate->double_tap()); 1965 EXPECT_FALSE(delegate->double_tap());
1963 EXPECT_FALSE(delegate->scroll_begin()); 1966 EXPECT_FALSE(delegate->scroll_begin());
1964 EXPECT_FALSE(delegate->scroll_update()); 1967 EXPECT_FALSE(delegate->scroll_update());
1965 EXPECT_FALSE(delegate->scroll_end()); 1968 EXPECT_FALSE(delegate->scroll_end());
1966 EXPECT_TRUE(delegate->two_finger_tap()); 1969 EXPECT_TRUE(delegate->two_finger_tap());
1967 1970
1968 // Lift second finger. 1971 // Lift second finger.
1969 // Make sure there is enough delay before the touch is released so that it is 1972 // Make sure there is enough delay before the touch is released so that it is
1970 // recognized as a tap. 1973 // recognized as a tap.
1971 delegate->Reset(); 1974 delegate->Reset();
1972 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 1975 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201),
1973 kTouchId2, press2.time_stamp() + 1976 kTouchId2, press2.time_stamp() +
1974 base::TimeDelta::FromMilliseconds(50)); 1977 base::TimeDelta::FromMilliseconds(50));
1975 1978
1976 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 1979 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
1977 EXPECT_FALSE(delegate->tap()); 1980 EXPECT_FALSE(delegate->tap());
1978 EXPECT_FALSE(delegate->tap_down()); 1981 EXPECT_FALSE(delegate->tap_down());
1979 EXPECT_FALSE(delegate->double_tap()); 1982 EXPECT_FALSE(delegate->double_tap());
1980 EXPECT_FALSE(delegate->scroll_begin()); 1983 EXPECT_FALSE(delegate->scroll_begin());
1981 EXPECT_FALSE(delegate->scroll_update()); 1984 EXPECT_FALSE(delegate->scroll_update());
1982 EXPECT_TRUE(delegate->scroll_end()); 1985 EXPECT_TRUE(delegate->scroll_end());
1983 EXPECT_FALSE(delegate->two_finger_tap()); 1986 EXPECT_FALSE(delegate->two_finger_tap());
1984 } 1987 }
1985 1988
1986 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) { 1989 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) {
1987 scoped_ptr<GestureEventConsumeDelegate> delegate( 1990 scoped_ptr<GestureEventConsumeDelegate> delegate(
1988 new GestureEventConsumeDelegate()); 1991 new GestureEventConsumeDelegate());
1989 const int kWindowWidth = 123; 1992 const int kWindowWidth = 123;
1990 const int kWindowHeight = 45; 1993 const int kWindowHeight = 45;
1991 const int kTouchId1 = 2; 1994 const int kTouchId1 = 2;
1992 const int kTouchId2 = 3; 1995 const int kTouchId2 = 3;
1993 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1996 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1994 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1997 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1995 delegate.get(), -1234, bounds, NULL)); 1998 delegate.get(), -1234, bounds, NULL));
1996 1999
1997 delegate->Reset(); 2000 delegate->Reset();
1998 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2001 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1999 kTouchId1, GetTime()); 2002 kTouchId1, GetTime());
2000 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2003 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2001 2004
2002 delegate->Reset(); 2005 delegate->Reset();
2003 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2006 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2004 kTouchId2, GetTime()); 2007 kTouchId2, GetTime());
2005 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2008 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2006 2009
2007 // Send release event after sufficient delay so that two finger time expires. 2010 // Send release event after sufficient delay so that two finger time expires.
2008 delegate->Reset(); 2011 delegate->Reset();
2009 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2012 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2010 kTouchId1, press1.time_stamp() + 2013 kTouchId1, press1.time_stamp() +
2011 base::TimeDelta::FromMilliseconds(1000)); 2014 base::TimeDelta::FromMilliseconds(1000));
2012 2015
2013 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2016 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
2014 EXPECT_FALSE(delegate->two_finger_tap()); 2017 EXPECT_FALSE(delegate->two_finger_tap());
2015 2018
2016 // Lift second finger. 2019 // Lift second finger.
2017 // Make sure there is enough delay before the touch is released so that it is 2020 // Make sure there is enough delay before the touch is released so that it is
2018 // recognized as a tap. 2021 // recognized as a tap.
2019 delegate->Reset(); 2022 delegate->Reset();
2020 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 2023 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201),
2021 kTouchId2, press2.time_stamp() + 2024 kTouchId2, press2.time_stamp() +
2022 base::TimeDelta::FromMilliseconds(50)); 2025 base::TimeDelta::FromMilliseconds(50));
2023 2026
2024 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2027 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
2025 EXPECT_FALSE(delegate->two_finger_tap()); 2028 EXPECT_FALSE(delegate->two_finger_tap());
2026 } 2029 }
2027 2030
2028 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) { 2031 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
2029 scoped_ptr<GestureEventConsumeDelegate> delegate( 2032 scoped_ptr<GestureEventConsumeDelegate> delegate(
2030 new GestureEventConsumeDelegate()); 2033 new GestureEventConsumeDelegate());
2031 const int kWindowWidth = 123; 2034 const int kWindowWidth = 123;
2032 const int kWindowHeight = 45; 2035 const int kWindowHeight = 45;
2033 const int kTouchId1 = 2; 2036 const int kTouchId1 = 2;
2034 const int kTouchId2 = 3; 2037 const int kTouchId2 = 3;
2035 2038
2036 // Test moving first finger 2039 // Test moving first finger
2037 { 2040 {
2038 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2041 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2039 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2042 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2040 delegate.get(), -1234, bounds, NULL)); 2043 delegate.get(), -1234, bounds, NULL));
2041 2044
2042 delegate->Reset(); 2045 delegate->Reset();
2043 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2046 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2044 kTouchId1, GetTime()); 2047 kTouchId1, GetTime());
2045 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2048 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2046 2049
2047 delegate->Reset(); 2050 delegate->Reset();
2048 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2051 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2049 kTouchId2, GetTime()); 2052 kTouchId2, GetTime());
2050 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2053 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2051 2054
2052 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 2055 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get());
2053 EXPECT_FALSE(delegate->two_finger_tap()); 2056 EXPECT_FALSE(delegate->two_finger_tap());
2054 EXPECT_TRUE(delegate->pinch_begin()); 2057 EXPECT_TRUE(delegate->pinch_begin());
2055 2058
2056 // Make sure there is enough delay before the touch is released so that it 2059 // Make sure there is enough delay before the touch is released so that it
2057 // is recognized as a tap. 2060 // is recognized as a tap.
2058 delegate->Reset(); 2061 delegate->Reset();
2059 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2062 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2060 kTouchId2, press1.time_stamp() + 2063 kTouchId2, press1.time_stamp() +
2061 base::TimeDelta::FromMilliseconds(50)); 2064 base::TimeDelta::FromMilliseconds(50));
2062 2065
2063 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2066 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2064 EXPECT_FALSE(delegate->two_finger_tap()); 2067 EXPECT_FALSE(delegate->two_finger_tap());
2065 EXPECT_TRUE(delegate->pinch_end()); 2068 EXPECT_TRUE(delegate->pinch_end());
2066 } 2069 }
2067 2070
2068 // Test moving second finger 2071 // Test moving second finger
2069 { 2072 {
2070 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2073 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2071 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2074 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2072 delegate.get(), -1234, bounds, NULL)); 2075 delegate.get(), -1234, bounds, NULL));
2073 2076
2074 delegate->Reset(); 2077 delegate->Reset();
2075 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2078 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2076 kTouchId1, GetTime()); 2079 kTouchId1, GetTime());
2077 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2080 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2078 2081
2079 delegate->Reset(); 2082 delegate->Reset();
2080 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2083 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2081 kTouchId2, GetTime()); 2084 kTouchId2, GetTime());
2082 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2085 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2083 2086
2084 SendScrollEvent(root_window(), 101, 230, kTouchId2, delegate.get()); 2087 SendScrollEvent(root_window(), 101, 230, kTouchId2, delegate.get());
2085 EXPECT_FALSE(delegate->two_finger_tap()); 2088 EXPECT_FALSE(delegate->two_finger_tap());
2086 EXPECT_TRUE(delegate->pinch_begin()); 2089 EXPECT_TRUE(delegate->pinch_begin());
2087 2090
2088 // Make sure there is enough delay before the touch is released so that it 2091 // Make sure there is enough delay before the touch is released so that it
2089 // is recognized as a tap. 2092 // is recognized as a tap.
2090 delegate->Reset(); 2093 delegate->Reset();
2091 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2094 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2092 kTouchId1, press1.time_stamp() + 2095 kTouchId1, press1.time_stamp() +
2093 base::TimeDelta::FromMilliseconds(50)); 2096 base::TimeDelta::FromMilliseconds(50));
2094 2097
2095 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2098 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2096 EXPECT_FALSE(delegate->two_finger_tap()); 2099 EXPECT_FALSE(delegate->two_finger_tap());
2097 EXPECT_TRUE(delegate->pinch_end()); 2100 EXPECT_TRUE(delegate->pinch_end());
2098 } 2101 }
2099 } 2102 }
2100 2103
2101 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) { 2104 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) {
2102 scoped_ptr<GestureEventConsumeDelegate> delegate( 2105 scoped_ptr<GestureEventConsumeDelegate> delegate(
2103 new GestureEventConsumeDelegate()); 2106 new GestureEventConsumeDelegate());
2104 const int kWindowWidth = 123; 2107 const int kWindowWidth = 123;
2105 const int kWindowHeight = 45; 2108 const int kWindowHeight = 45;
2106 const int kTouchId1 = 2; 2109 const int kTouchId1 = 2;
2107 const int kTouchId2 = 3; 2110 const int kTouchId2 = 3;
2108 2111
2109 // Test canceling first finger. 2112 // Test canceling first finger.
2110 { 2113 {
2111 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2114 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2112 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2115 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2113 delegate.get(), -1234, bounds, NULL)); 2116 delegate.get(), -1234, bounds, NULL));
2114 2117
2115 delegate->Reset(); 2118 delegate->Reset();
2116 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2119 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2117 kTouchId1, GetTime()); 2120 kTouchId1, GetTime());
2118 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2121 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2119 2122
2120 delegate->Reset(); 2123 delegate->Reset();
2121 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2124 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2122 kTouchId2, GetTime()); 2125 kTouchId2, GetTime());
2123 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2126 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2124 2127
2125 delegate->Reset(); 2128 delegate->Reset();
2126 TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), 2129 ui::TouchEventImpl cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201),
2127 kTouchId1, GetTime()); 2130 kTouchId1, GetTime());
2128 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel); 2131 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel);
2129 EXPECT_FALSE(delegate->two_finger_tap()); 2132 EXPECT_FALSE(delegate->two_finger_tap());
2130 2133
2131 // Make sure there is enough delay before the touch is released so that it 2134 // Make sure there is enough delay before the touch is released so that it
2132 // is recognized as a tap. 2135 // is recognized as a tap.
2133 delegate->Reset(); 2136 delegate->Reset();
2134 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2137 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2135 kTouchId2, press1.time_stamp() + 2138 kTouchId2, press1.time_stamp() +
2136 base::TimeDelta::FromMilliseconds(50)); 2139 base::TimeDelta::FromMilliseconds(50));
2137 2140
2138 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2141 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2139 EXPECT_FALSE(delegate->two_finger_tap()); 2142 EXPECT_FALSE(delegate->two_finger_tap());
2140 } 2143 }
2141 2144
2142 // Test canceling second finger 2145 // Test canceling second finger
2143 { 2146 {
2144 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2147 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2145 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2148 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2146 delegate.get(), -1234, bounds, NULL)); 2149 delegate.get(), -1234, bounds, NULL));
2147 2150
2148 delegate->Reset(); 2151 delegate->Reset();
2149 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2152 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2150 kTouchId1, GetTime()); 2153 kTouchId1, GetTime());
2151 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2154 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2152 2155
2153 delegate->Reset(); 2156 delegate->Reset();
2154 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2157 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2155 kTouchId2, GetTime()); 2158 kTouchId2, GetTime());
2156 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2159 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2157 2160
2158 delegate->Reset(); 2161 delegate->Reset();
2159 TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), 2162 ui::TouchEventImpl cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201),
2160 kTouchId2, GetTime()); 2163 kTouchId2, GetTime());
2161 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel); 2164 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel);
2162 EXPECT_FALSE(delegate->two_finger_tap()); 2165 EXPECT_FALSE(delegate->two_finger_tap());
2163 2166
2164 // Make sure there is enough delay before the touch is released so that it 2167 // Make sure there is enough delay before the touch is released so that it
2165 // is recognized as a tap. 2168 // is recognized as a tap.
2166 delegate->Reset(); 2169 delegate->Reset();
2167 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2170 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2168 kTouchId1, press1.time_stamp() + 2171 kTouchId1, press1.time_stamp() +
2169 base::TimeDelta::FromMilliseconds(50)); 2172 base::TimeDelta::FromMilliseconds(50));
2170 2173
2171 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2174 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2172 EXPECT_FALSE(delegate->two_finger_tap()); 2175 EXPECT_FALSE(delegate->two_finger_tap());
2173 } 2176 }
2174 } 2177 }
2175 2178
2176 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) { 2179 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) {
2177 scoped_ptr<GestureEventConsumeDelegate> delegate( 2180 scoped_ptr<GestureEventConsumeDelegate> delegate(
2178 new GestureEventConsumeDelegate()); 2181 new GestureEventConsumeDelegate());
2179 const int kWindowWidth = 523; 2182 const int kWindowWidth = 523;
2180 const int kWindowHeight = 45; 2183 const int kWindowHeight = 45;
2181 const int kTouchId1 = 2; 2184 const int kTouchId1 = 2;
2182 const int kTouchId2 = 3; 2185 const int kTouchId2 = 3;
2183 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2186 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2184 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2187 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2185 delegate.get(), -1234, bounds, NULL)); 2188 delegate.get(), -1234, bounds, NULL));
2186 2189
2187 delegate->Reset(); 2190 delegate->Reset();
2188 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2191 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2189 kTouchId1, GetTime()); 2192 kTouchId1, GetTime());
2190 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2193 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2191 EXPECT_FALSE(delegate->tap()); 2194 EXPECT_FALSE(delegate->tap());
2192 EXPECT_TRUE(delegate->tap_down()); 2195 EXPECT_TRUE(delegate->tap_down());
2193 EXPECT_FALSE(delegate->double_tap()); 2196 EXPECT_FALSE(delegate->double_tap());
2194 EXPECT_FALSE(delegate->scroll_begin()); 2197 EXPECT_FALSE(delegate->scroll_begin());
2195 EXPECT_FALSE(delegate->scroll_update()); 2198 EXPECT_FALSE(delegate->scroll_update());
2196 EXPECT_FALSE(delegate->scroll_end()); 2199 EXPECT_FALSE(delegate->scroll_end());
2197 EXPECT_FALSE(delegate->long_press()); 2200 EXPECT_FALSE(delegate->long_press());
2198 EXPECT_FALSE(delegate->two_finger_tap()); 2201 EXPECT_FALSE(delegate->two_finger_tap());
2199 2202
2200 delegate->Reset(); 2203 delegate->Reset();
2201 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(430, 201), 2204 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(430, 201),
2202 kTouchId2, GetTime()); 2205 kTouchId2, GetTime());
2203 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2206 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2204 EXPECT_FALSE(delegate->tap()); 2207 EXPECT_FALSE(delegate->tap());
2205 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 2208 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
2206 EXPECT_FALSE(delegate->double_tap()); 2209 EXPECT_FALSE(delegate->double_tap());
2207 EXPECT_TRUE(delegate->scroll_begin()); 2210 EXPECT_TRUE(delegate->scroll_begin());
2208 EXPECT_FALSE(delegate->scroll_update()); 2211 EXPECT_FALSE(delegate->scroll_update());
2209 EXPECT_FALSE(delegate->scroll_end()); 2212 EXPECT_FALSE(delegate->scroll_end());
2210 EXPECT_FALSE(delegate->long_press()); 2213 EXPECT_FALSE(delegate->long_press());
2211 EXPECT_FALSE(delegate->two_finger_tap()); 2214 EXPECT_FALSE(delegate->two_finger_tap());
2212 EXPECT_TRUE(delegate->pinch_begin()); 2215 EXPECT_TRUE(delegate->pinch_begin());
2213 } 2216 }
2214 2217
2215 // Verifies if a window is the target of multiple touch-ids and we hide the 2218 // Verifies if a window is the target of multiple touch-ids and we hide the
2216 // window everything is cleaned up correctly. 2219 // window everything is cleaned up correctly.
2217 TEST_F(GestureRecognizerTest, FlushAllOnHide) { 2220 TEST_F(GestureRecognizerTest, FlushAllOnHide) {
2218 scoped_ptr<GestureEventConsumeDelegate> delegate( 2221 scoped_ptr<GestureEventConsumeDelegate> delegate(
2219 new GestureEventConsumeDelegate()); 2222 new GestureEventConsumeDelegate());
2220 gfx::Rect bounds(0, 0, 200, 200); 2223 gfx::Rect bounds(0, 0, 200, 200);
2221 scoped_ptr<aura::Window> window( 2224 scoped_ptr<aura::Window> window(
2222 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, NULL)); 2225 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, NULL));
2223 const int kTouchId1 = 8; 2226 const int kTouchId1 = 8;
2224 const int kTouchId2 = 2; 2227 const int kTouchId2 = 2;
2225 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 2228 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
2226 kTouchId1, GetTime()); 2229 kTouchId1, GetTime());
2227 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2230 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2228 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 2231 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20),
2229 kTouchId2, GetTime()); 2232 kTouchId2, GetTime());
2230 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2233 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2231 window->Hide(); 2234 window->Hide();
2232 EXPECT_EQ(NULL, 2235 EXPECT_EQ(NULL,
2233 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press1)); 2236 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press1));
2234 EXPECT_EQ(NULL, 2237 EXPECT_EQ(NULL,
2235 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press2)); 2238 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press2));
2236 } 2239 }
2237 2240
2238 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) { 2241 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) {
2239 scoped_ptr<QueueTouchEventDelegate> delegate( 2242 scoped_ptr<QueueTouchEventDelegate> delegate(
2240 new QueueTouchEventDelegate(root_window())); 2243 new QueueTouchEventDelegate(root_window()));
2241 const int kTouchId = 2; 2244 const int kTouchId = 2;
2242 gfx::Rect bounds(100, 200, 100, 100); 2245 gfx::Rect bounds(100, 200, 100, 100);
2243 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2246 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2244 delegate.get(), -1234, bounds, NULL)); 2247 delegate.get(), -1234, bounds, NULL));
2245 delegate->set_window(window.get()); 2248 delegate->set_window(window.get());
2246 2249
2247 TimerTestGestureRecognizer* gesture_recognizer = 2250 TimerTestGestureRecognizer* gesture_recognizer =
2248 new TimerTestGestureRecognizer(root_window()); 2251 new TimerTestGestureRecognizer(root_window());
2249 TimerTestGestureSequence* gesture_sequence = 2252 TimerTestGestureSequence* gesture_sequence =
2250 static_cast<TimerTestGestureSequence*>( 2253 static_cast<TimerTestGestureSequence*>(
2251 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 2254 gesture_recognizer->GetGestureSequenceForTesting(window.get()));
2252 2255
2253 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 2256 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
2254 2257
2255 delegate->Reset(); 2258 delegate->Reset();
2256 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2259 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2257 kTouchId, GetTime()); 2260 kTouchId, GetTime());
2258 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2261 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
2259 // Scroll around, to cancel the long press 2262 // Scroll around, to cancel the long press
2260 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 2263 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get());
2261 2264
2262 delegate->Reset(); 2265 delegate->Reset();
2263 delegate->ReceivedAck(); 2266 delegate->ReceivedAck();
2264 EXPECT_TRUE(delegate->tap_down()); 2267 EXPECT_TRUE(delegate->tap_down());
2265 EXPECT_TRUE(gesture_sequence->IsTimerRunning()); 2268 EXPECT_TRUE(gesture_sequence->IsTimerRunning());
2266 2269
2267 delegate->Reset(); 2270 delegate->Reset();
2268 delegate->ReceivedAckPreventDefaulted(); 2271 delegate->ReceivedAckPreventDefaulted();
2269 EXPECT_FALSE(gesture_sequence->IsTimerRunning()); 2272 EXPECT_FALSE(gesture_sequence->IsTimerRunning());
2270 gesture_sequence->ForceTimeout(); 2273 gesture_sequence->ForceTimeout();
2271 EXPECT_FALSE(delegate->long_press()); 2274 EXPECT_FALSE(delegate->long_press());
2272 } 2275 }
2273 2276
2274 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events. 2277 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events.
2275 class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate { 2278 class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate {
2276 public: 2279 public:
2277 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {} 2280 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {}
2278 virtual ~ConsumesTouchMovesDelegate() {} 2281 virtual ~ConsumesTouchMovesDelegate() {}
2279 2282
2280 void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; } 2283 void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; }
2281 2284
2282 private: 2285 private:
2283 virtual ui::TouchStatus OnTouchEvent(TouchEvent* touch) OVERRIDE { 2286 virtual ui::TouchStatus OnTouchEvent(ui::TouchEventImpl* touch) OVERRIDE {
2284 if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED) 2287 if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED)
2285 return ui::TOUCH_STATUS_CONTINUE; 2288 return ui::TOUCH_STATUS_CONTINUE;
2286 return GestureEventConsumeDelegate::OnTouchEvent(touch); 2289 return GestureEventConsumeDelegate::OnTouchEvent(touch);
2287 } 2290 }
2288 2291
2289 bool consume_touch_move_; 2292 bool consume_touch_move_;
2290 2293
2291 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate); 2294 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate);
2292 }; 2295 };
2293 2296
2294 // Same as GestureEventScroll, but tests the different behaviour for consumed 2297 // Same as GestureEventScroll, but tests the different behaviour for consumed
2295 // touch-move events before and after scroll has started. 2298 // touch-move events before and after scroll has started.
2296 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) { 2299 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) {
2297 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 2300 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
2298 new ConsumesTouchMovesDelegate()); 2301 new ConsumesTouchMovesDelegate());
2299 const int kWindowWidth = 123; 2302 const int kWindowWidth = 123;
2300 const int kWindowHeight = 45; 2303 const int kWindowHeight = 45;
2301 const int kTouchId = 5; 2304 const int kTouchId = 5;
2302 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2305 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2303 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2306 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2304 delegate.get(), -1234, bounds, NULL)); 2307 delegate.get(), -1234, bounds, NULL));
2305 2308
2306 delegate->Reset(); 2309 delegate->Reset();
2307 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2310 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2308 kTouchId, GetTime()); 2311 kTouchId, GetTime());
2309 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2312 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
2310 EXPECT_FALSE(delegate->tap()); 2313 EXPECT_FALSE(delegate->tap());
2311 EXPECT_TRUE(delegate->tap_down()); 2314 EXPECT_TRUE(delegate->tap_down());
2312 EXPECT_TRUE(delegate->begin()); 2315 EXPECT_TRUE(delegate->begin());
2313 EXPECT_FALSE(delegate->double_tap()); 2316 EXPECT_FALSE(delegate->double_tap());
2314 EXPECT_FALSE(delegate->scroll_begin()); 2317 EXPECT_FALSE(delegate->scroll_begin());
2315 EXPECT_FALSE(delegate->scroll_update()); 2318 EXPECT_FALSE(delegate->scroll_update());
2316 EXPECT_FALSE(delegate->scroll_end()); 2319 EXPECT_FALSE(delegate->scroll_end());
2317 2320
2318 // Move the touch-point enough so that it would normally be considered a 2321 // Move the touch-point enough so that it would normally be considered a
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 EXPECT_FALSE(delegate->begin()); 2368 EXPECT_FALSE(delegate->begin());
2366 EXPECT_FALSE(delegate->double_tap()); 2369 EXPECT_FALSE(delegate->double_tap());
2367 EXPECT_FALSE(delegate->scroll_begin()); 2370 EXPECT_FALSE(delegate->scroll_begin());
2368 EXPECT_TRUE(delegate->scroll_update()); 2371 EXPECT_TRUE(delegate->scroll_update());
2369 EXPECT_FALSE(delegate->scroll_end()); 2372 EXPECT_FALSE(delegate->scroll_end());
2370 EXPECT_EQ(30, delegate->scroll_x()); 2373 EXPECT_EQ(30, delegate->scroll_x());
2371 EXPECT_EQ(4, delegate->scroll_y()); 2374 EXPECT_EQ(4, delegate->scroll_y());
2372 2375
2373 // Release the touch. This should end the scroll. 2376 // Release the touch. This should end the scroll.
2374 delegate->Reset(); 2377 delegate->Reset();
2375 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2378 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2376 kTouchId, press.time_stamp() + 2379 kTouchId, press.time_stamp() +
2377 base::TimeDelta::FromMilliseconds(50)); 2380 base::TimeDelta::FromMilliseconds(50));
2378 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2381 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2379 EXPECT_FALSE(delegate->tap()); 2382 EXPECT_FALSE(delegate->tap());
2380 EXPECT_FALSE(delegate->tap_down()); 2383 EXPECT_FALSE(delegate->tap_down());
2381 EXPECT_FALSE(delegate->begin()); 2384 EXPECT_FALSE(delegate->begin());
2382 EXPECT_TRUE(delegate->end()); 2385 EXPECT_TRUE(delegate->end());
2383 EXPECT_FALSE(delegate->double_tap()); 2386 EXPECT_FALSE(delegate->double_tap());
2384 EXPECT_FALSE(delegate->scroll_begin()); 2387 EXPECT_FALSE(delegate->scroll_begin());
2385 EXPECT_FALSE(delegate->scroll_update()); 2388 EXPECT_FALSE(delegate->scroll_update());
2386 EXPECT_TRUE(delegate->scroll_end()); 2389 EXPECT_TRUE(delegate->scroll_end());
2387 } 2390 }
2388 2391
2389 // Check that appropriate touch events generate double tap gesture events. 2392 // Check that appropriate touch events generate double tap gesture events.
2390 TEST_F(GestureRecognizerTest, GestureEventDoubleTap) { 2393 TEST_F(GestureRecognizerTest, GestureEventDoubleTap) {
2391 scoped_ptr<GestureEventConsumeDelegate> delegate( 2394 scoped_ptr<GestureEventConsumeDelegate> delegate(
2392 new GestureEventConsumeDelegate()); 2395 new GestureEventConsumeDelegate());
2393 const int kWindowWidth = 123; 2396 const int kWindowWidth = 123;
2394 const int kWindowHeight = 45; 2397 const int kWindowHeight = 45;
2395 const int kTouchId = 2; 2398 const int kTouchId = 2;
2396 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2399 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2397 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2400 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2398 delegate.get(), -1234, bounds, NULL)); 2401 delegate.get(), -1234, bounds, NULL));
2399 2402
2400 // First tap (tested in GestureEventTap) 2403 // First tap (tested in GestureEventTap)
2401 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201), 2404 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201),
2402 kTouchId, GetTime()); 2405 kTouchId, GetTime());
2403 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2406 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2404 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201), 2407 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201),
2405 kTouchId, press1.time_stamp() + 2408 kTouchId, press1.time_stamp() +
2406 base::TimeDelta::FromMilliseconds(50)); 2409 base::TimeDelta::FromMilliseconds(50));
2407 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2410 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
2408 delegate->Reset(); 2411 delegate->Reset();
2409 2412
2410 // Second tap 2413 // Second tap
2411 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 203), 2414 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 203),
2412 kTouchId, release1.time_stamp() + 2415 kTouchId, release1.time_stamp() +
2413 base::TimeDelta::FromMilliseconds(200)); 2416 base::TimeDelta::FromMilliseconds(200));
2414 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2417 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2415 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(102, 206), 2418 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(102, 206),
2416 kTouchId, press2.time_stamp() + 2419 kTouchId, press2.time_stamp() +
2417 base::TimeDelta::FromMilliseconds(50)); 2420 base::TimeDelta::FromMilliseconds(50));
2418 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2421 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
2419 2422
2420 EXPECT_TRUE(delegate->tap()); 2423 EXPECT_TRUE(delegate->tap());
2421 EXPECT_TRUE(delegate->tap_down()); 2424 EXPECT_TRUE(delegate->tap_down());
2422 EXPECT_TRUE(delegate->begin()); 2425 EXPECT_TRUE(delegate->begin());
2423 EXPECT_TRUE(delegate->end()); 2426 EXPECT_TRUE(delegate->end());
2424 EXPECT_TRUE(delegate->double_tap()); 2427 EXPECT_TRUE(delegate->double_tap());
2425 EXPECT_FALSE(delegate->scroll_begin()); 2428 EXPECT_FALSE(delegate->scroll_begin());
2426 EXPECT_FALSE(delegate->scroll_update()); 2429 EXPECT_FALSE(delegate->scroll_update());
2427 EXPECT_FALSE(delegate->scroll_end()); 2430 EXPECT_FALSE(delegate->scroll_end());
2428 2431
2429 EXPECT_EQ(2, delegate->tap_count()); 2432 EXPECT_EQ(2, delegate->tap_count());
2430 } 2433 }
2431 2434
2432 // Check that we don't get a double tap when the two taps are far apart. 2435 // Check that we don't get a double tap when the two taps are far apart.
2433 TEST_F(GestureRecognizerTest, TwoTapsFarApart) { 2436 TEST_F(GestureRecognizerTest, TwoTapsFarApart) {
2434 scoped_ptr<GestureEventConsumeDelegate> delegate( 2437 scoped_ptr<GestureEventConsumeDelegate> delegate(
2435 new GestureEventConsumeDelegate()); 2438 new GestureEventConsumeDelegate());
2436 const int kWindowWidth = 123; 2439 const int kWindowWidth = 123;
2437 const int kWindowHeight = 45; 2440 const int kWindowHeight = 45;
2438 const int kTouchId = 2; 2441 const int kTouchId = 2;
2439 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2442 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2440 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2443 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2441 delegate.get(), -1234, bounds, NULL)); 2444 delegate.get(), -1234, bounds, NULL));
2442 2445
2443 // First tap (tested in GestureEventTap) 2446 // First tap (tested in GestureEventTap)
2444 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2447 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2445 kTouchId, GetTime()); 2448 kTouchId, GetTime());
2446 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2449 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2447 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2450 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2448 kTouchId, press1.time_stamp() + 2451 kTouchId, press1.time_stamp() +
2449 base::TimeDelta::FromMilliseconds(50)); 2452 base::TimeDelta::FromMilliseconds(50));
2450 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2453 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
2451 delegate->Reset(); 2454 delegate->Reset();
2452 2455
2453 // Second tap, close in time but far in distance 2456 // Second tap, close in time but far in distance
2454 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(201, 201), 2457 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(201, 201),
2455 kTouchId, release1.time_stamp() + 2458 kTouchId, release1.time_stamp() +
2456 base::TimeDelta::FromMilliseconds(200)); 2459 base::TimeDelta::FromMilliseconds(200));
2457 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2460 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2458 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(201, 201), 2461 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(201, 201),
2459 kTouchId, press2.time_stamp() + 2462 kTouchId, press2.time_stamp() +
2460 base::TimeDelta::FromMilliseconds(50)); 2463 base::TimeDelta::FromMilliseconds(50));
2461 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2464 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
2462 2465
2463 EXPECT_TRUE(delegate->tap()); 2466 EXPECT_TRUE(delegate->tap());
2464 EXPECT_TRUE(delegate->tap_down()); 2467 EXPECT_TRUE(delegate->tap_down());
2465 EXPECT_TRUE(delegate->begin()); 2468 EXPECT_TRUE(delegate->begin());
2466 EXPECT_TRUE(delegate->end()); 2469 EXPECT_TRUE(delegate->end());
2467 EXPECT_FALSE(delegate->double_tap()); 2470 EXPECT_FALSE(delegate->double_tap());
2468 EXPECT_FALSE(delegate->scroll_begin()); 2471 EXPECT_FALSE(delegate->scroll_begin());
2469 EXPECT_FALSE(delegate->scroll_update()); 2472 EXPECT_FALSE(delegate->scroll_update());
2470 EXPECT_FALSE(delegate->scroll_end()); 2473 EXPECT_FALSE(delegate->scroll_end());
2471 2474
2472 EXPECT_EQ(1, delegate->tap_count()); 2475 EXPECT_EQ(1, delegate->tap_count());
2473 } 2476 }
2474 2477
2475 // Check that we don't get a double tap when the two taps have a long enough 2478 // Check that we don't get a double tap when the two taps have a long enough
2476 // delay in between. 2479 // delay in between.
2477 TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) { 2480 TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) {
2478 scoped_ptr<GestureEventConsumeDelegate> delegate( 2481 scoped_ptr<GestureEventConsumeDelegate> delegate(
2479 new GestureEventConsumeDelegate()); 2482 new GestureEventConsumeDelegate());
2480 const int kWindowWidth = 123; 2483 const int kWindowWidth = 123;
2481 const int kWindowHeight = 45; 2484 const int kWindowHeight = 45;
2482 const int kTouchId = 2; 2485 const int kTouchId = 2;
2483 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2486 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2484 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2487 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2485 delegate.get(), -1234, bounds, NULL)); 2488 delegate.get(), -1234, bounds, NULL));
2486 2489
2487 // First tap (tested in GestureEventTap) 2490 // First tap (tested in GestureEventTap)
2488 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2491 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2489 kTouchId, GetTime()); 2492 kTouchId, GetTime());
2490 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2493 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2491 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2494 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2492 kTouchId, press1.time_stamp() + 2495 kTouchId, press1.time_stamp() +
2493 base::TimeDelta::FromMilliseconds(50)); 2496 base::TimeDelta::FromMilliseconds(50));
2494 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2497 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
2495 delegate->Reset(); 2498 delegate->Reset();
2496 2499
2497 // Second tap, close in distance but after some delay 2500 // Second tap, close in distance but after some delay
2498 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2501 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2499 kTouchId, release1.time_stamp() + 2502 kTouchId, release1.time_stamp() +
2500 base::TimeDelta::FromMilliseconds(2000)); 2503 base::TimeDelta::FromMilliseconds(2000));
2501 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2504 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2502 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2505 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2503 kTouchId, press2.time_stamp() + 2506 kTouchId, press2.time_stamp() +
2504 base::TimeDelta::FromMilliseconds(50)); 2507 base::TimeDelta::FromMilliseconds(50));
2505 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2508 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
2506 2509
2507 EXPECT_TRUE(delegate->tap()); 2510 EXPECT_TRUE(delegate->tap());
2508 EXPECT_TRUE(delegate->tap_down()); 2511 EXPECT_TRUE(delegate->tap_down());
2509 EXPECT_TRUE(delegate->begin()); 2512 EXPECT_TRUE(delegate->begin());
2510 EXPECT_TRUE(delegate->end()); 2513 EXPECT_TRUE(delegate->end());
2511 EXPECT_FALSE(delegate->double_tap()); 2514 EXPECT_FALSE(delegate->double_tap());
2512 EXPECT_FALSE(delegate->scroll_begin()); 2515 EXPECT_FALSE(delegate->scroll_begin());
2513 EXPECT_FALSE(delegate->scroll_update()); 2516 EXPECT_FALSE(delegate->scroll_update());
2514 EXPECT_FALSE(delegate->scroll_end()); 2517 EXPECT_FALSE(delegate->scroll_end());
2515 2518
2516 EXPECT_EQ(1, delegate->tap_count()); 2519 EXPECT_EQ(1, delegate->tap_count());
2517 } 2520 }
2518 2521
2519 // Checks that if the bounding-box of a gesture changes because of change in 2522 // Checks that if the bounding-box of a gesture changes because of change in
2520 // radius of a touch-point, and not because of change in position, then there 2523 // radius of a touch-point, and not because of change in position, then there
2521 // are not gesture events from that. 2524 // are not gesture events from that.
2522 TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) { 2525 TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) {
2523 scoped_ptr<GestureEventConsumeDelegate> delegate( 2526 scoped_ptr<GestureEventConsumeDelegate> delegate(
2524 new GestureEventConsumeDelegate()); 2527 new GestureEventConsumeDelegate());
2525 const int kWindowWidth = 234; 2528 const int kWindowWidth = 234;
2526 const int kWindowHeight = 345; 2529 const int kWindowHeight = 345;
2527 const int kTouchId = 5, kTouchId2 = 7; 2530 const int kTouchId = 5, kTouchId2 = 7;
2528 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2531 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2529 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2532 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2530 delegate.get(), -1234, bounds, NULL)); 2533 delegate.get(), -1234, bounds, NULL));
2531 2534
2532 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId, 2535 ui::TouchEventImpl press1(
2533 GetTime()); 2536 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId, GetTime());
2534 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2537 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2535 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2538 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
2536 2539
2537 delegate->Reset(); 2540 delegate->Reset();
2538 2541
2539 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(201, 201), kTouchId2, 2542 ui::TouchEventImpl press2(
2543 ui::ET_TOUCH_PRESSED, gfx::Point(201, 201), kTouchId2,
2540 press1.time_stamp() + base::TimeDelta::FromMilliseconds(400)); 2544 press1.time_stamp() + base::TimeDelta::FromMilliseconds(400));
2541 press2.set_radius_x(5); 2545 press2.set_radius_x(5);
2542 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2546 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2543 EXPECT_FALSE(delegate->pinch_begin()); 2547 EXPECT_FALSE(delegate->pinch_begin());
2544 2548
2545 delegate->Reset(); 2549 delegate->Reset();
2546 2550
2547 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(141, 201), kTouchId, 2551 ui::TouchEventImpl move1(ui::ET_TOUCH_MOVED, gfx::Point(141, 201), kTouchId,
2548 press1.time_stamp() + base::TimeDelta::FromMilliseconds(40)); 2552 press1.time_stamp() + base::TimeDelta::FromMilliseconds(40));
2549 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 2553 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
2550 EXPECT_TRUE(delegate->pinch_begin()); 2554 EXPECT_TRUE(delegate->pinch_begin());
2551 EXPECT_EQ(gfx::Rect(141, 196, 65, 10).ToString(), 2555 EXPECT_EQ(gfx::Rect(141, 196, 65, 10).ToString(),
2552 delegate->bounding_box().ToString()); 2556 delegate->bounding_box().ToString());
2553 2557
2554 delegate->Reset(); 2558 delegate->Reset();
2555 2559
2556 // The position doesn't move, but the radius changes. 2560 // The position doesn't move, but the radius changes.
2557 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 201), kTouchId, 2561 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 201), kTouchId,
2558 press2.time_stamp() + base::TimeDelta::FromMilliseconds(40)); 2562 press2.time_stamp() + base::TimeDelta::FromMilliseconds(40));
2559 move2.set_radius_x(50); 2563 move2.set_radius_x(50);
2560 move2.set_radius_y(60); 2564 move2.set_radius_y(60);
2561 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 2565 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
2562 EXPECT_FALSE(delegate->tap()); 2566 EXPECT_FALSE(delegate->tap());
2563 EXPECT_FALSE(delegate->scroll_update()); 2567 EXPECT_FALSE(delegate->scroll_update());
2564 EXPECT_FALSE(delegate->pinch_update()); 2568 EXPECT_FALSE(delegate->pinch_update());
2565 2569
2566 delegate->Reset(); 2570 delegate->Reset();
2567 } 2571 }
2568 2572
2569 } // namespace test 2573 } // namespace test
2570 } // namespace aura 2574 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/focus_manager.cc ('k') | ui/aura/root_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698