Chromium Code Reviews| Index: ash/laser/laser_pointer_controller_unittest.cc |
| diff --git a/ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc b/ash/laser/laser_pointer_controller_unittest.cc |
| similarity index 64% |
| rename from ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc |
| rename to ash/laser/laser_pointer_controller_unittest.cc |
| index 985620aea88c56f2ccb68d969f10f8718a1e81dc..1f7956523b11a99ff0100b5e8f59a27ff13d2270 100644 |
| --- a/ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc |
| +++ b/ash/laser/laser_pointer_controller_unittest.cc |
| @@ -2,12 +2,11 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h" |
| -#include "ash/common/system/chromeos/palette/tools/laser_pointer_mode_test_api.h" |
| -#include "ash/common/system/chromeos/palette/tools/laser_pointer_points_test_api.h" |
| -#include "ash/common/system/chromeos/palette/tools/laser_pointer_view.h" |
| -#include "ash/common/test/test_palette_delegate.h" |
| -#include "ash/common/wm_shell.h" |
| +#include "ash/laser/laser_pointer_controller.h" |
| +#include "ash/laser/laser_pointer_controller_test_api.h" |
| +#include "ash/laser/laser_pointer_points_test_api.h" |
| +#include "ash/laser/laser_pointer_view.h" |
| +#include "ash/shell.h" |
| #include "ash/test/ash_test_base.h" |
| #include "ui/events/test/event_generator.h" |
| @@ -25,14 +24,6 @@ class LaserPointerPointsTest : public test::AshTestBase { |
| ~LaserPointerPointsTest() override {} |
| - void SetUp() override { |
| - AshTestBase::SetUp(); |
| - // Add a test delegate so that laser pointer mode does not complain when |
| - // being destroyed. |
| - WmShell::Get()->SetPaletteDelegateForTesting( |
| - base::MakeUnique<TestPaletteDelegate>()); |
| - } |
| - |
| protected: |
| LaserPointerPoints points_; |
| LaserPointerPointsTestApi points_test_api_; |
| @@ -41,32 +32,30 @@ class LaserPointerPointsTest : public test::AshTestBase { |
| DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); |
| }; |
| -class LaserPointerModeTest : public test::AshTestBase { |
| +class LaserPointerControllerTest : public test::AshTestBase { |
| public: |
| - LaserPointerModeTest() {} |
| - ~LaserPointerModeTest() override {} |
| + LaserPointerControllerTest() {} |
| + ~LaserPointerControllerTest() override {} |
| void SetUp() override { |
| AshTestBase::SetUp(); |
| - WmShell::Get()->SetPaletteDelegateForTesting( |
| - base::MakeUnique<TestPaletteDelegate>()); |
| - mode_test_api_.reset(new LaserPointerModeTestApi( |
| - base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr)))); |
| + controller_test_api_.reset(new LaserPointerControllerTestApi( |
| + base::WrapUnique<LaserPointerController>( |
|
James Cook
2016/09/14 17:52:28
MakeUnique
sammiequon
2016/09/14 21:44:10
Done.
|
| + new LaserPointerController()))); |
| } |
| void TearDown() override { |
| - // This needs to be called first to remove the pointer watcher otherwise |
| - // tear down will complain about there being more than zero pointer watcher |
| - // alive. |
| - mode_test_api_.reset(); |
| + // This needs to be called first to remove the event handler before the |
| + // shell instance gets torn down. |
| + controller_test_api_.reset(); |
| AshTestBase::TearDown(); |
| } |
| protected: |
| - std::unique_ptr<LaserPointerModeTestApi> mode_test_api_; |
| + std::unique_ptr<LaserPointerControllerTestApi> controller_test_api_; |
| private: |
| - DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest); |
| + DISALLOW_COPY_AND_ASSIGN(LaserPointerControllerTest); |
| }; |
| } // namespace |
| @@ -148,45 +137,60 @@ TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) { |
| } |
| // Test to ensure the class responsible for drawing the laser pointer receives |
| -// points from mouse movements as expected. |
| -TEST_F(LaserPointerModeTest, LaserPointerRenderer) { |
| +// points from stylus movements as expected. |
| +TEST_F(LaserPointerControllerTest, LaserPointerRenderer) { |
| // The laser pointer mode only works with stylus. |
| + |
| + // When disabled the laser pointer should not be showing. |
| 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.
|
| GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40)); |
| - EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); |
| + EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| - // Verify enabling the mode will start with a single point at the current |
| - // location. |
| - mode_test_api_->OnEnable(); |
| - EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); |
| + // Verify that by enabling the mode, the laser pointer should still not be |
| + // showing. |
| + controller_test_api_->OnEnable(); |
| + EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| - // Verify moving the mouse 4 times will add 4 more points. |
| - GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66)); |
| + // Verify moving the stylus 4 times will the laser pointer should still not be |
| + // showing. |
| + 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.
|
| GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38)); |
| GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
| GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
| - EXPECT_EQ(5, mode_test_api_->laser_points().GetNumberOfPoints()); |
| + EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| - // Verify disabling the mode will clear any active points. |
| - mode_test_api_->OnDisable(); |
| - EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); |
| + // Verify pressing the stylus will add a point, and the laser pointer should |
| + // be shown. |
| + GetEventGenerator().PressLeftButton(); |
| + EXPECT_TRUE(controller_test_api_->IsShowingLaserPointer()); |
| + EXPECT_EQ(1, controller_test_api_->laser_points().GetNumberOfPoints()); |
| + |
| + // Verify dragging the stylus 2 times will add 2 more points. |
| + GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
| + GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
| + EXPECT_EQ(3, controller_test_api_->laser_points().GetNumberOfPoints()); |
| + |
| + // Verify by releasing the stylus, the laser pointer will not be shown. |
| + GetEventGenerator().ReleaseLeftButton(); |
| + EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| + |
| + // Verify that by disabling the mode, the laser pointer view not be shown. |
| + controller_test_api_->OnDisable(); |
| + EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| // Verify that the laser pointer does not add points while disabled. |
| + GetEventGenerator().PressLeftButton(); |
| GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
| + GetEventGenerator().ReleaseLeftButton(); |
| GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
| - EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints()); |
| - |
| - // Verify that the laser pointer adds the last seen stylus point when enabled |
| - // even when stylus mode is disabled. |
| - GetEventGenerator().ExitPenPointerMode(); |
| - mode_test_api_->OnEnable(); |
| - EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); |
| - EXPECT_EQ(GetEventGenerator().current_location(), |
| - mode_test_api_->laser_points().GetNewest().location); |
| - // Verify that the laser pointer does not add additional points when move |
| - // events are not from stylus. |
| + EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| + |
| + // Verify that the laser pointer does not get shown if points are not coming |
| + // from the stylus. |
| + 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.
|
| GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
| GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
| - EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints()); |
| + EXPECT_FALSE(controller_test_api_->IsShowingLaserPointer()); |
| + GetEventGenerator().ReleaseLeftButton(); |
| } |
| } // namespace ash |