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

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: rebased 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
« no previous file with comments | « ui/chromeos/touch_exploration_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 // gesture is completed, enter touch exploration. 1112 // gesture is completed, enter touch exploration.
1113 TEST_F(TouchExplorationTest, EnterGestureInProgressState) { 1113 TEST_F(TouchExplorationTest, EnterGestureInProgressState) {
1114 SwitchTouchExplorationMode(true); 1114 SwitchTouchExplorationMode(true);
1115 EXPECT_FALSE(IsInTouchToMouseMode()); 1115 EXPECT_FALSE(IsInTouchToMouseMode());
1116 EXPECT_FALSE(IsInGestureInProgressState()); 1116 EXPECT_FALSE(IsInGestureInProgressState());
1117 1117
1118 float distance = gesture_detector_config_.touch_slop + 1; 1118 float distance = gesture_detector_config_.touch_slop + 1;
1119 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 1), 0, Now()); 1119 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 1), 0, Now());
1120 gfx::Point second_location(distance / 2, 1); 1120 gfx::Point second_location(distance / 2, 1);
1121 gfx::Point third_location(distance, 1); 1121 gfx::Point third_location(distance, 1);
1122 gfx::Point touch_exploration_location(20, 21);
1122 1123
1123 generator_->Dispatch(&first_press); 1124 generator_->Dispatch(&first_press);
1124 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1125 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1125 // Since we are not out of the touch slop yet, we should not be in gesture in 1126 // Since we are not out of the touch slop yet, we should not be in gesture in
1126 // progress. 1127 // progress.
1127 generator_->MoveTouch(second_location); 1128 generator_->MoveTouch(second_location);
1128 EXPECT_FALSE(IsInTouchToMouseMode()); 1129 EXPECT_FALSE(IsInTouchToMouseMode());
1129 EXPECT_FALSE(IsInGestureInProgressState()); 1130 EXPECT_FALSE(IsInGestureInProgressState());
1130 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1131 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1131 1132
1132 // Once we are out of slop, we should be in GestureInProgress. 1133 // Once we are out of slop, we should be in GestureInProgress.
1133 generator_->MoveTouch(third_location); 1134 generator_->MoveTouch(third_location);
1134 EXPECT_TRUE(IsInGestureInProgressState()); 1135 EXPECT_TRUE(IsInGestureInProgressState());
1135 EXPECT_FALSE(IsInTouchToMouseMode()); 1136 EXPECT_FALSE(IsInTouchToMouseMode());
1136 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1137 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1137 ASSERT_EQ(0U, captured_events.size()); 1138 ASSERT_EQ(0U, captured_events.size());
1138 1139
1139 // Exit out of gesture mode once grace period is over and enter touch 1140 // Exit out of gesture mode once grace period is over and enter touch
1140 // exploration. 1141 // exploration. There should be a move when entering touch exploration and
1142 // also for the touch move.
1141 AdvanceSimulatedTimePastTapDelay(); 1143 AdvanceSimulatedTimePastTapDelay();
1142 ASSERT_EQ(1U, captured_events.size()); 1144 generator_->MoveTouch(touch_exploration_location);
1145 ASSERT_EQ(2U, captured_events.size());
1143 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); 1146 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type());
1147 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type());
1144 EXPECT_TRUE(IsInTouchToMouseMode()); 1148 EXPECT_TRUE(IsInTouchToMouseMode());
1145 EXPECT_FALSE(IsInGestureInProgressState()); 1149 EXPECT_FALSE(IsInGestureInProgressState());
1146 } 1150 }
1147 1151
1148 // A swipe+direction gesture should trigger a Shift+Search+Direction 1152 // A swipe+direction gesture should trigger a Shift+Search+Direction
1149 // keyboard event. 1153 // keyboard event.
1150 TEST_F(TouchExplorationTest, GestureSwipe) { 1154 TEST_F(TouchExplorationTest, GestureSwipe) {
1151 SwitchTouchExplorationMode(true); 1155 SwitchTouchExplorationMode(true);
1152 std::vector<ui::KeyboardCode> directions; 1156 std::vector<ui::KeyboardCode> directions;
1153 directions.push_back(ui::VKEY_RIGHT); 1157 directions.push_back(ui::VKEY_RIGHT);
1154 directions.push_back(ui::VKEY_LEFT); 1158 directions.push_back(ui::VKEY_LEFT);
1155 directions.push_back(ui::VKEY_UP); 1159 directions.push_back(ui::VKEY_UP);
1156 directions.push_back(ui::VKEY_DOWN); 1160 directions.push_back(ui::VKEY_DOWN);
1157 1161
1158 for (std::vector<ui::KeyboardCode>::const_iterator it = directions.begin(); 1162 // This value was taken from gesture_recognizer_unittest.cc in a swipe
1159 it != directions.end(); 1163 // detector test, since it seems to be about the right amount to get a swipe.
1160 ++it) { 1164 const int kSteps = 15;
1161 int x = 30;
1162 int y = 31;
1163 ui::TouchEvent origin(ui::ET_TOUCH_PRESSED, gfx::Point(x, y), 0, Now());
1164 generator_->Dispatch(&origin);
1165 1165
1166 ui::KeyboardCode direction = *it; 1166 // There are gestures supported with up to four fingers.
1167 float distance = gesture_detector_config_.touch_slop + 1; 1167 for (int num_fingers = 1; num_fingers <= 4; num_fingers++) {
1168 scoped_ptr<gfx::Point> swipe; 1168 std::vector<gfx::Point> start_points;
1169 switch (direction) { 1169 for(int j = 0; j < num_fingers; j++){
1170 case ui::VKEY_RIGHT: 1170 start_points.push_back(gfx::Point(j * 10 + 100, j * 10 + 200));
1171 swipe.reset(new gfx::Point(x + distance, y));
1172 break;
1173 case ui::VKEY_LEFT:
1174 swipe.reset(new gfx::Point(x - distance, y));
1175 break;
1176 case ui::VKEY_UP:
1177 swipe.reset(new gfx::Point(x, y - distance));
1178 break;
1179 case ui::VKEY_DOWN:
1180 swipe.reset(new gfx::Point(x, y + distance));
1181 break;
1182 default:
1183 return;
1184 } 1171 }
1172 gfx::Point* start_points_array = &start_points[0];
1173 const float distance = gesture_detector_config_.touch_slop + 1;
1174 // Iterate through each swipe direction for this number of fingers.
1175 for (std::vector<ui::KeyboardCode>::const_iterator it = directions.begin();
1176 it != directions.end();
1177 ++it) {
1178 int move_x = 0;
1179 int move_y = 0;
1180 ui::KeyboardCode direction = *it;
1181 switch (direction) {
1182 case ui::VKEY_RIGHT:
1183 move_x = distance;
1184 break;
1185 case ui::VKEY_LEFT:
1186 move_x = 0 - distance;
1187 break;
1188 case ui::VKEY_UP:
1189 move_y = 0 - distance;
1190 break;
1191 case ui::VKEY_DOWN:
1192 move_y = distance;
1193 break;
1194 default:
1195 return;
1196 }
1185 1197
1186 // A swipe is made when a fling starts 1198 // A swipe is made when a fling starts
1187 float delta_time = 1199 float delta_time =
1188 distance / gesture_detector_config_.maximum_fling_velocity; 1200 distance / gesture_detector_config_.maximum_fling_velocity;
1189 simulated_clock_->Advance(base::TimeDelta::FromSecondsD(delta_time)); 1201 // delta_time is in seconds, so we convert to ms.
1190 generator_->MoveTouch(*swipe); 1202 int delta_time_ms = floor(delta_time * 1000);
1191 EXPECT_TRUE(IsInGestureInProgressState()); 1203 generator_->GestureMultiFingerScroll(num_fingers,
1192 EXPECT_FALSE(IsInTouchToMouseMode()); 1204 start_points_array,
1193 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1205 delta_time_ms,
1194 ASSERT_EQ(0U, captured_events.size()); 1206 kSteps,
1195 generator_->ReleaseTouch(); 1207 move_x * 2,
1208 move_y * 2);
1196 1209
1197 // The swipe registered and sent the appropriate key events. 1210 // The swipe registered and sent the appropriate key events.
1198 AssertDirectionalNavigationEvents(captured_events, direction); 1211 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1199 EXPECT_TRUE(IsInNoFingersDownState()); 1212 if (num_fingers == 1)
1200 EXPECT_FALSE(IsInTouchToMouseMode()); 1213 AssertDirectionalNavigationEvents(captured_events, direction);
1201 EXPECT_FALSE(IsInGestureInProgressState()); 1214 else {
1202 ClearCapturedEvents(); 1215 // Most of the time this is 2 right now, but two of the two finger
1216 // swipes are mapped to chromevox commands which dispatch 6 key events,
1217 // and these will probably be remapped a lot as we're developing.
1218 ASSERT_GE(captured_events.size(), 2U);
1219 std::vector<ui::Event>::size_type i;
1220 for (i = 0; i != captured_events.size(); i++) {
1221 EXPECT_TRUE(captured_events[i]->IsKeyEvent());
1222 }
1223 }
1224 EXPECT_TRUE(IsInNoFingersDownState());
1225 EXPECT_FALSE(IsInTouchToMouseMode());
1226 EXPECT_FALSE(IsInGestureInProgressState());
1227 ClearCapturedEvents();
1228 }
1203 } 1229 }
1204 } 1230 }
1205 1231
1206 // Since there are so many permutations, this test is too slow in debug 1232 // Since there are so many permutations, this test is fairly slow. Therefore, it
1207 // mode, so it will only be run in release mode. 1233 // is disabled and will be turned on to check during development.
1208 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1209 #define MAYBE_AllFingerPermutations AllFingerPermutations
1210 #else
1211 #define MAYBE_AllFingerPermutations DISABLED_AllFingerPermutations
1212 #endif
1213 1234
1214 TEST_F(TouchExplorationTest, MAYBE_AllFingerPermutations) { 1235 TEST_F(TouchExplorationTest, DISABLED_AllFingerPermutations) {
1215 SwitchTouchExplorationMode(true); 1236 SwitchTouchExplorationMode(true);
1216 SuppressVLOGs(true); 1237 SuppressVLOGs(true);
1217 // We will test all permutations of events from three different fingers 1238 // We will test all permutations of events from three different fingers
1218 // to ensure that we return to NO_FINGERS_DOWN when fingers have been 1239 // to ensure that we return to NO_FINGERS_DOWN when fingers have been
1219 // released. 1240 // released.
1220 ScopedVector<ui::TouchEvent> all_events; 1241 ScopedVector<ui::TouchEvent> all_events;
1221 for (int touch_id = 0; touch_id < 3; touch_id++){ 1242 for (int touch_id = 0; touch_id < 3; touch_id++){
1222 int x = 10*touch_id + 1; 1243 int x = 10*touch_id + 1;
1223 int y = 10*touch_id + 2; 1244 int y = 10*touch_id + 2;
1224 all_events.push_back(new TouchEvent( 1245 all_events.push_back(new TouchEvent(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 generator_->ReleaseTouchId(j); 1334 generator_->ReleaseTouchId(j);
1314 fingers_pressed[j] = false; 1335 fingers_pressed[j] = false;
1315 } 1336 }
1316 } 1337 }
1317 AdvanceSimulatedTimePastPotentialTapDelay(); 1338 AdvanceSimulatedTimePastPotentialTapDelay();
1318 EXPECT_TRUE(IsInNoFingersDownState()); 1339 EXPECT_TRUE(IsInNoFingersDownState());
1319 ClearCapturedEvents(); 1340 ClearCapturedEvents();
1320 } 1341 }
1321 } 1342 }
1322 1343
1323 // With the simple swipe gestures, if additional fingers are added, then the 1344 // With the simple swipe gestures, if additional fingers are added and the tap
1324 // state should change to the wait for one finger state. 1345 // timer times out, then the state should change to the wait for one finger
1346 // state.
1325 TEST_F(TouchExplorationTest, GestureAddedFinger) { 1347 TEST_F(TouchExplorationTest, GestureAddedFinger) {
1326 SwitchTouchExplorationMode(true); 1348 SwitchTouchExplorationMode(true);
1327 EXPECT_FALSE(IsInTouchToMouseMode()); 1349 EXPECT_FALSE(IsInTouchToMouseMode());
1328 EXPECT_FALSE(IsInGestureInProgressState()); 1350 EXPECT_FALSE(IsInGestureInProgressState());
1329 1351
1330 float distance = gesture_detector_config_.touch_slop + 1; 1352 float distance = gesture_detector_config_.touch_slop + 1;
1331 ui::TouchEvent first_press( 1353 ui::TouchEvent first_press(
1332 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 0, Now()); 1354 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 0, Now());
1333 generator_->Dispatch(&first_press); 1355 generator_->Dispatch(&first_press);
1334 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1356 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1335 gfx::Point second_location(100 + distance, 200); 1357 gfx::Point second_location(100 + distance, 200);
1336 generator_->MoveTouch(second_location); 1358 generator_->MoveTouch(second_location);
1337 EXPECT_TRUE(IsInGestureInProgressState()); 1359 EXPECT_TRUE(IsInGestureInProgressState());
1338 EXPECT_FALSE(IsInTouchToMouseMode()); 1360 EXPECT_FALSE(IsInTouchToMouseMode());
1339 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1361 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1340 ASSERT_EQ(0U, captured_events.size()); 1362 ASSERT_EQ(0U, captured_events.size());
1341 1363
1342 // Generate a second press that should prevent gestures from continuing to 1364 // Generate a second press, but time out past the gesture period so that
1343 // go through. 1365 // gestures are prevented from continuing to go through.
1344 ui::TouchEvent second_press( 1366 ui::TouchEvent second_press(
1345 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now()); 1367 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now());
1346 generator_->Dispatch(&second_press); 1368 generator_->Dispatch(&second_press);
1369 AdvanceSimulatedTimePastTapDelay();
1347 EXPECT_FALSE(IsInGestureInProgressState()); 1370 EXPECT_FALSE(IsInGestureInProgressState());
1348 EXPECT_FALSE(IsInTouchToMouseMode()); 1371 EXPECT_FALSE(IsInTouchToMouseMode());
1349 ASSERT_EQ(0U, captured_events.size()); 1372 ASSERT_EQ(0U, captured_events.size());
1350 } 1373 }
1351 1374
1352 TEST_F(TouchExplorationTest, EnterSlideGestureState) { 1375 TEST_F(TouchExplorationTest, EnterSlideGestureState) {
1353 SwitchTouchExplorationMode(true); 1376 SwitchTouchExplorationMode(true);
1354 EXPECT_FALSE(IsInTouchToMouseMode()); 1377 EXPECT_FALSE(IsInTouchToMouseMode());
1355 EXPECT_FALSE(IsInGestureInProgressState()); 1378 EXPECT_FALSE(IsInGestureInProgressState());
1356 1379
1357 int window_right = BoundsOfRootWindowInDIP().right(); 1380 int window_right = BoundsOfRootWindowInDIP().right();
1358 float distance = gesture_detector_config_.touch_slop + 1; 1381 float distance = gesture_detector_config_.touch_slop + 1;
1359 ui::TouchEvent first_press( 1382 ui::TouchEvent first_press(
1360 ui::ET_TOUCH_PRESSED, gfx::Point(window_right, 1), 0, Now()); 1383 ui::ET_TOUCH_PRESSED, gfx::Point(window_right, 1), 0, Now());
1361 gfx::Point second_location(window_right, 1 + distance / 2); 1384 gfx::Point second_location(window_right, 1 + distance / 2);
1362 gfx::Point third_location(window_right, 1 + distance); 1385 gfx::Point third_location(window_right, 1 + distance);
1386 gfx::Point fourth_location(window_right, 35);
1363 1387
1364 generator_->Dispatch(&first_press); 1388 generator_->Dispatch(&first_press);
1365 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1389 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1366 1390
1367 // Since we haven't moved past slop yet, we should not be in slide gesture. 1391 // Since we haven't moved past slop yet, we should not be in slide gesture.
1368 generator_->MoveTouch(second_location); 1392 generator_->MoveTouch(second_location);
1369 EXPECT_FALSE(IsInTouchToMouseMode()); 1393 EXPECT_FALSE(IsInTouchToMouseMode());
1370 EXPECT_FALSE(IsInGestureInProgressState()); 1394 EXPECT_FALSE(IsInGestureInProgressState());
1371 EXPECT_FALSE(IsInSlideGestureState()); 1395 EXPECT_FALSE(IsInSlideGestureState());
1372 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); 1396 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1373 1397
1374 // Once we are out of slop, we should be in slide gesture since we are along 1398 // Once we are out of slop, we should be in slide gesture since we are along
1375 // the edge of the screen. 1399 // the edge of the screen.
1376 generator_->MoveTouch(third_location); 1400 generator_->MoveTouch(third_location);
1377 EXPECT_FALSE(IsInGestureInProgressState()); 1401 EXPECT_FALSE(IsInGestureInProgressState());
1378 EXPECT_TRUE(IsInSlideGestureState()); 1402 EXPECT_TRUE(IsInSlideGestureState());
1379 EXPECT_FALSE(IsInTouchToMouseMode()); 1403 EXPECT_FALSE(IsInTouchToMouseMode());
1404
1405 // Now that we are in slide gesture, we can adjust the volume.
1406 generator_->MoveTouch(fourth_location);
1380 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1407 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1381 ASSERT_EQ(0U, captured_events.size()); 1408 ASSERT_EQ(0U, captured_events.size());
1382 1409
1383 // Since we are at the right edge of the screen, but the sound timer has not 1410 // Since we are at the right edge of the screen, but the sound timer has not
1384 // elapsed, there should have two sounds that fired and two volume 1411 // elapsed, there should have been a sound that fired and a volume
1385 // changes (one for each movement). 1412 // change.
1386 size_t num_adjust_sounds = delegate_.NumAdjustSounds(); 1413 size_t num_adjust_sounds = delegate_.NumAdjustSounds();
1387 ASSERT_EQ(2U, num_adjust_sounds); 1414 ASSERT_EQ(1U, num_adjust_sounds);
1388 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); 1415 ASSERT_EQ(1U, delegate_.VolumeChanges().size());
1389 1416
1390 // Exit out of slide gesture once touch is lifted, but not before even if the 1417 // Exit out of slide gesture once touch is lifted, but not before even if the
1391 // grace period is over. 1418 // grace period is over.
1392
1393 AdvanceSimulatedTimePastPotentialTapDelay(); 1419 AdvanceSimulatedTimePastPotentialTapDelay();
1394 ASSERT_EQ(0U, captured_events.size()); 1420 ASSERT_EQ(0U, captured_events.size());
1395 EXPECT_FALSE(IsInTouchToMouseMode()); 1421 EXPECT_FALSE(IsInTouchToMouseMode());
1396 EXPECT_FALSE(IsInGestureInProgressState()); 1422 EXPECT_FALSE(IsInGestureInProgressState());
1397 EXPECT_TRUE(IsInSlideGestureState()); 1423 EXPECT_TRUE(IsInSlideGestureState());
1398 1424
1399 generator_->ReleaseTouch(); 1425 generator_->ReleaseTouch();
1400 ASSERT_EQ(0U, captured_events.size()); 1426 ASSERT_EQ(0U, captured_events.size());
1401 EXPECT_FALSE(IsInTouchToMouseMode()); 1427 EXPECT_FALSE(IsInTouchToMouseMode());
1402 EXPECT_FALSE(IsInGestureInProgressState()); 1428 EXPECT_FALSE(IsInGestureInProgressState());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 // If the slide gesture begins within the boundaries and then moves 1470 // If the slide gesture begins within the boundaries and then moves
1445 // SlopDistanceFromEdge there should still be a sound change. If the finger 1471 // SlopDistanceFromEdge there should still be a sound change. If the finger
1446 // moves into the center screen, there should no longer be a sound change but it 1472 // moves into the center screen, there should no longer be a sound change but it
1447 // should still be in slide gesture. If the finger moves back into the edges 1473 // should still be in slide gesture. If the finger moves back into the edges
1448 // without lifting, it should start changing sound again. 1474 // without lifting, it should start changing sound again.
1449 TEST_F(TouchExplorationTest, TestingBoundaries) { 1475 TEST_F(TouchExplorationTest, TestingBoundaries) {
1450 SwitchTouchExplorationMode(true); 1476 SwitchTouchExplorationMode(true);
1451 1477
1452 gfx::Rect window = BoundsOfRootWindowInDIP(); 1478 gfx::Rect window = BoundsOfRootWindowInDIP();
1453 gfx::Point initial_press(window.right() - GetMaxDistanceFromEdge() / 2, 1); 1479 gfx::Point initial_press(window.right() - GetMaxDistanceFromEdge() / 2, 1);
1480
1481 gfx::Point center_screen(window.right() / 2, window.bottom() / 2);
1482
1454 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, initial_press, 0, Now()); 1483 ui::TouchEvent first_press(ui::ET_TOUCH_PRESSED, initial_press, 0, Now());
1455 gfx::Point touch_move(initial_press.x() + gesture_detector_config_.touch_slop, 1484 generator_->Dispatch(&first_press);
1456 1); 1485 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1486 EXPECT_FALSE(IsInGestureInProgressState());
1487 EXPECT_FALSE(IsInSlideGestureState());
1488 EXPECT_FALSE(IsInTouchToMouseMode());
1489
1490 // Move past the touch slop to begin slide gestures.
1491 // + slop + 1 to actually leave slop.
1492 gfx::Point touch_move(
1493 initial_press.x(),
1494 initial_press.y() + gesture_detector_config_.touch_slop + 1);
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.
1457 gfx::Point into_slop_boundaries( 1503 gfx::Point into_slop_boundaries(
1458 window.right() - GetSlopDistanceFromEdge() / 2, 1); 1504 window.right() - GetSlopDistanceFromEdge() / 2, 1);
1459 gfx::Point center_screen(window.right() / 2, window.bottom() / 2);
1460
1461 generator_->Dispatch(&first_press);
1462 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1463
1464 generator_->MoveTouch(touch_move);
1465 EXPECT_FALSE(IsInTouchToMouseMode());
1466 EXPECT_FALSE(IsInGestureInProgressState());
1467 EXPECT_FALSE(IsInSlideGestureState());
1468 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10));
1469
1470 // Move the touch into slop boundaries. It should stil be in slide gestures
1471 // and adjust the volume.
1472 generator_->MoveTouch(into_slop_boundaries); 1505 generator_->MoveTouch(into_slop_boundaries);
1473 EXPECT_FALSE(IsInGestureInProgressState()); 1506 EXPECT_FALSE(IsInGestureInProgressState());
1474 EXPECT_TRUE(IsInSlideGestureState()); 1507 EXPECT_TRUE(IsInSlideGestureState());
1475 EXPECT_FALSE(IsInTouchToMouseMode()); 1508 EXPECT_FALSE(IsInTouchToMouseMode());
1476 1509
1477 // The sound is rate limiting so it only activates every 150ms. 1510 // The sound is rate limiting so it only activates every 150ms.
1478 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); 1511 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200));
1479 1512
1480 size_t num_adjust_sounds = delegate_.NumAdjustSounds(); 1513 size_t num_adjust_sounds = delegate_.NumAdjustSounds();
1481 ASSERT_EQ(2U, num_adjust_sounds); 1514 ASSERT_EQ(1U, num_adjust_sounds);
1482 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); 1515 ASSERT_EQ(1U, delegate_.VolumeChanges().size());
1483 1516
1484 // 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
1485 // gestures, but there should not be anymore volume adjustments. 1518 // gestures, but there should not be anymore volume adjustments.
1486 generator_->MoveTouch(center_screen); 1519 generator_->MoveTouch(center_screen);
1487 EXPECT_FALSE(IsInGestureInProgressState()); 1520 EXPECT_FALSE(IsInGestureInProgressState());
1488 EXPECT_TRUE(IsInSlideGestureState()); 1521 EXPECT_TRUE(IsInSlideGestureState());
1489 EXPECT_FALSE(IsInTouchToMouseMode()); 1522 EXPECT_FALSE(IsInTouchToMouseMode());
1490 1523
1491 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); 1524 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200));
1492 num_adjust_sounds = delegate_.NumAdjustSounds(); 1525 num_adjust_sounds = delegate_.NumAdjustSounds();
1493 ASSERT_EQ(2U, num_adjust_sounds); 1526 ASSERT_EQ(1U, num_adjust_sounds);
1494 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); 1527 ASSERT_EQ(1U, delegate_.VolumeChanges().size());
1495 1528
1496 // 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
1497 // again. 1530 // again, one volume change for each new move.
1498 generator_->MoveTouch(into_slop_boundaries); 1531 generator_->MoveTouch(into_slop_boundaries);
1499 EXPECT_FALSE(IsInGestureInProgressState()); 1532 EXPECT_FALSE(IsInGestureInProgressState());
1500 EXPECT_TRUE(IsInSlideGestureState()); 1533 EXPECT_TRUE(IsInSlideGestureState());
1501 EXPECT_FALSE(IsInTouchToMouseMode()); 1534 EXPECT_FALSE(IsInTouchToMouseMode());
1502 1535
1503 generator_->MoveTouch( 1536 generator_->MoveTouch(
1504 gfx::Point(into_slop_boundaries.x() + gesture_detector_config_.touch_slop, 1537 gfx::Point(into_slop_boundaries.x() + gesture_detector_config_.touch_slop,
1505 into_slop_boundaries.y())); 1538 into_slop_boundaries.y()));
1506 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); 1539 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(200));
1507 1540
1508 num_adjust_sounds = delegate_.NumAdjustSounds(); 1541 num_adjust_sounds = delegate_.NumAdjustSounds();
1509 ASSERT_EQ(3U, num_adjust_sounds); 1542 ASSERT_EQ(2U, num_adjust_sounds);
1510 ASSERT_EQ(3U, delegate_.VolumeChanges().size()); 1543 ASSERT_EQ(3U, delegate_.VolumeChanges().size());
1511 1544
1512 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1545 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1513 ASSERT_EQ(0U, captured_events.size()); 1546 ASSERT_EQ(0U, captured_events.size());
1514 1547
1515 generator_->ReleaseTouch(); 1548 generator_->ReleaseTouch();
1516 } 1549 }
1517 1550
1518 // 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
1519 // within the grace period, it should go to touch exploration. 1552 // within the grace period, it should go to touch exploration.
(...skipping 16 matching lines...) Expand all
1536 EXPECT_FALSE(IsInGestureInProgressState()); 1569 EXPECT_FALSE(IsInGestureInProgressState());
1537 EXPECT_FALSE(IsInSlideGestureState()); 1570 EXPECT_FALSE(IsInSlideGestureState());
1538 EXPECT_TRUE(IsInTouchToMouseMode()); 1571 EXPECT_TRUE(IsInTouchToMouseMode());
1539 } 1572 }
1540 1573
1541 // If two fingers tap the screen at the same time and release before the tap 1574 // If two fingers tap the screen at the same time and release before the tap
1542 // timer runs out, a control key event should be sent to silence chromevox. 1575 // timer runs out, a control key event should be sent to silence chromevox.
1543 TEST_F(TouchExplorationTest, TwoFingerTap) { 1576 TEST_F(TouchExplorationTest, TwoFingerTap) {
1544 SwitchTouchExplorationMode(true); 1577 SwitchTouchExplorationMode(true);
1545 1578
1579 generator_->set_current_location(gfx::Point(101, 102));
1546 generator_->PressTouchId(1); 1580 generator_->PressTouchId(1);
1547 EXPECT_FALSE(IsInTwoFingerTapState()); 1581 EXPECT_FALSE(IsInTwoFingerTapState());
1548 1582
1549 generator_->PressTouchId(2); 1583 generator_->PressTouchId(2);
1550 EXPECT_TRUE(IsInTwoFingerTapState()); 1584 EXPECT_TRUE(IsInTwoFingerTapState());
1551 1585
1552 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1586 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1553 ASSERT_EQ(0U, captured_events.size()); 1587 ASSERT_EQ(0U, captured_events.size());
1554 1588
1555 generator_->ReleaseTouchId(1); 1589 generator_->ReleaseTouchId(1);
1590 EXPECT_TRUE(IsInTwoFingerTapState());
1556 generator_->ReleaseTouchId(2); 1591 generator_->ReleaseTouchId(2);
1557 1592
1558 // Two key events should have been sent to silence the feedback. 1593 // Two key events should have been sent to silence the feedback.
1559 EXPECT_EQ(2U, captured_events.size()); 1594 EXPECT_EQ(2U, captured_events.size());
1560 } 1595 }
1561 1596
1562 // If the fingers are not released before the tap timer runs out, a control 1597 // If the fingers are not released before the tap timer runs out, a control
1563 // keyevent is not sent and the state will no longer be in two finger tap. 1598 // keyevent is not sent and the state will no longer be in two finger tap.
1564 TEST_F(TouchExplorationTest, TwoFingerTapAndHold) { 1599 TEST_F(TouchExplorationTest, TwoFingerTapAndHold) {
1565 SwitchTouchExplorationMode(true); 1600 SwitchTouchExplorationMode(true);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 EXPECT_TRUE(IsInTwoFingerTapState()); 1690 EXPECT_TRUE(IsInTwoFingerTapState());
1656 1691
1657 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); 1692 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents();
1658 ASSERT_EQ(0U, captured_events.size()); 1693 ASSERT_EQ(0U, captured_events.size());
1659 1694
1660 generator_->Dispatch(&out_slop_id_2); 1695 generator_->Dispatch(&out_slop_id_2);
1661 EXPECT_FALSE(IsInTwoFingerTapState()); 1696 EXPECT_FALSE(IsInTwoFingerTapState());
1662 } 1697 }
1663 1698
1664 } // namespace ui 1699 } // namespace ui
OLDNEW
« no previous file with comments | « ui/chromeos/touch_exploration_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698