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

Unified 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 4 errors. 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 side-by-side diff with in-line comments
Download patch
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..f0cc1bdc7674b5b234184b91295a2deaff842d6d
--- /dev/null
+++ b/ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc
@@ -0,0 +1,171 @@
+// 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 {
+
+class LaserPointerPointsTestApi : public LaserPointerPoints {
+ public:
+ LaserPointerPointsTestApi(base::TimeDelta life_time)
+ : LaserPointerPoints(life_time) {}
+ ~LaserPointerPointsTestApi() {}
+
+ void AddTimedPoint(const base::Time& time, const gfx::Point& location) {
jdufault 2016/08/19 01:02:09 AddPointAtTime(...)
sammiequon 2016/08/19 20:28:47 Done.
+ LaserPointerPoints::LaserPoint new_point;
+ new_point.creation_time = time;
+ new_point.location = location;
+ points_.push_back(new_point);
+ ClearOldPoints();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTestApi);
+};
+
+class LaserPointerModeTestApi {
+ public:
+ LaserPointerModeTestApi(std::unique_ptr<LaserPointerMode> instance)
+ : instance_(std::move(instance)) {}
+ ~LaserPointerModeTestApi() {}
+
+ void OnEnable() { instance_->OnEnable(); }
+ void OnDisable() { instance_->OnDisable(); }
+
+ const LaserPointerPoints& laser_points() {
+ return instance_->laser_pointer_view_->laser_points_;
+ }
+
+ gfx::Point current_mouse_location() {
+ return instance_->current_mouse_location_;
+ }
+
+ private:
+ std::unique_ptr<LaserPointerMode> instance_;
+
+ DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTestApi);
+};
+
+namespace {
jdufault 2016/08/19 01:02:09 Move anonymous namespace contents to the top of th
sammiequon 2016/08/19 20:28:47 Done.
+const int kTestPointsLifetime = 5;
+
+class LaserPointerModeTest : public test::AshTestBase {
+ public:
+ LaserPointerModeTest()
+ : laser_pointer_points_(
+ base::TimeDelta::FromSeconds(kTestPointsLifetime)),
+ laser_pointer_points_delete_(
+ base::TimeDelta::FromSeconds(kTestPointsLifetime)) {}
+ ~LaserPointerModeTest() override {}
+
+ void SetUp() override {
+ AshTestBase::SetUp();
+ laser_pointer_mode_.reset(new LaserPointerModeTestApi(
+ base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr))));
+ }
+
+ void TearDown() override {
+ laser_pointer_mode_.reset();
+ AshTestBase::TearDown();
+ }
+
+ protected:
+ std::unique_ptr<LaserPointerModeTestApi> laser_pointer_mode_;
+ LaserPointerPoints laser_pointer_points_;
jdufault 2016/08/19 01:02:09 What about just points_?
sammiequon 2016/08/19 20:28:47 Done.
+ LaserPointerPointsTestApi laser_pointer_points_delete_;
jdufault 2016/08/19 01:02:08 points_test_api_?
jdufault 2016/08/19 01:02:09 If this test api instance is separate from laser_p
sammiequon 2016/08/19 20:28:46 Done.
sammiequon 2016/08/19 20:28:47 Done.
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest);
+};
+} // namespace
+
+// Tests that the laser pointers internal collection handles receiving points
+// and that the functions are returning the expected output.
+TEST_F(LaserPointerModeTest, LaserPointerInternalCollection) {
+ 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());
jdufault 2016/08/19 01:02:09 I think having renaming some of the points to top_
sammiequon 2016/08/19 20:28:46 Done.
+ EXPECT_EQ(point1, laser_pointer_points_.GetOldest().location);
+ EXPECT_EQ(point4, laser_pointer_points_.GetMostRecent().location);
+
+ laser_pointer_points_.AddPoint(point5);
jdufault 2016/08/19 01:02:09 Declare point here, ie, gfx::Point expanded_botto
sammiequon 2016/08/19 20:28:46 Done.
+ 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 the laser pointer points collection removes old points as expected.
+TEST_F(LaserPointerModeTest, LaserPointerInternalCollectionDeletion) {
+ gfx::Point test_point(0, 0);
+ base::Time start_time = base::Time::FromJsTime(0);
+ base::Time three_second_time = base::Time::FromJsTime(3000);
jdufault 2016/08/19 01:02:08 Use FromSeconds
sammiequon 2016/08/19 20:28:47 As per offline conv this is fine.
+ base::Time six_second_time = base::Time::FromJsTime(6000);
+ base::Time six_half_second_time = base::Time::FromJsTime(6500);
jdufault 2016/08/19 01:02:09 I don't think these constants aid in readability.
sammiequon 2016/08/19 20:28:47 Done.
+ base::Time seven_second_time = base::Time::FromJsTime(7000);
+ base::Time seven_half_second_time = base::Time::FromJsTime(7500);
+ base::Time twenty_second_time = base::Time::FromJsTime(20000);
+
+ // When a new point is added points older than 5 seconds (kTestPointsLifetime)
+ // // ago should be removed.
jdufault 2016/08/19 01:02:08 What about something like this for the comment?
sammiequon 2016/08/19 20:28:47 Done.
+ laser_pointer_points_delete_.AddTimedPoint(start_time, test_point);
+ EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 1);
+ laser_pointer_points_delete_.AddTimedPoint(three_second_time, test_point);
+ EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 2);
+ laser_pointer_points_delete_.AddTimedPoint(six_second_time, test_point);
+ EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 2);
+
+ laser_pointer_points_delete_.AddTimedPoint(six_half_second_time, test_point);
+ laser_pointer_points_delete_.AddTimedPoint(seven_second_time, test_point);
+ laser_pointer_points_delete_.AddTimedPoint(seven_half_second_time,
+ test_point);
+ EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 5);
+ laser_pointer_points_delete_.AddTimedPoint(twenty_second_time, test_point);
+ EXPECT_EQ(laser_pointer_points_delete_.GetNumberOfPoints(), 1);
jdufault 2016/08/19 01:02:08 This seems strange to me. Why does adding a 20 sec
sammiequon 2016/08/19 20:28:47 Done.
+}
+
+// Test to ensure the class responsible for drawing the laser pointer receives
+// points from mouse movements as expected.
+TEST_F(LaserPointerModeTest, LaserPointerRenderer) {
+ // TODO(sammiequon): Update these tests once event generator with stylus
+ // events cl lands.
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40));
+ EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints());
+ laser_pointer_mode_->OnEnable();
+
+ 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());
+
+ laser_pointer_mode_->OnDisable();
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
+ EXPECT_EQ(0, laser_pointer_mode_->laser_points().GetNumberOfPoints());
+
+ laser_pointer_mode_->OnEnable();
+ EXPECT_EQ(1, laser_pointer_mode_->laser_points().GetNumberOfPoints());
+ EXPECT_EQ(gfx::Point(19, 71),
jdufault 2016/08/19 01:02:09 GetEventGenerator().current_location()
sammiequon 2016/08/19 20:28:46 Done.
+ laser_pointer_mode_->laser_points().GetMostRecent().location);
+}
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698