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

Unified Diff: ash/laser/laser_pointer_controller_unittest.cc

Issue 2311393004: Laser tool blocks events from propagating. (Closed)
Patch Set: Created 4 years, 3 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/laser/laser_pointer_controller_unittest.cc
diff --git a/ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc b/ash/laser/laser_pointer_controller_unittest.cc
similarity index 66%
rename from ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc
rename to ash/laser/laser_pointer_controller_unittest.cc
index 985620aea88c56f2ccb68d969f10f8718a1e81dc..41c45b40e1dcad600ad24802d0ff1ec35d182def 100644
--- a/ash/common/system/chromeos/palette/tools/laser_pointer_unittest.cc
+++ b/ash/laser/laser_pointer_controller_unittest.cc
@@ -2,12 +2,11 @@
// 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/tools/laser_pointer_mode.h"
-#include "ash/common/system/chromeos/palette/tools/laser_pointer_mode_test_api.h"
-#include "ash/common/system/chromeos/palette/tools/laser_pointer_points_test_api.h"
-#include "ash/common/system/chromeos/palette/tools/laser_pointer_view.h"
-#include "ash/common/test/test_palette_delegate.h"
-#include "ash/common/wm_shell.h"
+#include "ash/laser/laser_pointer_controller.h"
+#include "ash/laser/laser_pointer_controller_test_api.h"
+#include "ash/laser/laser_pointer_points_test_api.h"
+#include "ash/laser/laser_pointer_view.h"
+#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/events/test/event_generator.h"
@@ -25,14 +24,6 @@ class LaserPointerPointsTest : public test::AshTestBase {
~LaserPointerPointsTest() override {}
- void SetUp() override {
- AshTestBase::SetUp();
- // Add a test delegate so that laser pointer mode does not complain when
- // being destroyed.
- WmShell::Get()->SetPaletteDelegateForTesting(
- base::MakeUnique<TestPaletteDelegate>());
- }
-
protected:
LaserPointerPoints points_;
LaserPointerPointsTestApi points_test_api_;
@@ -41,32 +32,30 @@ class LaserPointerPointsTest : public test::AshTestBase {
DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest);
};
-class LaserPointerModeTest : public test::AshTestBase {
+class LaserPointerControllerTest : public test::AshTestBase {
public:
- LaserPointerModeTest() {}
- ~LaserPointerModeTest() override {}
+ LaserPointerControllerTest() {}
+ ~LaserPointerControllerTest() override {}
void SetUp() override {
AshTestBase::SetUp();
- WmShell::Get()->SetPaletteDelegateForTesting(
- base::MakeUnique<TestPaletteDelegate>());
- mode_test_api_.reset(new LaserPointerModeTestApi(
- base::WrapUnique<LaserPointerMode>(new LaserPointerMode(nullptr))));
+ controller_test_api_.reset(new LaserPointerControllerTestApi(
+ base::WrapUnique<LaserPointerController>(
+ new LaserPointerController())));
}
void TearDown() override {
- // This needs to be called first to remove the pointer watcher otherwise
- // tear down will complain about there being more than zero pointer watcher
- // alive.
- mode_test_api_.reset();
+ // This needs to be called first to remove the event handler before the
+ // shell instance gets torn down.
+ controller_test_api_.reset();
AshTestBase::TearDown();
}
protected:
- std::unique_ptr<LaserPointerModeTestApi> mode_test_api_;
+ std::unique_ptr<LaserPointerControllerTestApi> controller_test_api_;
private:
- DISALLOW_COPY_AND_ASSIGN(LaserPointerModeTest);
+ DISALLOW_COPY_AND_ASSIGN(LaserPointerControllerTest);
};
} // namespace
@@ -149,44 +138,64 @@ TEST_F(LaserPointerPointsTest, LaserPointerInternalCollectionDeletion) {
// Test to ensure the class responsible for drawing the laser pointer receives
// points from mouse movements as expected.
-TEST_F(LaserPointerModeTest, LaserPointerRenderer) {
+TEST_F(LaserPointerControllerTest, LaserPointerRenderer) {
// The laser pointer mode only works with stylus.
+
+ // When disabled the laser pointer view object should be a null pointer.
GetEventGenerator().EnterPenPointerMode();
GetEventGenerator().MoveMouseToInHost(gfx::Point(10, 40));
- EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints());
+ EXPECT_EQ(nullptr, controller_test_api_->laser_pointer_view());
jdufault 2016/09/12 21:10:12 Maybe add an extra function to controller_test_api
sammiequon 2016/09/13 01:09:56 Done.
- // Verify enabling the mode will start with a single point at the current
- // location.
- mode_test_api_->OnEnable();
- EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints());
+ // Verify that by enabling the mode, the laser pointer view object will not be
+ // a null pointer .
+ controller_test_api_->OnEnable();
+ EXPECT_NE(nullptr, controller_test_api_->laser_pointer_view());
jdufault 2016/09/12 21:10:12 Why does the view get created immediately after en
sammiequon 2016/09/13 01:09:56 Done.
- // Verify moving the mouse 4 times will add 4 more points.
- GetEventGenerator().MoveMouseToInHost(gfx::Point(25, 66));
+ // Verify moving the mouse 4 times will add no more points.
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(29, 66));
GetEventGenerator().MoveMouseToInHost(gfx::Point(91, 38));
GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
- EXPECT_EQ(5, mode_test_api_->laser_points().GetNumberOfPoints());
+ EXPECT_EQ(0, controller_test_api_->laser_points().GetNumberOfPoints());
- // Verify disabling the mode will clear any active points.
- mode_test_api_->OnDisable();
- EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints());
+ // Verify pressing the mouse will add a points.
jdufault 2016/09/12 21:10:12 Replace "mouse" with "stylus" in these comments.
sammiequon 2016/09/13 01:09:56 Done.
+ GetEventGenerator().PressLeftButton();
+ EXPECT_EQ(1, controller_test_api_->laser_points().GetNumberOfPoints());
+
+ // Verify dragging the mouse 2 times will add 2 more points.
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
+ GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
+ EXPECT_EQ(3, controller_test_api_->laser_points().GetNumberOfPoints());
+
+ // Verify releasing the mouse will remove all points.
+ GetEventGenerator().ReleaseLeftButton();
+ EXPECT_EQ(0, controller_test_api_->laser_points().GetNumberOfPoints());
+
+ // Verify that by disabling the mode, the laser pointer view object will be a
+ // null pointer, thus clearing any active points.
+ controller_test_api_->OnDisable();
+ EXPECT_EQ(nullptr, controller_test_api_->laser_pointer_view());
// Verify that the laser pointer does not add points while disabled.
+ GetEventGenerator().PressLeftButton();
GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
+ GetEventGenerator().ReleaseLeftButton();
GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
- EXPECT_EQ(0, mode_test_api_->laser_points().GetNumberOfPoints());
+ EXPECT_EQ(nullptr, controller_test_api_->laser_pointer_view());
// Verify that the laser pointer adds the last seen stylus point when enabled
// even when stylus mode is disabled.
GetEventGenerator().ExitPenPointerMode();
- mode_test_api_->OnEnable();
- EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints());
- EXPECT_EQ(GetEventGenerator().current_location(),
- mode_test_api_->laser_points().GetNewest().location);
+ controller_test_api_->OnEnable();
+ EXPECT_NE(nullptr, controller_test_api_->laser_pointer_view());
+ EXPECT_EQ(0, controller_test_api_->laser_points().GetNumberOfPoints());
+
// Verify that the laser pointer does not add additional points when move
// events are not from stylus.
+ GetEventGenerator().PressLeftButton();
GetEventGenerator().MoveMouseToInHost(gfx::Point(34, 58));
GetEventGenerator().MoveMouseToInHost(gfx::Point(19, 71));
- EXPECT_EQ(1, mode_test_api_->laser_points().GetNumberOfPoints());
+ EXPECT_EQ(0, controller_test_api_->laser_points().GetNumberOfPoints());
+ GetEventGenerator().ReleaseLeftButton();
}
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698