OLD | NEW |
---|---|
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/common/system/chromeos/palette/tools/laser_pointer_mode.h" | 5 #include "ash/laser/laser_pointer_controller.h" |
6 #include "ash/common/system/chromeos/palette/tools/laser_pointer_mode_test_api.h " | 6 #include "ash/laser/laser_pointer_controller_test_api.h" |
7 #include "ash/common/system/chromeos/palette/tools/laser_pointer_points_test_api .h" | 7 #include "ash/laser/laser_pointer_points_test_api.h" |
8 #include "ash/common/system/chromeos/palette/tools/laser_pointer_view.h" | 8 #include "ash/laser/laser_pointer_view.h" |
9 #include "ash/common/test/test_palette_delegate.h" | 9 #include "ash/shell.h" |
10 #include "ash/common/wm_shell.h" | |
11 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
12 #include "ui/events/test/event_generator.h" | 11 #include "ui/events/test/event_generator.h" |
13 | 12 |
14 namespace ash { | 13 namespace ash { |
15 namespace { | 14 namespace { |
16 | 15 |
17 const int kTestPointsLifetimeSeconds = 5; | 16 const int kTestPointsLifetimeSeconds = 5; |
18 | 17 |
18 // TODO(sammiequon): Move this test into a different file. See | |
19 // http://crbug.com/646953. | |
19 class LaserPointerPointsTest : public test::AshTestBase { | 20 class LaserPointerPointsTest : public test::AshTestBase { |
20 public: | 21 public: |
21 LaserPointerPointsTest() | 22 LaserPointerPointsTest() |
22 : points_(base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)), | 23 : points_(base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)) {} |
23 points_test_api_(base::MakeUnique<LaserPointerPoints>( | |
24 base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds))) {} | |
25 | 24 |
26 ~LaserPointerPointsTest() override {} | 25 ~LaserPointerPointsTest() override {} |
27 | 26 |
28 void SetUp() override { | |
29 AshTestBase::SetUp(); | |
30 // Add a test delegate so that laser pointer mode does not complain when | |
31 // being destroyed. | |
32 WmShell::Get()->SetPaletteDelegateForTesting( | |
33 base::MakeUnique<TestPaletteDelegate>()); | |
34 } | |
35 | |
36 protected: | 27 protected: |
37 LaserPointerPoints points_; | 28 LaserPointerPoints points_; |
38 LaserPointerPointsTestApi points_test_api_; | |
39 | 29 |
40 private: | 30 private: |
41 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); | 31 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); |
42 }; | 32 }; |
43 | 33 |
44 class LaserPointerModeTest : public test::AshTestBase { | 34 class LaserPointerControllerTest : public test::AshTestBase { |
45 public: | 35 public: |
46 LaserPointerModeTest() {} | 36 LaserPointerControllerTest() {} |
47 ~LaserPointerModeTest() override {} | 37 ~LaserPointerControllerTest() override {} |
48 | 38 |
49 void SetUp() override { | 39 void SetUp() override { |
50 AshTestBase::SetUp(); | 40 AshTestBase::SetUp(); |
51 WmShell::Get()->SetPaletteDelegateForTesting( | 41 controller_.reset(new LaserPointerController()); |
52 base::MakeUnique<TestPaletteDelegate>()); | |
53 mode_test_api_.reset(new LaserPointerModeTestApi( | |
54 base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr)))); | |
55 } | 42 } |
56 | 43 |
57 void TearDown() override { | 44 void TearDown() override { |
58 // This needs to be called first to remove the pointer watcher otherwise | 45 // This needs to be called first to remove the event handler before the |
59 // tear down will complain about there being more than zero pointer watcher | 46 // shell instance gets torn down. |
60 // alive. | 47 controller_.reset(); |
61 mode_test_api_.reset(); | |
62 AshTestBase::TearDown(); | 48 AshTestBase::TearDown(); |
63 } | 49 } |
64 | 50 |
65 protected: | 51 protected: |
66 std::unique_ptr<LaserPointerModeTestApi> mode_test_api_; | 52 std::unique_ptr<LaserPointerController> controller_; |
67 | 53 |
68 private: | 54 private: |
69 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest); | 55 DISALLOW_COPY_AND_ASSIGN(LaserPointerControllerTest); |
70 }; | 56 }; |
71 | 57 |
72 } // namespace | 58 } // namespace |
73 | 59 |
74 // Tests that the laser pointers internal collection handles receiving points | 60 // Tests that the laser pointers internal collection handles receiving points |
75 // and that the functions are returning the expected output. | 61 // and that the functions are returning the expected output. |
76 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { | 62 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { |
77 EXPECT_TRUE(points_.IsEmpty()); | 63 EXPECT_TRUE(points_.IsEmpty()); |
78 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox()); | 64 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox()); |
79 const gfx::Point left(1, 1); | 65 const gfx::Point left(1, 1); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 points_.GetBoundingBox()); | 101 points_.GetBoundingBox()); |
116 | 102 |
117 // Verify clearing works. | 103 // Verify clearing works. |
118 points_.Clear(); | 104 points_.Clear(); |
119 EXPECT_TRUE(points_.IsEmpty()); | 105 EXPECT_TRUE(points_.IsEmpty()); |
120 } | 106 } |
121 | 107 |
122 // Test the laser pointer points collection to verify that old points are | 108 // Test the laser pointer points collection to verify that old points are |
123 // removed. | 109 // removed. |
124 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) { | 110 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) { |
111 LaserPointerPointsTestApi points_test_api_(&points_); | |
jdufault
2016/09/16 19:58:41
newline below this to separate init section from t
sammiequon
2016/09/16 20:37:40
Done.
| |
125 // When a point older than kTestPointsLifetime (5 seconds) is added, it | 112 // When a point older than kTestPointsLifetime (5 seconds) is added, it |
126 // should get removed. | 113 // should get removed. |
127 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 114 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
128 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); | 115 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); |
129 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 116 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
130 EXPECT_EQ(2, points_test_api_.GetNumberOfPoints()); | 117 EXPECT_EQ(2, points_test_api_.GetNumberOfPoints()); |
131 | 118 |
132 // Verify adding a point 10 seconds later will clear all other points, since | 119 // Verify adding a point 10 seconds later will clear all other points, since |
133 // they are older than 5 seconds. | 120 // they are older than 5 seconds. |
134 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(10)); | 121 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(10)); |
135 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); | 122 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); |
136 | 123 |
137 // Verify adding 3 points one second apart each will add 3 points to the | 124 // Verify adding 3 points one second apart each will add 3 points to the |
138 // collection, since all 4 poitns are younger than 5 seconds. | 125 // collection, since all 4 poitns are younger than 5 seconds. |
139 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 126 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
140 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 127 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
141 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 128 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
142 EXPECT_EQ(4, points_test_api_.GetNumberOfPoints()); | 129 EXPECT_EQ(4, points_test_api_.GetNumberOfPoints()); |
143 | 130 |
144 // Verify adding 1 point three seconds later will remove 2 points which are | 131 // Verify adding 1 point three seconds later will remove 2 points which are |
145 // older than 5 seconds. | 132 // older than 5 seconds. |
146 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); | 133 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); |
147 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); | 134 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); |
148 } | 135 } |
149 | 136 |
150 // Test to ensure the class responsible for drawing the laser pointer receives | 137 // Test to ensure the class responsible for drawing the laser pointer receives |
151 // points from mouse movements as expected. | 138 // points from stylus movements as expected. |
152 TEST_F(LaserPointerModeTest, LaserPointerRenderer) { | 139 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) { |
140 LaserPointerControllerTestApi controller_test_api_(controller_.get()); | |
141 | |
153 // The laser pointer mode only works with stylus. | 142 // The laser pointer mode only works with stylus. |
154 GetEventGenerator().EnterPenPointerMode(); | 143 GetEventGenerator().EnterPenPointerMode(); |
155 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40)); | |
156 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | |
157 | 144 |
158 // Verify enabling the mode will start with a single point at the current | 145 // When disabled the laser pointer should not be showing. |
159 // location. | 146 GetEventGenerator().MoveMouseToInHost(gfx::Point(1, 1)); |
160 mode_test_api_->OnEnable(); | 147 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
161 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | |
162 | 148 |
163 // Verify moving the mouse 4 times will add 4 more points. | 149 // Verify that by enabling the mode, the laser pointer should still not be |
164 GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66)); | 150 // showing. |
165 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38)); | 151 controller_test_api_.SetEnabled(true); |
166 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | 152 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
167 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | |
168 EXPECT_EQ(5, mode_test_api_->laser_points().GetNumberOfPoints()); | |
169 | 153 |
170 // Verify disabling the mode will clear any active points. | 154 // Verify moving the stylus 4 times will the laser pointer should still not be |
jdufault
2016/09/16 19:58:41
Please reword this comment.
sammiequon
2016/09/16 20:37:40
Done.
| |
171 mode_test_api_->OnDisable(); | 155 // showing. |
172 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | 156 GetEventGenerator().MoveMouseToInHost(gfx::Point(2, 2)); |
157 GetEventGenerator().MoveMouseToInHost(gfx::Point(3, 3)); | |
158 GetEventGenerator().MoveMouseToInHost(gfx::Point(4, 4)); | |
159 GetEventGenerator().MoveMouseToInHost(gfx::Point(5, 5)); | |
160 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
161 | |
162 // Verify pressing the stylus will add a point, and the laser pointer should | |
jdufault
2016/09/16 19:58:41
The comment and the code are in different orders.
sammiequon
2016/09/16 20:37:40
Done.
| |
163 // be shown. | |
164 GetEventGenerator().PressLeftButton(); | |
165 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); | |
166 EXPECT_EQ(1, controller_test_api_.laser_points().GetNumberOfPoints()); | |
167 | |
168 // Verify dragging the stylus 2 times will add 2 more points. | |
169 GetEventGenerator().MoveMouseToInHost(gfx::Point(6, 6)); | |
170 GetEventGenerator().MoveMouseToInHost(gfx::Point(7, 7)); | |
171 EXPECT_EQ(3, controller_test_api_.laser_points().GetNumberOfPoints()); | |
172 | |
173 // Verify by releasing the stylus, the laser pointer will not be shown. | |
jdufault
2016/09/16 19:58:41
// Verify that releasing the stylus hides the lase
sammiequon
2016/09/16 20:37:40
Done.
| |
174 GetEventGenerator().ReleaseLeftButton(); | |
175 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
176 | |
177 // Verify that by disabling the mode, the laser pointer view not be shown. | |
jdufault
2016/09/16 19:58:41
// Verify that disabling the mode turns hides the
sammiequon
2016/09/16 20:37:40
Done.
| |
178 controller_test_api_.SetEnabled(false); | |
jdufault
2016/09/16 19:58:41
Shouldn't this test happen after the laser point i
sammiequon
2016/09/16 20:37:40
Yes, I don't think its possible to disable the las
jdufault
2016/09/16 21:59:26
Keep the stylus on the screen, then use your finge
| |
179 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
173 | 180 |
174 // Verify that the laser pointer does not add points while disabled. | 181 // Verify that the laser pointer does not add points while disabled. |
175 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | 182 GetEventGenerator().PressLeftButton(); |
176 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | 183 GetEventGenerator().MoveMouseToInHost(gfx::Point(8, 8)); |
177 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | 184 GetEventGenerator().ReleaseLeftButton(); |
185 GetEventGenerator().MoveMouseToInHost(gfx::Point(9, 9)); | |
186 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
178 | 187 |
179 // Verify that the laser pointer adds the last seen stylus point when enabled | 188 // Verify that the laser pointer does not get shown if points are not coming |
180 // even when stylus mode is disabled. | 189 // from the stylus, even when enabled. |
181 GetEventGenerator().ExitPenPointerMode(); | 190 GetEventGenerator().ExitPenPointerMode(); |
182 mode_test_api_->OnEnable(); | 191 controller_test_api_.SetEnabled(true); |
183 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | 192 GetEventGenerator().PressLeftButton(); |
184 EXPECT_EQ(GetEventGenerator().current_location(), | 193 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 10)); |
185 mode_test_api_->laser_points().GetNewest().location); | 194 GetEventGenerator().MoveMouseToInHost(gfx::Point(11, 11)); |
186 // Verify that the laser pointer does not add additional points when move | 195 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
187 // events are not from stylus. | 196 GetEventGenerator().ReleaseLeftButton(); |
188 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | |
189 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | |
190 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | |
191 } | 197 } |
192 } // namespace ash | 198 } // namespace ash |
OLD | NEW |