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

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

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

Powered by Google App Engine
This is Rietveld 408576698