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

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

Issue 2644793004: chromeos: Split laser tests into two files. (Closed)
Patch Set: Fixed patch set 1 errors. Created 3 years, 11 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 | « ash/laser/laser_pointer_controller_unittest.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
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_points.h"
6 #include "ash/laser/laser_pointer_controller_test_api.h"
7 #include "ash/laser/laser_pointer_points_test_api.h" 6 #include "ash/laser/laser_pointer_points_test_api.h"
8 #include "ash/laser/laser_pointer_view.h"
9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 7 #include "ash/test/ash_test_base.h"
11 #include "ui/events/test/event_generator.h" 8 #include "ui/events/test/event_generator.h"
12 9
13 namespace ash { 10 namespace ash {
14 namespace { 11 namespace {
15 12
16 const int kTestPointsLifetimeSeconds = 5; 13 const int kTestPointsLifetimeSeconds = 5;
17 14
18 // TODO(sammiequon): Move this test into a different file. See
19 // http://crbug.com/646953.
20 class LaserPointerPointsTest : public test::AshTestBase { 15 class LaserPointerPointsTest : public test::AshTestBase {
21 public: 16 public:
22 LaserPointerPointsTest() 17 LaserPointerPointsTest()
23 : points_(base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)) {} 18 : points_(base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)) {}
24 19
25 ~LaserPointerPointsTest() override {} 20 ~LaserPointerPointsTest() override {}
26 21
27 protected: 22 protected:
28 LaserPointerPoints points_; 23 LaserPointerPoints points_;
29 24
30 private: 25 private:
31 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); 26 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest);
32 }; 27 };
33 28
34 class LaserPointerControllerTest : public test::AshTestBase {
35 public:
36 LaserPointerControllerTest() {}
37 ~LaserPointerControllerTest() override {}
38
39 void SetUp() override {
40 AshTestBase::SetUp();
41 controller_.reset(new LaserPointerController());
42 }
43
44 void TearDown() override {
45 // This needs to be called first to remove the event handler before the
46 // shell instance gets torn down.
47 controller_.reset();
48 AshTestBase::TearDown();
49 }
50
51 protected:
52 std::unique_ptr<LaserPointerController> controller_;
53
54 private:
55 DISALLOW_COPY_AND_ASSIGN(LaserPointerControllerTest);
56 };
57
58 } // namespace 29 } // namespace
59 30
60 // Tests that the laser pointers internal collection handles receiving points 31 // Tests that the laser pointers internal collection handles receiving points
61 // and that the functions are returning the expected output. 32 // and that the functions are returning the expected output.
62 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { 33 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) {
63 EXPECT_TRUE(points_.IsEmpty()); 34 EXPECT_TRUE(points_.IsEmpty());
64 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox()); 35 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox());
65 const gfx::Point left(1, 1); 36 const gfx::Point left(1, 1);
66 const gfx::Point bottom(1, 9); 37 const gfx::Point bottom(1, 9);
67 const gfx::Point top_right(30, 0); 38 const gfx::Point top_right(30, 0);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 EXPECT_FLOAT_EQ(0.6, points_test_api_.GetPointAtIndex(0).age); 110 EXPECT_FLOAT_EQ(0.6, points_test_api_.GetPointAtIndex(0).age);
140 EXPECT_FLOAT_EQ(0.4, points_test_api_.GetPointAtIndex(1).age); 111 EXPECT_FLOAT_EQ(0.4, points_test_api_.GetPointAtIndex(1).age);
141 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(2).age); 112 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(2).age);
142 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(3).age); 113 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(3).age);
143 114
144 // Verify adding 1 point three seconds later will remove 2 points which are 115 // Verify adding 1 point three seconds later will remove 2 points which are
145 // older than 5 seconds. 116 // older than 5 seconds.
146 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); 117 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3));
147 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); 118 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints());
148 } 119 }
149
150 // Test to ensure the class responsible for drawing the laser pointer receives
151 // points from stylus movements as expected.
152 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) {
153 LaserPointerControllerTestApi controller_test_api_(controller_.get());
154
155 // The laser pointer mode only works with stylus.
156 GetEventGenerator().EnterPenPointerMode();
157
158 // When disabled the laser pointer should not be showing.
159 GetEventGenerator().MoveTouch(gfx::Point(1, 1));
160 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
161
162 // Verify that by enabling the mode, the laser pointer should still not be
163 // showing.
164 controller_test_api_.SetEnabled(true);
165 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
166
167 // Verify moving the stylus 4 times will not display the laser pointer.
168 GetEventGenerator().MoveTouch(gfx::Point(2, 2));
169 GetEventGenerator().MoveTouch(gfx::Point(3, 3));
170 GetEventGenerator().MoveTouch(gfx::Point(4, 4));
171 GetEventGenerator().MoveTouch(gfx::Point(5, 5));
172 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
173
174 // Verify pressing the stylus will show the laser pointer and add a point but
175 // will not activate fading out.
176 GetEventGenerator().PressTouch();
177 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer());
178 EXPECT_FALSE(controller_test_api_.IsFadingAway());
179 EXPECT_EQ(1, controller_test_api_.laser_points().GetNumberOfPoints());
180
181 // Verify dragging the stylus 2 times will add 2 more points.
182 GetEventGenerator().MoveTouch(gfx::Point(6, 6));
183 GetEventGenerator().MoveTouch(gfx::Point(7, 7));
184 EXPECT_EQ(3, controller_test_api_.laser_points().GetNumberOfPoints());
185
186 // Verify releasing the stylus still shows the laser pointer, which is fading
187 // away.
188 GetEventGenerator().ReleaseTouch();
189 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer());
190 EXPECT_TRUE(controller_test_api_.IsFadingAway());
191
192 // Verify that disabling the mode does not display the laser pointer.
193 controller_test_api_.SetEnabled(false);
194 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
195
196 // Verify that disabling the mode while laser pointer is displayed does not
197 // display the laser pointer.
198 controller_test_api_.SetIsFadingAway(false);
199 controller_test_api_.SetEnabled(true);
200 GetEventGenerator().PressTouch();
201 GetEventGenerator().MoveTouch(gfx::Point(6, 6));
202 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer());
203 controller_test_api_.SetEnabled(false);
204 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
205
206 // Verify that the laser pointer does not add points while disabled.
207 GetEventGenerator().PressTouch();
208 GetEventGenerator().MoveTouch(gfx::Point(8, 8));
209 GetEventGenerator().ReleaseTouch();
210 GetEventGenerator().MoveTouch(gfx::Point(9, 9));
211 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
212
213 // Verify that the laser pointer does not get shown if points are not coming
214 // from the stylus, even when enabled.
215 GetEventGenerator().ExitPenPointerMode();
216 controller_test_api_.SetEnabled(true);
217 GetEventGenerator().PressTouch();
218 GetEventGenerator().MoveTouch(gfx::Point(10, 10));
219 GetEventGenerator().MoveTouch(gfx::Point(11, 11));
220 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
221 GetEventGenerator().ReleaseTouch();
222 }
223 } // namespace ash 120 } // namespace ash
OLDNEW
« no previous file with comments | « ash/laser/laser_pointer_controller_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698