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

Side by Side Diff: ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc

Issue 2239743004: Palette tool laser prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch
Patch Set: Fixed patch set 5 errors. Created 4 years, 4 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
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
jdufault 2016/08/19 21:05:56 No (c)
sammiequon 2016/08/22 18:07:20 Done.
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 "ash/common/system/chromeos/palette/tools/laser_pointer_unittest.h"
6
7 #include "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h"
8 #include "ash/common/system/chromeos/palette/tools/laser_pointer_view.h"
9 #include "ash/common/wm_shell.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ui/events/test/event_generator.h"
12
13 namespace ash {
14 namespace {
15
16 const int kTestPointsLifetime = 5;
17 const double kTestTimeMs = 100000.0;
jdufault 2016/08/19 21:05:56 Add comment for how long this is in a more readabl
sammiequon 2016/08/22 18:07:20 Done.
18
19 class LaserPointerPointsTest : public test::AshTestBase {
20 public:
21 LaserPointerPointsTest() {}
22 ~LaserPointerPointsTest() override {}
23
24 void SetUp() override {
25 AshTestBase::SetUp();
26 points_.reset(new LaserPointerPoints(
27 base::TimeDelta::FromSeconds(kTestPointsLifetime)));
28 points_test_api_.reset(new LaserPointerPointsTestApi(
29 base::TimeDelta::FromSeconds(kTestPointsLifetime)));
30 }
31
32 void TearDown() override {
33 points_.reset();
jdufault 2016/08/19 21:05:56 reset() should be called for you by the dtor
sammiequon 2016/08/22 18:07:19 Done.
34 points_test_api_.reset();
35 AshTestBase::TearDown();
jdufault 2016/08/19 21:05:56 TearDown should be the first fn call.
sammiequon 2016/08/22 18:07:20 Done.
36 }
37
38 protected:
39 std::unique_ptr<LaserPointerPoints> points_;
40 std::unique_ptr<LaserPointerPointsTestApi> points_test_api_;
41
42 private:
43 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest);
44 };
45
46 class LaserPointerModeTest : public test::AshTestBase {
47 public:
48 LaserPointerModeTest() {}
49 ~LaserPointerModeTest() override {}
50
51 void SetUp() override {
52 AshTestBase::SetUp();
53 laser_pointer_mode_.reset(new LaserPointerModeTestApi(
54 base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr))));
55 points_.reset(new LaserPointerPoints(
56 base::TimeDelta::FromSeconds(kTestPointsLifetime)));
57 points_test_api_.reset(new LaserPointerPointsTestApi(
58 base::TimeDelta::FromSeconds(kTestPointsLifetime)));
59 }
60
61 void TearDown() override {
62 points_.reset();
jdufault 2016/08/19 21:05:56 I don't think you need to reset these instances; t
sammiequon 2016/08/22 18:07:20 Laser pointer mode dtor removes the pointer watche
jdufault 2016/08/22 18:37:36 Please add a comment describing this requirement.
sammiequon 2016/08/23 00:20:33 Done.
63 points_test_api_.reset();
64 laser_pointer_mode_.reset();
65 AshTestBase::TearDown();
jdufault 2016/08/19 21:05:56 AshTestBase::TearDown should be the first function
sammiequon 2016/08/22 18:07:19 See above.
66 }
67
68 protected:
69 std::unique_ptr<LaserPointerModeTestApi> laser_pointer_mode_;
jdufault 2016/08/19 21:05:56 mode_test_api_?
sammiequon 2016/08/22 18:07:20 Done.
70 std::unique_ptr<LaserPointerPoints> points_;
71 std::unique_ptr<LaserPointerPointsTestApi> points_test_api_;
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest);
75 };
76 } // namespace
77
78 LaserPointerPointsTestApi::LaserPointerPointsTestApi(base::TimeDelta life_time)
79 : LaserPointerPoints(life_time) {}
80 LaserPointerPointsTestApi::~LaserPointerPointsTestApi() {}
81
82 void LaserPointerPointsTestApi::AddPointAtTime(const base::Time& time,
83 const gfx::Point& location) {
84 LaserPointerPoints::LaserPoint new_point;
85 new_point.creation_time = time;
86 new_point.location = location;
87 points_.push_back(new_point);
88 ClearOldPoints();
89 }
90
91 void LaserPointerPointsTestApi::MoveForwardInTime(int seconds) {
jdufault 2016/08/19 21:05:56 What about eliminating AddPointAtTime and making t
jdufault 2016/08/19 21:05:56 TimeDelta delta
sammiequon 2016/08/22 18:07:20 Done.
sammiequon 2016/08/22 18:07:20 Done.
92 for (LaserPointerPoints::LaserPoint& point : points_)
93 point.creation_time -= base::TimeDelta::FromSeconds(seconds);
94 AddPointAtTime(base::Time::FromJsTime(kTestTimeMs), gfx::Point());
95 }
96
97 LaserPointerModeTestApi::LaserPointerModeTestApi(
jdufault 2016/08/19 21:05:56 Where is the declaration for this class? If it is
sammiequon 2016/08/22 18:07:20 Done.
98 std::unique_ptr<LaserPointerMode> instance)
99 : instance_(std::move(instance)) {}
100
101 LaserPointerModeTestApi::~LaserPointerModeTestApi() {}
102
103 void LaserPointerModeTestApi::OnEnable() {
104 instance_->OnEnable();
105 }
106 void LaserPointerModeTestApi::OnDisable() {
107 instance_->OnDisable();
108 }
109
110 const LaserPointerPoints& LaserPointerModeTestApi::laser_points() {
111 return instance_->laser_pointer_view_->laser_points_;
112 }
113
114 gfx::Point LaserPointerModeTestApi::current_mouse_location() {
115 return instance_->current_mouse_location_;
116 }
117
118 // Tests that the laser pointers internal collection handles receiving points
119 // and that the functions are returning the expected output.
120 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) {
121 gfx::Point left(1, 1);
122 gfx::Point point2(2, 2);
123 gfx::Point bottom(3, 9);
124 gfx::Point top_right(30, 0);
125 points_->AddPoint(left);
126 points_->AddPoint(point2);
jdufault 2016/08/19 21:05:56 Inline point2 since we don't need to name it. Add
sammiequon 2016/08/22 18:07:20 Done.
127 points_->AddPoint(bottom);
128 points_->AddPoint(top_right);
129
130 // Test laser pointer points collection and helper functions.
131 EXPECT_EQ(4, points_->GetNumberOfPoints());
132 EXPECT_FALSE(points_->IsEmpty());
133 EXPECT_EQ(gfx::Rect(left.x(), top_right.y(), top_right.x() - left.x(),
134 bottom.y() - top_right.y()),
135 points_->GetBoundingBox());
136 EXPECT_EQ(left, points_->GetOldest().location);
137 EXPECT_EQ(top_right, points_->GetNewest().location);
138
139 gfx::Point new_left_bottom(0, 40);
140 points_->AddPoint(new_left_bottom);
141 EXPECT_EQ(5, points_->GetNumberOfPoints());
142 EXPECT_EQ(gfx::Rect(new_left_bottom.x(), top_right.y(),
143 top_right.x() - new_left_bottom.x(),
144 new_left_bottom.y() - top_right.y()),
145 points_->GetBoundingBox());
146
147 points_->Clear();
148 EXPECT_TRUE(points_->IsEmpty());
149 }
150
151 // Test the laser pointer points collection removes old points as expected.
jdufault 2016/08/19 21:05:56 What about a comment like: // Verify that old p
sammiequon 2016/08/22 18:07:20 Done.
152 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) {
153 gfx::Point test_point(0, 0);
154 base::Time start_time = base::Time::FromJsTime(kTestTimeMs);
155
156 // When a point older than kTestPointsLifetime is added, it should get
157 // removed.
158 points_test_api_->AddPointAtTime(start_time, test_point);
159 EXPECT_EQ(points_test_api_->GetNumberOfPoints(), 1);
160 points_test_api_->MoveForwardInTime(1);
161 EXPECT_EQ(points_test_api_->GetNumberOfPoints(), 2);
162 points_test_api_->MoveForwardInTime(10);
163 EXPECT_EQ(points_test_api_->GetNumberOfPoints(), 1);
164 points_test_api_->MoveForwardInTime(1);
165 points_test_api_->MoveForwardInTime(1);
166 points_test_api_->MoveForwardInTime(1);
167 EXPECT_EQ(points_test_api_->GetNumberOfPoints(), 4);
168 points_test_api_->MoveForwardInTime(3);
169 EXPECT_EQ(points_test_api_->GetNumberOfPoints(), 3);
170 }
171
172 // Test to ensure the class responsible for drawing the laser pointer receives
173 // points from mouse movements as expected.
174 TEST_F(LaserPointerModeTest, LaserPointerRenderer) {
175 // TODO(sammiequon): Update these tests once event generator with stylus
176 // events cl lands.
177 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40));
178 EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints());
179 laser_pointer_mode_->OnEnable();
180
181 GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66));
182 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38));
183 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
184 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
185
186 EXPECT_EQ(5, laser_pointer_mode_->laser_points().GetNumberOfPoints());
187
188 laser_pointer_mode_->OnDisable();
189 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
190 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
191 EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints());
192
193 laser_pointer_mode_->OnEnable();
194 EXPECT_EQ(1, laser_pointer_mode_->laser_points().GetNumberOfPoints());
195 EXPECT_EQ(GetEventGenerator().current_location(),
196 laser_pointer_mode_->laser_points().GetNewest().location);
197 }
198 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698