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