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 |
19 class LaserPointerPointsTest : public test::AshTestBase { | 18 class LaserPointerPointsTest : public test::AshTestBase { |
20 public: | 19 public: |
21 LaserPointerPointsTest() | 20 LaserPointerPointsTest() |
22 : points_(base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)), | 21 : points_(base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)), |
23 points_test_api_(base::MakeUnique<LaserPointerPoints>( | 22 points_test_api_(base::MakeUnique<LaserPointerPoints>( |
24 base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds))) {} | 23 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_; | 29 LaserPointerPointsTestApi points_test_api_; |
39 | 30 |
40 private: | 31 private: |
41 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); | 32 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); |
42 }; | 33 }; |
43 | 34 |
44 class LaserPointerModeTest : public test::AshTestBase { | 35 class LaserPointerControllerTest : public test::AshTestBase { |
45 public: | 36 public: |
46 LaserPointerModeTest() {} | 37 LaserPointerControllerTest() {} |
47 ~LaserPointerModeTest() override {} | 38 ~LaserPointerControllerTest() override {} |
48 | 39 |
49 void SetUp() override { | 40 void SetUp() override { |
50 AshTestBase::SetUp(); | 41 AshTestBase::SetUp(); |
51 WmShell::Get()->SetPaletteDelegateForTesting( | 42 controller_test_api_.reset(new LaserPointerControllerTestApi( |
52 base::MakeUnique<TestPaletteDelegate>()); | 43 base::WrapUnique<LaserPointerController>( |
53 mode_test_api_.reset(new LaserPointerModeTestApi( | 44 new LaserPointerController()))); |
54 base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr)))); | |
55 } | 45 } |
56 | 46 |
57 void TearDown() override { | 47 void TearDown() override { |
58 // This needs to be called first to remove the pointer watcher otherwise | 48 // 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 | 49 // shell instance gets torn down. |
60 // alive. | 50 controller_test_api_.reset(); |
61 mode_test_api_.reset(); | |
62 AshTestBase::TearDown(); | 51 AshTestBase::TearDown(); |
63 } | 52 } |
64 | 53 |
65 protected: | 54 protected: |
66 std::unique_ptr<LaserPointerModeTestApi> mode_test_api_; | 55 std::unique_ptr<LaserPointerControllerTestApi> controller_test_api_; |
67 | 56 |
68 private: | 57 private: |
69 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest); | 58 DISALLOW_COPY_AND_ASSIGN(LaserPointerControllerTest); |
70 }; | 59 }; |
71 | 60 |
72 } // namespace | 61 } // namespace |
73 | 62 |
74 // Tests that the laser pointers internal collection handles receiving points | 63 // Tests that the laser pointers internal collection handles receiving points |
75 // and that the functions are returning the expected output. | 64 // and that the functions are returning the expected output. |
76 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { | 65 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { |
77 EXPECT_TRUE(points_.IsEmpty()); | 66 EXPECT_TRUE(points_.IsEmpty()); |
78 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox()); | 67 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox()); |
79 const gfx::Point left(1, 1); | 68 const gfx::Point left(1, 1); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 EXPECT_EQ(4, points_test_api_.GetNumberOfPoints()); | 131 EXPECT_EQ(4, points_test_api_.GetNumberOfPoints()); |
143 | 132 |
144 // Verify adding 1 point three seconds later will remove 2 points which are | 133 // Verify adding 1 point three seconds later will remove 2 points which are |
145 // older than 5 seconds. | 134 // older than 5 seconds. |
146 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); | 135 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); |
147 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); | 136 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); |
148 } | 137 } |
149 | 138 |
150 // Test to ensure the class responsible for drawing the laser pointer receives | 139 // Test to ensure the class responsible for drawing the laser pointer receives |
151 // points from mouse movements as expected. | 140 // points from mouse movements as expected. |
152 TEST_F(LaserPointerModeTest, LaserPointerRenderer) { | 141 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) { |
153 // The laser pointer mode only works with stylus. | 142 // The laser pointer mode only works with stylus. |
143 | |
144 // When disabled the laser pointer view object should be a null pointer. | |
154 GetEventGenerator().EnterPenPointerMode(); | 145 GetEventGenerator().EnterPenPointerMode(); |
155 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40)); | 146 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40)); |
156 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | 147 EXPECT_EQ(nullptr, controller_test_api_->laser_pointer_view()); |
jdufault
2016/09/12 21:10:12
Maybe add an extra function to controller_test_api
sammiequon
2016/09/13 01:09:56
Done.
| |
157 | 148 |
158 // Verify enabling the mode will start with a single point at the current | 149 // Verify that by enabling the mode, the laser pointer view object will not be |
159 // location. | 150 // a null pointer . |
160 mode_test_api_->OnEnable(); | 151 controller_test_api_->OnEnable(); |
161 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | 152 EXPECT_NE(nullptr, controller_test_api_->laser_pointer_view()); |
jdufault
2016/09/12 21:10:12
Why does the view get created immediately after en
sammiequon
2016/09/13 01:09:56
Done.
| |
162 | 153 |
163 // Verify moving the mouse 4 times will add 4 more points. | 154 // Verify moving the mouse 4 times will add no more points. |
164 GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66)); | 155 GetEventGenerator().MoveMouseToInHost(gfx::Point(29, 66)); |
165 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38)); | 156 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38)); |
166 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | 157 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
167 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | 158 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
168 EXPECT_EQ(5, mode_test_api_->laser_points().GetNumberOfPoints()); | 159 EXPECT_EQ(0, controller_test_api_->laser_points().GetNumberOfPoints()); |
169 | 160 |
170 // Verify disabling the mode will clear any active points. | 161 // Verify pressing the mouse will add a points. |
jdufault
2016/09/12 21:10:12
Replace "mouse" with "stylus" in these comments.
sammiequon
2016/09/13 01:09:56
Done.
| |
171 mode_test_api_->OnDisable(); | 162 GetEventGenerator().PressLeftButton(); |
172 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | 163 EXPECT_EQ(1, controller_test_api_->laser_points().GetNumberOfPoints()); |
164 | |
165 // Verify dragging the mouse 2 times will add 2 more points. | |
166 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | |
167 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | |
168 EXPECT_EQ(3, controller_test_api_->laser_points().GetNumberOfPoints()); | |
169 | |
170 // Verify releasing the mouse will remove all points. | |
171 GetEventGenerator().ReleaseLeftButton(); | |
172 EXPECT_EQ(0, controller_test_api_->laser_points().GetNumberOfPoints()); | |
173 | |
174 // Verify that by disabling the mode, the laser pointer view object will be a | |
175 // null pointer, thus clearing any active points. | |
176 controller_test_api_->OnDisable(); | |
177 EXPECT_EQ(nullptr, controller_test_api_->laser_pointer_view()); | |
173 | 178 |
174 // Verify that the laser pointer does not add points while disabled. | 179 // Verify that the laser pointer does not add points while disabled. |
180 GetEventGenerator().PressLeftButton(); | |
175 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | 181 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
182 GetEventGenerator().ReleaseLeftButton(); | |
176 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | 183 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
177 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | 184 EXPECT_EQ(nullptr, controller_test_api_->laser_pointer_view()); |
178 | 185 |
179 // Verify that the laser pointer adds the last seen stylus point when enabled | 186 // Verify that the laser pointer adds the last seen stylus point when enabled |
180 // even when stylus mode is disabled. | 187 // even when stylus mode is disabled. |
181 GetEventGenerator().ExitPenPointerMode(); | 188 GetEventGenerator().ExitPenPointerMode(); |
182 mode_test_api_->OnEnable(); | 189 controller_test_api_->OnEnable(); |
183 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | 190 EXPECT_NE(nullptr, controller_test_api_->laser_pointer_view()); |
184 EXPECT_EQ(GetEventGenerator().current_location(), | 191 EXPECT_EQ(0, controller_test_api_->laser_points().GetNumberOfPoints()); |
185 mode_test_api_->laser_points().GetNewest().location); | 192 |
186 // Verify that the laser pointer does not add additional points when move | 193 // Verify that the laser pointer does not add additional points when move |
187 // events are not from stylus. | 194 // events are not from stylus. |
195 GetEventGenerator().PressLeftButton(); | |
188 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | 196 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
189 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | 197 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
190 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | 198 EXPECT_EQ(0, controller_test_api_->laser_points().GetNumberOfPoints()); |
199 GetEventGenerator().ReleaseLeftButton(); | |
191 } | 200 } |
192 } // namespace ash | 201 } // namespace ash |
OLD | NEW |