OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h" | |
6 #include "ash/common/system/chromeos/palette/tools/laser_pointer_testapis.h" | |
7 #include "ash/common/system/chromeos/palette/tools/laser_pointer_view.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 namespace { | |
14 | |
15 const int kTestPointsLifetimeSeconds = 5; | |
16 | |
17 class LaserPointerPointsTest : public test::AshTestBase { | |
18 public: | |
19 LaserPointerPointsTest() {} | |
20 ~LaserPointerPointsTest() override {} | |
21 | |
22 void SetUp() override { | |
23 AshTestBase::SetUp(); | |
24 points_.reset(new LaserPointerPoints( | |
25 base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds))); | |
26 points_test_api_.reset(new LaserPointerPointsTestApi( | |
27 base::WrapUnique<LaserPointerPoints>(new LaserPointerPoints( | |
28 base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds))))); | |
29 } | |
30 | |
31 void TearDown() override { AshTestBase::TearDown(); } | |
32 | |
33 protected: | |
34 std::unique_ptr<LaserPointerPoints> points_; | |
35 std::unique_ptr<LaserPointerPointsTestApi> points_test_api_; | |
36 | |
37 private: | |
38 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); | |
39 }; | |
40 | |
41 class LaserPointerModeTest : public test::AshTestBase { | |
42 public: | |
43 LaserPointerModeTest() {} | |
44 ~LaserPointerModeTest() override {} | |
45 | |
46 void SetUp() override { | |
47 AshTestBase::SetUp(); | |
48 mode_test_api_.reset(new LaserPointerModeTestApi( | |
49 base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr)))); | |
50 } | |
51 | |
52 void TearDown() override { | |
53 // This needs to be called first to remove the pointer watcher otherwise | |
54 // tear down will complain about there being more than zero pointer watcher | |
55 // alive. | |
56 mode_test_api_.reset(); | |
57 AshTestBase::TearDown(); | |
58 } | |
59 | |
60 protected: | |
61 std::unique_ptr<LaserPointerModeTestApi> mode_test_api_; | |
62 | |
63 private: | |
64 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest); | |
65 }; | |
66 } // namespace | |
67 | |
68 // Tests that the laser pointers internal collection handles receiving points | |
69 // and that the functions are returning the expected output. | |
70 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { | |
71 EXPECT_TRUE(points_->IsEmpty()); | |
72 EXPECT_EQ(gfx::Rect(), points_->GetBoundingBox()); | |
73 gfx::Point left(1, 1); | |
74 gfx::Point bottom(3, 9); | |
75 gfx::Point top_right(30, 0); | |
76 points_->AddPoint(left); | |
77 EXPECT_EQ(gfx::Rect(1, 1, 0, 0), points_->GetBoundingBox()); | |
78 // Should not expand bounding box. | |
jdufault
2016/08/23 02:11:26
These assertions should be verified as you go, so
sammiequon
2016/08/23 19:30:02
Done.
| |
79 points_->AddPoint(gfx::Point(2, 2)); | |
80 // Should be the new bottom of the bounding box. | |
81 points_->AddPoint(bottom); | |
82 // Should be the new top and right of the bounding box. | |
83 points_->AddPoint(top_right); | |
84 EXPECT_EQ(4, points_->GetNumberOfPoints()); | |
85 EXPECT_FALSE(points_->IsEmpty()); | |
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 // Points should be sorted in the order they are added. | |
90 EXPECT_EQ(left, points_->GetOldest().location); | |
91 EXPECT_EQ(top_right, points_->GetNewest().location); | |
92 | |
93 // Add a new point which will expand the bounding box. | |
94 gfx::Point new_left_bottom(0, 40); | |
95 points_->AddPoint(new_left_bottom); | |
96 EXPECT_EQ(5, points_->GetNumberOfPoints()); | |
97 EXPECT_EQ(gfx::Rect(new_left_bottom.x(), top_right.y(), | |
98 top_right.x() - new_left_bottom.x(), | |
99 new_left_bottom.y() - top_right.y()), | |
100 points_->GetBoundingBox()); | |
101 | |
102 points_->Clear(); | |
103 EXPECT_TRUE(points_->IsEmpty()); | |
104 } | |
105 | |
106 // Test the laser pointer points collection to verify that old points are | |
107 // removed. | |
108 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) { | |
109 gfx::Point test_point(0, 0); | |
110 base::Time start_time = base::Time::Now(); | |
111 | |
112 // When a point older than kTestPointsLifetime (5 seconds) is added, it | |
113 // should get removed. | |
114 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1), | |
115 start_time, test_point); | |
jdufault
2016/08/23 02:11:26
Every call uses the same two constant parameters;
sammiequon
2016/08/23 19:30:02
Done.
| |
116 EXPECT_EQ(points_test_api_->get_number_of_points(), 1); | |
117 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1), | |
118 start_time, test_point); | |
119 EXPECT_EQ(points_test_api_->get_number_of_points(), 2); | |
jdufault
2016/08/23 02:11:26
I don't think we specify it strictly, but typicall
sammiequon
2016/08/23 19:30:02
Done.
| |
120 // Verify adding a point 10 seconds later will clear all other points, since | |
121 // they are older than 5 seconds. | |
122 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(10), | |
123 start_time, test_point); | |
124 EXPECT_EQ(points_test_api_->get_number_of_points(), 1); | |
125 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1), | |
126 start_time, test_point); | |
127 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1), | |
128 start_time, test_point); | |
129 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1), | |
130 start_time, test_point); | |
131 // Verify adding 3 points one second apart each will add 3 points to the | |
jdufault
2016/08/23 02:11:26
This comment should go on line 125, before you add
sammiequon
2016/08/23 19:30:02
Done.
| |
132 // collection, since all 4 poitns are younger than 5 seconds. | |
133 EXPECT_EQ(points_test_api_->get_number_of_points(), 4); | |
134 // Verify adding 1 point three seconds later will remove 2 points which are | |
jdufault
2016/08/23 02:11:26
newline before each test "section" (ie, above each
sammiequon
2016/08/23 19:30:02
Done.
| |
135 // older than 5 seconds. | |
136 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(3), | |
137 start_time, test_point); | |
138 EXPECT_EQ(points_test_api_->get_number_of_points(), 3); | |
139 } | |
140 | |
141 // Test to ensure the class responsible for drawing the laser pointer receives | |
142 // points from mouse movements as expected. | |
143 TEST_F(LaserPointerModeTest, LaserPointerRenderer) { | |
144 // TODO(sammiequon): Update these tests once event generator with stylus | |
145 // events cl lands. | |
146 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40)); | |
147 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | |
148 mode_test_api_->OnEnable(); | |
149 // Verify enabling the mode will start with a single point at the current | |
jdufault
2016/08/23 02:11:26
Move comment up a line.
sammiequon
2016/08/23 19:30:02
Done.
| |
150 // location. | |
151 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | |
152 | |
153 GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66)); | |
154 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38)); | |
155 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | |
156 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | |
157 | |
158 EXPECT_EQ(5, mode_test_api_->laser_points().GetNumberOfPoints()); | |
159 | |
160 mode_test_api_->OnDisable(); | |
161 // Verify disabling the mode will clear any active points. | |
jdufault
2016/08/23 02:11:26
Move comment up a line
sammiequon
2016/08/23 19:30:02
Done.
| |
162 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | |
163 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | |
164 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | |
165 // Verify that the laser pointer does not add points while disabled. | |
jdufault
2016/08/23 02:11:26
Move comment up two lines, add a newline before it
sammiequon
2016/08/23 19:30:02
Done.
| |
166 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | |
167 | |
168 mode_test_api_->OnEnable(); | |
169 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | |
170 EXPECT_EQ(GetEventGenerator().current_location(), | |
171 mode_test_api_->laser_points().GetNewest().location); | |
172 } | |
173 } // namespace ash | |
OLD | NEW |