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

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: Addressed comments from issue 2231533004. 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..e4ab277d5ef419d8cdedf1e2106e869974974b30
--- /dev/null
+++ b/ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc
@@ -0,0 +1,175 @@
+// 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 {
+
+class TestPointerWatcherWithMove : public views::PointerWatcher {
+ public:
+ TestPointerWatcherWithMove() {}
+ ~TestPointerWatcherWithMove() override {}
+
+ void RegisterForEvents(bool wants_moves) {
+ WmShell::Get()->AddPointerWatcher(this, wants_moves);
+ }
+
+ void UnregisterForEvents() { WmShell::Get()->RemovePointerWatcher(this); }
+
+ void SetCurrentLocation(const gfx::Point& new_point) {
jdufault 2016/08/12 19:57:59 set_current_location
jdufault 2016/08/12 19:57:59 Rename new_point to current_location
sammiequon 2016/08/16 17:00:05 Removed this class/test since it is in another CL.
sammiequon 2016/08/16 17:00:06 Removed this class/test since it is in another CL.
+ current_location_ = new_point;
+ }
+
+ gfx::Point current_location_;
jdufault 2016/08/12 19:57:59 private:?
sammiequon 2016/08/16 17:00:05 Removed this class/test since it is in another CL.
+ // views::PointerWatcher:
jdufault 2016/08/12 19:57:59 Overrides should go above member vars.
sammiequon 2016/08/16 17:00:05 Removed this class/test since it is in another CL.
+ void OnPointerEventObserved(const ui::PointerEvent& event,
+ const gfx::Point& location_in_screen,
+ views::Widget* target) override {
+ if (event.type() == ui::ET_POINTER_MOVED)
+ current_location_ = location_in_screen;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(TestPointerWatcherWithMove);
+};
+
+class TestLaserPointerMode : public LaserPointerMode {
+ public:
+ TestLaserPointerMode(Delegate* delegate) : LaserPointerMode(delegate) {}
jdufault 2016/08/12 19:57:59 Add dtor
sammiequon 2016/08/16 17:00:06 Done.
+
+ // Expose the internal points structure for testing.
jdufault 2016/08/12 19:57:59 private:
sammiequon 2016/08/16 17:00:06 Done.
+ LaserPointerPoints GetPoints() { return laser_points_; }
+ bool Enabled() { return enabled(); }
+
+ DISALLOW_COPY_AND_ASSIGN(TestLaserPointerMode);
+};
+
+class LaserPointerModeTest : public test::AshTestBase,
+ public PaletteToolManager::Delegate {
+ public:
+ LaserPointerModeTest()
+ : laser_pointer_points_(base::TimeDelta::FromSecondsD(5.0)) {}
jdufault 2016/08/12 19:57:59 Pull into constant
sammiequon 2016/08/16 17:00:05 Done.
+ ~LaserPointerModeTest() override {}
+
+ void SetUp() override {
+ AshTestBase::SetUp();
+ palette_tool_manager_.reset(new PaletteToolManager(this));
+ laser_pointer_mode_ = new TestLaserPointerMode(NULL);
jdufault 2016/08/12 19:57:59 nullptr everywhere
sammiequon 2016/08/16 17:00:05 Done.
+ palette_tool_manager_->AddTool(base::WrapUnique(laser_pointer_mode_));
+ }
+
+ void TearDown() override {
+ laser_pointer_mode_ = NULL;
+ palette_tool_manager_.reset(nullptr);
+ AshTestBase::TearDown();
+ }
+
+ protected:
jdufault 2016/08/12 19:57:59 private
sammiequon 2016/08/16 17:00:05 Done.
+ // PaletteToolManager::Delegate:
+ void HidePalette() override {}
+ void OnActiveToolChanged() override {}
+ WmWindow* GetWindow() override {
+ NOTREACHED();
+ return nullptr;
+ }
+ std::unique_ptr<PaletteToolManager> palette_tool_manager_;
+ TestLaserPointerMode* laser_pointer_mode_;
+ TestPointerWatcherWithMove watcher_;
+ LaserPointerPoints laser_pointer_points_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest);
+};
+
+TEST_F(LaserPointerModeTest, PointerWatcherWithMove) {
+ gfx::Point point1(100, 1);
+ gfx::Point point2(2, 432);
+ gfx::Point point3(322, 19);
+ gfx::Point point4(0, 0);
+
+ // If move events wanted moving the point should change our local point.
+ watcher_.RegisterForEvents(true);
+ GetEventGenerator().MoveMouseToInHost(point1);
+ EXPECT_EQ(point1, watcher_.current_location_);
+ GetEventGenerator().MoveMouseToInHost(point2);
+ EXPECT_EQ(point2, watcher_.current_location_);
+ GetEventGenerator().MoveMouseToInHost(point3);
+ EXPECT_EQ(point3, watcher_.current_location_);
+ watcher_.UnregisterForEvents();
+
+ // If move events are not wanted moving the point should not affect our local
+ // point.
+ watcher_.RegisterForEvents(false);
+ watcher_.SetCurrentLocation(point4);
+ GetEventGenerator().MoveMouseToInHost(point1);
+ EXPECT_EQ(point4, watcher_.current_location_);
jdufault 2016/08/12 19:57:59 Use a getter or make the var public and remove the
sammiequon 2016/08/16 17:00:05 Removed this class/test since it is in another CL.
+ GetEventGenerator().MoveMouseToInHost(point2);
+ EXPECT_EQ(point4, watcher_.current_location_);
+ GetEventGenerator().MoveMouseToInHost(point3);
+ EXPECT_EQ(point4, watcher_.current_location_);
+ watcher_.UnregisterForEvents();
+}
+
+TEST_F(LaserPointerModeTest, LaserPointerPoints) {
+ 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) {
+ EXPECT_FALSE(laser_pointer_mode_->Enabled());
+ EXPECT_EQ(0, laser_pointer_mode_->GetPoints().GetNumberOfPoints());
+ palette_tool_manager_->ActivateTool(PaletteToolId::LASER_POINTER);
+ EXPECT_TRUE(laser_pointer_mode_->Enabled());
+ EXPECT_EQ(1, laser_pointer_mode_->GetPoints().GetNumberOfPoints());
+
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40));
+ 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(6, laser_pointer_mode_->GetPoints().GetNumberOfPoints());
+ EXPECT_EQ(gfx::Rect(0, 0, 91, 71),
+ laser_pointer_mode_->GetPoints().GetBoundingBox());
+
+ palette_tool_manager_->DeactivateTool(PaletteToolId::LASER_POINTER);
+ EXPECT_FALSE(laser_pointer_mode_->Enabled());
+ EXPECT_EQ(0, laser_pointer_mode_->GetPoints().GetNumberOfPoints());
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(49, 11));
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(43, 11));
+ palette_tool_manager_->ActivateTool(PaletteToolId::LASER_POINTER);
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(23, 51));
+ EXPECT_EQ(2, laser_pointer_mode_->GetPoints().GetNumberOfPoints());
+ EXPECT_EQ(gfx::Point(43, 11),
+ laser_pointer_mode_->GetPoints().GetOldest().location_);
+ EXPECT_EQ(gfx::Point(23, 51),
+ laser_pointer_mode_->GetPoints().GetMostRecent().location_);
+}
+}
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698