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

Side by Side Diff: ash/laser/laser_pointer_controller_unittest.cc

Issue 2362063002: cros: Laser pointer fades out on release, do not cover palette. (Closed)
Patch Set: Moved age logic to laser pointer points class. Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ash/laser/laser_pointer_controller.h" 5 #include "ash/laser/laser_pointer_controller.h"
6 #include "ash/laser/laser_pointer_controller_test_api.h" 6 #include "ash/laser/laser_pointer_controller_test_api.h"
7 #include "ash/laser/laser_pointer_points_test_api.h" 7 #include "ash/laser/laser_pointer_points_test_api.h"
8 #include "ash/laser/laser_pointer_view.h" 8 #include "ash/laser/laser_pointer_view.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 points_.Clear(); 104 points_.Clear();
105 EXPECT_TRUE(points_.IsEmpty()); 105 EXPECT_TRUE(points_.IsEmpty());
106 } 106 }
107 107
108 // Test the laser pointer points collection to verify that old points are 108 // Test the laser pointer points collection to verify that old points are
109 // removed. 109 // removed.
110 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) { 110 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) {
111 LaserPointerPointsTestApi points_test_api_(&points_); 111 LaserPointerPointsTestApi points_test_api_(&points_);
112 112
113 // When a point older than kTestPointsLifetime (5 seconds) is added, it 113 // When a point older than kTestPointsLifetime (5 seconds) is added, it
114 // should get removed. 114 // should get removed. The age of the point is a number between 0.0 and 1.0,
115 // with 0.0 specifying a newly added point and 1.0 specifying the age of a
116 // point added |kTestPointsLifetime| ago.
115 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); 117 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
116 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); 118 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints());
119 EXPECT_FLOAT_EQ(0.0, points_test_api_.AgeAtIndex(0));
120
121 // Verify when we move forward in time by one second, the age of the last
122 // point, added one second ago is 1 / |kTestPointsLifetime|.
117 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); 123 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
118 EXPECT_EQ(2, points_test_api_.GetNumberOfPoints()); 124 EXPECT_EQ(2, points_test_api_.GetNumberOfPoints());
125 EXPECT_FLOAT_EQ(0.2, points_test_api_.AgeAtIndex(0));
126 EXPECT_FLOAT_EQ(0.0, points_test_api_.AgeAtIndex(1));
119 127
120 // Verify adding a point 10 seconds later will clear all other points, since 128 // Verify adding a point 10 seconds later will clear all other points, since
121 // they are older than 5 seconds. 129 // they are older than 5 seconds.
122 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(10)); 130 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(10));
123 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); 131 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints());
124 132
125 // Verify adding 3 points one second apart each will add 3 points to the 133 // Verify adding 3 points one second apart each will add 3 points to the
126 // collection, since all 4 poitns are younger than 5 seconds. 134 // collection, since all 4 points are younger than 5 seconds. All 4 points are
135 // added 1 second apart so their age should be 0.2 apart.
127 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); 136 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
128 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); 137 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
129 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); 138 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
130 EXPECT_EQ(4, points_test_api_.GetNumberOfPoints()); 139 EXPECT_EQ(4, points_test_api_.GetNumberOfPoints());
140 EXPECT_FLOAT_EQ(0.6, points_test_api_.AgeAtIndex(0));
141 EXPECT_FLOAT_EQ(0.4, points_test_api_.AgeAtIndex(1));
142 EXPECT_FLOAT_EQ(0.2, points_test_api_.AgeAtIndex(2));
143 EXPECT_FLOAT_EQ(0.0, points_test_api_.AgeAtIndex(3));
131 144
132 // Verify adding 1 point three seconds later will remove 2 points which are 145 // Verify adding 1 point three seconds later will remove 2 points which are
133 // older than 5 seconds. 146 // older than 5 seconds.
134 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); 147 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3));
135 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); 148 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints());
136 } 149 }
137 150
138 // Test to ensure the class responsible for drawing the laser pointer receives 151 // Test to ensure the class responsible for drawing the laser pointer receives
139 // points from stylus movements as expected. 152 // points from stylus movements as expected.
140 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) { 153 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) {
(...skipping 11 matching lines...) Expand all
152 controller_test_api_.SetEnabled(true); 165 controller_test_api_.SetEnabled(true);
153 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); 166 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
154 167
155 // Verify moving the stylus 4 times will not display the laser pointer. 168 // Verify moving the stylus 4 times will not display the laser pointer.
156 GetEventGenerator().MoveMouseToInHost(gfx::Point(2, 2)); 169 GetEventGenerator().MoveMouseToInHost(gfx::Point(2, 2));
157 GetEventGenerator().MoveMouseToInHost(gfx::Point(3, 3)); 170 GetEventGenerator().MoveMouseToInHost(gfx::Point(3, 3));
158 GetEventGenerator().MoveMouseToInHost(gfx::Point(4, 4)); 171 GetEventGenerator().MoveMouseToInHost(gfx::Point(4, 4));
159 GetEventGenerator().MoveMouseToInHost(gfx::Point(5, 5)); 172 GetEventGenerator().MoveMouseToInHost(gfx::Point(5, 5));
160 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); 173 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
161 174
162 // Verify pressing the stylus will show the laser pointer and add a point. 175 // Verify pressing the stylus will show the laser pointer and add a point but
176 // will not activate fading out.
163 GetEventGenerator().PressLeftButton(); 177 GetEventGenerator().PressLeftButton();
164 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); 178 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer());
179 EXPECT_FALSE(controller_test_api_.IsFadingOut());
165 EXPECT_EQ(1, controller_test_api_.laser_points().GetNumberOfPoints()); 180 EXPECT_EQ(1, controller_test_api_.laser_points().GetNumberOfPoints());
166 181
167 // Verify dragging the stylus 2 times will add 2 more points. 182 // Verify dragging the stylus 2 times will add 2 more points.
168 GetEventGenerator().MoveMouseToInHost(gfx::Point(6, 6)); 183 GetEventGenerator().MoveMouseToInHost(gfx::Point(6, 6));
169 GetEventGenerator().MoveMouseToInHost(gfx::Point(7, 7)); 184 GetEventGenerator().MoveMouseToInHost(gfx::Point(7, 7));
170 EXPECT_EQ(3, controller_test_api_.laser_points().GetNumberOfPoints()); 185 EXPECT_EQ(3, controller_test_api_.laser_points().GetNumberOfPoints());
171 186
172 // Verify releasing the stylus hides the laser pointer. 187 // Verify releasing the stylus still shows the laser pointer, which is fading
188 // away.
173 GetEventGenerator().ReleaseLeftButton(); 189 GetEventGenerator().ReleaseLeftButton();
174 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); 190 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer());
191 EXPECT_TRUE(controller_test_api_.IsFadingOut());
175 192
176 // Verify that disabling the mode does not display the laser pointer. 193 // Verify that disabling the mode does not display the laser pointer.
177 controller_test_api_.SetEnabled(false); 194 controller_test_api_.SetEnabled(false);
178 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); 195 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
179 196
180 // Verify that disabling the mode while laser pointer is displayed does not 197 // Verify that disabling the mode while laser pointer is displayed does not
181 // display the laser pointer. 198 // display the laser pointer.
182 controller_test_api_.SetEnabled(true); 199 controller_test_api_.SetEnabled(true);
183 GetEventGenerator().PressLeftButton(); 200 GetEventGenerator().PressLeftButton();
184 GetEventGenerator().MoveMouseToInHost(gfx::Point(6, 6)); 201 GetEventGenerator().MoveMouseToInHost(gfx::Point(6, 6));
(...skipping 12 matching lines...) Expand all
197 // from the stylus, even when enabled. 214 // from the stylus, even when enabled.
198 GetEventGenerator().ExitPenPointerMode(); 215 GetEventGenerator().ExitPenPointerMode();
199 controller_test_api_.SetEnabled(true); 216 controller_test_api_.SetEnabled(true);
200 GetEventGenerator().PressLeftButton(); 217 GetEventGenerator().PressLeftButton();
201 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 10)); 218 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 10));
202 GetEventGenerator().MoveMouseToInHost(gfx::Point(11, 11)); 219 GetEventGenerator().MoveMouseToInHost(gfx::Point(11, 11));
203 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); 220 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
204 GetEventGenerator().ReleaseLeftButton(); 221 GetEventGenerator().ReleaseLeftButton();
205 } 222 }
206 } // namespace ash 223 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698