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