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

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

Issue 429633002: Added multi-finger gestures to touch_exploration_controller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@passthrough
Patch Set: updated swipe gesture code, added test Created 6 years, 4 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 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 // gesture is completed, enter touch exploration. 1109 // gesture is completed, enter touch exploration.
1110 TEST_F(TouchExplorationTest, EnterGestureInProgressState) { 1110 TEST_F(TouchExplorationTest, EnterGestureInProgressState) {
1111 SwitchTouchExplorationMode(true); 1111 SwitchTouchExplorationMode(true);
1112 EXPECT_FALSE(IsInTouchToMouseMode()); 1112 EXPECT_FALSE(IsInTouchToMouseMode());
1113 EXPECT_FALSE(IsInGestureInProgressState()); 1113 EXPECT_FALSE(IsInGestureInProgressState());
1114 1114
1115 float distance = gesture_detector_config_.touch_slop + 1; 1115 float distance = gesture_detector_config_.touch_slop + 1;
1116 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 1), 0, Now()); 1116 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 1), 0, Now());
1117 gfx::Point second_location(distance / 2, 1); 1117 gfx::Point second_location(distance / 2, 1);
1118 gfx::Point third_location(distance, 1); 1118 gfx::Point third_location(distance, 1);
1119 gfx::Point touch_exploration_location(20, 21);
1119 1120
1120 generator_->Dispatch(&first_press); 1121 generator_->Dispatch(&first_press);
1121 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1122 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1122 // Since we are not out of the touch slop yet, we should not be in gesture in 1123 // Since we are not out of the touch slop yet, we should not be in gesture in
1123 // progress. 1124 // progress.
1124 generator_->MoveTouch(second_location); 1125 generator_->MoveTouch(second_location);
1125 EXPECT_FALSE(IsInTouchToMouseMode()); 1126 EXPECT_FALSE(IsInTouchToMouseMode());
1126 EXPECT_FALSE(IsInGestureInProgressState()); 1127 EXPECT_FALSE(IsInGestureInProgressState());
1127 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1128 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1128 1129
1129 // Once we are out of slop, we should be in GestureInProgress. 1130 // Once we are out of slop, we should be in GestureInProgress.
1130 generator_->MoveTouch(third_location); 1131 generator_->MoveTouch(third_location);
1131 EXPECT_TRUE(IsInGestureInProgressState()); 1132 EXPECT_TRUE(IsInGestureInProgressState());
1132 EXPECT_FALSE(IsInTouchToMouseMode()); 1133 EXPECT_FALSE(IsInTouchToMouseMode());
1133 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1134 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1134 ASSERT_EQ(0U, captured_events.size()); 1135 ASSERT_EQ(0U, captured_events.size());
1135 1136
1136 // Exit out of gesture mode once grace period is over and enter touch 1137 // Exit out of gesture mode once grace period is over and enter touch
1137 // exploration. 1138 // exploration.
1138 AdvanceSimulatedTimePastTapDelay(); 1139 AdvanceSimulatedTimePastTapDelay();
1140 generator_->MoveTouch(touch_exploration_location);
1139 ASSERT_EQ(1U, captured_events.size()); 1141 ASSERT_EQ(1U, captured_events.size());
1140 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); 1142 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type());
1141 EXPECT_TRUE(IsInTouchToMouseMode()); 1143 EXPECT_TRUE(IsInTouchToMouseMode());
1142 EXPECT_FALSE(IsInGestureInProgressState()); 1144 EXPECT_FALSE(IsInGestureInProgressState());
1143 } 1145 }
1144 1146
1145 // A swipe+direction gesture should trigger a Shift+Search+Direction 1147 // A swipe+direction gesture should trigger a Shift+Search+Direction
1146 // keyboard event. 1148 // keyboard event.
1147 TEST_F(TouchExplorationTest, GestureSwipe) { 1149 TEST_F(TouchExplorationTest, GestureSwipe) {
1148 SwitchTouchExplorationMode(true); 1150 SwitchTouchExplorationMode(true);
1149 std::vector<ui::KeyboardCode> directions; 1151 std::vector<ui::KeyboardCode> directions;
1150 directions.push_back(ui::VKEY_RIGHT); 1152 directions.push_back(ui::VKEY_RIGHT);
1151 directions.push_back(ui::VKEY_LEFT); 1153 directions.push_back(ui::VKEY_LEFT);
1152 directions.push_back(ui::VKEY_UP); 1154 directions.push_back(ui::VKEY_UP);
1153 directions.push_back(ui::VKEY_DOWN); 1155 directions.push_back(ui::VKEY_DOWN);
1154 1156
1155 for (std::vector<ui::KeyboardCode>::const_iterator it = directions.begin(); 1157 // This value was taken from gesture_recognizer_unittest.cc in a swipe
1156 it != directions.end(); 1158 // detector test, since it seems to be about the right amount to get a swipe.
1157 ++it) { 1159 const int kSteps = 15;
1158 int x = 30;
1159 int y = 31;
1160 ui::TouchEvent origin(ui::ET_TOUCH_PRESSED, gfx::Point(x, y), 0, Now());
1161 generator_->Dispatch(&origin);
1162 1160
1163 ui::KeyboardCode direction = *it; 1161 // There are gestures supported with up to four fingers.
1164 float distance = gesture_detector_config_.touch_slop + 1; 1162 for (int num_fingers = 1; num_fingers <= 4; num_fingers++) {
1165 scoped_ptr<gfx::Point> swipe; 1163 std::vector<gfx::Point> start_points;
1166 switch (direction) { 1164 for(int j = 0; j < num_fingers; j++){
1167 case ui::VKEY_RIGHT: 1165 start_points.push_back(gfx::Point(j * 10 + 5, j * 10 + 6));
1168 swipe.reset(new gfx::Point(x + distance, y));
1169 break;
1170 case ui::VKEY_LEFT:
1171 swipe.reset(new gfx::Point(x - distance, y));
1172 break;
1173 case ui::VKEY_UP:
1174 swipe.reset(new gfx::Point(x, y - distance));
1175 break;
1176 case ui::VKEY_DOWN:
1177 swipe.reset(new gfx::Point(x, y + distance));
1178 break;
1179 default:
1180 return;
1181 } 1166 }
1167 gfx::Point* start_points_array = &start_points[0];
1168 const float distance = gesture_detector_config_.touch_slop + 1;
1169 // Iterate through each swipe direction for this number of fingers.
1170 for (std::vector<ui::KeyboardCode>::const_iterator it = directions.begin();
1171 it != directions.end();
1172 ++it) {
1173 int move_x = 0;
1174 int move_y = 0;
1175 ui::KeyboardCode direction = *it;
1176 switch (direction) {
1177 case ui::VKEY_RIGHT:
1178 move_x = distance;
1179 break;
1180 case ui::VKEY_LEFT:
1181 move_x = 0 - distance;
1182 break;
1183 case ui::VKEY_UP:
1184 move_y = 0 - distance;
1185 break;
1186 case ui::VKEY_DOWN:
1187 move_y = distance;
1188 break;
1189 default:
1190 return;
1191 }
1182 1192
1183 // A swipe is made when a fling starts 1193 // A swipe is made when a fling starts
1184 float delta_time = 1194 float delta_time =
1185 distance / gesture_detector_config_.maximum_fling_velocity; 1195 distance / gesture_detector_config_.maximum_fling_velocity;
1186 simulated_clock_->Advance(base::TimeDelta::FromSecondsD(delta_time)); 1196 // delta_time is in seconds, so we convert to ms.
1187 generator_->MoveTouch(*swipe); 1197 int delta_time_ms = floor(delta_time * 1000);
1188 EXPECT_TRUE(IsInGestureInProgressState()); 1198 VLOG(0) << "delta time is: " << delta_time_ms;
aboxhall 2014/08/04 23:58:09 logspam?
evy 2014/08/05 00:14:40 Done.
1189 EXPECT_FALSE(IsInTouchToMouseMode()); 1199 generator_->GestureMultiFingerScroll(num_fingers,
1190 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1200 start_points_array,
1191 ASSERT_EQ(0U, captured_events.size()); 1201 delta_time_ms,
1192 generator_->ReleaseTouch(); 1202 kSteps,
1203 move_x * 2,
1204 move_y * 2);
1193 1205
1194 // The swipe registered and sent the appropriate key events. 1206 // The swipe registered and sent the appropriate key events.
1195 AssertDirectionalNavigationEvents(captured_events, direction); 1207 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1196 EXPECT_TRUE(IsInNoFingersDownState()); 1208 if (num_fingers == 1)
1197 EXPECT_FALSE(IsInTouchToMouseMode()); 1209 AssertDirectionalNavigationEvents(captured_events, direction);
1198 EXPECT_FALSE(IsInGestureInProgressState()); 1210 else {
1199 ClearCapturedEvents(); 1211 // Most of the time this is 2 right now, but two of the two finger//
aboxhall 2014/08/04 23:58:09 nit: trailing //
evy 2014/08/05 00:14:40 Done.
1212 // swipes are mapped to chromevox commands which dispatch 6 key events,
1213 // and these will probably be remapped a lot as we're developing.
1214 ASSERT_GE(captured_events.size(), 2U);
1215 std::vector<ui::Event>::size_type i;
1216 for (i = 0; i != captured_events.size(); i++) {
1217 EXPECT_TRUE(captured_events[i]->IsKeyEvent());
1218 }
1219 }
1220 EXPECT_TRUE(IsInNoFingersDownState());
1221 EXPECT_FALSE(IsInTouchToMouseMode());
1222 EXPECT_FALSE(IsInGestureInProgressState());
1223 ClearCapturedEvents();
1224 }
1200 } 1225 }
1201 } 1226 }
1202 1227
1203 // Since there are so many permutations, this test is too slow in debug 1228 // Since there are so many permutations, this test is too slow in debug
1204 // mode, so it will only be run in release mode. 1229 // mode, so it will only be run in release mode.
1205 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 1230 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1206 #define MAYBE_AllFingerPermutations AllFingerPermutations 1231 #define MAYBE_AllFingerPermutations AllFingerPermutations
1207 #else 1232 #else
1208 #define MAYBE_AllFingerPermutations DISABLED_AllFingerPermutations 1233 #define MAYBE_AllFingerPermutations DISABLED_AllFingerPermutations
1209 #endif 1234 #endif
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 generator_->ReleaseTouchId(j); 1335 generator_->ReleaseTouchId(j);
1311 fingers_pressed[j] = false; 1336 fingers_pressed[j] = false;
1312 } 1337 }
1313 } 1338 }
1314 AdvanceSimulatedTimePastPotentialTapDelay(); 1339 AdvanceSimulatedTimePastPotentialTapDelay();
1315 EXPECT_TRUE(IsInNoFingersDownState()); 1340 EXPECT_TRUE(IsInNoFingersDownState());
1316 ClearCapturedEvents(); 1341 ClearCapturedEvents();
1317 } 1342 }
1318 } 1343 }
1319 1344
1320 // With the simple swipe gestures, if additional fingers are added, then the 1345 // With the simple swipe gestures, if additional fingers are added and the tap
1321 // state should change to the wait for one finger state. 1346 // timer times out, then the state should change to the wait for one finger
1347 // state.
1322 TEST_F(TouchExplorationTest, GestureAddedFinger) { 1348 TEST_F(TouchExplorationTest, GestureAddedFinger) {
1323 SwitchTouchExplorationMode(true); 1349 SwitchTouchExplorationMode(true);
1324 EXPECT_FALSE(IsInTouchToMouseMode()); 1350 EXPECT_FALSE(IsInTouchToMouseMode());
1325 EXPECT_FALSE(IsInGestureInProgressState()); 1351 EXPECT_FALSE(IsInGestureInProgressState());
1326 1352
1327 float distance = gesture_detector_config_.touch_slop + 1; 1353 float distance = gesture_detector_config_.touch_slop + 1;
1328 ui::TouchEvent first_press( 1354 ui::TouchEvent first_press(
1329 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 0, Now()); 1355 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 0, Now());
1330 generator_->Dispatch(&first_press); 1356 generator_->Dispatch(&first_press);
1331 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1357 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1332 gfx::Point second_location(100 + distance, 200); 1358 gfx::Point second_location(100 + distance, 200);
1333 generator_->MoveTouch(second_location); 1359 generator_->MoveTouch(second_location);
1334 EXPECT_TRUE(IsInGestureInProgressState()); 1360 EXPECT_TRUE(IsInGestureInProgressState());
1335 EXPECT_FALSE(IsInTouchToMouseMode()); 1361 EXPECT_FALSE(IsInTouchToMouseMode());
1336 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1362 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1337 ASSERT_EQ(0U, captured_events.size()); 1363 ASSERT_EQ(0U, captured_events.size());
1338 1364
1339 // Generate a second press that should prevent gestures from continuing to 1365 // Generate a second press, but time out past the gesture period so that
1340 // go through. 1366 // gestures are prevented from continuing to go through.
1341 ui::TouchEvent second_press( 1367 ui::TouchEvent second_press(
1342 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now()); 1368 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now());
1343 generator_->Dispatch(&second_press); 1369 generator_->Dispatch(&second_press);
1370 AdvanceSimulatedTimePastTapDelay();
1344 EXPECT_FALSE(IsInGestureInProgressState()); 1371 EXPECT_FALSE(IsInGestureInProgressState());
1345 EXPECT_FALSE(IsInTouchToMouseMode()); 1372 EXPECT_FALSE(IsInTouchToMouseMode());
1346 ASSERT_EQ(0U, captured_events.size()); 1373 ASSERT_EQ(0U, captured_events.size());
1347 } 1374 }
1348 1375
1349 TEST_F(TouchExplorationTest, EnterSlideGestureState) { 1376 TEST_F(TouchExplorationTest, EnterSlideGestureState) {
1350 SwitchTouchExplorationMode(true); 1377 SwitchTouchExplorationMode(true);
1351 EXPECT_FALSE(IsInTouchToMouseMode()); 1378 EXPECT_FALSE(IsInTouchToMouseMode());
1352 EXPECT_FALSE(IsInGestureInProgressState()); 1379 EXPECT_FALSE(IsInGestureInProgressState());
1353 1380
1354 int window_right = BoundsOfRootWindowInDIP().right(); 1381 int window_right = BoundsOfRootWindowInDIP().right();
1355 float distance = gesture_detector_config_.touch_slop + 1; 1382 float distance = gesture_detector_config_.touch_slop + 1;
1356 ui::TouchEvent first_press( 1383 ui::TouchEvent first_press(
1357 ui::ET_TOUCH_PRESSED, gfx::Point(window_right, 1), 0, Now()); 1384 ui::ET_TOUCH_PRESSED, gfx::Point(window_right, 1), 0, Now());
1358 gfx::Point second_location(window_right, 1 + distance / 2); 1385 gfx::Point second_location(window_right, 1 + distance / 2);
1359 gfx::Point third_location(window_right, 1 + distance); 1386 gfx::Point third_location(window_right, 1 + distance);
1387 gfx::Point fourth_location(window_right, 35);
1360 1388
1361 generator_->Dispatch(&first_press); 1389 generator_->Dispatch(&first_press);
1362 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1390 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1363 1391
1364 // Since we haven't moved past slop yet, we should not be in slide gesture. 1392 // Since we haven't moved past slop yet, we should not be in slide gesture.
1365 generator_->MoveTouch(second_location); 1393 generator_->MoveTouch(second_location);
1366 EXPECT_FALSE(IsInTouchToMouseMode()); 1394 EXPECT_FALSE(IsInTouchToMouseMode());
1367 EXPECT_FALSE(IsInGestureInProgressState()); 1395 EXPECT_FALSE(IsInGestureInProgressState());
1368 EXPECT_FALSE(IsInSlideGestureState()); 1396 EXPECT_FALSE(IsInSlideGestureState());
1369 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1397 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1370 1398
1371 // Once we are out of slop, we should be in slide gesture since we are along 1399 // Once we are out of slop, we should be in slide gesture since we are along
1372 // the edge of the screen. 1400 // the edge of the screen.
1373 generator_->MoveTouch(third_location); 1401 generator_->MoveTouch(third_location);
1374 EXPECT_FALSE(IsInGestureInProgressState()); 1402 EXPECT_FALSE(IsInGestureInProgressState());
1375 EXPECT_TRUE(IsInSlideGestureState()); 1403 EXPECT_TRUE(IsInSlideGestureState());
1376 EXPECT_FALSE(IsInTouchToMouseMode()); 1404 EXPECT_FALSE(IsInTouchToMouseMode());
1405
1406 // Now that we are in slide gesture, we can adjust the volume.
1407 generator_->MoveTouch(fourth_location);
1377 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1408 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1378 ASSERT_EQ(0U, captured_events.size()); 1409 ASSERT_EQ(0U, captured_events.size());
1379 1410
1380 // Since we are at the right edge of the screen, but the sound timer has not 1411 // Since we are at the right edge of the screen, but the sound timer has not
1381 // elapsed, there should have two sounds that fired and two volume 1412 // elapsed, there should have been a sound that fired and a volume
1382 // changes (one for each movement). 1413 // change.
1383 size_t num_adjust_sounds = delegate_.NumAdjustSounds(); 1414 size_t num_adjust_sounds = delegate_.NumAdjustSounds();
1384 ASSERT_EQ(2U, num_adjust_sounds); 1415 ASSERT_EQ(1U, num_adjust_sounds);
1385 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); 1416 ASSERT_EQ(1U, delegate_.VolumeChanges().size());
1386 1417
1387 // Exit out of slide gesture once touch is lifted, but not before even if the 1418 // Exit out of slide gesture once touch is lifted, but not before even if the
1388 // grace period is over. 1419 // grace period is over.
1389
1390 AdvanceSimulatedTimePastPotentialTapDelay(); 1420 AdvanceSimulatedTimePastPotentialTapDelay();
1391 ASSERT_EQ(0U, captured_events.size()); 1421 ASSERT_EQ(0U, captured_events.size());
1392 EXPECT_FALSE(IsInTouchToMouseMode()); 1422 EXPECT_FALSE(IsInTouchToMouseMode());
1393 EXPECT_FALSE(IsInGestureInProgressState()); 1423 EXPECT_FALSE(IsInGestureInProgressState());
1394 EXPECT_TRUE(IsInSlideGestureState()); 1424 EXPECT_TRUE(IsInSlideGestureState());
1395 1425
1396 generator_->ReleaseTouch(); 1426 generator_->ReleaseTouch();
1397 ASSERT_EQ(0U, captured_events.size()); 1427 ASSERT_EQ(0U, captured_events.size());
1398 EXPECT_FALSE(IsInTouchToMouseMode()); 1428 EXPECT_FALSE(IsInTouchToMouseMode());
1399 EXPECT_FALSE(IsInGestureInProgressState()); 1429 EXPECT_FALSE(IsInGestureInProgressState());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 // If the slide gesture begins within the boundaries and then moves 1471 // If the slide gesture begins within the boundaries and then moves
1442 // SlopDistanceFromEdge there should still be a sound change. If the finger 1472 // SlopDistanceFromEdge there should still be a sound change. If the finger
1443 // moves into the center screen, there should no longer be a sound change but it 1473 // moves into the center screen, there should no longer be a sound change but it
1444 // should still be in slide gesture. If the finger moves back into the edges 1474 // should still be in slide gesture. If the finger moves back into the edges
1445 // without lifting, it should start changing sound again. 1475 // without lifting, it should start changing sound again.
1446 TEST_F(TouchExplorationTest, TestingBoundaries) { 1476 TEST_F(TouchExplorationTest, TestingBoundaries) {
1447 SwitchTouchExplorationMode(true); 1477 SwitchTouchExplorationMode(true);
1448 1478
1449 gfx::Rect window = BoundsOfRootWindowInDIP(); 1479 gfx::Rect window = BoundsOfRootWindowInDIP();
1450 gfx::Point initial_press(window.right() - GetMaxDistanceFromEdge() / 2, 1); 1480 gfx::Point initial_press(window.right() - GetMaxDistanceFromEdge() / 2, 1);
1481
1482 gfx::Point center_screen(window.right() / 2, window.bottom() / 2);
1483
1451 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, initial_press, 0, Now()); 1484 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, initial_press, 0, Now());
1452 gfx::Point touch_move(initial_press.x() + gesture_detector_config_.touch_slop, 1485 generator_->Dispatch(&first_press);
1453 1); 1486 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1487 EXPECT_FALSE(IsInGestureInProgressState());
1488 EXPECT_FALSE(IsInSlideGestureState());
1489 EXPECT_FALSE(IsInTouchToMouseMode());
1490
1491 // Move past the touch slop to begin slide gestures.
1492 // + slop + 1 to actually leave slop.
1493 gfx::Point touch_move(
1494 initial_press.x() + gesture_detector_config_.touch_slop + 1, 1);
aboxhall 2014/08/04 23:58:09 I'm confused by this - this looks like it would mo
evy 2014/08/05 00:14:40 You're right, this should be in the y direction.
1495 generator_->MoveTouch(touch_move);
1496 EXPECT_FALSE(IsInGestureInProgressState());
1497 EXPECT_TRUE(IsInSlideGestureState());
1498 EXPECT_FALSE(IsInTouchToMouseMode());
1499 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1500
1501 // Move the touch into slop boundaries. It should still be in slide gestures
1502 // and adjust the volume.
1454 gfx::Point into_slop_boundaries( 1503 gfx::Point into_slop_boundaries(
1455 window.right() - GetSlopDistanceFromEdge() / 2, 1); 1504 window.right() - GetSlopDistanceFromEdge() / 2, 1);
1456 gfx::Point center_screen(window.right() / 2, window.bottom() / 2);
1457
1458 generator_->Dispatch(&first_press);
1459 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1460
1461 generator_->MoveTouch(touch_move);
1462 EXPECT_FALSE(IsInTouchToMouseMode());
1463 EXPECT_FALSE(IsInGestureInProgressState());
1464 EXPECT_FALSE(IsInSlideGestureState());
1465 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1466
1467 // Move the touch into slop boundaries. It should stil be in slide gestures
1468 // and adjust the volume.
1469 generator_->MoveTouch(into_slop_boundaries); 1505 generator_->MoveTouch(into_slop_boundaries);
1470 EXPECT_FALSE(IsInGestureInProgressState()); 1506 EXPECT_FALSE(IsInGestureInProgressState());
1471 EXPECT_TRUE(IsInSlideGestureState()); 1507 EXPECT_TRUE(IsInSlideGestureState());
1472 EXPECT_FALSE(IsInTouchToMouseMode()); 1508 EXPECT_FALSE(IsInTouchToMouseMode());
1473 1509
1474 // The sound is rate limiting so it only activates every 150ms. 1510 // The sound is rate limiting so it only activates every 150ms.
1475 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); 1511 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200));
1476 1512
1477 size_t num_adjust_sounds = delegate_.NumAdjustSounds(); 1513 size_t num_adjust_sounds = delegate_.NumAdjustSounds();
1478 ASSERT_EQ(2U, num_adjust_sounds); 1514 ASSERT_EQ(1U, num_adjust_sounds);
1479 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); 1515 ASSERT_EQ(1U, delegate_.VolumeChanges().size());
1480 1516
1481 // Move the touch into the center of the window. It should still be in slide 1517 // Move the touch into the center of the window. It should still be in slide
1482 // gestures, but there should not be anymore volume adjustments. 1518 // gestures, but there should not be anymore volume adjustments.
1483 generator_->MoveTouch(center_screen); 1519 generator_->MoveTouch(center_screen);
1484 EXPECT_FALSE(IsInGestureInProgressState()); 1520 EXPECT_FALSE(IsInGestureInProgressState());
1485 EXPECT_TRUE(IsInSlideGestureState()); 1521 EXPECT_TRUE(IsInSlideGestureState());
1486 EXPECT_FALSE(IsInTouchToMouseMode()); 1522 EXPECT_FALSE(IsInTouchToMouseMode());
1487 1523
1488 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); 1524 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200));
1489 num_adjust_sounds = delegate_.NumAdjustSounds(); 1525 num_adjust_sounds = delegate_.NumAdjustSounds();
1490 ASSERT_EQ(2U, num_adjust_sounds); 1526 ASSERT_EQ(1U, num_adjust_sounds);
1491 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); 1527 ASSERT_EQ(1U, delegate_.VolumeChanges().size());
1492 1528
1493 // Move the touch back into slop edge distance and volume should be changing 1529 // Move the touch back into slop edge distance and volume should be changing
1494 // again. 1530 // again, one volume change for each new move.
1495 generator_->MoveTouch(into_slop_boundaries); 1531 generator_->MoveTouch(into_slop_boundaries);
1496 EXPECT_FALSE(IsInGestureInProgressState()); 1532 EXPECT_FALSE(IsInGestureInProgressState());
1497 EXPECT_TRUE(IsInSlideGestureState()); 1533 EXPECT_TRUE(IsInSlideGestureState());
1498 EXPECT_FALSE(IsInTouchToMouseMode()); 1534 EXPECT_FALSE(IsInTouchToMouseMode());
1499 1535
1500 generator_->MoveTouch( 1536 generator_->MoveTouch(
1501 gfx::Point(into_slop_boundaries.x() + gesture_detector_config_.touch_slop, 1537 gfx::Point(into_slop_boundaries.x() + gesture_detector_config_.touch_slop,
1502 into_slop_boundaries.y())); 1538 into_slop_boundaries.y()));
1503 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); 1539 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200));
1504 1540
1505 num_adjust_sounds = delegate_.NumAdjustSounds(); 1541 num_adjust_sounds = delegate_.NumAdjustSounds();
1506 ASSERT_EQ(3U, num_adjust_sounds); 1542 ASSERT_EQ(2U, num_adjust_sounds);
1507 ASSERT_EQ(3U, delegate_.VolumeChanges().size()); 1543 ASSERT_EQ(3U, delegate_.VolumeChanges().size());
1508 1544
1509 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1545 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1510 ASSERT_EQ(0U, captured_events.size()); 1546 ASSERT_EQ(0U, captured_events.size());
1511 1547
1512 generator_->ReleaseTouch(); 1548 generator_->ReleaseTouch();
1513 } 1549 }
1514 1550
1515 // Even if the gesture starts within bounds, if it has not moved past slop 1551 // Even if the gesture starts within bounds, if it has not moved past slop
1516 // within the grace period, it should go to touch exploration. 1552 // within the grace period, it should go to touch exploration.
1517 TEST_F(TouchExplorationTest, InBoundariesTouchExploration) { 1553 TEST_F(TouchExplorationTest, InBoundariesTouchExploration) {
1518 SwitchTouchExplorationMode(true); 1554 SwitchTouchExplorationMode(true);
1519 1555
1520 gfx::Rect window = BoundsOfRootWindowInDIP(); 1556 gfx::Rect window = BoundsOfRootWindowInDIP();
1521 gfx::Point initial_press(window.right() - GetMaxDistanceFromEdge() / 2, 1); 1557 gfx::Point initial_press(window.right() - GetMaxDistanceFromEdge() / 2, 1);
1522 ui::TouchEvent first_press( 1558 ui::TouchEvent first_press(
1523 ui::ET_TOUCH_PRESSED, 1559 ui::ET_TOUCH_PRESSED,
1524 initial_press, 1560 initial_press,
1525 0, 1561 0,
1526 Now()); 1562 Now());
1527 generator_->Dispatch(&first_press); 1563 generator_->Dispatch(&first_press);
1528 EXPECT_FALSE(IsInGestureInProgressState()); 1564 EXPECT_FALSE(IsInGestureInProgressState());
1529 EXPECT_FALSE(IsInSlideGestureState()); 1565 EXPECT_FALSE(IsInSlideGestureState());
1530 EXPECT_FALSE(IsInTouchToMouseMode()); 1566 EXPECT_FALSE(IsInTouchToMouseMode());
1531 1567
1532 AdvanceSimulatedTimePastTapDelay(); 1568 AdvanceSimulatedTimePastTapDelay();
1533 EXPECT_FALSE(IsInGestureInProgressState()); 1569 EXPECT_FALSE(IsInGestureInProgressState());
1534 EXPECT_FALSE(IsInSlideGestureState()); 1570 EXPECT_FALSE(IsInSlideGestureState());
1535 EXPECT_TRUE(IsInTouchToMouseMode()); 1571 EXPECT_TRUE(IsInTouchToMouseMode());
1536 } 1572 }
1537 1573
1538 } // namespace ui 1574 } // 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