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

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 8 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 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_mode_testapi.h"
7 #include "ash/common/system/chromeos/palette/tools/laser_pointer_points_testapi. 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 kTestPointsLifetimeSeconds = 5;
17
18 class LaserPointerPointsTest : public test::AshTestBase {
19 public:
20 LaserPointerPointsTest() {}
21 ~LaserPointerPointsTest() override {}
22
23 void SetUp() override {
24 AshTestBase::SetUp();
25 points_.reset(new LaserPointerPoints(
26 base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)));
27 points_test_api_.reset(new LaserPointerPointsTestApi(
28 base::WrapUnique<LaserPointerPoints>(new LaserPointerPoints(
29 base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)))));
30 }
31
32 void TearDown() override { AshTestBase::TearDown(); }
33
34 protected:
35 std::unique_ptr<LaserPointerPoints> points_;
36 std::unique_ptr<LaserPointerPointsTestApi> points_test_api_;
37
38 private:
39 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest);
40 };
41
42 class LaserPointerModeTest : public test::AshTestBase {
43 public:
44 LaserPointerModeTest() {}
45 ~LaserPointerModeTest() override {}
46
47 void SetUp() override {
48 AshTestBase::SetUp();
49 mode_test_api_.reset(new LaserPointerModeTestApi(
50 base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr))));
51 }
52
53 void TearDown() override {
54 // This needs to be called first to remove the pointer watcher otherwise
55 // tear down will complain about there being more than zero pointer watcher
56 // alive.
57 mode_test_api_.reset();
58 AshTestBase::TearDown();
59 }
60
61 protected:
62 std::unique_ptr<LaserPointerModeTestApi> mode_test_api_;
63
64 private:
65 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest);
66 };
67 } // namespace
jdufault 2016/08/23 21:52:05 newline between end of class and end of namespace
sammiequon 2016/08/24 00:04:05 Done.
68
69 // Tests that the laser pointers internal collection handles receiving points
70 // and that the functions are returning the expected output.
71 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) {
72 EXPECT_TRUE(points_->IsEmpty());
73 EXPECT_EQ(gfx::Rect(), points_->GetBoundingBox());
74 gfx::Point left(1, 1);
75 gfx::Point bottom(1, 9);
76 gfx::Point top_right(30, 0);
77 gfx::Point last(2, 2);
78 points_->AddPoint(left);
79 EXPECT_EQ(gfx::Rect(1, 1, 0, 0), points_->GetBoundingBox());
80
81 // Should be the new bottom of the bounding box.
82 points_->AddPoint(bottom);
83 EXPECT_EQ(gfx::Rect(1, 1, 0, bottom.y() - 1), points_->GetBoundingBox());
84
85 // Should be the new top and right of the bounding box.
86 points_->AddPoint(top_right);
87 EXPECT_EQ(3, points_->GetNumberOfPoints());
88 EXPECT_FALSE(points_->IsEmpty());
89 EXPECT_EQ(gfx::Rect(left.x(), top_right.y(), top_right.x() - left.x(),
90 bottom.y() - top_right.y()),
91 points_->GetBoundingBox());
92
93 // Should not expand bounding box.
94 points_->AddPoint(last);
95 EXPECT_EQ(gfx::Rect(left.x(), top_right.y(), top_right.x() - left.x(),
96 bottom.y() - top_right.y()),
97 points_->GetBoundingBox());
98
99 // Points should be sorted in the order they are added.
100 EXPECT_EQ(left, points_->GetOldest().location);
101 EXPECT_EQ(last, points_->GetNewest().location);
102
103 // Add a new point which will expand the bounding box.
104 gfx::Point new_left_bottom(0, 40);
105 points_->AddPoint(new_left_bottom);
106 EXPECT_EQ(5, points_->GetNumberOfPoints());
107 EXPECT_EQ(gfx::Rect(new_left_bottom.x(), top_right.y(),
108 top_right.x() - new_left_bottom.x(),
109 new_left_bottom.y() - top_right.y()),
110 points_->GetBoundingBox());
111
112 // Verify clearing works.
113 points_->Clear();
114 EXPECT_TRUE(points_->IsEmpty());
115 }
116
117 // Test the laser pointer points collection to verify that old points are
118 // removed.
119 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) {
120 // When a point older than kTestPointsLifetime (5 seconds) is added, it
121 // should get removed.
122 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1));
123 EXPECT_EQ(1, points_test_api_->GetNumberOfPoints());
124 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1));
125 EXPECT_EQ(2, points_test_api_->GetNumberOfPoints());
126
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 poitns are younger than 5 seconds.
134 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1));
135 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1));
136 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(1));
137 EXPECT_EQ(4, points_test_api_->GetNumberOfPoints());
138
139 // Verify adding 1 point three seconds later will remove 2 points which are
jdufault 2016/08/23 21:52:05 Awesome! These tests read much better.
sammiequon 2016/08/24 00:04:05 =D
140 // older than 5 seconds.
141 points_test_api_->MoveForwardInTime(base::TimeDelta::FromSeconds(3));
142 EXPECT_EQ(3, points_test_api_->GetNumberOfPoints());
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, mode_test_api_->laser_points().GetNumberOfPoints());
152
153 // Verify enabling the mode will start with a single point at the current
154 // location.
155 mode_test_api_->OnEnable();
156 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints());
157
158 // Verify moving the mouse 4 times will add 4 more points.
159 GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66));
160 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38));
161 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
162 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
163 EXPECT_EQ(5, mode_test_api_->laser_points().GetNumberOfPoints());
164
165 // Verify disabling the mode will clear any active points.
166 mode_test_api_->OnDisable();
167 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints());
168
169 // Verify that the laser pointer does not add points while disabled.
170 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
171 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
172 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints());
173
174 mode_test_api_->OnEnable();
175 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints());
176 EXPECT_EQ(GetEventGenerator().current_location(),
177 mode_test_api_->laser_points().GetNewest().location);
178 }
179 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698