OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" | |
6 #include "ash/common/system/chromeos/palette/tools/laser_pointer_mode.h" | |
7 #include "ash/common/system/chromeos/palette/tools/laser_pointer_points.h" | |
8 #include "ash/common/wm_shell.h" | |
9 #include "ash/test/ash_test_base.h" | |
10 #include "ui/events/test/event_generator.h" | |
11 | |
12 namespace ash { | |
13 namespace { | |
14 const double kTestPointsLifetime = 5.0; | |
15 } // namespace | |
16 | |
17 class LaserPointerModeTestApi { | |
18 public: | |
19 LaserPointerModeTestApi(std::unique_ptr<LaserPointerMode> instance) { | |
20 instance_ = std::move(instance); | |
jdufault
2016/08/17 21:41:08
Use constructor list whenever possible.
: insta
sammiequon
2016/08/18 00:52:08
Done.
| |
21 } | |
22 ~LaserPointerModeTestApi() {} | |
23 | |
24 void OnEnable() { instance_->OnEnable(); } | |
25 void OnDisable() { instance_->OnDisable(); } | |
26 | |
27 const LaserPointerPoints& laser_points() { | |
28 return instance_->laser_pointer_view_->laser_points_; | |
29 } | |
30 | |
31 gfx::Point current_mouse_location() { | |
32 return instance_->current_mouse_location_; | |
33 } | |
34 | |
35 private: | |
36 std::unique_ptr<LaserPointerMode> instance_; | |
37 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTestApi); | |
jdufault
2016/08/17 21:41:08
newline above this
sammiequon
2016/08/18 00:52:08
Done.
| |
38 }; | |
39 | |
40 namespace { | |
jdufault
2016/08/17 21:41:08
Merge the different anonymous namespaces.
sammiequon
2016/08/18 00:52:08
Done.
| |
41 class LaserPointerModeTest : public test::AshTestBase { | |
42 public: | |
43 LaserPointerModeTest() | |
44 : laser_pointer_points_( | |
45 base::TimeDelta::FromSecondsD(kTestPointsLifetime)) {} | |
jdufault
2016/08/17 21:41:08
Make kTestPointsLifetime an integral type and use
sammiequon
2016/08/18 00:52:08
Done.
| |
46 ~LaserPointerModeTest() override {} | |
47 | |
48 void SetUp() override { | |
49 AshTestBase::SetUp(); | |
50 laser_pointer_mode_.reset(new LaserPointerModeTestApi( | |
51 base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr)))); | |
jdufault
2016/08/17 21:41:08
base::MakeUnique
sammiequon
2016/08/18 00:52:08
Done.
| |
52 } | |
53 | |
54 void TearDown() override { | |
55 laser_pointer_mode_.reset(); | |
56 AshTestBase::TearDown(); | |
57 } | |
58 | |
59 protected: | |
60 std::unique_ptr<LaserPointerModeTestApi> laser_pointer_mode_; | |
61 LaserPointerPoints laser_pointer_points_; | |
62 | |
63 private: | |
64 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest); | |
65 }; | |
66 } // namespace | |
67 | |
68 TEST_F(LaserPointerModeTest, LaserPointerInternalCollection) { | |
69 // Test to test the laser pointers internal collection is handling receiving | |
jdufault
2016/08/17 21:41:08
Replace "Test to test" with "Tests that the ...".
jdufault
2016/08/17 21:41:08
Comment goes above TEST_F function
// Test desc
sammiequon
2016/08/18 00:52:08
Done.
sammiequon
2016/08/18 00:52:08
Done.
| |
70 // points and that the functions are returning the expected output. | |
71 gfx::Point point1(1, 1); | |
72 gfx::Point point2(2, 2); | |
73 gfx::Point point3(3, 9); | |
74 gfx::Point point4(30, 0); | |
75 gfx::Point point5(0, 40); | |
76 laser_pointer_points_.AddPoint(point1); | |
77 laser_pointer_points_.AddPoint(point2); | |
78 laser_pointer_points_.AddPoint(point3); | |
79 laser_pointer_points_.AddPoint(point4); | |
80 | |
81 // Test laser pointer points collection and helper functions. | |
82 EXPECT_EQ(4, laser_pointer_points_.GetNumberOfPoints()); | |
jdufault
2016/08/17 21:41:08
If we're testing the functionality specifically fo
sammiequon
2016/08/18 00:52:08
Like write a LaserPointerPoints test in another fi
jdufault
2016/08/19 01:02:08
You have the LaserPointerRenderer test right now,
| |
83 EXPECT_FALSE(laser_pointer_points_.IsEmpty()); | |
84 EXPECT_EQ(gfx::Rect(1, 0, 29, 9), laser_pointer_points_.GetBoundingBox()); | |
85 EXPECT_EQ(point1, laser_pointer_points_.GetOldest().location); | |
86 EXPECT_EQ(point4, laser_pointer_points_.GetMostRecent().location); | |
87 | |
88 laser_pointer_points_.AddPoint(point5); | |
89 EXPECT_EQ(5, laser_pointer_points_.GetNumberOfPoints()); | |
90 EXPECT_EQ(gfx::Rect(0, 0, 30, 40), laser_pointer_points_.GetBoundingBox()); | |
91 | |
92 laser_pointer_points_.Clear(); | |
93 EXPECT_TRUE(laser_pointer_points_.IsEmpty()); | |
94 } | |
95 | |
jdufault
2016/08/17 21:41:08
You should add a test that verifies points will di
sammiequon
2016/08/18 00:52:08
Done.
| |
96 TEST_F(LaserPointerModeTest, LaserPointerRenderer) { | |
97 // Test to ensure the class responsible for drawing the laser pointer receives | |
98 // points from mouse movements as expected. | |
99 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40)); | |
100 EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints()); | |
101 laser_pointer_mode_->OnEnable(); | |
102 | |
103 GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66)); | |
104 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38)); | |
105 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | |
106 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | |
107 | |
108 EXPECT_EQ(5, laser_pointer_mode_->laser_points().GetNumberOfPoints()); | |
109 EXPECT_EQ(gfx::Rect(10, 38, 81, 33), | |
110 laser_pointer_mode_->laser_points().GetBoundingBox()); | |
111 | |
112 laser_pointer_mode_->OnDisable(); | |
113 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58)); | |
114 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71)); | |
115 EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints()); | |
116 | |
117 laser_pointer_mode_->OnEnable(); | |
118 EXPECT_EQ(1, laser_pointer_mode_->laser_points().GetNumberOfPoints()); | |
119 EXPECT_EQ(gfx::Point(19, 71), | |
120 laser_pointer_mode_->laser_points().GetMostRecent().location); | |
121 } | |
122 } // namespace ash | |
OLD | NEW |