Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: ui/chromeos/touch_exploration_controller_unittest.cc

Issue 385073009: Side Slide Gestures for Accessibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added Tests for Slide Gestures Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 }; 64 };
65 65
66 int Factorial(int n) { 66 int Factorial(int n) {
67 if (n <= 0) 67 if (n <= 0)
68 return 0; 68 return 0;
69 if (n == 1) 69 if (n == 1)
70 return 1; 70 return 1;
71 return n * Factorial(n - 1); 71 return n * Factorial(n - 1);
72 } 72 }
73 73
74 class MockTouchExplorationControllerDelegate
75 : public ui::TouchExplorationControllerDelegate {
76 public:
77 virtual void PlayVolumeAdjustSound() OVERRIDE {
78 ++num_times_adjust_sound_played_;
79 }
80 virtual void AdjustSound(float volume) OVERRIDE {
81 volume_changes_.push_back(volume);
82 }
83
84 const std::vector<float> VolumeChanges() { return volume_changes_; }
85 const int NumAdjustSounds() { return num_times_adjust_sound_played_; }
86
87 private:
88 std::vector<float> volume_changes_;
89 int num_times_adjust_sound_played_ = 0;
90 };
91
74 } // namespace 92 } // namespace
75 93
76 class TouchExplorationTest : public aura::test::AuraTestBase { 94 class TouchExplorationTest : public aura::test::AuraTestBase {
77 public: 95 public:
78 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { 96 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) {
79 // Tests fail if time is ever 0. 97 // Tests fail if time is ever 0.
80 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 98 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
81 } 99 }
82 virtual ~TouchExplorationTest() {} 100 virtual ~TouchExplorationTest() {}
83 101
84 virtual void SetUp() OVERRIDE { 102 virtual void SetUp() OVERRIDE {
85 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone) 103 if (gfx::GetGLImplementation() == gfx::kGLImplementationNone)
86 gfx::GLSurface::InitializeOneOffForTests(); 104 gfx::GLSurface::InitializeOneOffForTests();
87 aura::test::AuraTestBase::SetUp(); 105 aura::test::AuraTestBase::SetUp();
106 delegate_ = new MockTouchExplorationControllerDelegate();
88 cursor_client_.reset(new aura::test::TestCursorClient(root_window())); 107 cursor_client_.reset(new aura::test::TestCursorClient(root_window()));
89 root_window()->AddPreTargetHandler(&event_capturer_); 108 root_window()->AddPreTargetHandler(&event_capturer_);
90 generator_.reset(new aura::test::EventGenerator(root_window())); 109 generator_.reset(new aura::test::EventGenerator(root_window()));
91 // The generator takes ownership of the clock. 110 // The generator takes ownership of the clock.
92 generator_->SetTickClock(scoped_ptr<base::TickClock>(simulated_clock_)); 111 generator_->SetTickClock(scoped_ptr<base::TickClock>(simulated_clock_));
93 cursor_client()->ShowCursor(); 112 cursor_client()->ShowCursor();
94 cursor_client()->DisableMouseEvents(); 113 cursor_client()->DisableMouseEvents();
95 } 114 }
96 115
97 virtual void TearDown() OVERRIDE { 116 virtual void TearDown() OVERRIDE {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 176
158 void SuppressVLOGs(bool suppress) { 177 void SuppressVLOGs(bool suppress) {
159 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); 178 touch_exploration_controller_->SuppressVLOGsForTesting(suppress);
160 } 179 }
161 180
162 void SwitchTouchExplorationMode(bool on) { 181 void SwitchTouchExplorationMode(bool on) {
163 if (!on && touch_exploration_controller_.get()) { 182 if (!on && touch_exploration_controller_.get()) {
164 touch_exploration_controller_.reset(); 183 touch_exploration_controller_.reset();
165 } else if (on && !touch_exploration_controller_.get()) { 184 } else if (on && !touch_exploration_controller_.get()) {
166 touch_exploration_controller_.reset( 185 touch_exploration_controller_.reset(
167 new ui::TouchExplorationController(root_window())); 186 new ui::TouchExplorationController(root_window(), delegate_));
168 touch_exploration_controller_->SetEventHandlerForTesting( 187 touch_exploration_controller_->SetEventHandlerForTesting(
169 &event_capturer_); 188 &event_capturer_);
170 cursor_client()->ShowCursor(); 189 cursor_client()->ShowCursor();
171 cursor_client()->DisableMouseEvents(); 190 cursor_client()->DisableMouseEvents();
172 } 191 }
173 } 192 }
174 193
175 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { 194 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) {
176 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); 195 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now());
177 generator_->Dispatch(&touch_press); 196 generator_->Dispatch(&touch_press);
(...skipping 22 matching lines...) Expand all
200 219
201 bool IsInNoFingersDownState() { 220 bool IsInNoFingersDownState() {
202 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); 221 return touch_exploration_controller_->IsInNoFingersDownStateForTesting();
203 } 222 }
204 223
205 bool IsInGestureInProgressState() { 224 bool IsInGestureInProgressState() {
206 return touch_exploration_controller_ 225 return touch_exploration_controller_
207 ->IsInGestureInProgressStateForTesting(); 226 ->IsInGestureInProgressStateForTesting();
208 } 227 }
209 228
229 bool IsInSlideGestureState() {
230 return touch_exploration_controller_->IsInSlideGestureStateForTesting();
231 }
232
233 gfx::Rect BoundsOfWindowInDIP() {
234 return touch_exploration_controller_->BoundsOfWindowInDIPForTesting();
235 }
236
210 base::TimeDelta Now() { 237 base::TimeDelta Now() {
211 // This is the same as what EventTimeForNow() does, but here we do it 238 // This is the same as what EventTimeForNow() does, but here we do it
212 // with our simulated clock. 239 // with our simulated clock.
213 return base::TimeDelta::FromInternalValue( 240 return base::TimeDelta::FromInternalValue(
214 simulated_clock_->NowTicks().ToInternalValue()); 241 simulated_clock_->NowTicks().ToInternalValue());
215 } 242 }
216 243
217 scoped_ptr<aura::test::EventGenerator> generator_; 244 scoped_ptr<aura::test::EventGenerator> generator_;
218 ui::GestureDetector::Config gesture_detector_config_; 245 ui::GestureDetector::Config gesture_detector_config_;
219 // Owned by |generator_|. 246 // Owned by |generator_|.
220 base::SimpleTestTickClock* simulated_clock_; 247 base::SimpleTestTickClock* simulated_clock_;
248 MockTouchExplorationControllerDelegate* delegate_;
221 249
222 private: 250 private:
223 EventCapturer event_capturer_; 251 EventCapturer event_capturer_;
224 scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_; 252 scoped_ptr<ui::TouchExplorationController> touch_exploration_controller_;
225 scoped_ptr<aura::test::TestCursorClient> cursor_client_; 253 scoped_ptr<aura::test::TestCursorClient> cursor_client_;
226 254
227 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); 255 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest);
228 }; 256 };
229 257
230 // Executes a number of assertions to confirm that |e1| and |e2| are touch 258 // Executes a number of assertions to confirm that |e1| and |e2| are touch
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 1359
1332 // The rest of the events should occur in passthrough. 1360 // The rest of the events should occur in passthrough.
1333 generator_->ReleaseTouchId(0); 1361 generator_->ReleaseTouchId(0);
1334 ASSERT_EQ(1U, captured_events.size()); 1362 ASSERT_EQ(1U, captured_events.size());
1335 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); 1363 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type());
1336 ClearCapturedEvents(); 1364 ClearCapturedEvents();
1337 generator_->ReleaseTouchId(1); 1365 generator_->ReleaseTouchId(1);
1338 ASSERT_EQ(0U, captured_events.size()); 1366 ASSERT_EQ(0U, captured_events.size());
1339 } 1367 }
1340 1368
1369 TEST_F(TouchExplorationTest, EnterSlideGestureState) {
1370 SwitchTouchExplorationMode(true);
1371 EXPECT_FALSE(IsInTouchToMouseMode());
1372 EXPECT_FALSE(IsInGestureInProgressState());
1373
1374 gfx::Rect window = BoundsOfWindowInDIP();
1375 float distance = gesture_detector_config_.touch_slop + 1;
1376 ui::TouchEvent first_press(
1377 ui::ET_TOUCH_PRESSED, gfx::Point(window.right(), 1), 0, Now());
1378 gfx::Point second_location(window.right(), 1 + distance / 2);
1379 gfx::Point third_location(window.right(), 1 + distance);
1380
1381 generator_->Dispatch(&first_press);
1382 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1383
1384 // Since we haven't moved past slop yet, we should not be in slide gesture.
1385 generator_->MoveTouch(second_location);
1386 EXPECT_FALSE(IsInTouchToMouseMode());
1387 EXPECT_FALSE(IsInGestureInProgressState());
1388 EXPECT_FALSE(IsInSlideGestureState());
1389 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1390
1391 // Once we are out of slop, we should be in slide gesture since we are along
1392 // the edge of the screen.
1393 generator_->MoveTouch(third_location);
1394 EXPECT_FALSE(IsInGestureInProgressState());
1395 EXPECT_TRUE(IsInSlideGestureState());
1396 EXPECT_FALSE(IsInTouchToMouseMode());
1397 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1398 ASSERT_EQ(0U, captured_events.size());
1399
1400 // Since we are at the right edge of the screen, but the sound timer has not
1401 // elapsed, there should have two sounds that fired and two volume
1402 // changes (one for each movement).
1403 int num_adjust_sounds = delegate_->NumAdjustSounds();
1404 EXPECT_EQ(num_adjust_sounds, 2U);
1405 EXPECT_EQ(delegate_->VolumeChanges().size(), 2U);
1406
1407 // Exit out of slide gesture once touch is lifted, but not before even if the
1408 // grace period is over.
1409
1410 AdvanceSimulatedTimePastPotentialTapDelay();
1411 ASSERT_EQ(0U, captured_events.size());
1412 EXPECT_FALSE(IsInTouchToMouseMode());
1413 EXPECT_FALSE(IsInGestureInProgressState());
1414 EXPECT_TRUE(IsInSlideGestureState());
1415
1416 generator_->ReleaseTouch();
1417 ASSERT_EQ(0U, captured_events.size());
1418 EXPECT_FALSE(IsInTouchToMouseMode());
1419 EXPECT_FALSE(IsInGestureInProgressState());
1420 EXPECT_FALSE(IsInSlideGestureState());
1421 }
1422
1423 // If a press + move occurred outside the boundaries, but within the slop
1424 // boundaries and then moved into the boundaries of an edge, there still should
1425 // not be a slide gesture.
1426 TEST_F(TouchExplorationTest, AvoidEnteringSlideGesture) {
1427 SwitchTouchExplorationMode(true);
1428
1429 // DO SOMETHING TO MAKE THESE CONSTANTS ACCESSIBLE FROM ORIGINAL FILE
1430 const float kMaxDistanceFromEdge = 75;
1431 const float kSlopDistanceFromEdge = kMaxDistanceFromEdge + 40;
1432
1433 gfx::Rect window = BoundsOfWindowInDIP();
1434 float distance = gesture_detector_config_.touch_slop + 1;
1435 ui::TouchEvent first_press(
1436 ui::ET_TOUCH_PRESSED,
1437 gfx::Point(window.right() - kSlopDistanceFromEdge, 1),
1438 0,
1439 Now());
1440 gfx::Point out_of_slop(window.right() - kSlopDistanceFromEdge + distance, 1);
1441 gfx::Point into_boundaries(window.right() - kMaxDistanceFromEdge / 2, 1);
1442
1443 generator_->Dispatch(&first_press);
1444 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1445
1446 generator_->MoveTouch(out_of_slop);
1447 EXPECT_FALSE(IsInTouchToMouseMode());
1448 EXPECT_TRUE(IsInGestureInProgressState());
1449 EXPECT_FALSE(IsInSlideGestureState());
1450 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1451
1452 // Since we did not start moving while in the boundaries, we should not be in
1453 // slide gestures.
1454 generator_->MoveTouch(into_boundaries);
1455 EXPECT_TRUE(IsInGestureInProgressState());
1456 EXPECT_FALSE(IsInSlideGestureState());
1457 EXPECT_FALSE(IsInTouchToMouseMode());
1458 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1459 ASSERT_EQ(0U, captured_events.size());
1460
1461 generator_->ReleaseTouch();
1462 }
1463
1464 // If the slide gesture begins within the boundaries and then moves
1465 // SlopDistanceFromEdge there should still be a sound change. If the finger
1466 // moves into the center screen, there should no longer be a sound change but it
1467 // should still be in slide gesture. If the finger moves back into the edges
1468 // without lifting, it should start changing sound again.
1469 TEST_F(TouchExplorationTest, TestingBoundaries) {
1470 SwitchTouchExplorationMode(true);
1471
1472 // DO SOMETHING TO MAKE THESE CONSTANTS ACCESSIBLE FROM ORIGINAL FILE
1473 const float kMaxDistanceFromEdge = 75;
1474 const float kSlopDistanceFromEdge = kMaxDistanceFromEdge + 40;
1475
1476 gfx::Rect window = BoundsOfWindowInDIP();
1477 gfx::Point initial_press(window.right() - kMaxDistanceFromEdge / 2, 1);
1478 ui::TouchEvent first_press(
1479 ui::ET_TOUCH_PRESSED,
1480 initial_press,
1481 0,
1482 Now());
1483 gfx::Point touch_move(initial_press.x() + gesture_detector_config_.touch_slop,
1484 1);
1485 gfx::Point into_slop_boundaries(window.right() - kSlopDistanceFromEdge / 2,
1486 1);
1487 gfx::Point center_screen(window.right() / 2, window.bottom() / 2);
1488
1489 generator_->Dispatch(&first_press);
1490 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1491
1492 generator_->MoveTouch(touch_move);
1493 EXPECT_FALSE(IsInTouchToMouseMode());
1494 EXPECT_FALSE(IsInGestureInProgressState());
1495 EXPECT_FALSE(IsInSlideGestureState());
1496 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1497
1498 // Move the touch into slop boundaries. It should stil be in slide gestures
1499 // and adjust the volume.
1500 generator_->MoveTouch(into_slop_boundaries);
1501 EXPECT_FALSE(IsInGestureInProgressState());
1502 EXPECT_TRUE(IsInSlideGestureState());
1503 EXPECT_FALSE(IsInTouchToMouseMode());
1504
1505 // The sound is rate limiting so it only activates every 150ms.
1506 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200));
1507
1508 int num_adjust_sounds = delegate_->NumAdjustSounds();
1509 EXPECT_EQ(num_adjust_sounds, 2U);
1510 EXPECT_EQ(delegate_->VolumeChanges().size(), 2U);
1511
1512 // Move the touch into the center of the window. It should still be in slide
1513 // gestures, but there should not be anymore volume adjustments.
1514 generator_->MoveTouch(center_screen);
1515 EXPECT_FALSE(IsInGestureInProgressState());
1516 EXPECT_TRUE(IsInSlideGestureState());
1517 EXPECT_FALSE(IsInTouchToMouseMode());
1518
1519 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200));
1520 num_adjust_sounds = delegate_->NumAdjustSounds();
1521 EXPECT_EQ(num_adjust_sounds, 2U);
1522 EXPECT_EQ(delegate_->VolumeChanges().size(), 2U);
1523
1524 // Move the touch back into slop edge distance and volume should be changing
1525 // again.
1526 generator_->MoveTouch(into_slop_boundaries);
1527 EXPECT_FALSE(IsInGestureInProgressState());
1528 EXPECT_TRUE(IsInSlideGestureState());
1529 EXPECT_FALSE(IsInTouchToMouseMode());
1530
1531 generator_->MoveTouch(
1532 gfx::Point(into_slop_boundaries.x() + gesture_detector_config_.touch_slop,
1533 into_slop_boundaries.y()));
1534 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200));
1535
1536 num_adjust_sounds = delegate_->NumAdjustSounds();
1537 EXPECT_EQ(num_adjust_sounds, 3U);
1538 EXPECT_EQ(delegate_->VolumeChanges().size(), 3U);
1539
1540 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1541 ASSERT_EQ(0U, captured_events.size());
1542
1543 generator_->ReleaseTouch();
1544 }
1545
1546 // Even if the gesture starts within bounds, if it has not moved past slop
1547 // within the grace period, it should go to touch exploration.
1548 TEST_F(TouchExplorationTest, InBoundariesTouchExploration) {
1549 SwitchTouchExplorationMode(true);
1550
1551 // DO SOMETHING TO MAKE THESE CONSTANTS ACCESSIBLE FROM ORIGINAL FILE
1552 const float kMaxDistanceFromEdge = 75;
1553
1554 gfx::Rect window = BoundsOfWindowInDIP();
1555 gfx::Point initial_press(window.right() - kMaxDistanceFromEdge / 2, 1);
1556 ui::TouchEvent first_press(
1557 ui::ET_TOUCH_PRESSED,
1558 initial_press,
1559 0,
1560 Now());
1561 generator_->Dispatch(&first_press);
1562 EXPECT_FALSE(IsInGestureInProgressState());
1563 EXPECT_FALSE(IsInSlideGestureState());
1564 EXPECT_FALSE(IsInTouchToMouseMode());
1565
1566 AdvanceSimulatedTimePastTapDelay();
1567 EXPECT_FALSE(IsInGestureInProgressState());
1568 EXPECT_FALSE(IsInSlideGestureState());
1569 EXPECT_TRUE(IsInTouchToMouseMode());
1570 }
1571
1341 } // namespace ui 1572 } // namespace ui
OLDNEW
« ui/chromeos/touch_exploration_controller.cc ('K') | « ui/chromeos/touch_exploration_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698