| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ash/touch/touch_observer_hud.h" | 5 #include "ash/touch/touch_observer_hud.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 284 |
| 285 TouchHudProjection* GetInternalTouchHudProjection() { | 285 TouchHudProjection* GetInternalTouchHudProjection() { |
| 286 return GetInternalRootController()->touch_hud_projection(); | 286 return GetInternalRootController()->touch_hud_projection(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 int GetInternalTouchPointsCount() { | 289 int GetInternalTouchPointsCount() { |
| 290 return GetInternalTouchHudProjection()->points_.size(); | 290 return GetInternalTouchHudProjection()->points_.size(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void SendTouchEventToInternalHud(ui::EventType type, | 293 void SendTouchEventToInternalHud(ui::EventType type, |
| 294 const gfx::Point& location, | 294 const gfx::PointF& location, |
| 295 int touch_id) { | 295 int touch_id) { |
| 296 ui::TouchEvent event(type, location, touch_id, event_time); | 296 ui::TouchEvent event(type, location, touch_id, event_time); |
| 297 GetInternalTouchHudProjection()->OnTouchEvent(&event); | 297 GetInternalTouchHudProjection()->OnTouchEvent(&event); |
| 298 | 298 |
| 299 // Advance time for next event. | 299 // Advance time for next event. |
| 300 event_time += base::TimeDelta::FromMilliseconds(100); | 300 event_time += base::TimeDelta::FromMilliseconds(100); |
| 301 } | 301 } |
| 302 | 302 |
| 303 private: | 303 private: |
| 304 base::TimeDelta event_time; | 304 base::TimeDelta event_time; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 // and touch-released events. | 493 // and touch-released events. |
| 494 TEST_F(TouchHudProjectionTest, TouchMoveRelease) { | 494 TEST_F(TouchHudProjectionTest, TouchMoveRelease) { |
| 495 SetupSingleDisplay(); | 495 SetupSingleDisplay(); |
| 496 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); | 496 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); |
| 497 | 497 |
| 498 EnableTouchHudProjection(); | 498 EnableTouchHudProjection(); |
| 499 EXPECT_NE(static_cast<TouchHudProjection*>(NULL), | 499 EXPECT_NE(static_cast<TouchHudProjection*>(NULL), |
| 500 GetInternalTouchHudProjection()); | 500 GetInternalTouchHudProjection()); |
| 501 EXPECT_EQ(0, GetInternalTouchPointsCount()); | 501 EXPECT_EQ(0, GetInternalTouchPointsCount()); |
| 502 | 502 |
| 503 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1); | 503 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::PointF(10.f, 10.f), 1); |
| 504 EXPECT_EQ(1, GetInternalTouchPointsCount()); | 504 EXPECT_EQ(1, GetInternalTouchPointsCount()); |
| 505 | 505 |
| 506 SendTouchEventToInternalHud(ui::ET_TOUCH_MOVED, gfx::Point(10, 20), 1); | 506 SendTouchEventToInternalHud(ui::ET_TOUCH_MOVED, gfx::PointF(10.f, 20.f), 1); |
| 507 EXPECT_EQ(1, GetInternalTouchPointsCount()); | 507 EXPECT_EQ(1, GetInternalTouchPointsCount()); |
| 508 | 508 |
| 509 SendTouchEventToInternalHud(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 1); | 509 SendTouchEventToInternalHud(ui::ET_TOUCH_RELEASED, gfx::PointF(10.f, 20.f), |
| 510 1); |
| 510 EXPECT_EQ(0, GetInternalTouchPointsCount()); | 511 EXPECT_EQ(0, GetInternalTouchPointsCount()); |
| 511 | 512 |
| 512 // Disabling projection touch HUD shoud remove it without crashing. | 513 // Disabling projection touch HUD shoud remove it without crashing. |
| 513 DisableTouchHudProjection(); | 514 DisableTouchHudProjection(); |
| 514 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); | 515 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); |
| 515 } | 516 } |
| 516 | 517 |
| 517 // Checks projection touch HUD with a sequence of touch-pressed, touch-moved, | 518 // Checks projection touch HUD with a sequence of touch-pressed, touch-moved, |
| 518 // and touch-cancelled events. | 519 // and touch-cancelled events. |
| 519 TEST_F(TouchHudProjectionTest, TouchMoveCancel) { | 520 TEST_F(TouchHudProjectionTest, TouchMoveCancel) { |
| 520 SetupSingleDisplay(); | 521 SetupSingleDisplay(); |
| 521 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); | 522 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); |
| 522 | 523 |
| 523 EnableTouchHudProjection(); | 524 EnableTouchHudProjection(); |
| 524 EXPECT_NE(static_cast<TouchHudProjection*>(NULL), | 525 EXPECT_NE(static_cast<TouchHudProjection*>(NULL), |
| 525 GetInternalTouchHudProjection()); | 526 GetInternalTouchHudProjection()); |
| 526 EXPECT_EQ(0, GetInternalTouchPointsCount()); | 527 EXPECT_EQ(0, GetInternalTouchPointsCount()); |
| 527 | 528 |
| 528 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1); | 529 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::PointF(10.f, 10.f), 1); |
| 529 EXPECT_EQ(1, GetInternalTouchPointsCount()); | 530 EXPECT_EQ(1, GetInternalTouchPointsCount()); |
| 530 | 531 |
| 531 SendTouchEventToInternalHud(ui::ET_TOUCH_MOVED, gfx::Point(10, 20), 1); | 532 SendTouchEventToInternalHud(ui::ET_TOUCH_MOVED, gfx::PointF(10.f, 20.f), 1); |
| 532 EXPECT_EQ(1, GetInternalTouchPointsCount()); | 533 EXPECT_EQ(1, GetInternalTouchPointsCount()); |
| 533 | 534 |
| 534 SendTouchEventToInternalHud(ui::ET_TOUCH_CANCELLED, gfx::Point(10, 20), 1); | 535 SendTouchEventToInternalHud(ui::ET_TOUCH_CANCELLED, gfx::PointF(10.f, 20.f), |
| 536 1); |
| 535 EXPECT_EQ(0, GetInternalTouchPointsCount()); | 537 EXPECT_EQ(0, GetInternalTouchPointsCount()); |
| 536 | 538 |
| 537 // Disabling projection touch HUD shoud remove it without crashing. | 539 // Disabling projection touch HUD shoud remove it without crashing. |
| 538 DisableTouchHudProjection(); | 540 DisableTouchHudProjection(); |
| 539 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); | 541 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); |
| 540 } | 542 } |
| 541 | 543 |
| 542 // Checks projection touch HUD with two simultaneous touches. | 544 // Checks projection touch HUD with two simultaneous touches. |
| 543 TEST_F(TouchHudProjectionTest, DoubleTouch) { | 545 TEST_F(TouchHudProjectionTest, DoubleTouch) { |
| 544 SetupSingleDisplay(); | 546 SetupSingleDisplay(); |
| 545 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); | 547 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); |
| 546 | 548 |
| 547 EnableTouchHudProjection(); | 549 EnableTouchHudProjection(); |
| 548 EXPECT_NE(static_cast<TouchHudProjection*>(NULL), | 550 EXPECT_NE(static_cast<TouchHudProjection*>(NULL), |
| 549 GetInternalTouchHudProjection()); | 551 GetInternalTouchHudProjection()); |
| 550 EXPECT_EQ(0, GetInternalTouchPointsCount()); | 552 EXPECT_EQ(0, GetInternalTouchPointsCount()); |
| 551 | 553 |
| 552 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1); | 554 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::PointF(10.f, 10.f), 1); |
| 553 EXPECT_EQ(1, GetInternalTouchPointsCount()); | 555 EXPECT_EQ(1, GetInternalTouchPointsCount()); |
| 554 | 556 |
| 555 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::Point(20, 10), 2); | 557 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::PointF(20.f, 10.f), 2); |
| 556 EXPECT_EQ(2, GetInternalTouchPointsCount()); | 558 EXPECT_EQ(2, GetInternalTouchPointsCount()); |
| 557 | 559 |
| 558 SendTouchEventToInternalHud(ui::ET_TOUCH_MOVED, gfx::Point(10, 20), 1); | 560 SendTouchEventToInternalHud(ui::ET_TOUCH_MOVED, gfx::PointF(10.f, 20.f), 1); |
| 559 EXPECT_EQ(2, GetInternalTouchPointsCount()); | 561 EXPECT_EQ(2, GetInternalTouchPointsCount()); |
| 560 | 562 |
| 561 SendTouchEventToInternalHud(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 2); | 563 SendTouchEventToInternalHud(ui::ET_TOUCH_MOVED, gfx::PointF(20.f, 20.f), 2); |
| 562 EXPECT_EQ(2, GetInternalTouchPointsCount()); | 564 EXPECT_EQ(2, GetInternalTouchPointsCount()); |
| 563 | 565 |
| 564 SendTouchEventToInternalHud(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 1); | 566 SendTouchEventToInternalHud(ui::ET_TOUCH_RELEASED, gfx::PointF(10.f, 20.f), |
| 567 1); |
| 565 EXPECT_EQ(1, GetInternalTouchPointsCount()); | 568 EXPECT_EQ(1, GetInternalTouchPointsCount()); |
| 566 | 569 |
| 567 SendTouchEventToInternalHud(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 2); | 570 SendTouchEventToInternalHud(ui::ET_TOUCH_RELEASED, gfx::PointF(20.f, 20.f), |
| 571 2); |
| 568 EXPECT_EQ(0, GetInternalTouchPointsCount()); | 572 EXPECT_EQ(0, GetInternalTouchPointsCount()); |
| 569 | 573 |
| 570 // Disabling projection touch HUD shoud remove it without crashing. | 574 // Disabling projection touch HUD shoud remove it without crashing. |
| 571 DisableTouchHudProjection(); | 575 DisableTouchHudProjection(); |
| 572 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); | 576 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); |
| 573 } | 577 } |
| 574 | 578 |
| 575 // Checks if turning off touch HUD projection while touching the screen is | 579 // Checks if turning off touch HUD projection while touching the screen is |
| 576 // handled correctly. | 580 // handled correctly. |
| 577 TEST_F(TouchHudProjectionTest, DisableWhileTouching) { | 581 TEST_F(TouchHudProjectionTest, DisableWhileTouching) { |
| 578 SetupSingleDisplay(); | 582 SetupSingleDisplay(); |
| 579 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); | 583 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); |
| 580 | 584 |
| 581 EnableTouchHudProjection(); | 585 EnableTouchHudProjection(); |
| 582 EXPECT_NE(static_cast<TouchHudProjection*>(NULL), | 586 EXPECT_NE(static_cast<TouchHudProjection*>(NULL), |
| 583 GetInternalTouchHudProjection()); | 587 GetInternalTouchHudProjection()); |
| 584 EXPECT_EQ(0, GetInternalTouchPointsCount()); | 588 EXPECT_EQ(0, GetInternalTouchPointsCount()); |
| 585 | 589 |
| 586 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1); | 590 SendTouchEventToInternalHud(ui::ET_TOUCH_PRESSED, gfx::PointF(10.f, 10.f), 1); |
| 587 EXPECT_EQ(1, GetInternalTouchPointsCount()); | 591 EXPECT_EQ(1, GetInternalTouchPointsCount()); |
| 588 | 592 |
| 589 // Disabling projection touch HUD shoud remove it without crashing. | 593 // Disabling projection touch HUD shoud remove it without crashing. |
| 590 DisableTouchHudProjection(); | 594 DisableTouchHudProjection(); |
| 591 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); | 595 EXPECT_EQ(NULL, GetInternalTouchHudProjection()); |
| 592 } | 596 } |
| 593 | 597 |
| 594 } // namespace ash | 598 } // namespace ash |
| OLD | NEW |