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 TEST_F(TouchExplorationTest, TwoFingerTap) { | |
James Cook
2014/08/08 18:06:31
Comment above what you are testing and why.
lisayin
2014/08/08 19:06:15
Done.
| |
1542 SwitchTouchExplorationMode(true); | |
1543 | |
1544 generator_->PressTouchId(1); | |
1545 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1546 | |
1547 generator_->PressTouchId(2); | |
1548 EXPECT_TRUE(IsInTwoFingerTapState()); | |
1549 | |
1550 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
1551 ASSERT_EQ(0U, captured_events.size()); | |
1552 | |
1553 generator_->ReleaseTouchId(1); | |
1554 generator_->ReleaseTouchId(2); | |
1555 | |
1556 // Two key events should have been sent to silence the feedback. | |
1557 ASSERT_EQ(2U, captured_events.size()); | |
James Cook
2014/08/08 18:06:30
Probably EXPECT_EQ is better -- the test should fa
lisayin
2014/08/08 19:06:15
Done.
| |
1558 } | |
1559 | |
1560 TEST_F(TouchExplorationTest, TwoFingerTapWithDelay) { | |
James Cook
2014/08/08 18:06:31
Comment please.
lisayin
2014/08/08 19:06:15
Removed the timing check for two finger tap, so th
| |
1561 SwitchTouchExplorationMode(true); | |
1562 | |
1563 generator_->PressTouchId(1); | |
1564 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1565 | |
1566 // If the second finger is placed before the delay, then a two finger tap is | |
1567 // still sent. | |
1568 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
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 generator_->ReleaseTouchId(1); | |
1577 generator_->ReleaseTouchId(2); | |
1578 | |
1579 // Two key events should have been sent to silence the feedback. | |
1580 ASSERT_EQ(2U, captured_events.size()); | |
James Cook
2014/08/08 18:06:31
EXPECT_EQ I think
| |
1581 ClearCapturedEvents(); | |
1582 | |
1583 generator_->PressTouchId(1); | |
1584 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1585 | |
1586 // If the second finger is placed after the delay, then a two finger tap is | |
1587 // not made. | |
1588 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(100)); | |
James Cook
2014/08/08 18:06:31
I would use a much larger delay (like 1000) just i
| |
1589 | |
1590 generator_->PressTouchId(2); | |
1591 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1592 | |
1593 ASSERT_EQ(0U, captured_events.size()); | |
James Cook
2014/08/08 18:06:31
EXPECT_EQ ?
| |
1594 } | |
1595 | |
1596 TEST_F(TouchExplorationTest, TwoFingerTapAndHold) { | |
James Cook
2014/08/08 18:06:30
Comment please
lisayin
2014/08/08 19:06:15
Done.
| |
1597 SwitchTouchExplorationMode(true); | |
1598 | |
1599 generator_->PressTouchId(1); | |
1600 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1601 | |
1602 generator_->PressTouchId(2); | |
1603 EXPECT_TRUE(IsInTwoFingerTapState()); | |
1604 | |
1605 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
1606 ASSERT_EQ(0U, captured_events.size()); | |
1607 | |
1608 AdvanceSimulatedTimePastTapDelay(); | |
1609 // Since the tap delay has elapsed, it should no longer be in two finger tap. | |
1610 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1611 } | |
1612 | |
1613 TEST_F(TouchExplorationTest, TwoFingerTapAndMoveFirstFinger) { | |
James Cook
2014/08/08 18:06:31
ditto
lisayin
2014/08/08 19:06:15
Done.
| |
1614 SwitchTouchExplorationMode(true); | |
1615 | |
1616 // Once one of the fingers leaves slop, it should no longer be in two finger | |
1617 // tap. | |
1618 ui::TouchEvent first_press_id_1( | |
1619 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, Now()); | |
James Cook
2014/08/08 18:06:31
I like how you use 100 vs. 200 for x vs. y -- much
lisayin
2014/08/08 19:06:15
Acknowledged.
| |
1620 ui::TouchEvent first_press_id_2( | |
1621 ui::ET_TOUCH_PRESSED, gfx::Point(110, 200), 2, Now()); | |
1622 | |
1623 ui::TouchEvent slop_move_id_1( | |
1624 ui::ET_TOUCH_MOVED, | |
1625 gfx::Point(100 + gesture_detector_config_.touch_slop, 200), | |
1626 1, | |
1627 Now()); | |
1628 ui::TouchEvent slop_move_id_2( | |
1629 ui::ET_TOUCH_MOVED, | |
1630 gfx::Point(110 + gesture_detector_config_.touch_slop, 200), | |
1631 2, | |
1632 Now()); | |
1633 | |
1634 ui::TouchEvent out_slop_id_1( | |
1635 ui::ET_TOUCH_MOVED, | |
1636 gfx::Point(100 + gesture_detector_config_.touch_slop + 1, 200), | |
1637 1, | |
1638 Now()); | |
1639 | |
1640 generator_->Dispatch(&first_press_id_1); | |
James Cook
2014/08/08 18:06:31
Comment each of these little sections of code with
lisayin
2014/08/08 19:06:16
Done.
| |
1641 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1642 generator_->Dispatch(&first_press_id_2); | |
1643 EXPECT_TRUE(IsInTwoFingerTapState()); | |
1644 | |
1645 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
1646 ASSERT_EQ(0U, captured_events.size()); | |
1647 | |
1648 generator_->Dispatch(&slop_move_id_1); | |
1649 EXPECT_TRUE(IsInTwoFingerTapState()); | |
1650 generator_->Dispatch(&slop_move_id_2); | |
1651 EXPECT_TRUE(IsInTwoFingerTapState()); | |
1652 | |
1653 generator_->Dispatch(&out_slop_id_1); | |
1654 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1655 } | |
1656 | |
1657 TEST_F(TouchExplorationTest, TwoFingerTapAndMoveSecondFinger) { | |
James Cook
2014/08/08 18:06:30
comment
lisayin
2014/08/08 19:06:15
Done.
| |
1658 SwitchTouchExplorationMode(true); | |
1659 | |
1660 // Once one of the fingers leaves slop, it should no longer be in two finger | |
1661 // tap. | |
1662 ui::TouchEvent first_press_id_1( | |
1663 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, Now()); | |
1664 ui::TouchEvent first_press_id_2( | |
1665 ui::ET_TOUCH_PRESSED, gfx::Point(110, 200), 2, Now()); | |
1666 | |
1667 ui::TouchEvent out_slop_id_2( | |
1668 ui::ET_TOUCH_MOVED, | |
1669 gfx::Point(100 + gesture_detector_config_.touch_slop + 1, 200), | |
1670 1, | |
1671 Now()); | |
1672 | |
1673 generator_->Dispatch(&first_press_id_1); | |
1674 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1675 | |
1676 generator_->Dispatch(&first_press_id_2); | |
1677 EXPECT_TRUE(IsInTwoFingerTapState()); | |
1678 | |
1679 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
1680 ASSERT_EQ(0U, captured_events.size()); | |
1681 | |
1682 generator_->Dispatch(&out_slop_id_2); | |
1683 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1684 } | |
1685 | |
1530 } // namespace ui | 1686 } // namespace ui |
OLD | NEW |