OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 // testing::Test | 47 // testing::Test |
48 void SetUp() override { | 48 void SetUp() override { |
49 #if defined(USE_AURA) | 49 #if defined(USE_AURA) |
50 aura::Env::CreateInstance(true); | 50 aura::Env::CreateInstance(true); |
51 screen_.reset(aura::TestScreen::Create(gfx::Size())); | 51 screen_.reset(aura::TestScreen::Create(gfx::Size())); |
52 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | 52 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
53 #endif | 53 #endif |
54 | 54 |
55 emulator_.reset(new TouchEmulator(this)); | 55 emulator_.reset(new TouchEmulator(this)); |
56 emulator_->Enable(); | 56 emulator_->Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); |
57 } | 57 } |
58 | 58 |
59 void TearDown() override { | 59 void TearDown() override { |
60 emulator_->Disable(); | 60 emulator_->Disable(); |
61 EXPECT_EQ("", ExpectedEvents()); | 61 EXPECT_EQ("", ExpectedEvents()); |
62 | 62 |
63 #if defined(USE_AURA) | 63 #if defined(USE_AURA) |
64 aura::Env::DeleteInstance(); | 64 aura::Env::DeleteInstance(); |
65 screen_.reset(); | 65 screen_.reset(); |
66 #endif | 66 #endif |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 EXPECT_EQ("TouchMove GesturePinchBegin", ExpectedEvents()); | 366 EXPECT_EQ("TouchMove GesturePinchBegin", ExpectedEvents()); |
367 | 367 |
368 // Disable while pinch is in progress. | 368 // Disable while pinch is in progress. |
369 emulator()->Disable(); | 369 emulator()->Disable(); |
370 EXPECT_EQ("TouchCancel GesturePinchEnd GestureScrollEnd", ExpectedEvents()); | 370 EXPECT_EQ("TouchCancel GesturePinchEnd GestureScrollEnd", ExpectedEvents()); |
371 MouseUp(300, 200); | 371 MouseUp(300, 200); |
372 ReleaseShift(); | 372 ReleaseShift(); |
373 MouseMove(300, 300); | 373 MouseMove(300, 300); |
374 EXPECT_EQ("", ExpectedEvents()); | 374 EXPECT_EQ("", ExpectedEvents()); |
375 | 375 |
376 emulator()->Enable(); | 376 emulator()->Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); |
377 MouseDown(300, 300); | 377 MouseDown(300, 300); |
378 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); | 378 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); |
379 MouseDrag(300, 400); | 379 MouseDrag(300, 400); |
| 380 EXPECT_EQ( |
| 381 "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate", |
| 382 ExpectedEvents()); |
| 383 |
| 384 // Disable while scroll is in progress. |
| 385 emulator()->Disable(); |
| 386 EXPECT_EQ("TouchCancel GestureScrollEnd", ExpectedEvents()); |
| 387 } |
| 388 |
| 389 TEST_F(TouchEmulatorTest, DisableAndReenableDifferentConfig) { |
| 390 MouseDown(100, 200); |
| 391 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); |
| 392 MouseDrag(200, 200); |
| 393 EXPECT_EQ( |
| 394 "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate", |
| 395 ExpectedEvents()); |
| 396 PressShift(); |
| 397 MouseDrag(300, 200); |
| 398 EXPECT_EQ("TouchMove GesturePinchBegin", ExpectedEvents()); |
| 399 |
| 400 // Disable while pinch is in progress. |
| 401 emulator()->Disable(); |
| 402 EXPECT_EQ("TouchCancel GesturePinchEnd GestureScrollEnd", ExpectedEvents()); |
| 403 MouseUp(300, 200); |
| 404 ReleaseShift(); |
| 405 MouseMove(300, 300); |
| 406 EXPECT_EQ("", ExpectedEvents()); |
| 407 |
| 408 emulator()->Enable(ui::GestureProviderConfigType::GENERIC_DESKTOP); |
| 409 MouseDown(300, 300); |
| 410 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); |
| 411 MouseDrag(300, 400); |
380 EXPECT_EQ( | 412 EXPECT_EQ( |
381 "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate", | 413 "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate", |
382 ExpectedEvents()); | 414 ExpectedEvents()); |
383 | 415 |
384 // Disable while scroll is in progress. | 416 // Disable while scroll is in progress. |
385 emulator()->Disable(); | 417 emulator()->Disable(); |
386 EXPECT_EQ("TouchCancel GestureScrollEnd", ExpectedEvents()); | 418 EXPECT_EQ("TouchCancel GestureScrollEnd", ExpectedEvents()); |
387 } | 419 } |
388 | 420 |
389 TEST_F(TouchEmulatorTest, MouseMovesDropped) { | 421 TEST_F(TouchEmulatorTest, MouseMovesDropped) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 EXPECT_FALSE(SendMouseWheelEvent()); | 458 EXPECT_FALSE(SendMouseWheelEvent()); |
427 MouseUp(100, 200); | 459 MouseUp(100, 200); |
428 EXPECT_EQ("TouchEnd GestureShowPress GestureTap", ExpectedEvents()); | 460 EXPECT_EQ("TouchEnd GestureShowPress GestureTap", ExpectedEvents()); |
429 EXPECT_TRUE(SendMouseWheelEvent()); | 461 EXPECT_TRUE(SendMouseWheelEvent()); |
430 MouseDown(300, 200); | 462 MouseDown(300, 200); |
431 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); | 463 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); |
432 EXPECT_FALSE(SendMouseWheelEvent()); | 464 EXPECT_FALSE(SendMouseWheelEvent()); |
433 emulator()->Disable(); | 465 emulator()->Disable(); |
434 EXPECT_EQ("TouchCancel GestureTapCancel", ExpectedEvents()); | 466 EXPECT_EQ("TouchCancel GestureTapCancel", ExpectedEvents()); |
435 EXPECT_TRUE(SendMouseWheelEvent()); | 467 EXPECT_TRUE(SendMouseWheelEvent()); |
436 emulator()->Enable(); | 468 emulator()->Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); |
437 EXPECT_TRUE(SendMouseWheelEvent()); | 469 EXPECT_TRUE(SendMouseWheelEvent()); |
438 } | 470 } |
439 | 471 |
440 TEST_F(TouchEmulatorTest, MultipleTouchStreams) { | 472 TEST_F(TouchEmulatorTest, MultipleTouchStreams) { |
441 // Native stream should be blocked while emulated is active. | 473 // Native stream should be blocked while emulated is active. |
442 MouseMove(100, 200); | 474 MouseMove(100, 200); |
443 EXPECT_EQ("", ExpectedEvents()); | 475 EXPECT_EQ("", ExpectedEvents()); |
444 MouseDown(100, 200); | 476 MouseDown(100, 200); |
445 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); | 477 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); |
446 EXPECT_FALSE(TouchStart(10, 10, true)); | 478 EXPECT_FALSE(TouchStart(10, 10, true)); |
447 EXPECT_FALSE(TouchMove(20, 20, true)); | 479 EXPECT_FALSE(TouchMove(20, 20, true)); |
448 MouseUp(200, 200); | 480 MouseUp(200, 200); |
449 EXPECT_EQ( | 481 EXPECT_EQ( |
450 "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate" | 482 "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate" |
451 " TouchEnd GestureScrollEnd", | 483 " TouchEnd GestureScrollEnd", |
452 ExpectedEvents()); | 484 ExpectedEvents()); |
453 EXPECT_FALSE(TouchEnd(20, 20, true)); | 485 EXPECT_FALSE(TouchEnd(20, 20, true)); |
454 | 486 |
455 // Emulated stream should be blocked while native is active. | 487 // Emulated stream should be blocked while native is active. |
456 EXPECT_TRUE(TouchStart(10, 10, true)); | 488 EXPECT_TRUE(TouchStart(10, 10, true)); |
457 EXPECT_TRUE(TouchMove(20, 20, true)); | 489 EXPECT_TRUE(TouchMove(20, 20, true)); |
458 MouseDown(300, 200); | 490 MouseDown(300, 200); |
459 EXPECT_EQ("", ExpectedEvents()); | 491 EXPECT_EQ("", ExpectedEvents()); |
460 // Re-enabling in the middle of a touch sequence should not affect this. | 492 // Re-enabling in the middle of a touch sequence should not affect this. |
461 emulator()->Disable(); | 493 emulator()->Disable(); |
462 emulator()->Enable(); | 494 emulator()->Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); |
463 MouseDrag(300, 300); | 495 MouseDrag(300, 300); |
464 EXPECT_EQ("", ExpectedEvents()); | 496 EXPECT_EQ("", ExpectedEvents()); |
465 MouseUp(300, 300); | 497 MouseUp(300, 300); |
466 EXPECT_EQ("", ExpectedEvents()); | 498 EXPECT_EQ("", ExpectedEvents()); |
467 EXPECT_TRUE(TouchEnd(20, 20, true)); | 499 EXPECT_TRUE(TouchEnd(20, 20, true)); |
468 EXPECT_EQ("", ExpectedEvents()); | 500 EXPECT_EQ("", ExpectedEvents()); |
469 | 501 |
470 // Late ack for TouchEnd should not mess things up. | 502 // Late ack for TouchEnd should not mess things up. |
471 EXPECT_TRUE(TouchStart(10, 10, false)); | 503 EXPECT_TRUE(TouchStart(10, 10, false)); |
472 EXPECT_TRUE(TouchMove(20, 20, false)); | 504 EXPECT_TRUE(TouchMove(20, 20, false)); |
473 emulator()->Disable(); | 505 emulator()->Disable(); |
474 EXPECT_TRUE(TouchEnd(20, 20, false)); | 506 EXPECT_TRUE(TouchEnd(20, 20, false)); |
475 EXPECT_TRUE(TouchStart(30, 30, false)); | 507 EXPECT_TRUE(TouchStart(30, 30, false)); |
476 AckOldestTouchEvent(); // TouchStart. | 508 AckOldestTouchEvent(); // TouchStart. |
477 emulator()->Enable(); | 509 emulator()->Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); |
478 AckOldestTouchEvent(); // TouchMove. | 510 AckOldestTouchEvent(); // TouchMove. |
479 AckOldestTouchEvent(); // TouchEnd. | 511 AckOldestTouchEvent(); // TouchEnd. |
480 MouseDown(300, 200); | 512 MouseDown(300, 200); |
481 EXPECT_EQ("", ExpectedEvents()); | 513 EXPECT_EQ("", ExpectedEvents()); |
482 MouseDrag(300, 300); | 514 MouseDrag(300, 300); |
483 EXPECT_EQ("", ExpectedEvents()); | 515 EXPECT_EQ("", ExpectedEvents()); |
484 MouseUp(300, 300); | 516 MouseUp(300, 300); |
485 EXPECT_EQ("", ExpectedEvents()); | 517 EXPECT_EQ("", ExpectedEvents()); |
486 AckOldestTouchEvent(); // TouchStart. | 518 AckOldestTouchEvent(); // TouchStart. |
487 MouseDown(300, 200); | 519 MouseDown(300, 200); |
(...skipping 25 matching lines...) Expand all Loading... |
513 MouseDown(100, 200); | 545 MouseDown(100, 200); |
514 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); | 546 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); |
515 MouseUp(200, 200); | 547 MouseUp(200, 200); |
516 EXPECT_EQ( | 548 EXPECT_EQ( |
517 "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate" | 549 "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate" |
518 " TouchEnd GestureScrollEnd", | 550 " TouchEnd GestureScrollEnd", |
519 ExpectedEvents()); | 551 ExpectedEvents()); |
520 } | 552 } |
521 | 553 |
522 } // namespace content | 554 } // namespace content |
OLD | NEW |