| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 } | 684 } |
| 685 | 685 |
| 686 virtual void SetUp() OVERRIDE { | 686 virtual void SetUp() OVERRIDE { |
| 687 // TODO(tdresser): Once unified GR has landed, only run these tests once. | 687 // TODO(tdresser): Once unified GR has landed, only run these tests once. |
| 688 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 688 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 689 switches::kUnifiedGestureDetector, | 689 switches::kUnifiedGestureDetector, |
| 690 UsingUnifiedGR() ? switches::kUnifiedGestureDetectorEnabled | 690 UsingUnifiedGR() ? switches::kUnifiedGestureDetectorEnabled |
| 691 : switches::kUnifiedGestureDetectorDisabled); | 691 : switches::kUnifiedGestureDetectorDisabled); |
| 692 | 692 |
| 693 AuraTestBase::SetUp(); | 693 AuraTestBase::SetUp(); |
| 694 ui::GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click( |
| 695 0.001); |
| 696 ui::GestureConfiguration::set_show_press_delay_in_ms(2); |
| 697 ui::GestureConfiguration::set_long_press_time_in_seconds(0.003); |
| 694 } | 698 } |
| 695 | 699 |
| 696 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); | 700 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); |
| 697 }; | 701 }; |
| 698 | 702 |
| 699 // Check that appropriate touch events generate tap gesture events. | 703 // Check that appropriate touch events generate tap gesture events. |
| 700 TEST_P(GestureRecognizerTest, GestureEventTap) { | 704 TEST_P(GestureRecognizerTest, GestureEventTap) { |
| 701 scoped_ptr<GestureEventConsumeDelegate> delegate( | 705 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 702 new GestureEventConsumeDelegate()); | 706 new GestureEventConsumeDelegate()); |
| 703 TimedEvents tes; | 707 TimedEvents tes; |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 DispatchEventUsingWindowDispatcher(&release); | 1322 DispatchEventUsingWindowDispatcher(&release); |
| 1319 | 1323 |
| 1320 EXPECT_TRUE(delegate->fling()); | 1324 EXPECT_TRUE(delegate->fling()); |
| 1321 EXPECT_FALSE(delegate->scroll_end()); | 1325 EXPECT_FALSE(delegate->scroll_end()); |
| 1322 EXPECT_GT(delegate->velocity_x(), 0); | 1326 EXPECT_GT(delegate->velocity_x(), 0); |
| 1323 EXPECT_GT(delegate->velocity_y(), 0); | 1327 EXPECT_GT(delegate->velocity_y(), 0); |
| 1324 } | 1328 } |
| 1325 | 1329 |
| 1326 // Check that appropriate touch events generate long press events | 1330 // Check that appropriate touch events generate long press events |
| 1327 TEST_P(GestureRecognizerTest, GestureEventLongPress) { | 1331 TEST_P(GestureRecognizerTest, GestureEventLongPress) { |
| 1332 ui::GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click( |
| 1333 0.0025); |
| 1334 |
| 1328 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1335 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1329 new GestureEventConsumeDelegate()); | 1336 new GestureEventConsumeDelegate()); |
| 1330 const int kWindowWidth = 123; | 1337 const int kWindowWidth = 123; |
| 1331 const int kWindowHeight = 45; | 1338 const int kWindowHeight = 45; |
| 1332 const int kTouchId = 2; | 1339 const int kTouchId = 2; |
| 1333 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1340 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 1334 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1341 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1335 delegate.get(), -1234, bounds, root_window())); | 1342 delegate.get(), -1234, bounds, root_window())); |
| 1336 | 1343 |
| 1337 delegate->Reset(); | 1344 delegate->Reset(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 // Note the tap cancel isn't dispatched until the release | 1376 // Note the tap cancel isn't dispatched until the release |
| 1370 EXPECT_TRUE(delegate->tap_cancel()); | 1377 EXPECT_TRUE(delegate->tap_cancel()); |
| 1371 EXPECT_FALSE(delegate->tap()); | 1378 EXPECT_FALSE(delegate->tap()); |
| 1372 } | 1379 } |
| 1373 | 1380 |
| 1374 // Check that scrolling cancels a long press | 1381 // Check that scrolling cancels a long press |
| 1375 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { | 1382 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { |
| 1376 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1383 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1377 new GestureEventConsumeDelegate()); | 1384 new GestureEventConsumeDelegate()); |
| 1378 TimedEvents tes; | 1385 TimedEvents tes; |
| 1379 ui::GestureConfiguration::set_long_press_time_in_seconds(.01); | |
| 1380 const int kWindowWidth = 123; | 1386 const int kWindowWidth = 123; |
| 1381 const int kWindowHeight = 45; | 1387 const int kWindowHeight = 45; |
| 1382 const int kTouchId = 6; | 1388 const int kTouchId = 6; |
| 1383 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1389 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 1384 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1390 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1385 delegate.get(), -1234, bounds, root_window())); | 1391 delegate.get(), -1234, bounds, root_window())); |
| 1386 | 1392 |
| 1387 delegate->Reset(); | 1393 delegate->Reset(); |
| 1388 | 1394 |
| 1389 TimerTestGestureRecognizer* gesture_recognizer = | 1395 TimerTestGestureRecognizer* gesture_recognizer = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1413 delegate->Reset(); | 1419 delegate->Reset(); |
| 1414 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1420 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
| 1415 kTouchId, tes.LeapForward(10)); | 1421 kTouchId, tes.LeapForward(10)); |
| 1416 DispatchEventUsingWindowDispatcher(&release1); | 1422 DispatchEventUsingWindowDispatcher(&release1); |
| 1417 EXPECT_FALSE(delegate->long_press()); | 1423 EXPECT_FALSE(delegate->long_press()); |
| 1418 EXPECT_FALSE(delegate->tap_cancel()); | 1424 EXPECT_FALSE(delegate->tap_cancel()); |
| 1419 } | 1425 } |
| 1420 | 1426 |
| 1421 // Check that appropriate touch events generate long tap events | 1427 // Check that appropriate touch events generate long tap events |
| 1422 TEST_P(GestureRecognizerTest, GestureEventLongTap) { | 1428 TEST_P(GestureRecognizerTest, GestureEventLongTap) { |
| 1429 ui::GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click( |
| 1430 0.0025); |
| 1423 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1431 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1424 new GestureEventConsumeDelegate()); | 1432 new GestureEventConsumeDelegate()); |
| 1425 const int kWindowWidth = 123; | 1433 const int kWindowWidth = 123; |
| 1426 const int kWindowHeight = 45; | 1434 const int kWindowHeight = 45; |
| 1427 const int kTouchId = 2; | 1435 const int kTouchId = 2; |
| 1428 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1436 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 1429 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1437 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1430 delegate.get(), -1234, bounds, root_window())); | 1438 delegate.get(), -1234, bounds, root_window())); |
| 1431 | 1439 |
| 1432 delegate->Reset(); | 1440 delegate->Reset(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 // Note the tap cancel isn't dispatched until the release | 1473 // Note the tap cancel isn't dispatched until the release |
| 1466 EXPECT_TRUE(delegate->tap_cancel()); | 1474 EXPECT_TRUE(delegate->tap_cancel()); |
| 1467 EXPECT_FALSE(delegate->tap()); | 1475 EXPECT_FALSE(delegate->tap()); |
| 1468 } | 1476 } |
| 1469 | 1477 |
| 1470 // Check that second tap cancels a long press | 1478 // Check that second tap cancels a long press |
| 1471 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { | 1479 TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { |
| 1472 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1480 scoped_ptr<GestureEventConsumeDelegate> delegate( |
| 1473 new GestureEventConsumeDelegate()); | 1481 new GestureEventConsumeDelegate()); |
| 1474 TimedEvents tes; | 1482 TimedEvents tes; |
| 1475 ui::GestureConfiguration::set_long_press_time_in_seconds(.01); | |
| 1476 const int kWindowWidth = 300; | 1483 const int kWindowWidth = 300; |
| 1477 const int kWindowHeight = 400; | 1484 const int kWindowHeight = 400; |
| 1478 const int kTouchId1 = 8; | 1485 const int kTouchId1 = 8; |
| 1479 const int kTouchId2 = 2; | 1486 const int kTouchId2 = 2; |
| 1480 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); | 1487 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); |
| 1481 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1488 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1482 delegate.get(), -1234, bounds, root_window())); | 1489 delegate.get(), -1234, bounds, root_window())); |
| 1483 | 1490 |
| 1484 TimerTestGestureRecognizer* gesture_recognizer = | 1491 TimerTestGestureRecognizer* gesture_recognizer = |
| 1485 new TimerTestGestureRecognizer(); | 1492 new TimerTestGestureRecognizer(); |
| (...skipping 2844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4330 EXPECT_TRUE(delegate->show_press()); | 4337 EXPECT_TRUE(delegate->show_press()); |
| 4331 EXPECT_EQ(0U, delegate->latency_info().latency_components.size()); | 4338 EXPECT_EQ(0U, delegate->latency_info().latency_components.size()); |
| 4332 } | 4339 } |
| 4333 | 4340 |
| 4334 INSTANTIATE_TEST_CASE_P(GestureRecognizer, | 4341 INSTANTIATE_TEST_CASE_P(GestureRecognizer, |
| 4335 GestureRecognizerTest, | 4342 GestureRecognizerTest, |
| 4336 ::testing::Bool()); | 4343 ::testing::Bool()); |
| 4337 | 4344 |
| 4338 } // namespace test | 4345 } // namespace test |
| 4339 } // namespace aura | 4346 } // namespace aura |
| OLD | NEW |