Chromium Code Reviews| Index: ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc |
| diff --git a/ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc b/ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b30d36cdbe69cb556f03f4ef0dbbc648da1fcdec |
| --- /dev/null |
| +++ b/ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc |
| @@ -0,0 +1,123 @@ |
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +// 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/palette_tool_manager.h" |
| +#include "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h" |
| +#include "ash/common/system/chromeos/palette/tools/laser_pointer_points.h" |
| +#include "ash/common/wm_shell.h" |
| +#include "ash/test/ash_test_base.h" |
| +#include "ui/events/test/event_generator.h" |
| + |
| +namespace ash { |
| +namespace { |
| +const double kTestPointsLifetime = 5.0; |
| +} // namespace |
| + |
| +class LaserPointerModeTestApi { |
| + public: |
| + LaserPointerModeTestApi(LaserPointerMode* instance) { instance_ = instance; } |
| + ~LaserPointerModeTestApi() { delete instance_; } |
|
jdufault
2016/08/16 19:33:57
If LaserPointerModeTestApi takes ownership of Lase
sammiequon
2016/08/16 23:18:55
Done.
|
| + |
| + void enable() { instance_->OnEnable(); } |
|
jdufault
2016/08/16 19:33:57
OnEnable
sammiequon
2016/08/16 23:18:55
Done.
|
| + void disable() { instance_->OnDisable(); } |
|
jdufault
2016/08/16 19:33:57
OnDisable
sammiequon
2016/08/16 23:18:55
Done.
|
| + |
| + const LaserPointerPoints& laser_points() { |
| + return instance_->laser_pointer_view_->laser_points_; |
| + } |
| + |
| + gfx::Point current_mouse_location() { |
| + return instance_->current_mouse_location_; |
| + } |
| + |
| + private: |
| + LaserPointerMode* instance_; |
| + DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTestApi); |
| +}; |
| + |
| +class LaserPointerModeTest : public test::AshTestBase, |
|
jdufault
2016/08/16 19:33:57
Move the LaserPointerModeTest class into anonymous
sammiequon
2016/08/16 23:18:55
Done.
|
| + public PaletteToolManager::Delegate { |
|
jdufault
2016/08/16 19:33:57
Does LaserPointerModeTest need to extend PaletteTo
sammiequon
2016/08/16 23:18:55
Done.
|
| + public: |
| + LaserPointerModeTest() |
| + : laser_pointer_points_( |
| + base::TimeDelta::FromSecondsD(kTestPointsLifetime)) {} |
| + ~LaserPointerModeTest() override {} |
| + |
| + void SetUp() override { |
| + AshTestBase::SetUp(); |
| + laser_pointer_mode_.reset( |
| + new LaserPointerModeTestApi(new LaserPointerMode(nullptr))); |
| + } |
| + |
| + void TearDown() override { |
| + laser_pointer_mode_.reset(); |
| + AshTestBase::TearDown(); |
|
jdufault
2016/08/16 19:33:57
Make TearDown to the first line of the function
sammiequon
2016/08/16 23:18:55
This will cause the test to crash.
|
| + } |
| + |
| + protected: |
| + // PaletteToolManager::Delegate: |
| + void HidePalette() override {} |
| + void OnActiveToolChanged() override {} |
| + WmWindow* GetWindow() override { |
| + NOTREACHED(); |
| + return nullptr; |
| + } |
| + |
| + std::unique_ptr<LaserPointerModeTestApi> laser_pointer_mode_; |
| + LaserPointerPoints laser_pointer_points_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest); |
| +}; |
| + |
| +TEST_F(LaserPointerModeTest, LaserPointerPoints) { |
|
jdufault
2016/08/16 19:33:56
Please use a more descriptive test name - LaserPoi
jdufault
2016/08/16 19:33:57
Add a comment describing what the test does.
sammiequon
2016/08/16 23:18:54
Done.
sammiequon
2016/08/16 23:18:55
Done.
|
| + gfx::Point point1(1, 1); |
| + gfx::Point point2(2, 2); |
| + gfx::Point point3(3, 9); |
| + gfx::Point point4(30, 0); |
| + gfx::Point point5(0, 40); |
| + laser_pointer_points_.AddPoint(point1); |
| + laser_pointer_points_.AddPoint(point2); |
| + laser_pointer_points_.AddPoint(point3); |
| + laser_pointer_points_.AddPoint(point4); |
| + |
| + // Test laser pointer points collection and helper functions. |
| + EXPECT_EQ(4, laser_pointer_points_.GetNumberOfPoints()); |
| + EXPECT_FALSE(laser_pointer_points_.IsEmpty()); |
| + EXPECT_EQ(gfx::Rect(1, 0, 29, 9), laser_pointer_points_.GetBoundingBox()); |
| + EXPECT_EQ(point1, laser_pointer_points_.GetOldest().location); |
| + EXPECT_EQ(point4, laser_pointer_points_.GetMostRecent().location); |
| + |
| + laser_pointer_points_.AddPoint(point5); |
| + EXPECT_EQ(5, laser_pointer_points_.GetNumberOfPoints()); |
| + EXPECT_EQ(gfx::Rect(0, 0, 30, 40), laser_pointer_points_.GetBoundingBox()); |
| + |
| + laser_pointer_points_.Clear(); |
| + EXPECT_TRUE(laser_pointer_points_.IsEmpty()); |
| +} |
| + |
| +TEST_F(LaserPointerModeTest, LaserPointerView) { |
|
jdufault
2016/08/16 19:33:56
Add a comment describing the test.
jdufault
2016/08/16 19:33:57
Please rename test to be more descriptive.
sammiequon
2016/08/16 23:18:55
Done.
sammiequon
2016/08/16 23:18:55
Done.
|
| + GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40)); |
| + EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints()); |
| + laser_pointer_mode_->enable(); |
| + |
| + GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66)); |
| + GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38)); |
| + GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
| + GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
| + |
| + EXPECT_EQ(5, laser_pointer_mode_->laser_points().GetNumberOfPoints()); |
| + EXPECT_EQ(gfx::Rect(10, 38, 81, 33), |
| + laser_pointer_mode_->laser_points().GetBoundingBox()); |
| + |
| + laser_pointer_mode_->disable(); |
| + GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); |
| + GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); |
| + EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints()); |
| + |
| + laser_pointer_mode_->enable(); |
| + EXPECT_EQ(1, laser_pointer_mode_->laser_points().GetNumberOfPoints()); |
| + EXPECT_EQ(gfx::Point(19, 71), |
| + laser_pointer_mode_->laser_points().GetMostRecent().location); |
| +} |
| +} // namespace ash |