Chromium Code Reviews| 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/laser/laser_pointer_controller.h" | |
| 6 #include "ash/laser/laser_pointer_controller_test_api.h" | |
| 7 #include "ash/laser/laser_pointer_points_test_api.h" | 5 #include "ash/laser/laser_pointer_points_test_api.h" |
|
James Cook
2017/01/19 22:10:16
nit: #include the file under test (laser_pointer_p
sammiequon
2017/01/20 00:00:38
Done.
| |
| 8 #include "ash/laser/laser_pointer_view.h" | |
| 9 #include "ash/shell.h" | |
| 10 #include "ash/test/ash_test_base.h" | 6 #include "ash/test/ash_test_base.h" |
| 11 #include "ui/events/test/event_generator.h" | 7 #include "ui/events/test/event_generator.h" |
| 12 | 8 |
| 13 namespace ash { | 9 namespace ash { |
| 14 namespace { | 10 namespace { |
| 15 | 11 |
| 16 const int kTestPointsLifetimeSeconds = 5; | 12 const int kTestPointsLifetimeSeconds = 5; |
| 17 | 13 |
| 18 // TODO(sammiequon): Move this test into a different file. See | |
| 19 // http://crbug.com/646953. | |
| 20 class LaserPointerPointsTest : public test::AshTestBase { | 14 class LaserPointerPointsTest : public test::AshTestBase { |
| 21 public: | 15 public: |
| 22 LaserPointerPointsTest() | 16 LaserPointerPointsTest() |
| 23 : points_(base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)) {} | 17 : points_(base::TimeDelta::FromSeconds(kTestPointsLifetimeSeconds)) {} |
| 24 | 18 |
| 25 ~LaserPointerPointsTest() override {} | 19 ~LaserPointerPointsTest() override {} |
| 26 | 20 |
| 27 protected: | 21 protected: |
| 28 LaserPointerPoints points_; | 22 LaserPointerPoints points_; |
| 29 | 23 |
| 30 private: | 24 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); | 25 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); |
| 32 }; | 26 }; |
| 33 | 27 |
| 34 class LaserPointerControllerTest : public test::AshTestBase { | |
| 35 public: | |
| 36 LaserPointerControllerTest() {} | |
| 37 ~LaserPointerControllerTest() override {} | |
| 38 | |
| 39 void SetUp() override { | |
| 40 AshTestBase::SetUp(); | |
| 41 controller_.reset(new LaserPointerController()); | |
| 42 } | |
| 43 | |
| 44 void TearDown() override { | |
| 45 // This needs to be called first to remove the event handler before the | |
| 46 // shell instance gets torn down. | |
| 47 controller_.reset(); | |
| 48 AshTestBase::TearDown(); | |
| 49 } | |
| 50 | |
| 51 protected: | |
| 52 std::unique_ptr<LaserPointerController> controller_; | |
| 53 | |
| 54 private: | |
| 55 DISALLOW_COPY_AND_ASSIGN(LaserPointerControllerTest); | |
| 56 }; | |
| 57 | |
| 58 } // namespace | 28 } // namespace |
| 59 | 29 |
| 60 // Tests that the laser pointers internal collection handles receiving points | 30 // Tests that the laser pointers internal collection handles receiving points |
| 61 // and that the functions are returning the expected output. | 31 // and that the functions are returning the expected output. |
| 62 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { | 32 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { |
| 63 EXPECT_TRUE(points_.IsEmpty()); | 33 EXPECT_TRUE(points_.IsEmpty()); |
| 64 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox()); | 34 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox()); |
| 65 const gfx::Point left(1, 1); | 35 const gfx::Point left(1, 1); |
| 66 const gfx::Point bottom(1, 9); | 36 const gfx::Point bottom(1, 9); |
| 67 const gfx::Point top_right(30, 0); | 37 const gfx::Point top_right(30, 0); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 EXPECT_FLOAT_EQ(0.6, points_test_api_.GetPointAtIndex(0).age); | 109 EXPECT_FLOAT_EQ(0.6, points_test_api_.GetPointAtIndex(0).age); |
| 140 EXPECT_FLOAT_EQ(0.4, points_test_api_.GetPointAtIndex(1).age); | 110 EXPECT_FLOAT_EQ(0.4, points_test_api_.GetPointAtIndex(1).age); |
| 141 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(2).age); | 111 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(2).age); |
| 142 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(3).age); | 112 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(3).age); |
| 143 | 113 |
| 144 // Verify adding 1 point three seconds later will remove 2 points which are | 114 // Verify adding 1 point three seconds later will remove 2 points which are |
| 145 // older than 5 seconds. | 115 // older than 5 seconds. |
| 146 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); | 116 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); |
| 147 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); | 117 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); |
| 148 } | 118 } |
| 149 | |
| 150 // Test to ensure the class responsible for drawing the laser pointer receives | |
| 151 // points from stylus movements as expected. | |
| 152 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) { | |
| 153 LaserPointerControllerTestApi controller_test_api_(controller_.get()); | |
| 154 | |
| 155 // The laser pointer mode only works with stylus. | |
| 156 GetEventGenerator().EnterPenPointerMode(); | |
| 157 | |
| 158 // When disabled the laser pointer should not be showing. | |
| 159 GetEventGenerator().MoveTouch(gfx::Point(1, 1)); | |
| 160 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
| 161 | |
| 162 // Verify that by enabling the mode, the laser pointer should still not be | |
| 163 // showing. | |
| 164 controller_test_api_.SetEnabled(true); | |
| 165 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
| 166 | |
| 167 // Verify moving the stylus 4 times will not display the laser pointer. | |
| 168 GetEventGenerator().MoveTouch(gfx::Point(2, 2)); | |
| 169 GetEventGenerator().MoveTouch(gfx::Point(3, 3)); | |
| 170 GetEventGenerator().MoveTouch(gfx::Point(4, 4)); | |
| 171 GetEventGenerator().MoveTouch(gfx::Point(5, 5)); | |
| 172 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
| 173 | |
| 174 // Verify pressing the stylus will show the laser pointer and add a point but | |
| 175 // will not activate fading out. | |
| 176 GetEventGenerator().PressTouch(); | |
| 177 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); | |
| 178 EXPECT_FALSE(controller_test_api_.IsFadingAway()); | |
| 179 EXPECT_EQ(1, controller_test_api_.laser_points().GetNumberOfPoints()); | |
| 180 | |
| 181 // Verify dragging the stylus 2 times will add 2 more points. | |
| 182 GetEventGenerator().MoveTouch(gfx::Point(6, 6)); | |
| 183 GetEventGenerator().MoveTouch(gfx::Point(7, 7)); | |
| 184 EXPECT_EQ(3, controller_test_api_.laser_points().GetNumberOfPoints()); | |
| 185 | |
| 186 // Verify releasing the stylus still shows the laser pointer, which is fading | |
| 187 // away. | |
| 188 GetEventGenerator().ReleaseTouch(); | |
| 189 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); | |
| 190 EXPECT_TRUE(controller_test_api_.IsFadingAway()); | |
| 191 | |
| 192 // Verify that disabling the mode does not display the laser pointer. | |
| 193 controller_test_api_.SetEnabled(false); | |
| 194 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
| 195 | |
| 196 // Verify that disabling the mode while laser pointer is displayed does not | |
| 197 // display the laser pointer. | |
| 198 controller_test_api_.SetIsFadingAway(false); | |
| 199 controller_test_api_.SetEnabled(true); | |
| 200 GetEventGenerator().PressTouch(); | |
| 201 GetEventGenerator().MoveTouch(gfx::Point(6, 6)); | |
| 202 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); | |
| 203 controller_test_api_.SetEnabled(false); | |
| 204 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
| 205 | |
| 206 // Verify that the laser pointer does not add points while disabled. | |
| 207 GetEventGenerator().PressTouch(); | |
| 208 GetEventGenerator().MoveTouch(gfx::Point(8, 8)); | |
| 209 GetEventGenerator().ReleaseTouch(); | |
| 210 GetEventGenerator().MoveTouch(gfx::Point(9, 9)); | |
| 211 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
| 212 | |
| 213 // Verify that the laser pointer does not get shown if points are not coming | |
| 214 // from the stylus, even when enabled. | |
| 215 GetEventGenerator().ExitPenPointerMode(); | |
| 216 controller_test_api_.SetEnabled(true); | |
| 217 GetEventGenerator().PressTouch(); | |
| 218 GetEventGenerator().MoveTouch(gfx::Point(10, 10)); | |
| 219 GetEventGenerator().MoveTouch(gfx::Point(11, 11)); | |
| 220 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | |
| 221 GetEventGenerator().ReleaseTouch(); | |
| 222 } | |
| 223 } // namespace ash | 119 } // namespace ash |
| OLD | NEW |