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) { | |
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()); | |
aboxhall
2014/08/06 18:30:01
Can you assert what these events were?
They should
| |
1558 } | |
1559 | |
1560 TEST_F(TouchExplorationTest, TwoFingerTapWithDelay) { | |
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()); | |
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)); | |
1589 | |
1590 generator_->PressTouchId(2); | |
1591 EXPECT_FALSE(IsInTwoFingerTapState()); | |
1592 | |
1593 ASSERT_EQ(0U, captured_events.size()); | |
1594 } | |
1595 | |
1596 TEST_F(TouchExplorationTest, TwoFingerTapAndHold) { | |
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 | |
1530 } // namespace ui | 1613 } // namespace ui |
OLD | NEW |