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 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 generator_->GestureMultiFingerScroll(num_fingers, |
1189 EXPECT_FALSE(IsInTouchToMouseMode()); | 1199 start_points_array, |
1190 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | 1200 delta_time_ms, |
1191 ASSERT_EQ(0U, captured_events.size()); | 1201 kSteps, |
1192 generator_->ReleaseTouch(); | 1202 move_x * 2, |
1203 move_y * 2); | |
1193 | 1204 |
1194 // The swipe registered and sent the appropriate key events. | 1205 // The swipe registered and sent the appropriate key events. |
1195 AssertDirectionalNavigationEvents(captured_events, direction); | 1206 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
1196 EXPECT_TRUE(IsInNoFingersDownState()); | 1207 if (num_fingers == 1) |
1197 EXPECT_FALSE(IsInTouchToMouseMode()); | 1208 AssertDirectionalNavigationEvents(captured_events, direction); |
1198 EXPECT_FALSE(IsInGestureInProgressState()); | 1209 else { |
1199 ClearCapturedEvents(); | 1210 // Most of the time this is 2 right now, but two of the two finger |
1211 // swipes are mapped to chromevox commands which dispatch 6 key events, | |
1212 // and these will probably be remapped a lot as we're developing. | |
1213 ASSERT_GE(captured_events.size(), 2U); | |
1214 std::vector<ui::Event>::size_type i; | |
1215 for (i = 0; i != captured_events.size(); i++) { | |
1216 EXPECT_TRUE(captured_events[i]->IsKeyEvent()); | |
1217 } | |
1218 } | |
1219 EXPECT_TRUE(IsInNoFingersDownState()); | |
1220 EXPECT_FALSE(IsInTouchToMouseMode()); | |
1221 EXPECT_FALSE(IsInGestureInProgressState()); | |
1222 ClearCapturedEvents(); | |
1223 } | |
1200 } | 1224 } |
1201 } | 1225 } |
1202 | 1226 |
1203 // Since there are so many permutations, this test is too slow in debug | 1227 // Since there are so many permutations, this test is too slow in debug |
1204 // mode, so it will only be run in release mode. | 1228 // mode, so it will only be run in release mode. |
1205 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 1229 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
1206 #define MAYBE_AllFingerPermutations AllFingerPermutations | 1230 #define MAYBE_AllFingerPermutations AllFingerPermutations |
1207 #else | 1231 #else |
1208 #define MAYBE_AllFingerPermutations DISABLED_AllFingerPermutations | 1232 #define MAYBE_AllFingerPermutations DISABLED_AllFingerPermutations |
1209 #endif | 1233 #endif |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1310 generator_->ReleaseTouchId(j); | 1334 generator_->ReleaseTouchId(j); |
1311 fingers_pressed[j] = false; | 1335 fingers_pressed[j] = false; |
1312 } | 1336 } |
1313 } | 1337 } |
1314 AdvanceSimulatedTimePastPotentialTapDelay(); | 1338 AdvanceSimulatedTimePastPotentialTapDelay(); |
1315 EXPECT_TRUE(IsInNoFingersDownState()); | 1339 EXPECT_TRUE(IsInNoFingersDownState()); |
1316 ClearCapturedEvents(); | 1340 ClearCapturedEvents(); |
1317 } | 1341 } |
1318 } | 1342 } |
1319 | 1343 |
1320 // 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 |
1321 // 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. | |
1322 TEST_F(TouchExplorationTest, GestureAddedFinger) { | 1347 TEST_F(TouchExplorationTest, GestureAddedFinger) { |
1323 SwitchTouchExplorationMode(true); | 1348 SwitchTouchExplorationMode(true); |
1324 EXPECT_FALSE(IsInTouchToMouseMode()); | 1349 EXPECT_FALSE(IsInTouchToMouseMode()); |
1325 EXPECT_FALSE(IsInGestureInProgressState()); | 1350 EXPECT_FALSE(IsInGestureInProgressState()); |
1326 | 1351 |
1327 float distance = gesture_detector_config_.touch_slop + 1; | 1352 float distance = gesture_detector_config_.touch_slop + 1; |
1328 ui::TouchEvent first_press( | 1353 ui::TouchEvent first_press( |
1329 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 0, Now()); | 1354 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 0, Now()); |
1330 generator_->Dispatch(&first_press); | 1355 generator_->Dispatch(&first_press); |
1331 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 1356 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
1332 gfx::Point second_location(100 + distance, 200); | 1357 gfx::Point second_location(100 + distance, 200); |
1333 generator_->MoveTouch(second_location); | 1358 generator_->MoveTouch(second_location); |
1334 EXPECT_TRUE(IsInGestureInProgressState()); | 1359 EXPECT_TRUE(IsInGestureInProgressState()); |
1335 EXPECT_FALSE(IsInTouchToMouseMode()); | 1360 EXPECT_FALSE(IsInTouchToMouseMode()); |
1336 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | 1361 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
1337 ASSERT_EQ(0U, captured_events.size()); | 1362 ASSERT_EQ(0U, captured_events.size()); |
1338 | 1363 |
1339 // 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 |
1340 // go through. | 1365 // gestures are prevented from continuing to go through. |
1341 ui::TouchEvent second_press( | 1366 ui::TouchEvent second_press( |
1342 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now()); | 1367 ui::ET_TOUCH_PRESSED, gfx::Point(20, 21), 1, Now()); |
1343 generator_->Dispatch(&second_press); | 1368 generator_->Dispatch(&second_press); |
1369 AdvanceSimulatedTimePastTapDelay(); | |
1344 EXPECT_FALSE(IsInGestureInProgressState()); | 1370 EXPECT_FALSE(IsInGestureInProgressState()); |
1345 EXPECT_FALSE(IsInTouchToMouseMode()); | 1371 EXPECT_FALSE(IsInTouchToMouseMode()); |
1346 ASSERT_EQ(0U, captured_events.size()); | 1372 ASSERT_EQ(0U, captured_events.size()); |
1347 } | 1373 } |
1348 | 1374 |
1349 TEST_F(TouchExplorationTest, EnterSlideGestureState) { | 1375 TEST_F(TouchExplorationTest, EnterSlideGestureState) { |
1350 SwitchTouchExplorationMode(true); | 1376 SwitchTouchExplorationMode(true); |
1351 EXPECT_FALSE(IsInTouchToMouseMode()); | 1377 EXPECT_FALSE(IsInTouchToMouseMode()); |
1352 EXPECT_FALSE(IsInGestureInProgressState()); | 1378 EXPECT_FALSE(IsInGestureInProgressState()); |
1353 | 1379 |
1354 int window_right = BoundsOfRootWindowInDIP().right(); | 1380 int window_right = BoundsOfRootWindowInDIP().right(); |
1355 float distance = gesture_detector_config_.touch_slop + 1; | 1381 float distance = gesture_detector_config_.touch_slop + 1; |
1356 ui::TouchEvent first_press( | 1382 ui::TouchEvent first_press( |
1357 ui::ET_TOUCH_PRESSED, gfx::Point(window_right, 1), 0, Now()); | 1383 ui::ET_TOUCH_PRESSED, gfx::Point(window_right, 1), 0, Now()); |
1358 gfx::Point second_location(window_right, 1 + distance / 2); | 1384 gfx::Point second_location(window_right, 1 + distance / 2); |
1359 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); | |
1360 | 1387 |
1361 generator_->Dispatch(&first_press); | 1388 generator_->Dispatch(&first_press); |
1362 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 1389 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
1363 | 1390 |
1364 // 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. |
1365 generator_->MoveTouch(second_location); | 1392 generator_->MoveTouch(second_location); |
1366 EXPECT_FALSE(IsInTouchToMouseMode()); | 1393 EXPECT_FALSE(IsInTouchToMouseMode()); |
1367 EXPECT_FALSE(IsInGestureInProgressState()); | 1394 EXPECT_FALSE(IsInGestureInProgressState()); |
1368 EXPECT_FALSE(IsInSlideGestureState()); | 1395 EXPECT_FALSE(IsInSlideGestureState()); |
1369 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 1396 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
1370 | 1397 |
1371 // 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 |
1372 // the edge of the screen. | 1399 // the edge of the screen. |
1373 generator_->MoveTouch(third_location); | 1400 generator_->MoveTouch(third_location); |
1374 EXPECT_FALSE(IsInGestureInProgressState()); | 1401 EXPECT_FALSE(IsInGestureInProgressState()); |
1375 EXPECT_TRUE(IsInSlideGestureState()); | 1402 EXPECT_TRUE(IsInSlideGestureState()); |
1376 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); | |
1377 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); | 1407 const ScopedVector<ui::Event>& captured_events = GetCapturedEvents(); |
1378 ASSERT_EQ(0U, captured_events.size()); | 1408 ASSERT_EQ(0U, captured_events.size()); |
1379 | 1409 |
1380 // 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 |
1381 // elapsed, there should have two sounds that fired and two volume | 1411 // elapsed, there should have been a sound that fired and a volume |
1382 // changes (one for each movement). | 1412 // change. |
1383 size_t num_adjust_sounds = delegate_.NumAdjustSounds(); | 1413 size_t num_adjust_sounds = delegate_.NumAdjustSounds(); |
1384 ASSERT_EQ(2U, num_adjust_sounds); | 1414 ASSERT_EQ(1U, num_adjust_sounds); |
1385 ASSERT_EQ(2U, delegate_.VolumeChanges().size()); | 1415 ASSERT_EQ(1U, delegate_.VolumeChanges().size()); |
1386 | 1416 |
1387 // 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 |
1388 // grace period is over. | 1418 // grace period is over. |
1389 | |
1390 AdvanceSimulatedTimePastPotentialTapDelay(); | 1419 AdvanceSimulatedTimePastPotentialTapDelay(); |
1391 ASSERT_EQ(0U, captured_events.size()); | 1420 ASSERT_EQ(0U, captured_events.size()); |
1392 EXPECT_FALSE(IsInTouchToMouseMode()); | 1421 EXPECT_FALSE(IsInTouchToMouseMode()); |
1393 EXPECT_FALSE(IsInGestureInProgressState()); | 1422 EXPECT_FALSE(IsInGestureInProgressState()); |
1394 EXPECT_TRUE(IsInSlideGestureState()); | 1423 EXPECT_TRUE(IsInSlideGestureState()); |
1395 | 1424 |
1396 generator_->ReleaseTouch(); | 1425 generator_->ReleaseTouch(); |
1397 ASSERT_EQ(0U, captured_events.size()); | 1426 ASSERT_EQ(0U, captured_events.size()); |
1398 EXPECT_FALSE(IsInTouchToMouseMode()); | 1427 EXPECT_FALSE(IsInTouchToMouseMode()); |
1399 EXPECT_FALSE(IsInGestureInProgressState()); | 1428 EXPECT_FALSE(IsInGestureInProgressState()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1441 // If the slide gesture begins within the boundaries and then moves | 1470 // If the slide gesture begins within the boundaries and then moves |
1442 // SlopDistanceFromEdge there should still be a sound change. If the finger | 1471 // 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 | 1472 // 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 | 1473 // should still be in slide gesture. If the finger moves back into the edges |
1445 // without lifting, it should start changing sound again. | 1474 // without lifting, it should start changing sound again. |
1446 TEST_F(TouchExplorationTest, TestingBoundaries) { | 1475 TEST_F(TouchExplorationTest, TestingBoundaries) { |
1447 SwitchTouchExplorationMode(true); | 1476 SwitchTouchExplorationMode(true); |
1448 | 1477 |
1449 gfx::Rect window = BoundsOfRootWindowInDIP(); | 1478 gfx::Rect window = BoundsOfRootWindowInDIP(); |
1450 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 | |
1451 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()); |
1452 gfx::Point touch_move(initial_press.x() + gesture_detector_config_.touch_slop, | 1484 generator_->Dispatch(&first_press); |
1453 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. | |
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 } |
lisayin
2014/08/06 22:43:29
nit: Extra space.
evy
2014/08/06 22:59:14
Done.
| |
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 |
OLD | NEW |