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 | |
93 } // namespace | 75 } // namespace |
94 | 76 |
95 class TouchExplorationControllerTestApi { | 77 class TouchExplorationControllerTestApi { |
96 public: | 78 public: |
97 TouchExplorationControllerTestApi( | 79 TouchExplorationControllerTestApi( |
98 TouchExplorationController* touch_exploration_controller) { | 80 TouchExplorationController* touch_exploration_controller) { |
99 touch_exploration_controller_.reset(touch_exploration_controller); | 81 touch_exploration_controller_.reset(touch_exploration_controller); |
100 } | 82 } |
101 | 83 |
102 void CallTapTimerNowForTesting() { | 84 void CallTapTimerNowForTesting() { |
(...skipping 18 matching lines...) Expand all Loading... |
121 bool IsInNoFingersDownStateForTesting() const { | 103 bool IsInNoFingersDownStateForTesting() const { |
122 return touch_exploration_controller_->state_ == | 104 return touch_exploration_controller_->state_ == |
123 touch_exploration_controller_->NO_FINGERS_DOWN; | 105 touch_exploration_controller_->NO_FINGERS_DOWN; |
124 } | 106 } |
125 | 107 |
126 bool IsInGestureInProgressStateForTesting() const { | 108 bool IsInGestureInProgressStateForTesting() const { |
127 return touch_exploration_controller_->state_ == | 109 return touch_exploration_controller_->state_ == |
128 touch_exploration_controller_->GESTURE_IN_PROGRESS; | 110 touch_exploration_controller_->GESTURE_IN_PROGRESS; |
129 } | 111 } |
130 | 112 |
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 | |
140 // VLOGs should be suppressed in tests that generate a lot of logs, | 113 // VLOGs should be suppressed in tests that generate a lot of logs, |
141 // for example permutations of nine touch events. | 114 // for example permutations of nine touch events. |
142 void SuppressVLOGsForTesting(bool suppress) { | 115 void SuppressVLOGsForTesting(bool suppress) { |
143 touch_exploration_controller_->VLOG_on_ = !suppress; | 116 touch_exploration_controller_->VLOG_on_ = !suppress; |
144 } | 117 } |
145 | 118 |
146 float GetMaxDistanceFromEdge() const { | |
147 return touch_exploration_controller_->kMaxDistanceFromEdge; | |
148 } | |
149 | |
150 float GetSlopDistanceFromEdge() const { | |
151 return touch_exploration_controller_->kSlopDistanceFromEdge; | |
152 } | |
153 | |
154 private: | 119 private: |
155 scoped_ptr<TouchExplorationController> touch_exploration_controller_; | 120 scoped_ptr<TouchExplorationController> touch_exploration_controller_; |
156 | 121 |
157 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); | 122 DISALLOW_COPY_AND_ASSIGN(TouchExplorationControllerTestApi); |
158 }; | 123 }; |
159 | 124 |
160 class TouchExplorationTest : public aura::test::AuraTestBase { | 125 class TouchExplorationTest : public aura::test::AuraTestBase { |
161 public: | 126 public: |
162 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { | 127 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { |
163 // Tests fail if time is ever 0. | 128 // Tests fail if time is ever 0. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 205 } |
241 | 206 |
242 void SuppressVLOGs(bool suppress) { | 207 void SuppressVLOGs(bool suppress) { |
243 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); | 208 touch_exploration_controller_->SuppressVLOGsForTesting(suppress); |
244 } | 209 } |
245 | 210 |
246 void SwitchTouchExplorationMode(bool on) { | 211 void SwitchTouchExplorationMode(bool on) { |
247 if (!on && touch_exploration_controller_.get()) { | 212 if (!on && touch_exploration_controller_.get()) { |
248 touch_exploration_controller_.reset(); | 213 touch_exploration_controller_.reset(); |
249 } else if (on && !touch_exploration_controller_.get()) { | 214 } else if (on && !touch_exploration_controller_.get()) { |
250 touch_exploration_controller_.reset( | 215 touch_exploration_controller_.reset(new TouchExplorationControllerTestApi( |
251 new ui::TouchExplorationControllerTestApi( | 216 new ui::TouchExplorationController(root_window()))); |
252 new TouchExplorationController(root_window(), &delegate_))); | |
253 touch_exploration_controller_->SetEventHandlerForTesting( | 217 touch_exploration_controller_->SetEventHandlerForTesting( |
254 &event_capturer_); | 218 &event_capturer_); |
255 cursor_client()->ShowCursor(); | 219 cursor_client()->ShowCursor(); |
256 cursor_client()->DisableMouseEvents(); | 220 cursor_client()->DisableMouseEvents(); |
257 } | 221 } |
258 } | 222 } |
259 | 223 |
260 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { | 224 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { |
261 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); | 225 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); |
262 generator_->Dispatch(&touch_press); | 226 generator_->Dispatch(&touch_press); |
(...skipping 22 matching lines...) Expand all Loading... |
285 | 249 |
286 bool IsInNoFingersDownState() { | 250 bool IsInNoFingersDownState() { |
287 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); | 251 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); |
288 } | 252 } |
289 | 253 |
290 bool IsInGestureInProgressState() { | 254 bool IsInGestureInProgressState() { |
291 return touch_exploration_controller_ | 255 return touch_exploration_controller_ |
292 ->IsInGestureInProgressStateForTesting(); | 256 ->IsInGestureInProgressStateForTesting(); |
293 } | 257 } |
294 | 258 |
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 GetMaxDistanceFromEdge() const{ | |
304 return touch_exploration_controller_->GetMaxDistanceFromEdge(); | |
305 } | |
306 | |
307 float GetSlopDistanceFromEdge() const{ | |
308 return touch_exploration_controller_->GetSlopDistanceFromEdge(); | |
309 } | |
310 | |
311 base::TimeDelta Now() { | 259 base::TimeDelta Now() { |
312 // This is the same as what EventTimeForNow() does, but here we do it | 260 // This is the same as what EventTimeForNow() does, but here we do it |
313 // with our simulated clock. | 261 // with our simulated clock. |
314 return base::TimeDelta::FromInternalValue( | 262 return base::TimeDelta::FromInternalValue( |
315 simulated_clock_->NowTicks().ToInternalValue()); | 263 simulated_clock_->NowTicks().ToInternalValue()); |
316 } | 264 } |
317 | 265 |
318 scoped_ptr<aura::test::EventGenerator> generator_; | 266 scoped_ptr<aura::test::EventGenerator> generator_; |
319 ui::GestureDetector::Config gesture_detector_config_; | 267 ui::GestureDetector::Config gesture_detector_config_; |
320 // Owned by |generator_|. | 268 // Owned by |generator_|. |
321 base::SimpleTestTickClock* simulated_clock_; | 269 base::SimpleTestTickClock* simulated_clock_; |
322 MockTouchExplorationControllerDelegate delegate_; | |
323 | 270 |
324 private: | 271 private: |
325 EventCapturer event_capturer_; | 272 EventCapturer event_capturer_; |
326 scoped_ptr<TouchExplorationControllerTestApi> | 273 scoped_ptr<TouchExplorationControllerTestApi> |
327 touch_exploration_controller_; | 274 touch_exploration_controller_; |
328 scoped_ptr<aura::test::TestCursorClient> cursor_client_; | 275 scoped_ptr<aura::test::TestCursorClient> cursor_client_; |
329 | 276 |
330 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 277 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
331 }; | 278 }; |
332 | 279 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); | 502 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); |
556 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); | 503 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); |
557 EXPECT_TRUE(IsInNoFingersDownState()); | 504 EXPECT_TRUE(IsInNoFingersDownState()); |
558 } | 505 } |
559 | 506 |
560 // If an event is received after the double-tap timeout has elapsed, but | 507 // If an event is received after the double-tap timeout has elapsed, but |
561 // before the timer has fired, a mouse move should still be generated. | 508 // before the timer has fired, a mouse move should still be generated. |
562 TEST_F(TouchExplorationTest, TimerFiresLateDuringTouchExploration) { | 509 TEST_F(TouchExplorationTest, TimerFiresLateDuringTouchExploration) { |
563 SwitchTouchExplorationMode(true); | 510 SwitchTouchExplorationMode(true); |
564 | 511 |
565 // Make sure the touch is not in a corner of the screen. | |
566 generator_->MoveTouch(gfx::Point(100, 200)); | |
567 | |
568 // Send a press, then add another finger after the double-tap timeout. | 512 // Send a press, then add another finger after the double-tap timeout. |
569 generator_->PressTouchId(1); | 513 generator_->PressTouchId(1); |
570 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); | 514 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(1000)); |
571 generator_->PressTouchId(2); | 515 generator_->PressTouchId(2); |
572 std::vector<ui::LocatedEvent*> events = | 516 std::vector<ui::LocatedEvent*> events = |
573 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); | 517 GetCapturedLocatedEventsOfType(ui::ET_MOUSE_MOVED); |
574 ASSERT_EQ(1U, events.size()); | 518 ASSERT_EQ(1U, events.size()); |
575 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | 519 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); |
576 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | 520 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); |
577 | 521 |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 } | 1350 } |
1407 | 1351 |
1408 // With the simple swipe gestures, if additional fingers are added, then the | 1352 // With the simple swipe gestures, if additional fingers are added, then the |
1409 // state should change to passthrough. | 1353 // state should change to passthrough. |
1410 TEST_F(TouchExplorationTest, FromGestureToPassthrough) { | 1354 TEST_F(TouchExplorationTest, FromGestureToPassthrough) { |
1411 SwitchTouchExplorationMode(true); | 1355 SwitchTouchExplorationMode(true); |
1412 EXPECT_FALSE(IsInTouchToMouseMode()); | 1356 EXPECT_FALSE(IsInTouchToMouseMode()); |
1413 EXPECT_FALSE(IsInGestureInProgressState()); | 1357 EXPECT_FALSE(IsInGestureInProgressState()); |
1414 | 1358 |
1415 float distance = gesture_detector_config_.touch_slop + 1; | 1359 float distance = gesture_detector_config_.touch_slop + 1; |
1416 ui::TouchEvent first_press( | 1360 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 1), 0, Now()); |
1417 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 0, Now()); | |
1418 generator_->Dispatch(&first_press); | 1361 generator_->Dispatch(&first_press); |
1419 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 1362 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
1420 gfx::Point second_location(100 + distance, 200); | 1363 gfx::Point second_location(distance, 1); |
1421 generator_->MoveTouch(second_location); | 1364 generator_->MoveTouch(second_location); |
1422 EXPECT_TRUE(IsInGestureInProgressState()); | 1365 EXPECT_TRUE(IsInGestureInProgressState()); |
1423 EXPECT_FALSE(IsInTouchToMouseMode()); | 1366 EXPECT_FALSE(IsInTouchToMouseMode()); |
1424 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | 1367 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
1425 ASSERT_EQ(0U, captured_events.size()); | 1368 ASSERT_EQ(0U, captured_events.size()); |
1426 | 1369 |
1427 // Generate a second press that should go through as is. | 1370 // Generate a second press that should go through as is. |
1428 ui::TouchEvent second_press( | 1371 ui::TouchEvent second_press( |
1429 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now()); | 1372 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now()); |
1430 generator_->Dispatch(&second_press); | 1373 generator_->Dispatch(&second_press); |
1431 EXPECT_FALSE(IsInGestureInProgressState()); | 1374 EXPECT_FALSE(IsInGestureInProgressState()); |
1432 EXPECT_FALSE(IsInTouchToMouseMode()); | 1375 EXPECT_FALSE(IsInTouchToMouseMode()); |
1433 std::vector<ui::LocatedEvent*> captured_located_events = | 1376 std::vector<ui::LocatedEvent*> captured_located_events = |
1434 GetCapturedLocatedEvents(); | 1377 GetCapturedLocatedEvents(); |
1435 ASSERT_EQ(1U, captured_events.size()); | 1378 ASSERT_EQ(1U, captured_events.size()); |
1436 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_located_events[0], &second_press); | 1379 CONFIRM_EVENTS_ARE_TOUCH_AND_EQUAL(captured_located_events[0], &second_press); |
1437 ClearCapturedEvents(); | 1380 ClearCapturedEvents(); |
1438 | 1381 |
1439 // The rest of the events should occur in passthrough. | 1382 // The rest of the events should occur in passthrough. |
1440 generator_->ReleaseTouchId(0); | 1383 generator_->ReleaseTouchId(0); |
1441 ASSERT_EQ(1U, captured_events.size()); | 1384 ASSERT_EQ(1U, captured_events.size()); |
1442 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); | 1385 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); |
1443 ClearCapturedEvents(); | 1386 ClearCapturedEvents(); |
1444 generator_->ReleaseTouchId(1); | 1387 generator_->ReleaseTouchId(1); |
1445 ASSERT_EQ(0U, captured_events.size()); | 1388 ASSERT_EQ(0U, captured_events.size()); |
1446 } | 1389 } |
1447 | 1390 |
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() - GetSlopDistanceFromEdge(), 1), | |
1513 0, | |
1514 Now()); | |
1515 gfx::Point out_of_slop(window.right() - GetSlopDistanceFromEdge() + distance, | |
1516 1); | |
1517 gfx::Point into_boundaries(window.right() - GetMaxDistanceFromEdge() / 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() - GetMaxDistanceFromEdge() / 2, 1); | |
1550 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, initial_press, 0, Now()); | |
1551 gfx::Point touch_move(initial_press.x() + gesture_detector_config_.touch_slop, | |
1552 1); | |
1553 gfx::Point into_slop_boundaries( | |
1554 window.right() - GetSlopDistanceFromEdge() / 2, 1); | |
1555 gfx::Point center_screen(window.right() / 2, window.bottom() / 2); | |
1556 | |
1557 generator_->Dispatch(&first_press); | |
1558 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
1559 | |
1560 generator_->MoveTouch(touch_move); | |
1561 EXPECT_FALSE(IsInTouchToMouseMode()); | |
1562 EXPECT_FALSE(IsInGestureInProgressState()); | |
1563 EXPECT_FALSE(IsInSlideGestureState()); | |
1564 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | |
1565 | |
1566 // Move the touch into slop boundaries. It should stil be in slide gestures | |
1567 // and adjust the volume. | |
1568 generator_->MoveTouch(into_slop_boundaries); | |
1569 EXPECT_FALSE(IsInGestureInProgressState()); | |
1570 EXPECT_TRUE(IsInSlideGestureState()); | |
1571 EXPECT_FALSE(IsInTouchToMouseMode()); | |
1572 | |
1573 // The sound is rate limiting so it only activates every 150ms. | |
1574 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); | |
1575 | |
1576 size_t num_adjust_sounds = delegate_.NumAdjustSounds(); | |
1577 ASSERT_EQ(2U, num_adjust_sounds); | |
1578 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); | |
1579 | |
1580 // Move the touch into the center of the window. It should still be in slide | |
1581 // gestures, but there should not be anymore volume adjustments. | |
1582 generator_->MoveTouch(center_screen); | |
1583 EXPECT_FALSE(IsInGestureInProgressState()); | |
1584 EXPECT_TRUE(IsInSlideGestureState()); | |
1585 EXPECT_FALSE(IsInTouchToMouseMode()); | |
1586 | |
1587 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); | |
1588 num_adjust_sounds = delegate_.NumAdjustSounds(); | |
1589 ASSERT_EQ(2U, num_adjust_sounds); | |
1590 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); | |
1591 | |
1592 // Move the touch back into slop edge distance and volume should be changing | |
1593 // again. | |
1594 generator_->MoveTouch(into_slop_boundaries); | |
1595 EXPECT_FALSE(IsInGestureInProgressState()); | |
1596 EXPECT_TRUE(IsInSlideGestureState()); | |
1597 EXPECT_FALSE(IsInTouchToMouseMode()); | |
1598 | |
1599 generator_->MoveTouch( | |
1600 gfx::Point(into_slop_boundaries.x() + gesture_detector_config_.touch_slop, | |
1601 into_slop_boundaries.y())); | |
1602 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); | |
1603 | |
1604 num_adjust_sounds = delegate_.NumAdjustSounds(); | |
1605 ASSERT_EQ(3U, num_adjust_sounds); | |
1606 ASSERT_EQ(3U, delegate_.VolumeChanges().size()); | |
1607 | |
1608 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | |
1609 ASSERT_EQ(0U, captured_events.size()); | |
1610 | |
1611 generator_->ReleaseTouch(); | |
1612 } | |
1613 | |
1614 // Even if the gesture starts within bounds, if it has not moved past slop | |
1615 // within the grace period, it should go to touch exploration. | |
1616 TEST_F(TouchExplorationTest, InBoundariesTouchExploration) { | |
1617 SwitchTouchExplorationMode(true); | |
1618 | |
1619 gfx::Rect window = BoundsOfRootWindowInDIP(); | |
1620 gfx::Point initial_press(window.right() - GetMaxDistanceFromEdge() / 2, 1); | |
1621 ui::TouchEvent first_press( | |
1622 ui::ET_TOUCH_PRESSED, | |
1623 initial_press, | |
1624 0, | |
1625 Now()); | |
1626 generator_->Dispatch(&first_press); | |
1627 EXPECT_FALSE(IsInGestureInProgressState()); | |
1628 EXPECT_FALSE(IsInSlideGestureState()); | |
1629 EXPECT_FALSE(IsInTouchToMouseMode()); | |
1630 | |
1631 AdvanceSimulatedTimePastTapDelay(); | |
1632 EXPECT_FALSE(IsInGestureInProgressState()); | |
1633 EXPECT_FALSE(IsInSlideGestureState()); | |
1634 EXPECT_TRUE(IsInTouchToMouseMode()); | |
1635 } | |
1636 | |
1637 } // namespace ui | 1391 } // namespace ui |
OLD | NEW |