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

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

Issue 1975533002: Change ui::Event::time_stamp from TimeDelta to TimeTicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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 <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 381 }
382 382
383 float GetMaxDistanceFromEdge() const { 383 float GetMaxDistanceFromEdge() const {
384 return touch_exploration_controller_->GetMaxDistanceFromEdge(); 384 return touch_exploration_controller_->GetMaxDistanceFromEdge();
385 } 385 }
386 386
387 float GetSlopDistanceFromEdge() const { 387 float GetSlopDistanceFromEdge() const {
388 return touch_exploration_controller_->GetSlopDistanceFromEdge(); 388 return touch_exploration_controller_->GetSlopDistanceFromEdge();
389 } 389 }
390 390
391 base::TimeDelta Now() { 391 base::TimeTicks Now() {
392 // This is the same as what EventTimeForNow() does, but here we do it 392 // This is the same as what EventTimeForNow() does, but here we do it
393 // with our simulated clock. 393 // with our simulated clock.
394 return base::TimeDelta::FromInternalValue( 394 return simulated_clock_->NowTicks();
395 simulated_clock_->NowTicks().ToInternalValue());
396 } 395 }
397 396
398 std::unique_ptr<test::EventGenerator> generator_; 397 std::unique_ptr<test::EventGenerator> generator_;
399 ui::GestureDetector::Config gesture_detector_config_; 398 ui::GestureDetector::Config gesture_detector_config_;
400 // Owned by |generator_|. 399 // Owned by |generator_|.
401 base::SimpleTestTickClock* simulated_clock_; 400 base::SimpleTestTickClock* simulated_clock_;
402 MockTouchExplorationControllerDelegate delegate_; 401 MockTouchExplorationControllerDelegate delegate_;
403 402
404 private: 403 private:
405 EventCapturer event_capturer_; 404 EventCapturer event_capturer_;
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 generator_->PressTouch(); 828 generator_->PressTouch();
830 // Advance to the finger passing through, and then to the longpress timeout. 829 // Advance to the finger passing through, and then to the longpress timeout.
831 AdvanceSimulatedTimePastTapDelay(); 830 AdvanceSimulatedTimePastTapDelay();
832 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); 831 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
833 generator_->ReleaseTouch(); 832 generator_->ReleaseTouch();
834 833
835 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); 834 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents();
836 ASSERT_EQ(2U, captured_events.size()); 835 ASSERT_EQ(2U, captured_events.size());
837 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); 836 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
838 EXPECT_EQ(tap_location, captured_events[0]->location()); 837 EXPECT_EQ(tap_location, captured_events[0]->location());
839 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); 838 base::TimeTicks pressed_time = captured_events[0]->time_stamp();
840 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); 839 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
841 EXPECT_EQ(tap_location, captured_events[1]->location()); 840 EXPECT_EQ(tap_location, captured_events[1]->location());
842 base::TimeDelta released_time = captured_events[1]->time_stamp(); 841 base::TimeTicks released_time = captured_events[1]->time_stamp();
843 EXPECT_EQ(released_time - pressed_time, 842 EXPECT_EQ(released_time - pressed_time,
844 gesture_detector_config_.longpress_timeout); 843 gesture_detector_config_.longpress_timeout);
845 } 844 }
846 845
847 // Single-tapping should send a touch press and release through to the location 846 // Single-tapping should send a touch press and release through to the location
848 // of the last successful touch exploration if the grace period has not 847 // of the last successful touch exploration if the grace period has not
849 // elapsed. 848 // elapsed.
850 TEST_F(TouchExplorationTest, SingleTap) { 849 TEST_F(TouchExplorationTest, SingleTap) {
851 SwitchTouchExplorationMode(true); 850 SwitchTouchExplorationMode(true);
852 851
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 ui::TouchEvent split_tap_release( 1039 ui::TouchEvent split_tap_release(
1041 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); 1040 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now());
1042 generator_->Dispatch(&split_tap_release); 1041 generator_->Dispatch(&split_tap_release);
1043 EXPECT_FALSE(IsInNoFingersDownState()); 1042 EXPECT_FALSE(IsInNoFingersDownState());
1044 EXPECT_TRUE(IsInTouchToMouseMode()); 1043 EXPECT_TRUE(IsInTouchToMouseMode());
1045 1044
1046 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); 1045 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents();
1047 ASSERT_EQ(2U, captured_events.size()); 1046 ASSERT_EQ(2U, captured_events.size());
1048 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); 1047 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
1049 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); 1048 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
1050 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); 1049 base::TimeTicks pressed_time = captured_events[0]->time_stamp();
1051 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); 1050 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
1052 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); 1051 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
1053 base::TimeDelta released_time = captured_events[1]->time_stamp(); 1052 base::TimeTicks released_time = captured_events[1]->time_stamp();
1054 EXPECT_EQ(gesture_detector_config_.longpress_timeout, 1053 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
1055 released_time - pressed_time); 1054 released_time - pressed_time);
1056 } 1055 }
1057 1056
1058 // If split tap is started but the touch explore finger is released first, 1057 // If split tap is started but the touch explore finger is released first,
1059 // there should still be a touch press and release sent to the location of 1058 // there should still be a touch press and release sent to the location of
1060 // the last successful touch exploration. If the remaining finger is held 1059 // the last successful touch exploration. If the remaining finger is held
1061 // as a longpress, there should be a delay between the sent touch and release 1060 // as a longpress, there should be a delay between the sent touch and release
1062 // events (right click).All fingers should be released after the click 1061 // events (right click).All fingers should be released after the click
1063 // goes through. 1062 // goes through.
(...skipping 23 matching lines...) Expand all
1087 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); 1086 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout);
1088 ui::TouchEvent split_tap_release( 1087 ui::TouchEvent split_tap_release(
1089 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); 1088 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now());
1090 generator_->Dispatch(&split_tap_release); 1089 generator_->Dispatch(&split_tap_release);
1091 EXPECT_TRUE(IsInTouchToMouseMode()); 1090 EXPECT_TRUE(IsInTouchToMouseMode());
1092 1091
1093 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); 1092 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents();
1094 ASSERT_EQ(2U, captured_events.size()); 1093 ASSERT_EQ(2U, captured_events.size());
1095 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); 1094 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type());
1096 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); 1095 EXPECT_EQ(initial_touch_location, captured_events[0]->location());
1097 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); 1096 base::TimeTicks pressed_time = captured_events[0]->time_stamp();
1098 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); 1097 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type());
1099 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); 1098 EXPECT_EQ(initial_touch_location, captured_events[1]->location());
1100 base::TimeDelta released_time = captured_events[1]->time_stamp(); 1099 base::TimeTicks released_time = captured_events[1]->time_stamp();
1101 EXPECT_EQ(gesture_detector_config_.longpress_timeout, 1100 EXPECT_EQ(gesture_detector_config_.longpress_timeout,
1102 released_time - pressed_time); 1101 released_time - pressed_time);
1103 } 1102 }
1104 1103
1105 TEST_F(TouchExplorationTest, SplitTapMultiFinger) { 1104 TEST_F(TouchExplorationTest, SplitTapMultiFinger) {
1106 SwitchTouchExplorationMode(true); 1105 SwitchTouchExplorationMode(true);
1107 gfx::Point initial_touch_location(11, 12); 1106 gfx::Point initial_touch_location(11, 12);
1108 gfx::Point second_touch_location(33, 34); 1107 gfx::Point second_touch_location(33, 34);
1109 gfx::Point third_touch_location(16, 17); 1108 gfx::Point third_touch_location(16, 17);
1110 1109
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 generator_->PressTouch(); 1889 generator_->PressTouch();
1891 generator_->MoveTouch(initial_press); 1890 generator_->MoveTouch(initial_press);
1892 generator_->MoveTouch(*point); 1891 generator_->MoveTouch(*point);
1893 generator_->ReleaseTouch(); 1892 generator_->ReleaseTouch();
1894 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); 1893 ASSERT_EQ(1U, delegate_.NumExitScreenSounds());
1895 delegate_.ResetCountersToZero(); 1894 delegate_.ResetCountersToZero();
1896 } 1895 }
1897 } 1896 }
1898 1897
1899 } // namespace ui 1898 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698