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