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 <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 183 } |
184 | 184 |
185 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { | 185 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { |
186 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); | 186 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); |
187 } | 187 } |
188 | 188 |
189 void SetExcludeBounds(const gfx::Rect& bounds) { | 189 void SetExcludeBounds(const gfx::Rect& bounds) { |
190 touch_exploration_controller_->SetExcludeBounds(bounds); | 190 touch_exploration_controller_->SetExcludeBounds(bounds); |
191 } | 191 } |
192 | 192 |
| 193 void SetLiftActivationBounds(const gfx::Rect& bounds) { |
| 194 touch_exploration_controller_->SetLiftActivationBounds(bounds); |
| 195 } |
| 196 |
193 private: | 197 private: |
194 std::unique_ptr<TouchExplorationController> touch_exploration_controller_; | 198 std::unique_ptr<TouchExplorationController> touch_exploration_controller_; |
195 | 199 |
196 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); | 200 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); |
197 }; | 201 }; |
198 | 202 |
199 class TouchExplorationTest : public aura::test::AuraTestBase { | 203 class TouchExplorationTest : public aura::test::AuraTestBase { |
200 public: | 204 public: |
201 TouchExplorationTest() : simulated_clock_(nullptr) {} | 205 TouchExplorationTest() : simulated_clock_(nullptr) {} |
202 ~TouchExplorationTest() override {} | 206 ~TouchExplorationTest() override {} |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 base::TimeTicks Now() { return ui::EventTimeForNow(); } | 410 base::TimeTicks Now() { return ui::EventTimeForNow(); } |
407 | 411 |
408 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { | 412 void SetTouchAccessibilityAnchorPoint(const gfx::Point& location) { |
409 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); | 413 touch_exploration_controller_->SetTouchAccessibilityAnchorPoint(location); |
410 } | 414 } |
411 | 415 |
412 void SetExcludeBounds(const gfx::Rect& bounds) { | 416 void SetExcludeBounds(const gfx::Rect& bounds) { |
413 touch_exploration_controller_->SetExcludeBounds(bounds); | 417 touch_exploration_controller_->SetExcludeBounds(bounds); |
414 } | 418 } |
415 | 419 |
| 420 void SetLiftActivationBounds(const gfx::Rect& bounds) { |
| 421 touch_exploration_controller_->SetLiftActivationBounds(bounds); |
| 422 } |
| 423 |
416 std::unique_ptr<test::EventGenerator> generator_; | 424 std::unique_ptr<test::EventGenerator> generator_; |
417 ui::GestureDetector::Config gesture_detector_config_; | 425 ui::GestureDetector::Config gesture_detector_config_; |
418 // Owned by |ui|. | 426 // Owned by |ui|. |
419 base::SimpleTestTickClock* simulated_clock_; | 427 base::SimpleTestTickClock* simulated_clock_; |
420 MockTouchExplorationControllerDelegate delegate_; | 428 MockTouchExplorationControllerDelegate delegate_; |
421 | 429 |
422 private: | 430 private: |
423 EventCapturer event_capturer_; | 431 EventCapturer event_capturer_; |
424 std::unique_ptr<TouchExplorationControllerTestApi> | 432 std::unique_ptr<TouchExplorationControllerTestApi> |
425 touch_exploration_controller_; | 433 touch_exploration_controller_; |
(...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1969 generator_->ReleaseTouchId(0); | 1977 generator_->ReleaseTouchId(0); |
1970 AdvanceSimulatedTimePastTapDelay(); | 1978 AdvanceSimulatedTimePastTapDelay(); |
1971 EXPECT_TRUE(IsInNoFingersDownState()); | 1979 EXPECT_TRUE(IsInNoFingersDownState()); |
1972 | 1980 |
1973 ASSERT_EQ(1U, GetCapturedEvents().size()); | 1981 ASSERT_EQ(1U, GetCapturedEvents().size()); |
1974 EXPECT_EQ(ui::ET_MOUSE_MOVED, GetCapturedEvents()[0]->type()); | 1982 EXPECT_EQ(ui::ET_MOUSE_MOVED, GetCapturedEvents()[0]->type()); |
1975 ClearCapturedEvents(); | 1983 ClearCapturedEvents(); |
1976 } | 1984 } |
1977 } | 1985 } |
1978 | 1986 |
| 1987 TEST_F(TouchExplorationTest, SingleTapInLiftActivationArea) { |
| 1988 SwitchTouchExplorationMode(true); |
| 1989 |
| 1990 gfx::Rect lift_activation = BoundsOfRootWindowInDIP(); |
| 1991 lift_activation.Inset(0, 0, 0, 30); |
| 1992 SetLiftActivationBounds(lift_activation); |
| 1993 |
| 1994 // Tap at one location, and get tap and mouse move events. |
| 1995 gfx::Point tap_location = lift_activation.CenterPoint(); |
| 1996 |
| 1997 // The user has to have previously selected something. |
| 1998 SetTouchAccessibilityAnchorPoint(tap_location); |
| 1999 |
| 2000 generator_->set_current_location(tap_location); |
| 2001 generator_->PressTouchId(1); |
| 2002 generator_->ReleaseTouchId(1); |
| 2003 AdvanceSimulatedTimePastTapDelay(); |
| 2004 |
| 2005 const EventList& captured_events = GetCapturedEvents(); |
| 2006 ASSERT_EQ(3U, captured_events.size()); |
| 2007 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 2008 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 2009 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[2]->type()); |
| 2010 ClearCapturedEvents(); |
| 2011 |
| 2012 gfx::Point out_tap_location(tap_location.x(), lift_activation.bottom() + 20); |
| 2013 SetTouchAccessibilityAnchorPoint(out_tap_location); |
| 2014 generator_->set_current_location(out_tap_location); |
| 2015 generator_->PressTouchId(1); |
| 2016 generator_->ReleaseTouchId(1); |
| 2017 AdvanceSimulatedTimePastTapDelay(); |
| 2018 |
| 2019 const EventList& out_captured_events = GetCapturedEvents(); |
| 2020 ASSERT_EQ(1U, out_captured_events.size()); |
| 2021 EXPECT_EQ(ui::ET_MOUSE_MOVED, out_captured_events[0]->type()); |
| 2022 } |
| 2023 |
| 2024 TEST_F(TouchExplorationTest, TouchExploreLiftInLiftActivationArea) { |
| 2025 SwitchTouchExplorationMode(true); |
| 2026 |
| 2027 gfx::Rect lift_activation = BoundsOfRootWindowInDIP(); |
| 2028 lift_activation.Inset(0, 0, 0, 30); |
| 2029 SetLiftActivationBounds(lift_activation); |
| 2030 |
| 2031 // Explore at one location, and get tap and mouse move events. |
| 2032 gfx::Point tap_location = lift_activation.CenterPoint(); |
| 2033 EnterTouchExplorationModeAtLocation(tap_location); |
| 2034 ClearCapturedEvents(); |
| 2035 |
| 2036 // A touch release should trigger a tap. |
| 2037 ui::TouchEvent touch_explore_release( |
| 2038 ui::ET_TOUCH_RELEASED, tap_location, Now(), |
| 2039 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); |
| 2040 generator_->Dispatch(&touch_explore_release); |
| 2041 AdvanceSimulatedTimePastTapDelay(); |
| 2042 |
| 2043 const EventList& captured_events = GetCapturedEvents(); |
| 2044 ASSERT_EQ(3U, captured_events.size()); |
| 2045 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 2046 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 2047 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[2]->type()); |
| 2048 ClearCapturedEvents(); |
| 2049 |
| 2050 // Touch explore inside the activation bounds, but lift outside. |
| 2051 gfx::Point out_tap_location(tap_location.x(), lift_activation.bottom() + 20); |
| 2052 SetTouchAccessibilityAnchorPoint(out_tap_location); |
| 2053 EnterTouchExplorationModeAtLocation(tap_location); |
| 2054 ClearCapturedEvents(); |
| 2055 ui::TouchEvent out_touch_explore_release( |
| 2056 ui::ET_TOUCH_RELEASED, out_tap_location, Now(), |
| 2057 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); |
| 2058 generator_->Dispatch(&out_touch_explore_release); |
| 2059 AdvanceSimulatedTimePastTapDelay(); |
| 2060 |
| 2061 const EventList& out_captured_events = GetCapturedEvents(); |
| 2062 ASSERT_EQ(1U, out_captured_events.size()); |
| 2063 EXPECT_EQ(ui::ET_MOUSE_MOVED, out_captured_events[0]->type()); |
| 2064 } |
| 2065 |
1979 } // namespace ui | 2066 } // namespace ui |
OLD | NEW |