Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc

Issue 2239743004: Palette tool laser prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch
Patch Set: Fixed patch set 2 errors and removed patch dependency. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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(LaserPointerMode* instance) { instance_ = instance; }
20 ~LaserPointerModeTestApi() { delete instance_; }
jdufault 2016/08/16 19:33:57 If LaserPointerModeTestApi takes ownership of Lase
sammiequon 2016/08/16 23:18:55 Done.
21
22 void enable() { instance_->OnEnable(); }
jdufault 2016/08/16 19:33:57 OnEnable
sammiequon 2016/08/16 23:18:55 Done.
23 void disable() { instance_->OnDisable(); }
jdufault 2016/08/16 19:33:57 OnDisable
sammiequon 2016/08/16 23:18:55 Done.
24
25 const LaserPointerPoints& laser_points() {
26 return instance_->laser_pointer_view_->laser_points_;
27 }
28
29 gfx::Point current_mouse_location() {
30 return instance_->current_mouse_location_;
31 }
32
33 private:
34 LaserPointerMode* instance_;
35 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTestApi);
36 };
37
38 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.
39 public PaletteToolManager::Delegate {
jdufault 2016/08/16 19:33:57 Does LaserPointerModeTest need to extend PaletteTo
sammiequon 2016/08/16 23:18:55 Done.
40 public:
41 LaserPointerModeTest()
42 : laser_pointer_points_(
43 base::TimeDelta::FromSecondsD(kTestPointsLifetime)) {}
44 ~LaserPointerModeTest() override {}
45
46 void SetUp() override {
47 AshTestBase::SetUp();
48 laser_pointer_mode_.reset(
49 new LaserPointerModeTestApi(new LaserPointerMode(nullptr)));
50 }
51
52 void TearDown() override {
53 laser_pointer_mode_.reset();
54 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.
55 }
56
57 protected:
58 // PaletteToolManager::Delegate:
59 void HidePalette() override {}
60 void OnActiveToolChanged() override {}
61 WmWindow* GetWindow() override {
62 NOTREACHED();
63 return nullptr;
64 }
65
66 std::unique_ptr<LaserPointerModeTestApi> laser_pointer_mode_;
67 LaserPointerPoints laser_pointer_points_;
68
69 private:
70 DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest);
71 };
72
73 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.
74 gfx::Point point1(1, 1);
75 gfx::Point point2(2, 2);
76 gfx::Point point3(3, 9);
77 gfx::Point point4(30, 0);
78 gfx::Point point5(0, 40);
79 laser_pointer_points_.AddPoint(point1);
80 laser_pointer_points_.AddPoint(point2);
81 laser_pointer_points_.AddPoint(point3);
82 laser_pointer_points_.AddPoint(point4);
83
84 // Test laser pointer points collection and helper functions.
85 EXPECT_EQ(4, laser_pointer_points_.GetNumberOfPoints());
86 EXPECT_FALSE(laser_pointer_points_.IsEmpty());
87 EXPECT_EQ(gfx::Rect(1, 0, 29, 9), laser_pointer_points_.GetBoundingBox());
88 EXPECT_EQ(point1, laser_pointer_points_.GetOldest().location);
89 EXPECT_EQ(point4, laser_pointer_points_.GetMostRecent().location);
90
91 laser_pointer_points_.AddPoint(point5);
92 EXPECT_EQ(5, laser_pointer_points_.GetNumberOfPoints());
93 EXPECT_EQ(gfx::Rect(0, 0, 30, 40), laser_pointer_points_.GetBoundingBox());
94
95 laser_pointer_points_.Clear();
96 EXPECT_TRUE(laser_pointer_points_.IsEmpty());
97 }
98
99 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.
100 GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40));
101 EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints());
102 laser_pointer_mode_->enable();
103
104 GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66));
105 GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38));
106 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
107 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
108
109 EXPECT_EQ(5, laser_pointer_mode_->laser_points().GetNumberOfPoints());
110 EXPECT_EQ(gfx::Rect(10, 38, 81, 33),
111 laser_pointer_mode_->laser_points().GetBoundingBox());
112
113 laser_pointer_mode_->disable();
114 GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
115 GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
116 EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints());
117
118 laser_pointer_mode_->enable();
119 EXPECT_EQ(1, laser_pointer_mode_->laser_points().GetNumberOfPoints());
120 EXPECT_EQ(gfx::Point(19, 71),
121 laser_pointer_mode_->laser_points().GetMostRecent().location);
122 }
123 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698