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 0da7268379771e842be4c3208786bbc40465d97d..99f3577c3d60764bc18380ed7013583b4e78d92e 100644 |
| --- a/ui/chromeos/touch_exploration_controller_unittest.cc |
| +++ b/ui/chromeos/touch_exploration_controller_unittest.cc |
| @@ -75,19 +75,43 @@ int Factorial(int n) { |
| class MockTouchExplorationControllerDelegate |
| : public ui::TouchExplorationControllerDelegate { |
| public: |
| - virtual void PlayVolumeAdjustSound() OVERRIDE { |
| - ++num_times_adjust_sound_played_; |
| - } |
| virtual void SetOutputLevel(int volume) OVERRIDE { |
| volume_changes_.push_back(volume); |
| } |
| + virtual void PlayVolumeAdjustEarcon() OVERRIDE { |
| + ++num_times_adjust_sound_played_; |
| + } |
| + virtual void PlayPassthroughEarcon() OVERRIDE { |
| + ++num_times_passthrough_played_; |
| + } |
| + virtual void PlayExitScreenEarcon() OVERRIDE { |
| + ++num_times_exit_screen_played_; |
| + } |
| + virtual void PlayEnterScreenEarcon() OVERRIDE { |
| + ++num_times_enter_screen_played_; |
| + } |
| const std::vector<float> VolumeChanges() { return volume_changes_; } |
| const size_t NumAdjustSounds() { return num_times_adjust_sound_played_; } |
| + const size_t NumPassthroughSounds() { return num_times_passthrough_played_; } |
| + const size_t NumExitScreenSounds() { return num_times_exit_screen_played_; } |
| + const size_t NumEnterScreenSounds() { |
| + return num_times_enter_screen_played_; |
| + } |
| + |
| + void ResetCountersToZero() { |
| + num_times_adjust_sound_played_ = 0; |
| + num_times_passthrough_played_ = 0; |
| + num_times_exit_screen_played_ = 0; |
| + num_times_enter_screen_played_ = 0; |
| + } |
| private: |
| std::vector<float> volume_changes_; |
| size_t num_times_adjust_sound_played_ = 0; |
| + size_t num_times_passthrough_played_ = 0; |
| + size_t num_times_exit_screen_played_ = 0; |
| + size_t num_times_enter_screen_played_ = 0; |
| }; |
| } // namespace |
| @@ -105,6 +129,12 @@ class TouchExplorationControllerTestApi { |
| touch_exploration_controller_->OnTapTimerFired(); |
| } |
| + void CallLongPressTimerNowForTesting() { |
| + DCHECK(touch_exploration_controller_->long_press_timer_.IsRunning()); |
| + touch_exploration_controller_->long_press_timer_.Stop(); |
| + touch_exploration_controller_->OnLongPressTimerFired(); |
| + } |
| + |
| void CallTapTimerNowIfRunningForTesting() { |
| if (touch_exploration_controller_->tap_timer_.IsRunning()) { |
| touch_exploration_controller_->tap_timer_.Stop(); |
| @@ -133,6 +163,11 @@ class TouchExplorationControllerTestApi { |
| touch_exploration_controller_->SLIDE_GESTURE; |
| } |
| + bool IsInCornerPassthroughStateForTesting() const { |
| + return touch_exploration_controller_->state_ == |
| + touch_exploration_controller_->CORNER_PASSTHROUGH; |
| + } |
| + |
| gfx::Rect BoundsOfRootWindowInDIPForTesting() const { |
| return touch_exploration_controller_->root_window_->GetBoundsInScreen(); |
| } |
| @@ -234,6 +269,11 @@ class TouchExplorationTest : public aura::test::AuraTestBase { |
| touch_exploration_controller_->CallTapTimerNowForTesting(); |
| } |
| + void AdvanceSimulatedTimePastLongPressDelay() { |
| + simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
| + touch_exploration_controller_->CallLongPressTimerNowForTesting(); |
| + } |
| + |
| void AdvanceSimulatedTimePastPotentialTapDelay() { |
| simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
| touch_exploration_controller_->CallTapTimerNowIfRunningForTesting(); |
| @@ -275,11 +315,53 @@ class TouchExplorationTest : public aura::test::AuraTestBase { |
| generator_->Dispatch(&second_touch_press); |
| } |
| + // Checks that Corner Passthrough is working. Assumes that corner is the |
| + // bottom left corner or the bottom right corner. |
| + void AssertCornerPassthroughWorking(gfx::Point corner) { |
| + ASSERT_EQ(0U, delegate_.NumPassthroughSounds()); |
| + |
| + ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, corner, 0, Now()); |
| + generator_->Dispatch(&first_press); |
| + |
| + AdvanceSimulatedTimePastLongPressDelay(); |
| + EXPECT_FALSE(IsInGestureInProgressState()); |
| + EXPECT_FALSE(IsInSlideGestureState()); |
| + EXPECT_FALSE(IsInTouchToMouseMode()); |
| + EXPECT_TRUE(IsInCornerPassthroughState()); |
| + |
| + gfx::Rect window = BoundsOfRootWindowInDIP(); |
| + // The following events should be passed through. |
| + gfx::Point passthrough(window.right() / 2, window.bottom() / 2); |
| + ui::TouchEvent passthrough_press( |
| + ui::ET_TOUCH_PRESSED, passthrough, 1, Now()); |
| + ASSERT_EQ(1U, delegate_.NumPassthroughSounds()); |
| + generator_->Dispatch(&passthrough_press); |
| + generator_->ReleaseTouchId(1); |
| + generator_->PressTouchId(1); |
| + EXPECT_FALSE(IsInGestureInProgressState()); |
| + EXPECT_FALSE(IsInSlideGestureState()); |
| + EXPECT_TRUE(IsInCornerPassthroughState()); |
| + |
| + std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
| + ASSERT_EQ(3U, captured_events.size()); |
| + EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| + EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| + EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[2]->type()); |
| + generator_->ReleaseTouchId(1); |
| + ClearCapturedEvents(); |
| + |
| + generator_->ReleaseTouchId(0); |
| + captured_events = GetCapturedLocatedEvents(); |
| + ASSERT_EQ(0U, captured_events.size()); |
| + EXPECT_FALSE(IsInTouchToMouseMode()); |
| + EXPECT_FALSE(IsInCornerPassthroughState()); |
| + ClearCapturedEvents(); |
| + } |
| + |
| bool IsInTouchToMouseMode() { |
| aura::client::CursorClient* cursor_client = |
| aura::client::GetCursorClient(root_window()); |
| - return cursor_client && |
| - cursor_client->IsMouseEventsEnabled() && |
| + return cursor_client && cursor_client->IsMouseEventsEnabled() && |
| !cursor_client->IsCursorVisible(); |
| } |
| @@ -296,11 +378,16 @@ class TouchExplorationTest : public aura::test::AuraTestBase { |
| return touch_exploration_controller_->IsInSlideGestureStateForTesting(); |
| } |
| + bool IsInCornerPassthroughState() { |
| + return touch_exploration_controller_ |
| + ->IsInCornerPassthroughStateForTesting(); |
| + } |
| + |
| gfx::Rect BoundsOfRootWindowInDIP() { |
| return touch_exploration_controller_->BoundsOfRootWindowInDIPForTesting(); |
| } |
| - float GetMaxDistanceFromEdge() const{ |
| + float GetMaxDistanceFromEdge() const { |
| return touch_exploration_controller_->GetMaxDistanceFromEdge(); |
| } |
| @@ -1640,4 +1727,113 @@ TEST_F(TouchExplorationTest, InBoundariesTouchExploration) { |
| EXPECT_TRUE(IsInTouchToMouseMode()); |
| } |
| +// Corner passthrough should turn on if the user first holds down on either the |
| +// right or left corner past a delay and then places a finger anywhere else on |
| +// the screen. |
| +TEST_F(TouchExplorationTest, ActivateLeftCornerPassthrough) { |
| + SwitchTouchExplorationMode(true); |
| + |
| + gfx::Rect window = BoundsOfRootWindowInDIP(); |
| + gfx::Point left_corner(10, window.bottom() - GetMaxDistanceFromEdge() / 2); |
| + AssertCornerPassthroughWorking(left_corner); |
| +} |
| + |
| +TEST_F(TouchExplorationTest, ActivateRightCornerPassthrough) { |
| + SwitchTouchExplorationMode(true); |
| + |
| + gfx::Rect window = BoundsOfRootWindowInDIP(); |
| + gfx::Point right_corner(window.right() - GetMaxDistanceFromEdge() / 2, |
| + window.bottom() - GetMaxDistanceFromEdge() / 2); |
| + AssertCornerPassthroughWorking(right_corner); |
| +} |
| + |
| +// Earcons should play if the user slides off the screen or enters the screen |
| +// from the edge. |
| +TEST_F(TouchExplorationTest, EnterEarconPlays) { |
| + SwitchTouchExplorationMode(true); |
| + |
| + gfx::Rect window = BoundsOfRootWindowInDIP(); |
| + ui::TouchEvent upper_left_corner( |
|
aboxhall
2014/07/28 22:41:44
Suggestion (similarly for ExitEarconPlays test): p
|
| + ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, Now()); |
| + ui::TouchEvent upper_right_corner( |
| + ui::ET_TOUCH_PRESSED, gfx::Point(window.right(), 0), 1, Now()); |
| + ui::TouchEvent lower_left_corner( |
| + ui::ET_TOUCH_PRESSED, gfx::Point(0, window.bottom()), 1, Now()); |
| + ui::TouchEvent lower_right_corner(ui::ET_TOUCH_PRESSED, |
| + gfx::Point(window.right(), window.bottom()), |
| + 1, |
| + Now()); |
| + |
| + generator_->Dispatch(&upper_left_corner); |
| + ASSERT_EQ(1U, delegate_.NumEnterScreenSounds()); |
| + generator_->ReleaseTouchId(1); |
| + delegate_.ResetCountersToZero(); |
| + |
| + generator_->Dispatch(&upper_right_corner); |
| + ASSERT_EQ(1U, delegate_.NumEnterScreenSounds()); |
| + generator_->ReleaseTouchId(1); |
| + delegate_.ResetCountersToZero(); |
| + |
| + generator_->Dispatch(&lower_left_corner); |
| + ASSERT_EQ(1U, delegate_.NumEnterScreenSounds()); |
| + generator_->ReleaseTouchId(1); |
| + delegate_.ResetCountersToZero(); |
| + |
| + generator_->Dispatch(&lower_right_corner); |
| + ASSERT_EQ(1U, delegate_.NumEnterScreenSounds()); |
| + generator_->ReleaseTouchId(1); |
| + delegate_.ResetCountersToZero(); |
| +} |
| + |
| +TEST_F(TouchExplorationTest, ExitEarconPlays) { |
| + SwitchTouchExplorationMode(true); |
| + |
| + // On the device, it cannot actually tell if the finger has left the screen or |
| + // not. If the finger has left the screen, it reads it as a release that |
| + // occurred very close to the edge of the screen even if the finger is still |
| + // technically touching the moniter. To simulate this, a release that occurs |
| + // close to the edge is dispatched. |
| + gfx::Point initial_press(100, 200); |
| + gfx::Rect window = BoundsOfRootWindowInDIP(); |
| + gfx::Point upper_left_corner(0, 0); |
| + gfx::Point upper_right_corner(window.right(), 0); |
| + gfx::Point lower_left_corner(0, window.bottom()); |
| + gfx::Point lower_right_corner(window.right(), window.bottom()); |
| + |
| + generator_->PressTouch(); |
| + generator_->MoveTouch(initial_press); |
| + generator_->MoveTouch(upper_left_corner); |
| + generator_->ReleaseTouch(); |
| + ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
| + delegate_.ResetCountersToZero(); |
| + |
| + generator_->PressTouch(); |
| + generator_->MoveTouch(initial_press); |
| + generator_->MoveTouch(upper_left_corner); |
| + generator_->ReleaseTouch(); |
| + ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
| + delegate_.ResetCountersToZero(); |
| + |
| + generator_->PressTouch(); |
| + generator_->MoveTouch(initial_press); |
| + generator_->MoveTouch(upper_right_corner); |
| + generator_->ReleaseTouch(); |
| + ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
| + delegate_.ResetCountersToZero(); |
| + |
| + generator_->PressTouch(); |
| + generator_->MoveTouch(initial_press); |
| + generator_->MoveTouch(lower_left_corner); |
| + generator_->ReleaseTouch(); |
| + ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
| + delegate_.ResetCountersToZero(); |
| + |
| + generator_->PressTouch(); |
| + generator_->MoveTouch(initial_press); |
| + generator_->MoveTouch(lower_right_corner); |
| + generator_->ReleaseTouch(); |
| + ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
| + delegate_.ResetCountersToZero(); |
| +} |
| + |
| } // namespace ui |