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 "ui/chromeos/touch_exploration_controller.h" | 5 #include "ui/chromeos/touch_exploration_controller.h" |
6 | 6 |
7 #include "base/test/simple_test_tick_clock.h" | 7 #include "base/test/simple_test_tick_clock.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 class MockTouchExplorationControllerDelegate | 75 class MockTouchExplorationControllerDelegate |
76 : public ui::TouchExplorationControllerDelegate { | 76 : public ui::TouchExplorationControllerDelegate { |
77 public: | 77 public: |
78 virtual void PlayVolumeAdjustSound() OVERRIDE { | 78 virtual void PlayVolumeAdjustSound() OVERRIDE { |
79 ++num_times_adjust_sound_played_; | 79 ++num_times_adjust_sound_played_; |
80 } | 80 } |
81 virtual void SetOutputLevel(int volume) OVERRIDE { | 81 virtual void SetOutputLevel(int volume) OVERRIDE { |
82 volume_changes_.push_back(volume); | 82 volume_changes_.push_back(volume); |
83 } | 83 } |
| 84 virtual void SilenceSpokenFeedback() OVERRIDE { |
| 85 } |
84 | 86 |
85 const std::vector<float> VolumeChanges() { return volume_changes_; } | 87 const std::vector<float> VolumeChanges() { return volume_changes_; } |
86 const size_t NumAdjustSounds() { return num_times_adjust_sound_played_; } | 88 const size_t NumAdjustSounds() { return num_times_adjust_sound_played_; } |
87 | 89 |
88 private: | 90 private: |
89 std::vector<float> volume_changes_; | 91 std::vector<float> volume_changes_; |
90 size_t num_times_adjust_sound_played_ = 0; | 92 size_t num_times_adjust_sound_played_ = 0; |
91 }; | 93 }; |
92 | 94 |
93 } // namespace | 95 } // namespace |
(...skipping 26 matching lines...) Expand all Loading... |
120 bool IsInGestureInProgressStateForTesting() const { | 122 bool IsInGestureInProgressStateForTesting() const { |
121 return touch_exploration_controller_->state_ == | 123 return touch_exploration_controller_->state_ == |
122 touch_exploration_controller_->GESTURE_IN_PROGRESS; | 124 touch_exploration_controller_->GESTURE_IN_PROGRESS; |
123 } | 125 } |
124 | 126 |
125 bool IsInSlideGestureStateForTesting() const { | 127 bool IsInSlideGestureStateForTesting() const { |
126 return touch_exploration_controller_->state_ == | 128 return touch_exploration_controller_->state_ == |
127 touch_exploration_controller_->SLIDE_GESTURE; | 129 touch_exploration_controller_->SLIDE_GESTURE; |
128 } | 130 } |
129 | 131 |
| 132 bool IsInTwoFingerTapStateForTesting() const { |
| 133 return touch_exploration_controller_->state_ == |
| 134 touch_exploration_controller_->TWO_FINGER_TAP; |
| 135 } |
| 136 |
130 gfx::Rect BoundsOfRootWindowInDIPForTesting() const { | 137 gfx::Rect BoundsOfRootWindowInDIPForTesting() const { |
131 return touch_exploration_controller_->root_window_->GetBoundsInScreen(); | 138 return touch_exploration_controller_->root_window_->GetBoundsInScreen(); |
132 } | 139 } |
133 | 140 |
134 // VLOGs should be suppressed in tests that generate a lot of logs, | 141 // VLOGs should be suppressed in tests that generate a lot of logs, |
135 // for example permutations of nine touch events. | 142 // for example permutations of nine touch events. |
136 void SuppressVLOGsForTesting(bool suppress) { | 143 void SuppressVLOGsForTesting(bool suppress) { |
137 touch_exploration_controller_->VLOG_on_ = !suppress; | 144 touch_exploration_controller_->VLOG_on_ = !suppress; |
138 } | 145 } |
139 | 146 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 287 |
281 bool IsInGestureInProgressState() { | 288 bool IsInGestureInProgressState() { |
282 return touch_exploration_controller_ | 289 return touch_exploration_controller_ |
283 ->IsInGestureInProgressStateForTesting(); | 290 ->IsInGestureInProgressStateForTesting(); |
284 } | 291 } |
285 | 292 |
286 bool IsInSlideGestureState() { | 293 bool IsInSlideGestureState() { |
287 return touch_exploration_controller_->IsInSlideGestureStateForTesting(); | 294 return touch_exploration_controller_->IsInSlideGestureStateForTesting(); |
288 } | 295 } |
289 | 296 |
| 297 bool IsInTwoFingerTapState() { |
| 298 return touch_exploration_controller_->IsInTwoFingerTapStateForTesting(); |
| 299 } |
| 300 |
290 gfx::Rect BoundsOfRootWindowInDIP() { | 301 gfx::Rect BoundsOfRootWindowInDIP() { |
291 return touch_exploration_controller_->BoundsOfRootWindowInDIPForTesting(); | 302 return touch_exploration_controller_->BoundsOfRootWindowInDIPForTesting(); |
292 } | 303 } |
293 | 304 |
294 float GetMaxDistanceFromEdge() const{ | 305 float GetMaxDistanceFromEdge() const{ |
295 return touch_exploration_controller_->GetMaxDistanceFromEdge(); | 306 return touch_exploration_controller_->GetMaxDistanceFromEdge(); |
296 } | 307 } |
297 | 308 |
298 float GetSlopDistanceFromEdge() const{ | 309 float GetSlopDistanceFromEdge() const{ |
299 return touch_exploration_controller_->GetSlopDistanceFromEdge(); | 310 return touch_exploration_controller_->GetSlopDistanceFromEdge(); |
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 EXPECT_FALSE(IsInGestureInProgressState()); | 1531 EXPECT_FALSE(IsInGestureInProgressState()); |
1521 EXPECT_FALSE(IsInSlideGestureState()); | 1532 EXPECT_FALSE(IsInSlideGestureState()); |
1522 EXPECT_FALSE(IsInTouchToMouseMode()); | 1533 EXPECT_FALSE(IsInTouchToMouseMode()); |
1523 | 1534 |
1524 AdvanceSimulatedTimePastTapDelay(); | 1535 AdvanceSimulatedTimePastTapDelay(); |
1525 EXPECT_FALSE(IsInGestureInProgressState()); | 1536 EXPECT_FALSE(IsInGestureInProgressState()); |
1526 EXPECT_FALSE(IsInSlideGestureState()); | 1537 EXPECT_FALSE(IsInSlideGestureState()); |
1527 EXPECT_TRUE(IsInTouchToMouseMode()); | 1538 EXPECT_TRUE(IsInTouchToMouseMode()); |
1528 } | 1539 } |
1529 | 1540 |
| 1541 // If two fingers tap the screen at the same time and release before the tap |
| 1542 // timer runs out, a control key event should be sent to silence chromevox. |
| 1543 TEST_F(TouchExplorationTest, TwoFingerTap) { |
| 1544 SwitchTouchExplorationMode(true); |
| 1545 |
| 1546 generator_->PressTouchId(1); |
| 1547 EXPECT_FALSE(IsInTwoFingerTapState()); |
| 1548 |
| 1549 generator_->PressTouchId(2); |
| 1550 EXPECT_TRUE(IsInTwoFingerTapState()); |
| 1551 |
| 1552 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| 1553 ASSERT_EQ(0U, captured_events.size()); |
| 1554 |
| 1555 generator_->ReleaseTouchId(1); |
| 1556 generator_->ReleaseTouchId(2); |
| 1557 |
| 1558 // Two key events should have been sent to silence the feedback. |
| 1559 EXPECT_EQ(2U, captured_events.size()); |
| 1560 } |
| 1561 |
| 1562 // If the fingers are not released before the tap timer runs out, a control |
| 1563 // keyevent is not sent and the state will no longer be in two finger tap. |
| 1564 TEST_F(TouchExplorationTest, TwoFingerTapAndHold) { |
| 1565 SwitchTouchExplorationMode(true); |
| 1566 |
| 1567 generator_->PressTouchId(1); |
| 1568 EXPECT_FALSE(IsInTwoFingerTapState()); |
| 1569 |
| 1570 generator_->PressTouchId(2); |
| 1571 EXPECT_TRUE(IsInTwoFingerTapState()); |
| 1572 |
| 1573 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| 1574 ASSERT_EQ(0U, captured_events.size()); |
| 1575 |
| 1576 AdvanceSimulatedTimePastTapDelay(); |
| 1577 // Since the tap delay has elapsed, it should no longer be in two finger tap. |
| 1578 EXPECT_FALSE(IsInTwoFingerTapState()); |
| 1579 } |
| 1580 |
| 1581 // The next two tests set up two finger swipes to happen. If one of the fingers |
| 1582 // moves out of slop before the tap timer fires, a two finger tap is not made. |
| 1583 // In this first test, the first finger placed will move out of slop. |
| 1584 TEST_F(TouchExplorationTest, TwoFingerTapAndMoveFirstFinger) { |
| 1585 SwitchTouchExplorationMode(true); |
| 1586 |
| 1587 // Once one of the fingers leaves slop, it should no longer be in two finger |
| 1588 // tap. |
| 1589 ui::TouchEvent first_press_id_1( |
| 1590 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, Now()); |
| 1591 ui::TouchEvent first_press_id_2( |
| 1592 ui::ET_TOUCH_PRESSED, gfx::Point(110, 200), 2, Now()); |
| 1593 |
| 1594 ui::TouchEvent slop_move_id_1( |
| 1595 ui::ET_TOUCH_MOVED, |
| 1596 gfx::Point(100 + gesture_detector_config_.touch_slop, 200), |
| 1597 1, |
| 1598 Now()); |
| 1599 ui::TouchEvent slop_move_id_2( |
| 1600 ui::ET_TOUCH_MOVED, |
| 1601 gfx::Point(110 + gesture_detector_config_.touch_slop, 200), |
| 1602 2, |
| 1603 Now()); |
| 1604 |
| 1605 ui::TouchEvent out_slop_id_1( |
| 1606 ui::ET_TOUCH_MOVED, |
| 1607 gfx::Point(100 + gesture_detector_config_.touch_slop + 1, 200), |
| 1608 1, |
| 1609 Now()); |
| 1610 |
| 1611 // Dispatch the inital presses. |
| 1612 generator_->Dispatch(&first_press_id_1); |
| 1613 EXPECT_FALSE(IsInTwoFingerTapState()); |
| 1614 generator_->Dispatch(&first_press_id_2); |
| 1615 EXPECT_TRUE(IsInTwoFingerTapState()); |
| 1616 |
| 1617 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| 1618 ASSERT_EQ(0U, captured_events.size()); |
| 1619 |
| 1620 // The presses have not moved out of slop yet so it should still be in |
| 1621 // TwoFingerTap. |
| 1622 generator_->Dispatch(&slop_move_id_1); |
| 1623 EXPECT_TRUE(IsInTwoFingerTapState()); |
| 1624 generator_->Dispatch(&slop_move_id_2); |
| 1625 EXPECT_TRUE(IsInTwoFingerTapState()); |
| 1626 |
| 1627 // Once one of the fingers moves out of slop, we are no longer in |
| 1628 // TwoFingerTap. |
| 1629 generator_->Dispatch(&out_slop_id_1); |
| 1630 EXPECT_FALSE(IsInTwoFingerTapState()); |
| 1631 } |
| 1632 |
| 1633 // Similar test to the previous test except the second finger placed will be the |
| 1634 // one to move out of slop. |
| 1635 TEST_F(TouchExplorationTest, TwoFingerTapAndMoveSecondFinger) { |
| 1636 SwitchTouchExplorationMode(true); |
| 1637 |
| 1638 // Once one of the fingers leaves slop, it should no longer be in two finger |
| 1639 // tap. |
| 1640 ui::TouchEvent first_press_id_1( |
| 1641 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, Now()); |
| 1642 ui::TouchEvent first_press_id_2( |
| 1643 ui::ET_TOUCH_PRESSED, gfx::Point(110, 200), 2, Now()); |
| 1644 |
| 1645 ui::TouchEvent out_slop_id_2( |
| 1646 ui::ET_TOUCH_MOVED, |
| 1647 gfx::Point(100 + gesture_detector_config_.touch_slop + 1, 200), |
| 1648 1, |
| 1649 Now()); |
| 1650 |
| 1651 generator_->Dispatch(&first_press_id_1); |
| 1652 EXPECT_FALSE(IsInTwoFingerTapState()); |
| 1653 |
| 1654 generator_->Dispatch(&first_press_id_2); |
| 1655 EXPECT_TRUE(IsInTwoFingerTapState()); |
| 1656 |
| 1657 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| 1658 ASSERT_EQ(0U, captured_events.size()); |
| 1659 |
| 1660 generator_->Dispatch(&out_slop_id_2); |
| 1661 EXPECT_FALSE(IsInTwoFingerTapState()); |
| 1662 } |
| 1663 |
1530 } // namespace ui | 1664 } // namespace ui |
OLD | NEW |