Chromium Code Reviews| Index: ui/chromeos/touch_exploration_controller_unittest.cc |
| diff --git a/ui/chromeos/touch_exploration_controller_unittest.cc b/ui/chromeos/touch_exploration_controller_unittest.cc |
| index ffe4d090b8b3ce8779e8785a3c7ba77a58577ead..b3205fa33a11deab2566fce1db45809b7cc1596d 100644 |
| --- a/ui/chromeos/touch_exploration_controller_unittest.cc |
| +++ b/ui/chromeos/touch_exploration_controller_unittest.cc |
| @@ -81,6 +81,8 @@ class MockTouchExplorationControllerDelegate |
| virtual void SetOutputLevel(int volume) OVERRIDE { |
| volume_changes_.push_back(volume); |
| } |
| + virtual void SilenceSpokenFeedback() OVERRIDE { |
| + } |
| const std::vector<float> VolumeChanges() { return volume_changes_; } |
| const size_t NumAdjustSounds() { return num_times_adjust_sound_played_; } |
| @@ -127,6 +129,11 @@ class TouchExplorationControllerTestApi { |
| touch_exploration_controller_->SLIDE_GESTURE; |
| } |
| + bool IsInTwoFingerTapStateForTesting() const { |
| + return touch_exploration_controller_->state_ == |
| + touch_exploration_controller_->TWO_FINGER_TAP; |
| + } |
| + |
| gfx::Rect BoundsOfRootWindowInDIPForTesting() const { |
| return touch_exploration_controller_->root_window_->GetBoundsInScreen(); |
| } |
| @@ -287,6 +294,10 @@ class TouchExplorationTest : public aura::test::AuraTestBase { |
| return touch_exploration_controller_->IsInSlideGestureStateForTesting(); |
| } |
| + bool IsInTwoFingerTapState() { |
| + return touch_exploration_controller_->IsInTwoFingerTapStateForTesting(); |
| + } |
| + |
| gfx::Rect BoundsOfRootWindowInDIP() { |
| return touch_exploration_controller_->BoundsOfRootWindowInDIPForTesting(); |
| } |
| @@ -1527,4 +1538,149 @@ TEST_F(TouchExplorationTest, InBoundariesTouchExploration) { |
| EXPECT_TRUE(IsInTouchToMouseMode()); |
| } |
| +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.
|
| + SwitchTouchExplorationMode(true); |
| + |
| + generator_->PressTouchId(1); |
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| + |
| + generator_->PressTouchId(2); |
| + EXPECT_TRUE(IsInTwoFingerTapState()); |
| + |
| + const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| + ASSERT_EQ(0U, captured_events.size()); |
| + |
| + generator_->ReleaseTouchId(1); |
| + generator_->ReleaseTouchId(2); |
| + |
| + // Two key events should have been sent to silence the feedback. |
| + 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.
|
| +} |
| + |
| +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
|
| + SwitchTouchExplorationMode(true); |
| + |
| + generator_->PressTouchId(1); |
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| + |
| + // If the second finger is placed before the delay, then a two finger tap is |
| + // still sent. |
| + simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
| + |
| + generator_->PressTouchId(2); |
| + EXPECT_TRUE(IsInTwoFingerTapState()); |
| + |
| + const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| + ASSERT_EQ(0U, captured_events.size()); |
| + |
| + generator_->ReleaseTouchId(1); |
| + generator_->ReleaseTouchId(2); |
| + |
| + // Two key events should have been sent to silence the feedback. |
| + ASSERT_EQ(2U, captured_events.size()); |
|
James Cook
2014/08/08 18:06:31
EXPECT_EQ I think
|
| + ClearCapturedEvents(); |
| + |
| + generator_->PressTouchId(1); |
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| + |
| + // If the second finger is placed after the delay, then a two finger tap is |
| + // not made. |
| + 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
|
| + |
| + generator_->PressTouchId(2); |
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| + |
| + ASSERT_EQ(0U, captured_events.size()); |
|
James Cook
2014/08/08 18:06:31
EXPECT_EQ ?
|
| +} |
| + |
| +TEST_F(TouchExplorationTest, TwoFingerTapAndHold) { |
|
James Cook
2014/08/08 18:06:30
Comment please
lisayin
2014/08/08 19:06:15
Done.
|
| + SwitchTouchExplorationMode(true); |
| + |
| + generator_->PressTouchId(1); |
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| + |
| + generator_->PressTouchId(2); |
| + EXPECT_TRUE(IsInTwoFingerTapState()); |
| + |
| + const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| + ASSERT_EQ(0U, captured_events.size()); |
| + |
| + AdvanceSimulatedTimePastTapDelay(); |
| + // Since the tap delay has elapsed, it should no longer be in two finger tap. |
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| +} |
| + |
| +TEST_F(TouchExplorationTest, TwoFingerTapAndMoveFirstFinger) { |
|
James Cook
2014/08/08 18:06:31
ditto
lisayin
2014/08/08 19:06:15
Done.
|
| + SwitchTouchExplorationMode(true); |
| + |
| + // Once one of the fingers leaves slop, it should no longer be in two finger |
| + // tap. |
| + ui::TouchEvent first_press_id_1( |
| + 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.
|
| + ui::TouchEvent first_press_id_2( |
| + ui::ET_TOUCH_PRESSED, gfx::Point(110, 200), 2, Now()); |
| + |
| + ui::TouchEvent slop_move_id_1( |
| + ui::ET_TOUCH_MOVED, |
| + gfx::Point(100 + gesture_detector_config_.touch_slop, 200), |
| + 1, |
| + Now()); |
| + ui::TouchEvent slop_move_id_2( |
| + ui::ET_TOUCH_MOVED, |
| + gfx::Point(110 + gesture_detector_config_.touch_slop, 200), |
| + 2, |
| + Now()); |
| + |
| + ui::TouchEvent out_slop_id_1( |
| + ui::ET_TOUCH_MOVED, |
| + gfx::Point(100 + gesture_detector_config_.touch_slop + 1, 200), |
| + 1, |
| + Now()); |
| + |
| + 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.
|
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| + generator_->Dispatch(&first_press_id_2); |
| + EXPECT_TRUE(IsInTwoFingerTapState()); |
| + |
| + const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| + ASSERT_EQ(0U, captured_events.size()); |
| + |
| + generator_->Dispatch(&slop_move_id_1); |
| + EXPECT_TRUE(IsInTwoFingerTapState()); |
| + generator_->Dispatch(&slop_move_id_2); |
| + EXPECT_TRUE(IsInTwoFingerTapState()); |
| + |
| + generator_->Dispatch(&out_slop_id_1); |
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| +} |
| + |
| +TEST_F(TouchExplorationTest, TwoFingerTapAndMoveSecondFinger) { |
|
James Cook
2014/08/08 18:06:30
comment
lisayin
2014/08/08 19:06:15
Done.
|
| + SwitchTouchExplorationMode(true); |
| + |
| + // Once one of the fingers leaves slop, it should no longer be in two finger |
| + // tap. |
| + ui::TouchEvent first_press_id_1( |
| + ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, Now()); |
| + ui::TouchEvent first_press_id_2( |
| + ui::ET_TOUCH_PRESSED, gfx::Point(110, 200), 2, Now()); |
| + |
| + ui::TouchEvent out_slop_id_2( |
| + ui::ET_TOUCH_MOVED, |
| + gfx::Point(100 + gesture_detector_config_.touch_slop + 1, 200), |
| + 1, |
| + Now()); |
| + |
| + generator_->Dispatch(&first_press_id_1); |
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| + |
| + generator_->Dispatch(&first_press_id_2); |
| + EXPECT_TRUE(IsInTwoFingerTapState()); |
| + |
| + const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| + ASSERT_EQ(0U, captured_events.size()); |
| + |
| + generator_->Dispatch(&out_slop_id_2); |
| + EXPECT_FALSE(IsInTwoFingerTapState()); |
| +} |
| + |
| } // namespace ui |