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

Side by Side Diff: ui/aura/gestures/velocity_calculator_unittest.cc

Issue 9310031: Event smoothing in CrOS gesture recognizer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixes for clang chromium-style-check. Created 8 years, 10 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/aura/gestures/velocity_calculator.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/aura/gestures/velocity_calculator.h"
8 #include "ui/aura/test/aura_test_base.h"
9
10 namespace aura {
11 namespace test {
12
13 namespace {
14
15 static void AddPoints(VelocityCalculator* velocity_calculator,
16 float x_increment,
17 float y_increment,
18 float time_increment_seconds,
19 int num_points) {
20 float x = 0;
21 float y = 0;
22 double time = 0;
23
24 for (int i = 0; i < num_points; ++i) {
25 velocity_calculator->PointSeen(x, y, time);
26 x += x_increment;
27 y += y_increment;
28 time += time_increment_seconds * 1000000;
29 }
30 }
31
32 } // namespace
33
34 typedef AuraTestBase VelocityCalculatorTest;
35
36 // Test that the velocity returned is reasonable
37 TEST_F(VelocityCalculatorTest, ReturnsReasonableVelocity) {
38 VelocityCalculator velocity_calculator(5);
39 AddPoints(&velocity_calculator, 10, -10, 1, 7);
40
41 EXPECT_GT(velocity_calculator.XVelocity(), 9.9);
42 EXPECT_LT(velocity_calculator.XVelocity(), 10.1);
43 EXPECT_GT(velocity_calculator.YVelocity(), -10.1);
44 EXPECT_LT(velocity_calculator.YVelocity(), -9.9);
45
46 velocity_calculator.PointSeen(9, -11, 5500000);
47 velocity_calculator.PointSeen(21, -19, 6000000);
48 velocity_calculator.PointSeen(30, -32, 6500000);
49 velocity_calculator.PointSeen(38, -40, 7000000);
50 velocity_calculator.PointSeen(50, -51, 7500000);
51
52 EXPECT_GT(velocity_calculator.XVelocity(), 19);
53 EXPECT_LT(velocity_calculator.XVelocity(), 21);
54 EXPECT_GT(velocity_calculator.YVelocity(), -21);
55 EXPECT_LT(velocity_calculator.YVelocity(), -19);
56
57 // Significantly larger difference in position
58 velocity_calculator.PointSeen(70, -70, 8000000);
59
60 EXPECT_GT(velocity_calculator.XVelocity(), 20);
61 EXPECT_LT(velocity_calculator.XVelocity(), 25);
62 EXPECT_GT(velocity_calculator.YVelocity(), -25);
63 EXPECT_LT(velocity_calculator.YVelocity(), -20);
64 }
65
66 TEST_F(VelocityCalculatorTest, IsAccurateWithLargeTimes) {
67 VelocityCalculator velocity_calculator(5);
68 int64 start_time = 0;
69 velocity_calculator.PointSeen(9, -11, start_time);
70 velocity_calculator.PointSeen(21, -19, start_time + 8);
71 velocity_calculator.PointSeen(30, -32, start_time + 16);
72 velocity_calculator.PointSeen(38, -40, start_time + 24);
73 velocity_calculator.PointSeen(50, -51, start_time + 32);
74
75 EXPECT_GT(velocity_calculator.XVelocity(), 1230000);
76 EXPECT_LT(velocity_calculator.XVelocity(), 1260000);
77 EXPECT_GT(velocity_calculator.YVelocity(), -1270000);
78 EXPECT_LT(velocity_calculator.YVelocity(), -1240000);
79
80 start_time = 1223372036800000000;
81 velocity_calculator.PointSeen(9, -11, start_time);
82 velocity_calculator.PointSeen(21, -19, start_time + 8);
83 velocity_calculator.PointSeen(30, -32, start_time + 16);
84 velocity_calculator.PointSeen(38, -40, start_time + 24);
85 velocity_calculator.PointSeen(50, -51, start_time + 32);
86
87 EXPECT_GT(velocity_calculator.XVelocity(), 1230000);
88 EXPECT_LT(velocity_calculator.XVelocity(), 1260000);
89 EXPECT_GT(velocity_calculator.YVelocity(), -1270000);
90 EXPECT_LT(velocity_calculator.YVelocity(), -124000);
91 }
92
93 // Check that the velocity returned is 0 if the velocity calculator
94 // doesn't have enough data
95 TEST_F(VelocityCalculatorTest, RequiresEnoughData) {
96 VelocityCalculator velocity_calculator(5);
97 EXPECT_EQ(velocity_calculator.XVelocity(), 0);
98 EXPECT_EQ(velocity_calculator.YVelocity(), 0);
99
100 AddPoints(&velocity_calculator, 10, 10, 1, 4);
101
102 // We've only seen 4 points, the buffer size is 5
103 // Since the buffer isn't full, return 0
104 EXPECT_EQ(velocity_calculator.XVelocity(), 0);
105 EXPECT_EQ(velocity_calculator.YVelocity(), 0);
106
107 AddPoints(&velocity_calculator, 10, 10, 1, 1);
108
109 EXPECT_GT(velocity_calculator.XVelocity(), 9.9);
110 EXPECT_GT(velocity_calculator.YVelocity(), 9.9);
111 }
112
113 // Ensures ClearHistory behaves correctly
114 TEST_F(VelocityCalculatorTest, ClearsHistory) {
115 VelocityCalculator velocity_calculator(5);
116 AddPoints(&velocity_calculator, 10, -10, 1, 7);
117
118 EXPECT_GT(velocity_calculator.XVelocity(), 9.9);
119 EXPECT_LT(velocity_calculator.XVelocity(), 10.1);
120 EXPECT_GT(velocity_calculator.YVelocity(), -10.1);
121 EXPECT_LT(velocity_calculator.YVelocity(), -9.9);
122
123 velocity_calculator.ClearHistory();
124
125 EXPECT_EQ(velocity_calculator.XVelocity(), 0);
126 EXPECT_EQ(velocity_calculator.YVelocity(), 0);
127 }
128
129 // Ensure data older than the buffer size is ignored
130 TEST_F(VelocityCalculatorTest, IgnoresOldData) {
131 VelocityCalculator velocity_calculator(5);
132 AddPoints(&velocity_calculator, 10, -10, 1, 7);
133
134 EXPECT_GT(velocity_calculator.XVelocity(), 9.9);
135 EXPECT_LT(velocity_calculator.XVelocity(), 10.1);
136 EXPECT_GT(velocity_calculator.YVelocity(), -10.1);
137 EXPECT_LT(velocity_calculator.YVelocity(), -9.9);
138
139 AddPoints(&velocity_calculator, 0, 0, 1, 5);
140
141 EXPECT_EQ(velocity_calculator.XVelocity(), 0);
142 EXPECT_EQ(velocity_calculator.YVelocity(), 0);
143 }
144
145 } // namespace test
146 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/gestures/velocity_calculator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698