| 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" | 5 #include "ash/laser/laser_pointer_controller.h" |
| 6 #include "ash/laser/laser_pointer_controller_test_api.h" | 6 #include "ash/laser/laser_pointer_controller_test_api.h" |
| 7 #include "ash/laser/laser_pointer_view.h" | 7 #include "ash/laser/laser_pointer_view.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ui/events/test/event_generator.h" | 10 #include "ui/events/test/event_generator.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // Verify that the laser pointer does not get shown if points are not coming | 104 // Verify that the laser pointer does not get shown if points are not coming |
| 105 // from the stylus, even when enabled. | 105 // from the stylus, even when enabled. |
| 106 GetEventGenerator().ExitPenPointerMode(); | 106 GetEventGenerator().ExitPenPointerMode(); |
| 107 controller_test_api_.SetEnabled(true); | 107 controller_test_api_.SetEnabled(true); |
| 108 GetEventGenerator().PressTouch(); | 108 GetEventGenerator().PressTouch(); |
| 109 GetEventGenerator().MoveTouch(gfx::Point(10, 10)); | 109 GetEventGenerator().MoveTouch(gfx::Point(10, 10)); |
| 110 GetEventGenerator().MoveTouch(gfx::Point(11, 11)); | 110 GetEventGenerator().MoveTouch(gfx::Point(11, 11)); |
| 111 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | 111 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
| 112 GetEventGenerator().ReleaseTouch(); | 112 GetEventGenerator().ReleaseTouch(); |
| 113 } | 113 } |
| 114 |
| 115 // Test to ensure the class responsible for drawing the laser pointer handles |
| 116 // prediction as expected when it receives points from stylus movements. |
| 117 TEST_F(LaserPointerControllerTest, LaserPointerPrediction) { |
| 118 LaserPointerControllerTestApi controller_test_api_(controller_.get()); |
| 119 |
| 120 controller_test_api_.SetEnabled(true); |
| 121 // The laser pointer mode only works with stylus. |
| 122 GetEventGenerator().EnterPenPointerMode(); |
| 123 GetEventGenerator().PressTouch(); |
| 124 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); |
| 125 |
| 126 EXPECT_EQ(1, controller_test_api_.laser_points().GetNumberOfPoints()); |
| 127 // Initial press event shouldn't generate any predicted points as there's no |
| 128 // history to use for prediction. |
| 129 EXPECT_EQ(0, |
| 130 controller_test_api_.predicted_laser_points().GetNumberOfPoints()); |
| 131 |
| 132 // Verify dragging the stylus 3 times will add some predicted points. |
| 133 GetEventGenerator().MoveTouch(gfx::Point(10, 10)); |
| 134 GetEventGenerator().MoveTouch(gfx::Point(20, 20)); |
| 135 GetEventGenerator().MoveTouch(gfx::Point(30, 30)); |
| 136 EXPECT_NE(0, |
| 137 controller_test_api_.predicted_laser_points().GetNumberOfPoints()); |
| 138 // Verify predicted points are in the right direction. |
| 139 for (const auto& point : |
| 140 controller_test_api_.predicted_laser_points().laser_points()) { |
| 141 EXPECT_LT(30, point.location.x()); |
| 142 EXPECT_LT(30, point.location.y()); |
| 143 } |
| 144 |
| 145 // Verify releasing the stylus removes predicted points. |
| 146 GetEventGenerator().ReleaseTouch(); |
| 147 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); |
| 148 EXPECT_TRUE(controller_test_api_.IsFadingAway()); |
| 149 EXPECT_EQ(0, |
| 150 controller_test_api_.predicted_laser_points().GetNumberOfPoints()); |
| 151 } |
| 152 |
| 114 } // namespace ash | 153 } // namespace ash |
| OLD | NEW |