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

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 4 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.
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/palette_tool_manager.h"
6 #include "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h"
7 #include "ash/common/system/chromeos/palette/tools/laser_pointer_points.h"
8 #include "ash/common/wm_shell.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ui/events/test/event_generator.h"
11
12 namespace ash {
13
14 class LaserPointerPointsTestApi : public LaserPointerPoints {
15 public:
16 LaserPointerPointsTestApi(base::TimeDelta life_time)
17 : LaserPointerPoints(life_time) {}
18 ~LaserPointerPointsTestApi() {}
19
20 void AddTimedPoint(const base::Time& time, const gfx::Point& location) {
jdufault 2016/08/19 01:02:09 AddPointAtTime(...)
sammiequon 2016/08/19 20:28:47 Done.
21 LaserPointerPoints::LaserPoint new_point;
22 new_point.creation_time = time;
23 new_point.location = location;
24 points_.push_back(new_point);
25 ClearOldPoints();
26 }
27
28 private:
29 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTestApi);
30 };
31
32 class LaserPointerModeTestApi {
33 public:
34 LaserPointerModeTestApi(std::unique_ptr<LaserPointerMode> instance)
35 : instance_(std::move(instance)) {}
36 ~LaserPointerModeTestApi() {}
37
38 void OnEnable() { instance_->OnEnable(); }
39 void OnDisable() { instance_->OnDisable(); }
40
41 const LaserPointerPoints& laser_points() {
42 return instance_->laser_pointer_view_->laser_points_;
43 }
44
45 gfx::Point current_mouse_location() {
46 return instance_->current_mouse_location_;
47 }
48
49 private:
50 std::unique_ptr<LaserPointerMode> instance_;
51
52 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTestApi);
53 };
54
55 namespace {
jdufault 2016/08/19 01:02:09 Move anonymous namespace contents to the top of th
sammiequon 2016/08/19 20:28:47 Done.
56 const int kTestPointsLifetime = 5;
57
58 class LaserPointerModeTest : public test::AshTestBase {
59 public:
60 LaserPointerModeTest()
61 : laser_pointer_points_(
62 base::TimeDelta::FromSeconds(kTestPointsLifetime)),
63 laser_pointer_points_delete_(
64 base::TimeDelta::FromSeconds(kTestPointsLifetime)) {}
65 ~LaserPointerModeTest() override {}
66
67 void SetUp() override {
68 AshTestBase::SetUp();
69 laser_pointer_mode_.reset(new LaserPointerModeTestApi(
70 base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr))));
71 }
72
73 void TearDown() override {
74 laser_pointer_mode_.reset();
75 AshTestBase::TearDown();
76 }
77
78 protected:
79 std::unique_ptr<LaserPointerModeTestApi> laser_pointer_mode_;
80 LaserPointerPoints laser_pointer_points_;
jdufault 2016/08/19 01:02:09 What about just points_?
sammiequon 2016/08/19 20:28:47 Done.
81 LaserPointerPointsTestApi laser_pointer_points_delete_;
jdufault 2016/08/19 01:02:08 points_test_api_?
jdufault 2016/08/19 01:02:09 If this test api instance is separate from laser_p
sammiequon 2016/08/19 20:28:46 Done.
sammiequon 2016/08/19 20:28:47 Done.
82
83 private:
84 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest);
85 };
86 } // namespace
87
88 // Tests that the laser pointers internal collection handles receiving points
89 // and that the functions are returning the expected output.
90 TEST_F(LaserPointerModeTest, LaserPointerInternalCollection) {
91 gfx::Point point1(1, 1);
92 gfx::Point point2(2, 2);
93 gfx::Point point3(3, 9);
94 gfx::Point point4(30, 0);
95 gfx::Point point5(0, 40);
96 laser_pointer_points_.AddPoint(point1);
97 laser_pointer_points_.AddPoint(point2);
98 laser_pointer_points_.AddPoint(point3);
99 laser_pointer_points_.AddPoint(point4);
100
101 // Test laser pointer points collection and helper functions.
102 EXPECT_EQ(4, laser_pointer_points_.GetNumberOfPoints());
103 EXPECT_FALSE(laser_pointer_points_.IsEmpty());
104 EXPECT_EQ(gfx::Rect(1, 0, 29, 9), laser_pointer_points_.GetBoundingBox());
jdufault 2016/08/19 01:02:09 I think having renaming some of the points to top_
sammiequon 2016/08/19 20:28:46 Done.
105 EXPECT_EQ(point1, laser_pointer_points_.GetOldest().location);
106 EXPECT_EQ(point4, laser_pointer_points_.GetMostRecent().location);
107
108 laser_pointer_points_.AddPoint(point5);
jdufault 2016/08/19 01:02:09 Declare point here, ie, gfx::Point expanded_botto
sammiequon 2016/08/19 20:28:46 Done.
109 EXPECT_EQ(5, laser_pointer_points_.GetNumberOfPoints());
110 EXPECT_EQ(gfx::Rect(0, 0, 30, 40), laser_pointer_points_.GetBoundingBox());
111
112 laser_pointer_points_.Clear();
113 EXPECT_TRUE(laser_pointer_points_.IsEmpty());
114 }
115
116 // Test the laser pointer points collection removes old points as expected.
117 TEST_F(LaserPointerModeTest, LaserPointerInternalCollectionDeletion) {
118 gfx::Point test_point(0, 0);
119 base::Time start_time = base::Time::FromJsTime(0);
120 base::Time three_second_time = base::Time::FromJsTime(3000);
jdufault 2016/08/19 01:02:08 Use FromSeconds
sammiequon 2016/08/19 20:28:47 As per offline conv this is fine.
121 base::Time six_second_time = base::Time::FromJsTime(6000);
122 base::Time six_half_second_time = base::Time::FromJsTime(6500);
jdufault 2016/08/19 01:02:09 I don't think these constants aid in readability.
sammiequon 2016/08/19 20:28:47 Done.
123 base::Time seven_second_time = base::Time::FromJsTime(7000);
124 base::Time seven_half_second_time = base::Time::FromJsTime(7500);
125 base::Time twenty_second_time = base::Time::FromJsTime(20000);
126
127 // When a new point is added points older than 5 seconds (kTestPointsLifetime)
128 // // ago should be removed.
jdufault 2016/08/19 01:02:08 What about something like this for the comment?
sammiequon 2016/08/19 20:28:47 Done.
129 laser_pointer_points_delete_.AddTimedPoint(start_time, test_point);
130 EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 1);
131 laser_pointer_points_delete_.AddTimedPoint(three_second_time, test_point);
132 EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 2);
133 laser_pointer_points_delete_.AddTimedPoint(six_second_time, test_point);
134 EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 2);
135
136 laser_pointer_points_delete_.AddTimedPoint(six_half_second_time, test_point);
137 laser_pointer_points_delete_.AddTimedPoint(seven_second_time, test_point);
138 laser_pointer_points_delete_.AddTimedPoint(seven_half_second_time,
139 test_point);
140 EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 5);
141 laser_pointer_points_delete_.AddTimedPoint(twenty_second_time, test_point);
142 EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 1);
jdufault 2016/08/19 01:02:08 This seems strange to me. Why does adding a 20 sec
sammiequon 2016/08/19 20:28:47 Done.
143 }
144
145 // Test to ensure the class responsible for drawing the laser pointer receives
146 // points from mouse movements as expected.
147 TEST_F(LaserPointerModeTest, LaserPointerRenderer) {
148 // TODO(sammiequon): Update these tests once event generator with stylus
149 // events cl lands.
150 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40));
151 EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints());
152 laser_pointer_mode_->OnEnable();
153
154 GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66));
155 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38));
156 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
157 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
158
159 EXPECT_EQ(5, laser_pointer_mode_->laser_points().GetNumberOfPoints());
160
161 laser_pointer_mode_->OnDisable();
162 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
163 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
164 EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints());
165
166 laser_pointer_mode_->OnEnable();
167 EXPECT_EQ(1, laser_pointer_mode_->laser_points().GetNumberOfPoints());
168 EXPECT_EQ(gfx::Point(19, 71),
jdufault 2016/08/19 01:02:09 GetEventGenerator().current_location()
sammiequon 2016/08/19 20:28:46 Done.
169 laser_pointer_mode_->laser_points().GetMostRecent().location);
170 }
171 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698