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

Side by Side Diff: ash/laser/laser_pointer_controller_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/BUILD.gn ('k') | ash/laser/laser_pointer_points_unittest.cc » ('j') | 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_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"
8 #include "ash/laser/laser_pointer_view.h" 7 #include "ash/laser/laser_pointer_view.h"
9 #include "ash/shell.h" 8 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
11 #include "ui/events/test/event_generator.h" 10 #include "ui/events/test/event_generator.h"
12 11
13 namespace ash { 12 namespace ash {
14 namespace { 13 namespace {
15 14
16 const int kTestPointsLifetimeSeconds = 5;
17
18 // TODO(sammiequon): Move this test into a different file. See
19 // http://crbug.com/646953.
20 class LaserPointerPointsTest : public test::AshTestBase {
21 public:
22 LaserPointerPointsTest()
23 : points_(base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)) {}
24
25 ~LaserPointerPointsTest() override {}
26
27 protected:
28 LaserPointerPoints points_;
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest);
32 };
33
34 class LaserPointerControllerTest : public test::AshTestBase { 15 class LaserPointerControllerTest : public test::AshTestBase {
35 public: 16 public:
36 LaserPointerControllerTest() {} 17 LaserPointerControllerTest() {}
37 ~LaserPointerControllerTest() override {} 18 ~LaserPointerControllerTest() override {}
38 19
39 void SetUp() override { 20 void SetUp() override {
40 AshTestBase::SetUp(); 21 AshTestBase::SetUp();
41 controller_.reset(new LaserPointerController()); 22 controller_.reset(new LaserPointerController());
42 } 23 }
43 24
44 void TearDown() override { 25 void TearDown() override {
45 // This needs to be called first to remove the event handler before the 26 // This needs to be called first to remove the event handler before the
46 // shell instance gets torn down. 27 // shell instance gets torn down.
47 controller_.reset(); 28 controller_.reset();
48 AshTestBase::TearDown(); 29 AshTestBase::TearDown();
49 } 30 }
50 31
51 protected: 32 protected:
52 std::unique_ptr<LaserPointerController> controller_; 33 std::unique_ptr<LaserPointerController> controller_;
53 34
54 private: 35 private:
55 DISALLOW_COPY_AND_ASSIGN(LaserPointerControllerTest); 36 DISALLOW_COPY_AND_ASSIGN(LaserPointerControllerTest);
56 }; 37 };
57 38
58 } // namespace 39 } // namespace
59 40
60 // Tests that the laser pointers internal collection handles receiving points
61 // and that the functions are returning the expected output.
62 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) {
63 EXPECT_TRUE(points_.IsEmpty());
64 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox());
65 const gfx::Point left(1, 1);
66 const gfx::Point bottom(1, 9);
67 const gfx::Point top_right(30, 0);
68 const gfx::Point last(2, 2);
69 points_.AddPoint(left);
70 EXPECT_EQ(gfx::Rect(1, 1, 0, 0), points_.GetBoundingBox());
71
72 // Should be the new bottom of the bounding box.
73 points_.AddPoint(bottom);
74 EXPECT_EQ(gfx::Rect(1, 1, 0, bottom.y() - 1), points_.GetBoundingBox());
75
76 // Should be the new top and right of the bounding box.
77 points_.AddPoint(top_right);
78 EXPECT_EQ(3, points_.GetNumberOfPoints());
79 EXPECT_FALSE(points_.IsEmpty());
80 EXPECT_EQ(gfx::Rect(left.x(), top_right.y(), top_right.x() - left.x(),
81 bottom.y() - top_right.y()),
82 points_.GetBoundingBox());
83
84 // Should not expand bounding box.
85 points_.AddPoint(last);
86 EXPECT_EQ(gfx::Rect(left.x(), top_right.y(), top_right.x() - left.x(),
87 bottom.y() - top_right.y()),
88 points_.GetBoundingBox());
89
90 // Points should be sorted in the order they are added.
91 EXPECT_EQ(left, points_.GetOldest().location);
92 EXPECT_EQ(last, points_.GetNewest().location);
93
94 // Add a new point which will expand the bounding box.
95 gfx::Point new_left_bottom(0, 40);
96 points_.AddPoint(new_left_bottom);
97 EXPECT_EQ(5, points_.GetNumberOfPoints());
98 EXPECT_EQ(gfx::Rect(new_left_bottom.x(), top_right.y(),
99 top_right.x() - new_left_bottom.x(),
100 new_left_bottom.y() - top_right.y()),
101 points_.GetBoundingBox());
102
103 // Verify clearing works.
104 points_.Clear();
105 EXPECT_TRUE(points_.IsEmpty());
106 }
107
108 // Test the laser pointer points collection to verify that old points are
109 // removed.
110 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) {
111 LaserPointerPointsTestApi points_test_api_(&points_);
112
113 // When a point older than kTestPointsLifetime (5 seconds) is added, it
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.
117 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
118 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints());
119 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(0).age);
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|.
123 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
124 EXPECT_EQ(2, points_test_api_.GetNumberOfPoints());
125 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(0).age);
126 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(1).age);
127 // Verify adding a point 10 seconds later will clear all other points, since
128 // they are older than 5 seconds.
129 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(10));
130 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints());
131
132 // Verify adding 3 points one second apart each will add 3 points to the
133 // collection, since all 4 points are younger than 5 seconds. All 4 points are
134 // added 1 second apart so their age should be 0.2 apart.
135 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
136 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
137 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1));
138 EXPECT_EQ(4, points_test_api_.GetNumberOfPoints());
139 EXPECT_FLOAT_EQ(0.6, points_test_api_.GetPointAtIndex(0).age);
140 EXPECT_FLOAT_EQ(0.4, points_test_api_.GetPointAtIndex(1).age);
141 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(2).age);
142 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(3).age);
143
144 // Verify adding 1 point three seconds later will remove 2 points which are
145 // older than 5 seconds.
146 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3));
147 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints());
148 }
149
150 // Test to ensure the class responsible for drawing the laser pointer receives 41 // Test to ensure the class responsible for drawing the laser pointer receives
151 // points from stylus movements as expected. 42 // points from stylus movements as expected.
152 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) { 43 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) {
153 LaserPointerControllerTestApi controller_test_api_(controller_.get()); 44 LaserPointerControllerTestApi controller_test_api_(controller_.get());
154 45
155 // The laser pointer mode only works with stylus. 46 // The laser pointer mode only works with stylus.
156 GetEventGenerator().EnterPenPointerMode(); 47 GetEventGenerator().EnterPenPointerMode();
157 48
158 // When disabled the laser pointer should not be showing. 49 // When disabled the laser pointer should not be showing.
159 GetEventGenerator().MoveTouch(gfx::Point(1, 1)); 50 GetEventGenerator().MoveTouch(gfx::Point(1, 1));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // from the stylus, even when enabled. 105 // from the stylus, even when enabled.
215 GetEventGenerator().ExitPenPointerMode(); 106 GetEventGenerator().ExitPenPointerMode();
216 controller_test_api_.SetEnabled(true); 107 controller_test_api_.SetEnabled(true);
217 GetEventGenerator().PressTouch(); 108 GetEventGenerator().PressTouch();
218 GetEventGenerator().MoveTouch(gfx::Point(10, 10)); 109 GetEventGenerator().MoveTouch(gfx::Point(10, 10));
219 GetEventGenerator().MoveTouch(gfx::Point(11, 11)); 110 GetEventGenerator().MoveTouch(gfx::Point(11, 11));
220 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); 111 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer());
221 GetEventGenerator().ReleaseTouch(); 112 GetEventGenerator().ReleaseTouch();
222 } 113 }
223 } // namespace ash 114 } // namespace ash
OLDNEW
« no previous file with comments | « ash/BUILD.gn ('k') | ash/laser/laser_pointer_points_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698