Chromium Code Reviews| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 int Factorial(int n) { | 67 int Factorial(int n) { |
| 68 if (n <= 0) | 68 if (n <= 0) |
| 69 return 0; | 69 return 0; |
| 70 if (n == 1) | 70 if (n == 1) |
| 71 return 1; | 71 return 1; |
| 72 return n * Factorial(n - 1); | 72 return n * Factorial(n - 1); |
| 73 } | 73 } |
| 74 | 74 |
| 75 class MockTouchExplorationControllerDelegate | |
| 76 : public ui::TouchExplorationControllerDelegate { | |
| 77 public: | |
| 78 virtual void PlayVolumeAdjustSound() OVERRIDE { | |
| 79 ++num_times_adjust_sound_played_; | |
| 80 } | |
| 81 virtual void SetOutputLevel(int volume) OVERRIDE { | |
| 82 volume_changes_.push_back(volume); | |
| 83 } | |
| 84 | |
| 85 const std::vector<float> VolumeChanges() { return volume_changes_; } | |
| 86 const size_t NumAdjustSounds() { return num_times_adjust_sound_played_; } | |
| 87 | |
| 88 private: | |
| 89 std::vector<float> volume_changes_; | |
| 90 size_t num_times_adjust_sound_played_ = 0; | |
| 91 }; | |
| 92 | |
| 75 } // namespace | 93 } // namespace |
| 76 | 94 |
| 77 class TouchExplorationControllerTestApi { | 95 class TouchExplorationControllerTestApi { |
| 78 public: | 96 public: |
| 79 TouchExplorationControllerTestApi( | 97 TouchExplorationControllerTestApi( |
| 80 TouchExplorationController* touch_exploration_controller) { | 98 TouchExplorationController* touch_exploration_controller) { |
| 81 touch_exploration_controller_.reset(touch_exploration_controller); | 99 touch_exploration_controller_.reset(touch_exploration_controller); |
| 82 } | 100 } |
| 83 | 101 |
| 84 void CallTapTimerNowForTesting() { | 102 void CallTapTimerNowForTesting() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 103 bool IsInNoFingersDownStateForTesting() const { | 121 bool IsInNoFingersDownStateForTesting() const { |
| 104 return touch_exploration_controller_->state_ == | 122 return touch_exploration_controller_->state_ == |
| 105 touch_exploration_controller_->NO_FINGERS_DOWN; | 123 touch_exploration_controller_->NO_FINGERS_DOWN; |
| 106 } | 124 } |
| 107 | 125 |
| 108 bool IsInGestureInProgressStateForTesting() const { | 126 bool IsInGestureInProgressStateForTesting() const { |
| 109 return touch_exploration_controller_->state_ == | 127 return touch_exploration_controller_->state_ == |
| 110 touch_exploration_controller_->GESTURE_IN_PROGRESS; | 128 touch_exploration_controller_->GESTURE_IN_PROGRESS; |
| 111 } | 129 } |
| 112 | 130 |
| 131 bool IsInSlideGestureStateForTesting() const { | |
| 132 return touch_exploration_controller_->state_ == | |
| 133 touch_exploration_controller_->SLIDE_GESTURE; | |
| 134 } | |
| 135 | |
| 136 gfx::Rect BoundsOfRootWindowInDIPForTesting() const { | |
| 137 return touch_exploration_controller_->root_window_->GetBoundsInScreen(); | |
| 138 } | |
| 139 | |
| 113 // VLOGs should be suppressed in tests that generate a lot of logs, | 140 // VLOGs should be suppressed in tests that generate a lot of logs, |
| 114 // for example permutations of nine touch events. | 141 // for example permutations of nine touch events. |
| 115 void SuppressVLOGsForTesting(bool suppress) { | 142 void SuppressVLOGsForTesting(bool suppress) { |
| 116 touch_exploration_controller_->VLOG_on_ = !suppress; | 143 touch_exploration_controller_->VLOG_on_ = !suppress; |
| 117 } | 144 } |
| 118 | 145 |
| 146 float kMaxDistanceFromEdge() const { | |
|
dmazzoni
2014/07/22 18:15:33
This is basically right but you can't name a funct
aboxhall
2014/07/22 18:16:47
Is this used?
lisayin
2014/07/22 18:26:51
Done.
lisayin
2014/07/22 18:26:51
It is used in the slide functions to make sure we
aboxhall
2014/07/22 18:28:37
Ahhh I see it now. I was confused by the name :)
T
| |
| 147 return touch_exploration_controller_->kMaxDistanceFromEdge; | |
| 148 } | |
| 149 | |
| 150 float kSlopDistanceFromEdge() const { | |
| 151 return touch_exploration_controller_->kSlopDistanceFromEdge; | |
| 152 } | |
| 153 | |
| 119 private: | 154 private: |
| 120 scoped_ptr<TouchExplorationController> touch_exploration_controller_; | 155 scoped_ptr<TouchExplorationController> touch_exploration_controller_; |
| 121 | 156 |
| 122 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); | 157 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); |
| 123 }; | 158 }; |
| 124 | 159 |
| 125 class TouchExplorationTest : public aura::test::AuraTestBase { | 160 class TouchExplorationTest : public aura::test::AuraTestBase { |
| 126 public: | 161 public: |
| 127 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { | 162 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { |
| 128 // Tests fail if time is ever 0. | 163 // Tests fail if time is ever 0. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 } | 240 } |
| 206 | 241 |
| 207 void SuppressVLOGs(bool suppress) { | 242 void SuppressVLOGs(bool suppress) { |
| 208 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); | 243 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); |
| 209 } | 244 } |
| 210 | 245 |
| 211 void SwitchTouchExplorationMode(bool on) { | 246 void SwitchTouchExplorationMode(bool on) { |
| 212 if (!on && touch_exploration_controller_.get()) { | 247 if (!on && touch_exploration_controller_.get()) { |
| 213 touch_exploration_controller_.reset(); | 248 touch_exploration_controller_.reset(); |
| 214 } else if (on && !touch_exploration_controller_.get()) { | 249 } else if (on && !touch_exploration_controller_.get()) { |
| 215 touch_exploration_controller_.reset(new TouchExplorationControllerTestApi( | 250 touch_exploration_controller_.reset( |
| 216 new ui::TouchExplorationController(root_window()))); | 251 new ui::TouchExplorationControllerTestApi( |
| 252 new TouchExplorationController(root_window(), &delegate_))); | |
| 217 touch_exploration_controller_->SetEventHandlerForTesting( | 253 touch_exploration_controller_->SetEventHandlerForTesting( |
| 218 &event_capturer_); | 254 &event_capturer_); |
| 219 cursor_client()->ShowCursor(); | 255 cursor_client()->ShowCursor(); |
| 220 cursor_client()->DisableMouseEvents(); | 256 cursor_client()->DisableMouseEvents(); |
| 221 } | 257 } |
| 222 } | 258 } |
| 223 | 259 |
| 224 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { | 260 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { |
| 225 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); | 261 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); |
| 226 generator_->Dispatch(&touch_press); | 262 generator_->Dispatch(&touch_press); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 249 | 285 |
| 250 bool IsInNoFingersDownState() { | 286 bool IsInNoFingersDownState() { |
| 251 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); | 287 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); |
| 252 } | 288 } |
| 253 | 289 |
| 254 bool IsInGestureInProgressState() { | 290 bool IsInGestureInProgressState() { |
| 255 return touch_exploration_controller_ | 291 return touch_exploration_controller_ |
| 256 ->IsInGestureInProgressStateForTesting(); | 292 ->IsInGestureInProgressStateForTesting(); |
| 257 } | 293 } |
| 258 | 294 |
| 295 bool IsInSlideGestureState() { | |
| 296 return touch_exploration_controller_->IsInSlideGestureStateForTesting(); | |
| 297 } | |
| 298 | |
| 299 gfx::Rect BoundsOfRootWindowInDIP() { | |
| 300 return touch_exploration_controller_->BoundsOfRootWindowInDIPForTesting(); | |
| 301 } | |
| 302 | |
| 303 float kMaxDistanceFromEdge() const{ | |
| 304 return touch_exploration_controller_->kMaxDistanceFromEdge(); | |
| 305 } | |
| 306 | |
| 307 float kSlopDistanceFromEdge() const{ | |
| 308 return touch_exploration_controller_->kSlopDistanceFromEdge(); | |
| 309 } | |
| 310 | |
| 259 base::TimeDelta Now() { | 311 base::TimeDelta Now() { |
| 260 // This is the same as what EventTimeForNow() does, but here we do it | 312 // This is the same as what EventTimeForNow() does, but here we do it |
| 261 // with our simulated clock. | 313 // with our simulated clock. |
| 262 return base::TimeDelta::FromInternalValue( | 314 return base::TimeDelta::FromInternalValue( |
| 263 simulated_clock_->NowTicks().ToInternalValue()); | 315 simulated_clock_->NowTicks().ToInternalValue()); |
| 264 } | 316 } |
| 265 | 317 |
| 266 scoped_ptr<aura::test::EventGenerator> generator_; | 318 scoped_ptr<aura::test::EventGenerator> generator_; |
| 267 ui::GestureDetector::Config gesture_detector_config_; | 319 ui::GestureDetector::Config gesture_detector_config_; |
| 268 // Owned by |generator_|. | 320 // Owned by |generator_|. |
| 269 base::SimpleTestTickClock* simulated_clock_; | 321 base::SimpleTestTickClock* simulated_clock_; |
| 322 MockTouchExplorationControllerDelegate delegate_; | |
| 270 | 323 |
| 271 private: | 324 private: |
| 272 EventCapturer event_capturer_; | 325 EventCapturer event_capturer_; |
| 273 scoped_ptr<TouchExplorationControllerTestApi> | 326 scoped_ptr<TouchExplorationControllerTestApi> |
| 274 touch_exploration_controller_; | 327 touch_exploration_controller_; |
| 275 scoped_ptr<aura::test::TestCursorClient> cursor_client_; | 328 scoped_ptr<aura::test::TestCursorClient> cursor_client_; |
| 276 | 329 |
| 277 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 330 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
| 278 }; | 331 }; |
| 279 | 332 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); | 555 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); |
| 503 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); | 556 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); |
| 504 EXPECT_TRUE(IsInNoFingersDownState()); | 557 EXPECT_TRUE(IsInNoFingersDownState()); |
| 505 } | 558 } |
| 506 | 559 |
| 507 // If an event is received after the double-tap timeout has elapsed, but | 560 // If an event is received after the double-tap timeout has elapsed, but |
| 508 // before the timer has fired, a mouse move should still be generated. | 561 // before the timer has fired, a mouse move should still be generated. |
| 509 TEST_F(TouchExplorationTest, TimerFiresLateDuringTouchExploration) { | 562 TEST_F(TouchExplorationTest, TimerFiresLateDuringTouchExploration) { |
| 510 SwitchTouchExplorationMode(true); | 563 SwitchTouchExplorationMode(true); |
| 511 | 564 |
| 565 // Make sure the touch is not in a corner of the screen. | |
| 566 generator_->MoveTouch(gfx::Point(100, 200)); | |
| 567 | |
| 512 // Send a press, then add another finger after the double-tap timeout. | 568 // Send a press, then add another finger after the double-tap timeout. |
| 513 generator_->PressTouchId(1); | 569 generator_->PressTouchId(1); |
| 514 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); | 570 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
| 515 generator_->PressTouchId(2); | 571 generator_->PressTouchId(2); |
| 516 std::vector<ui::LocatedEvent*> events = | 572 std::vector<ui::LocatedEvent*> events = |
| 517 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 573 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
| 518 ASSERT_EQ(1U, events.size()); | 574 ASSERT_EQ(1U, events.size()); |
| 519 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 575 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
| 520 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 576 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
| 521 | 577 |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1350 } | 1406 } |
| 1351 | 1407 |
| 1352 // With the simple swipe gestures, if additional fingers are added, then the | 1408 // With the simple swipe gestures, if additional fingers are added, then the |
| 1353 // state should change to passthrough. | 1409 // state should change to passthrough. |
| 1354 TEST_F(TouchExplorationTest, FromGestureToPassthrough) { | 1410 TEST_F(TouchExplorationTest, FromGestureToPassthrough) { |
| 1355 SwitchTouchExplorationMode(true); | 1411 SwitchTouchExplorationMode(true); |
| 1356 EXPECT_FALSE(IsInTouchToMouseMode()); | 1412 EXPECT_FALSE(IsInTouchToMouseMode()); |
| 1357 EXPECT_FALSE(IsInGestureInProgressState()); | 1413 EXPECT_FALSE(IsInGestureInProgressState()); |
| 1358 | 1414 |
| 1359 float distance = gesture_detector_config_.touch_slop + 1; | 1415 float distance = gesture_detector_config_.touch_slop + 1; |
| 1360 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 1), 0, Now()); | 1416 ui::TouchEvent first_press( |
| 1417 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 0, Now()); | |
| 1361 generator_->Dispatch(&first_press); | 1418 generator_->Dispatch(&first_press); |
| 1362 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 1419 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
| 1363 gfx::Point second_location(distance, 1); | 1420 gfx::Point second_location(100 + distance, 200); |
| 1364 generator_->MoveTouch(second_location); | 1421 generator_->MoveTouch(second_location); |
| 1365 EXPECT_TRUE(IsInGestureInProgressState()); | 1422 EXPECT_TRUE(IsInGestureInProgressState()); |
| 1366 EXPECT_FALSE(IsInTouchToMouseMode()); | 1423 EXPECT_FALSE(IsInTouchToMouseMode()); |
| 1367 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | 1424 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
| 1368 ASSERT_EQ(0U, captured_events.size()); | 1425 ASSERT_EQ(0U, captured_events.size()); |
| 1369 | 1426 |
| 1370 // Generate a second press that should go through as is. | 1427 // Generate a second press that should go through as is. |
| 1371 ui::TouchEvent second_press( | 1428 ui::TouchEvent second_press( |
| 1372 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now()); | 1429 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now()); |
| 1373 generator_->Dispatch(&second_press); | 1430 generator_->Dispatch(&second_press); |
| 1374 EXPECT_FALSE(IsInGestureInProgressState()); | 1431 EXPECT_FALSE(IsInGestureInProgressState()); |
| 1375 EXPECT_FALSE(IsInTouchToMouseMode()); | 1432 EXPECT_FALSE(IsInTouchToMouseMode()); |
| 1376 std::vector<ui::LocatedEvent*> captured_located_events = | 1433 std::vector<ui::LocatedEvent*> captured_located_events = |
| 1377 GetCapturedLocatedEvents(); | 1434 GetCapturedLocatedEvents(); |
| 1378 ASSERT_EQ(1U, captured_events.size()); | 1435 ASSERT_EQ(1U, captured_events.size()); |
| 1379 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_located_events[0], &second_press); | 1436 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_located_events[0], &second_press); |
| 1380 ClearCapturedEvents(); | 1437 ClearCapturedEvents(); |
| 1381 | 1438 |
| 1382 // The rest of the events should occur in passthrough. | 1439 // The rest of the events should occur in passthrough. |
| 1383 generator_->ReleaseTouchId(0); | 1440 generator_->ReleaseTouchId(0); |
| 1384 ASSERT_EQ(1U, captured_events.size()); | 1441 ASSERT_EQ(1U, captured_events.size()); |
| 1385 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); | 1442 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); |
| 1386 ClearCapturedEvents(); | 1443 ClearCapturedEvents(); |
| 1387 generator_->ReleaseTouchId(1); | 1444 generator_->ReleaseTouchId(1); |
| 1388 ASSERT_EQ(0U, captured_events.size()); | 1445 ASSERT_EQ(0U, captured_events.size()); |
| 1389 } | 1446 } |
| 1390 | 1447 |
| 1448 TEST_F(TouchExplorationTest, EnterSlideGestureState) { | |
| 1449 SwitchTouchExplorationMode(true); | |
| 1450 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1451 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1452 | |
| 1453 gfx::Rect window = BoundsOfRootWindowInDIP(); | |
| 1454 float distance = gesture_detector_config_.touch_slop + 1; | |
| 1455 ui::TouchEvent first_press( | |
| 1456 ui::ET_TOUCH_PRESSED, gfx::Point(window.right(), 1), 0, Now()); | |
| 1457 gfx::Point second_location(window.right(), 1 + distance / 2); | |
| 1458 gfx::Point third_location(window.right(), 1 + distance); | |
| 1459 | |
| 1460 generator_->Dispatch(&first_press); | |
| 1461 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 1462 | |
| 1463 // Since we haven't moved past slop yet, we should not be in slide gesture. | |
| 1464 generator_->MoveTouch(second_location); | |
| 1465 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1466 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1467 EXPECT_FALSE(IsInSlideGestureState()); | |
| 1468 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 1469 | |
| 1470 // Once we are out of slop, we should be in slide gesture since we are along | |
| 1471 // the edge of the screen. | |
| 1472 generator_->MoveTouch(third_location); | |
| 1473 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1474 EXPECT_TRUE(IsInSlideGestureState()); | |
| 1475 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1476 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
| 1477 ASSERT_EQ(0U, captured_events.size()); | |
| 1478 | |
| 1479 // Since we are at the right edge of the screen, but the sound timer has not | |
| 1480 // elapsed, there should have two sounds that fired and two volume | |
| 1481 // changes (one for each movement). | |
| 1482 size_t num_adjust_sounds = delegate_.NumAdjustSounds(); | |
| 1483 ASSERT_EQ(2U, num_adjust_sounds); | |
| 1484 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); | |
| 1485 | |
| 1486 // Exit out of slide gesture once touch is lifted, but not before even if the | |
| 1487 // grace period is over. | |
| 1488 | |
| 1489 AdvanceSimulatedTimePastPotentialTapDelay(); | |
| 1490 ASSERT_EQ(0U, captured_events.size()); | |
| 1491 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1492 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1493 EXPECT_TRUE(IsInSlideGestureState()); | |
| 1494 | |
| 1495 generator_->ReleaseTouch(); | |
| 1496 ASSERT_EQ(0U, captured_events.size()); | |
| 1497 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1498 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1499 EXPECT_FALSE(IsInSlideGestureState()); | |
| 1500 } | |
| 1501 | |
| 1502 // If a press + move occurred outside the boundaries, but within the slop | |
| 1503 // boundaries and then moved into the boundaries of an edge, there still should | |
| 1504 // not be a slide gesture. | |
| 1505 TEST_F(TouchExplorationTest, AvoidEnteringSlideGesture) { | |
| 1506 SwitchTouchExplorationMode(true); | |
| 1507 | |
| 1508 gfx::Rect window = BoundsOfRootWindowInDIP(); | |
| 1509 float distance = gesture_detector_config_.touch_slop + 1; | |
| 1510 ui::TouchEvent first_press( | |
| 1511 ui::ET_TOUCH_PRESSED, | |
| 1512 gfx::Point(window.right() - kSlopDistanceFromEdge(), 1), | |
| 1513 0, | |
| 1514 Now()); | |
| 1515 gfx::Point out_of_slop(window.right() - kSlopDistanceFromEdge() + distance, | |
| 1516 1); | |
| 1517 gfx::Point into_boundaries(window.right() - kMaxDistanceFromEdge() / 2, 1); | |
| 1518 | |
| 1519 generator_->Dispatch(&first_press); | |
| 1520 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 1521 | |
| 1522 generator_->MoveTouch(out_of_slop); | |
| 1523 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1524 EXPECT_TRUE(IsInGestureInProgressState()); | |
| 1525 EXPECT_FALSE(IsInSlideGestureState()); | |
| 1526 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 1527 | |
| 1528 // Since we did not start moving while in the boundaries, we should not be in | |
| 1529 // slide gestures. | |
| 1530 generator_->MoveTouch(into_boundaries); | |
| 1531 EXPECT_TRUE(IsInGestureInProgressState()); | |
| 1532 EXPECT_FALSE(IsInSlideGestureState()); | |
| 1533 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1534 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
| 1535 ASSERT_EQ(0U, captured_events.size()); | |
| 1536 | |
| 1537 generator_->ReleaseTouch(); | |
| 1538 } | |
| 1539 | |
| 1540 // If the slide gesture begins within the boundaries and then moves | |
| 1541 // SlopDistanceFromEdge there should still be a sound change. If the finger | |
| 1542 // moves into the center screen, there should no longer be a sound change but it | |
| 1543 // should still be in slide gesture. If the finger moves back into the edges | |
| 1544 // without lifting, it should start changing sound again. | |
| 1545 TEST_F(TouchExplorationTest, TestingBoundaries) { | |
| 1546 SwitchTouchExplorationMode(true); | |
| 1547 | |
| 1548 gfx::Rect window = BoundsOfRootWindowInDIP(); | |
| 1549 gfx::Point initial_press(window.right() - kMaxDistanceFromEdge() / 2, 1); | |
| 1550 ui::TouchEvent first_press( | |
| 1551 ui::ET_TOUCH_PRESSED, | |
| 1552 initial_press, | |
| 1553 0, | |
| 1554 Now()); | |
| 1555 gfx::Point touch_move(initial_press.x() + gesture_detector_config_.touch_slop, | |
| 1556 1); | |
| 1557 gfx::Point into_slop_boundaries(window.right() - kSlopDistanceFromEdge() / 2, | |
| 1558 1); | |
| 1559 gfx::Point center_screen(window.right() / 2, window.bottom() / 2); | |
| 1560 | |
| 1561 generator_->Dispatch(&first_press); | |
| 1562 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 1563 | |
| 1564 generator_->MoveTouch(touch_move); | |
| 1565 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1566 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1567 EXPECT_FALSE(IsInSlideGestureState()); | |
| 1568 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
| 1569 | |
| 1570 // Move the touch into slop boundaries. It should stil be in slide gestures | |
| 1571 // and adjust the volume. | |
| 1572 generator_->MoveTouch(into_slop_boundaries); | |
| 1573 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1574 EXPECT_TRUE(IsInSlideGestureState()); | |
| 1575 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1576 | |
| 1577 // The sound is rate limiting so it only activates every 150ms. | |
| 1578 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); | |
| 1579 | |
| 1580 size_t num_adjust_sounds = delegate_.NumAdjustSounds(); | |
| 1581 ASSERT_EQ(2U, num_adjust_sounds); | |
| 1582 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); | |
| 1583 | |
| 1584 // Move the touch into the center of the window. It should still be in slide | |
| 1585 // gestures, but there should not be anymore volume adjustments. | |
| 1586 generator_->MoveTouch(center_screen); | |
| 1587 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1588 EXPECT_TRUE(IsInSlideGestureState()); | |
| 1589 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1590 | |
| 1591 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); | |
| 1592 num_adjust_sounds = delegate_.NumAdjustSounds(); | |
| 1593 ASSERT_EQ(2U, num_adjust_sounds); | |
| 1594 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); | |
| 1595 | |
| 1596 // Move the touch back into slop edge distance and volume should be changing | |
| 1597 // again. | |
| 1598 generator_->MoveTouch(into_slop_boundaries); | |
| 1599 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1600 EXPECT_TRUE(IsInSlideGestureState()); | |
| 1601 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1602 | |
| 1603 generator_->MoveTouch( | |
| 1604 gfx::Point(into_slop_boundaries.x() + gesture_detector_config_.touch_slop, | |
| 1605 into_slop_boundaries.y())); | |
| 1606 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); | |
| 1607 | |
| 1608 num_adjust_sounds = delegate_.NumAdjustSounds(); | |
| 1609 ASSERT_EQ(3U, num_adjust_sounds); | |
| 1610 ASSERT_EQ(3U, delegate_.VolumeChanges().size()); | |
| 1611 | |
| 1612 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
| 1613 ASSERT_EQ(0U, captured_events.size()); | |
| 1614 | |
| 1615 generator_->ReleaseTouch(); | |
| 1616 } | |
| 1617 | |
| 1618 // Even if the gesture starts within bounds, if it has not moved past slop | |
| 1619 // within the grace period, it should go to touch exploration. | |
| 1620 TEST_F(TouchExplorationTest, InBoundariesTouchExploration) { | |
| 1621 SwitchTouchExplorationMode(true); | |
| 1622 | |
| 1623 gfx::Rect window = BoundsOfRootWindowInDIP(); | |
| 1624 gfx::Point initial_press(window.right() - kMaxDistanceFromEdge() / 2, 1); | |
| 1625 ui::TouchEvent first_press( | |
| 1626 ui::ET_TOUCH_PRESSED, | |
| 1627 initial_press, | |
| 1628 0, | |
| 1629 Now()); | |
| 1630 generator_->Dispatch(&first_press); | |
| 1631 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1632 EXPECT_FALSE(IsInSlideGestureState()); | |
| 1633 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 1634 | |
| 1635 AdvanceSimulatedTimePastTapDelay(); | |
| 1636 EXPECT_FALSE(IsInGestureInProgressState()); | |
| 1637 EXPECT_FALSE(IsInSlideGestureState()); | |
| 1638 EXPECT_TRUE(IsInTouchToMouseMode()); | |
| 1639 } | |
| 1640 | |
| 1391 } // namespace ui | 1641 } // namespace ui |
| OLD | NEW |