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/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 { |
|
James Cook
2016/09/14 17:52:28
not for this CL: How about putting these tests in
sammiequon
2016/09/14 21:44:10
Done.
| |
| 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>( |
|
James Cook
2016/09/14 17:52:28
MakeUnique
sammiequon
2016/09/14 21:44:10
Done.
| |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); | 130 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(1)); |
| 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 stylus 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 should not be showing. | |
| 154 GetEventGenerator().EnterPenPointerMode(); | 145 GetEventGenerator().EnterPenPointerMode(); |
|
James Cook
2016/09/14 17:52:28
move this to 143. It's very important for the read
sammiequon
2016/09/14 21:44:10
Done.
| |
| 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_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| 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 should still not be |
| 159 // location. | 150 // showing. |
| 160 mode_test_api_->OnEnable(); | 151 controller_test_api_->OnEnable(); |
| 161 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | 152 EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| 162 | 153 |
| 163 // Verify moving the mouse 4 times will add 4 more points. | 154 // Verify moving the stylus 4 times will the laser pointer should still not be |
| 164 GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66)); | 155 // showing. |
| 156 GetEventGenerator().MoveMouseToInHost(gfx::Point(29, 66)); | |
|
James Cook
2016/09/14 17:52:28
nit: If these points are arbitrary data, use somet
sammiequon
2016/09/14 21:44:10
Done.
| |
| 165 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38)); | 157 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38)); |
| 166 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | 158 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
| 167 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | 159 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
| 168 EXPECT_EQ(5, mode_test_api_->laser_points().GetNumberOfPoints()); | 160 EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| 169 | 161 |
| 170 // Verify disabling the mode will clear any active points. | 162 // Verify pressing the stylus will add a point, and the laser pointer should |
| 171 mode_test_api_->OnDisable(); | 163 // be shown. |
| 172 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | 164 GetEventGenerator().PressLeftButton(); |
| 165 EXPECT_TRUE(controller_test_api_->IsShowingLaserPointer()); | |
| 166 EXPECT_EQ(1, controller_test_api_->laser_points().GetNumberOfPoints()); | |
| 167 | |
| 168 // Verify dragging the stylus 2 times will add 2 more points. | |
| 169 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | |
| 170 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | |
| 171 EXPECT_EQ(3, controller_test_api_->laser_points().GetNumberOfPoints()); | |
| 172 | |
| 173 // Verify by releasing the stylus, the laser pointer will not be shown. | |
| 174 GetEventGenerator().ReleaseLeftButton(); | |
| 175 EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); | |
| 176 | |
| 177 // Verify that by disabling the mode, the laser pointer view not be shown. | |
| 178 controller_test_api_->OnDisable(); | |
| 179 EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); | |
| 173 | 180 |
| 174 // Verify that the laser pointer does not add points while disabled. | 181 // Verify that the laser pointer does not add points while disabled. |
| 182 GetEventGenerator().PressLeftButton(); | |
| 183 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | |
| 184 GetEventGenerator().ReleaseLeftButton(); | |
| 185 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | |
| 186 EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); | |
| 187 | |
| 188 // Verify that the laser pointer does not get shown if points are not coming | |
| 189 // from the stylus. | |
| 190 GetEventGenerator().PressLeftButton(); | |
|
James Cook
2016/09/14 17:52:28
Didn't you just test this case above? The controll
sammiequon
2016/09/14 21:44:10
Yes that was the original intention. Done.
| |
| 175 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | 191 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
| 176 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | 192 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
| 177 EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); | 193 EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| 178 | 194 GetEventGenerator().ReleaseLeftButton(); |
| 179 // Verify that the laser pointer adds the last seen stylus point when enabled | |
| 180 // even when stylus mode is disabled. | |
| 181 GetEventGenerator().ExitPenPointerMode(); | |
| 182 mode_test_api_->OnEnable(); | |
| 183 EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); | |
| 184 EXPECT_EQ(GetEventGenerator().current_location(), | |
| 185 mode_test_api_->laser_points().GetNewest().location); | |
| 186 // Verify that the laser pointer does not add additional points when move | |
| 187 // events are not from stylus. | |
| 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 } | 195 } |
| 192 } // namespace ash | 196 } // namespace ash |
| OLD | NEW |