| 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_points_test_api.h" | 7 #include "ash/laser/laser_pointer_points_test_api.h" |
| 8 #include "ash/laser/laser_pointer_view.h" | 8 #include "ash/laser/laser_pointer_view.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 points_.Clear(); | 104 points_.Clear(); |
| 105 EXPECT_TRUE(points_.IsEmpty()); | 105 EXPECT_TRUE(points_.IsEmpty()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // 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 |
| 109 // removed. | 109 // removed. |
| 110 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) { | 110 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) { |
| 111 LaserPointerPointsTestApi points_test_api_(&points_); | 111 LaserPointerPointsTestApi points_test_api_(&points_); |
| 112 | 112 |
| 113 // When a point older than kTestPointsLifetime (5 seconds) is added, it | 113 // When a point older than kTestPointsLifetime (5 seconds) is added, it |
| 114 // should get removed. | 114 // should get removed. The age of the point is a number between 0.0 and 1.0, |
| 115 // with 0.0 specifying a newly added point and 1.0 specifying the age of a |
| 116 // point added |kTestPointsLifetime| ago. |
| 115 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 117 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
| 116 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); | 118 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); |
| 119 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(0).age); |
| 120 |
| 121 // Verify when we move forward in time by one second, the age of the last |
| 122 // point, added one second ago is 1 / |kTestPointsLifetime|. |
| 117 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 123 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
| 118 EXPECT_EQ(2, points_test_api_.GetNumberOfPoints()); | 124 EXPECT_EQ(2, points_test_api_.GetNumberOfPoints()); |
| 119 | 125 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(0).age); |
| 126 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(1).age); |
| 120 // Verify adding a point 10 seconds later will clear all other points, since | 127 // Verify adding a point 10 seconds later will clear all other points, since |
| 121 // they are older than 5 seconds. | 128 // they are older than 5 seconds. |
| 122 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(10)); | 129 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(10)); |
| 123 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); | 130 EXPECT_EQ(1, points_test_api_.GetNumberOfPoints()); |
| 124 | 131 |
| 125 // Verify adding 3 points one second apart each will add 3 points to the | 132 // Verify adding 3 points one second apart each will add 3 points to the |
| 126 // collection, since all 4 poitns are younger than 5 seconds. | 133 // collection, since all 4 points are younger than 5 seconds. All 4 points are |
| 134 // added 1 second apart so their age should be 0.2 apart. |
| 127 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 135 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
| 128 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 136 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
| 129 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 137 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
| 130 EXPECT_EQ(4, points_test_api_.GetNumberOfPoints()); | 138 EXPECT_EQ(4, points_test_api_.GetNumberOfPoints()); |
| 139 EXPECT_FLOAT_EQ(0.6, points_test_api_.GetPointAtIndex(0).age); |
| 140 EXPECT_FLOAT_EQ(0.4, points_test_api_.GetPointAtIndex(1).age); |
| 141 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(2).age); |
| 142 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(3).age); |
| 131 | 143 |
| 132 // Verify adding 1 point three seconds later will remove 2 points which are | 144 // Verify adding 1 point three seconds later will remove 2 points which are |
| 133 // older than 5 seconds. | 145 // older than 5 seconds. |
| 134 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); | 146 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); |
| 135 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); | 147 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); |
| 136 } | 148 } |
| 137 | 149 |
| 138 // Test to ensure the class responsible for drawing the laser pointer receives | 150 // Test to ensure the class responsible for drawing the laser pointer receives |
| 139 // points from stylus movements as expected. | 151 // points from stylus movements as expected. |
| 140 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) { | 152 TEST_F(LaserPointerControllerTest, LaserPointerRenderer) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 152 controller_test_api_.SetEnabled(true); | 164 controller_test_api_.SetEnabled(true); |
| 153 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | 165 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
| 154 | 166 |
| 155 // Verify moving the stylus 4 times will not display the laser pointer. | 167 // Verify moving the stylus 4 times will not display the laser pointer. |
| 156 GetEventGenerator().MoveMouseToInHost(gfx::Point(2, 2)); | 168 GetEventGenerator().MoveMouseToInHost(gfx::Point(2, 2)); |
| 157 GetEventGenerator().MoveMouseToInHost(gfx::Point(3, 3)); | 169 GetEventGenerator().MoveMouseToInHost(gfx::Point(3, 3)); |
| 158 GetEventGenerator().MoveMouseToInHost(gfx::Point(4, 4)); | 170 GetEventGenerator().MoveMouseToInHost(gfx::Point(4, 4)); |
| 159 GetEventGenerator().MoveMouseToInHost(gfx::Point(5, 5)); | 171 GetEventGenerator().MoveMouseToInHost(gfx::Point(5, 5)); |
| 160 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | 172 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
| 161 | 173 |
| 162 // Verify pressing the stylus will show the laser pointer and add a point. | 174 // Verify pressing the stylus will show the laser pointer and add a point but |
| 175 // will not activate fading out. |
| 163 GetEventGenerator().PressLeftButton(); | 176 GetEventGenerator().PressLeftButton(); |
| 164 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); | 177 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); |
| 178 EXPECT_FALSE(controller_test_api_.IsFadingAway()); |
| 165 EXPECT_EQ(1, controller_test_api_.laser_points().GetNumberOfPoints()); | 179 EXPECT_EQ(1, controller_test_api_.laser_points().GetNumberOfPoints()); |
| 166 | 180 |
| 167 // Verify dragging the stylus 2 times will add 2 more points. | 181 // Verify dragging the stylus 2 times will add 2 more points. |
| 168 GetEventGenerator().MoveMouseToInHost(gfx::Point(6, 6)); | 182 GetEventGenerator().MoveMouseToInHost(gfx::Point(6, 6)); |
| 169 GetEventGenerator().MoveMouseToInHost(gfx::Point(7, 7)); | 183 GetEventGenerator().MoveMouseToInHost(gfx::Point(7, 7)); |
| 170 EXPECT_EQ(3, controller_test_api_.laser_points().GetNumberOfPoints()); | 184 EXPECT_EQ(3, controller_test_api_.laser_points().GetNumberOfPoints()); |
| 171 | 185 |
| 172 // Verify releasing the stylus hides the laser pointer. | 186 // Verify releasing the stylus still shows the laser pointer, which is fading |
| 187 // away. |
| 173 GetEventGenerator().ReleaseLeftButton(); | 188 GetEventGenerator().ReleaseLeftButton(); |
| 174 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | 189 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); |
| 190 EXPECT_TRUE(controller_test_api_.IsFadingAway()); |
| 175 | 191 |
| 176 // Verify that disabling the mode does not display the laser pointer. | 192 // Verify that disabling the mode does not display the laser pointer. |
| 177 controller_test_api_.SetEnabled(false); | 193 controller_test_api_.SetEnabled(false); |
| 178 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | 194 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
| 179 | 195 |
| 180 // Verify that disabling the mode while laser pointer is displayed does not | 196 // Verify that disabling the mode while laser pointer is displayed does not |
| 181 // display the laser pointer. | 197 // display the laser pointer. |
| 198 controller_test_api_.SetIsFadingAway(false); |
| 182 controller_test_api_.SetEnabled(true); | 199 controller_test_api_.SetEnabled(true); |
| 183 GetEventGenerator().PressLeftButton(); | 200 GetEventGenerator().PressLeftButton(); |
| 184 GetEventGenerator().MoveMouseToInHost(gfx::Point(6, 6)); | 201 GetEventGenerator().MoveMouseToInHost(gfx::Point(6, 6)); |
| 185 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); | 202 EXPECT_TRUE(controller_test_api_.IsShowingLaserPointer()); |
| 186 controller_test_api_.SetEnabled(false); | 203 controller_test_api_.SetEnabled(false); |
| 187 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | 204 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
| 188 | 205 |
| 189 // Verify that the laser pointer does not add points while disabled. | 206 // Verify that the laser pointer does not add points while disabled. |
| 190 GetEventGenerator().PressLeftButton(); | 207 GetEventGenerator().PressLeftButton(); |
| 191 GetEventGenerator().MoveMouseToInHost(gfx::Point(8, 8)); | 208 GetEventGenerator().MoveMouseToInHost(gfx::Point(8, 8)); |
| 192 GetEventGenerator().ReleaseLeftButton(); | 209 GetEventGenerator().ReleaseLeftButton(); |
| 193 GetEventGenerator().MoveMouseToInHost(gfx::Point(9, 9)); | 210 GetEventGenerator().MoveMouseToInHost(gfx::Point(9, 9)); |
| 194 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | 211 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
| 195 | 212 |
| 196 // Verify that the laser pointer does not get shown if points are not coming | 213 // Verify that the laser pointer does not get shown if points are not coming |
| 197 // from the stylus, even when enabled. | 214 // from the stylus, even when enabled. |
| 198 GetEventGenerator().ExitPenPointerMode(); | 215 GetEventGenerator().ExitPenPointerMode(); |
| 199 controller_test_api_.SetEnabled(true); | 216 controller_test_api_.SetEnabled(true); |
| 200 GetEventGenerator().PressLeftButton(); | 217 GetEventGenerator().PressLeftButton(); |
| 201 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 10)); | 218 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 10)); |
| 202 GetEventGenerator().MoveMouseToInHost(gfx::Point(11, 11)); | 219 GetEventGenerator().MoveMouseToInHost(gfx::Point(11, 11)); |
| 203 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); | 220 EXPECT_FALSE(controller_test_api_.IsShowingLaserPointer()); |
| 204 GetEventGenerator().ReleaseLeftButton(); | 221 GetEventGenerator().ReleaseLeftButton(); |
| 205 } | 222 } |
| 206 } // namespace ash | 223 } // namespace ash |
| OLD | NEW |