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

Unified Diff: ash/wm/maximize_mode/maximize_mode_event_blocker_unittest.cc

Issue 313913004: Block internal PlatformEvents before they are dispatched in touchview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove obsolete comment and unnecessary includes. Created 6 years, 6 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/wm/maximize_mode/maximize_mode_event_blocker_unittest.cc
diff --git a/ash/wm/maximize_mode/maximize_mode_event_blocker_unittest.cc b/ash/wm/maximize_mode/maximize_mode_event_blocker_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0ff027cb0b2f3d099edc5f2c4039e04b8e149598
--- /dev/null
+++ b/ash/wm/maximize_mode/maximize_mode_event_blocker_unittest.cc
@@ -0,0 +1,170 @@
+// Copyright 2014 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/wm/maximize_mode/maximize_mode_event_blocker.h"
+
+#include "ash/shell.h"
+#include "ash/test/ash_test_base.h"
+#include "ash/wm/maximize_mode/internal_input_device_list.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/aura/env.h"
+#include "ui/aura/window_tree_host.h"
+
+#if defined(USE_X11)
+#include "ash/wm/maximize_mode/internal_input_device_list_x11.h"
+#include "ui/events/test/events_test_utils_x11.h"
+#include "ui/events/x/touch_factory_x11.h"
+#endif
+
+namespace ash {
+
+#if defined(USE_X11)
+
+namespace {
+
+// Test device ids for a device which is considered internal and external.
+const int kTestInternalDeviceId = 1;
+const int kTestExternalDeviceId = 2;
+
+class TestInternalInputDeviceListX11 : public InternalInputDeviceListX11 {
+ public:
+ TestInternalInputDeviceListX11() {
+ internal_device_ids_.clear();
+ internal_device_ids_.insert(kTestInternalDeviceId);
+ }
+ virtual ~TestInternalInputDeviceListX11() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestInternalInputDeviceListX11);
+};
+
+gfx::Point GetMouseLocation() {
+ return aura::Env::GetInstance()->last_mouse_location();
+}
+
+void SetMouseLocation(const gfx::Point& location) {
+ Shell::GetInstance()->GetPrimaryRootWindow()->GetHost()->MoveCursorTo(
+ location);
+}
+
+} // namespace
+
+class MaximizeModeEventBlockerX11Test : public test::AshTestBase {
+ public:
+ MaximizeModeEventBlockerX11Test() {
+ }
+ virtual ~MaximizeModeEventBlockerX11Test() {}
+
+ virtual void SetUp() OVERRIDE {
+ test::AshTestBase::SetUp();
+ event_blocker_.reset(new MaximizeModeEventBlocker);
+ event_blocker_->internal_devices_.reset(new TestInternalInputDeviceListX11);
+ std::vector<unsigned int> device_list;
+ device_list.push_back(kTestInternalDeviceId);
+ device_list.push_back(kTestExternalDeviceId);
+ ui::TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ event_blocker_.reset();
+ test::AshTestBase::TearDown();
+ }
+
+ bool ShouldDispatchEvent(const ui::PlatformEvent& event) {
+ return event_blocker_->ShouldDispatchEvent(event);
+ }
+
+ private:
+ scoped_ptr<MaximizeModeEventBlocker> event_blocker_;
+
+ DISALLOW_COPY_AND_ASSIGN(MaximizeModeEventBlockerX11Test);
+};
+
+// Tests that the event blocker only blocks internal mouse events.
+TEST_F(MaximizeModeEventBlockerX11Test, BlocksInternalMouseOnly) {
+ {
+ ui::ScopedXI2Event xev;
+ xev.InitGenericButtonEvent(kTestInternalDeviceId,
+ ui::ET_MOUSE_PRESSED,
+ gfx::Point(),
+ ui::EF_LEFT_MOUSE_BUTTON);
+ EXPECT_FALSE(ShouldDispatchEvent(xev));
+ }
+ {
+ // External mouse events should not be blocked.
+ ui::ScopedXI2Event xev;
+ xev.InitGenericButtonEvent(kTestExternalDeviceId,
+ ui::ET_MOUSE_PRESSED,
+ gfx::Point(),
+ ui::EF_LEFT_MOUSE_BUTTON);
+ EXPECT_TRUE(ShouldDispatchEvent(xev));
+ }
+ {
+ // Internal touch events should not be blocked.
+ ui::ScopedXI2Event xev;
+ std::vector<ui::Valuator> valuators;
+ xev.InitTouchEvent(kTestInternalDeviceId, ui::ET_TOUCH_PRESSED, 1,
+ gfx::Point(), valuators);
+ EXPECT_TRUE(ShouldDispatchEvent(xev));
+ }
+}
+
+// Tests that general key press events are blocked.
+TEST_F(MaximizeModeEventBlockerX11Test, BlocksKeyboard) {
+ ui::ScopedXI2Event xev;
+
+ xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0);
+ EXPECT_FALSE(ShouldDispatchEvent(xev));
+
+ xev.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_ESCAPE, 0);
+ EXPECT_FALSE(ShouldDispatchEvent(xev));
+}
+
+// Tests that volume and power keys are still allowed.
+TEST_F(MaximizeModeEventBlockerX11Test, AllowsVolumeAndPower) {
+ ui::ScopedXI2Event xev;
+
+ xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_UP, 0);
+ EXPECT_TRUE(ShouldDispatchEvent(xev));
+
+ xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_DOWN, 0);
+ EXPECT_TRUE(ShouldDispatchEvent(xev));
+
+ xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_POWER, 0);
+ EXPECT_TRUE(ShouldDispatchEvent(xev));
+}
+
+// The mouse cursor movement happens before the event is delivered, this tests
+// that the event blocker attempts to lock the cursor in place when it receives
+// an internal mouse event.
+TEST_F(MaximizeModeEventBlockerX11Test, LocksMousePosition) {
+ gfx::Point external_point(100, 0);
+ gfx::Point internal_point(0, 0);
+ // Move the cursor to a position and send an external mouse event.
+ SetMouseLocation(external_point);
+ {
+ ui::ScopedXI2Event xev;
+ xev.InitGenericButtonEvent(kTestExternalDeviceId,
+ ui::ET_MOUSE_PRESSED,
+ external_point,
+ ui::EF_LEFT_MOUSE_BUTTON);
+ EXPECT_TRUE(ShouldDispatchEvent(xev));
+ }
+ EXPECT_EQ(external_point.ToString(), GetMouseLocation().ToString());
+
+ // Move the cursor to another
+ SetMouseLocation(internal_point);
+ {
+ ui::ScopedXI2Event xev;
+ xev.InitGenericButtonEvent(kTestInternalDeviceId,
+ ui::ET_MOUSE_PRESSED,
+ internal_point,
+ ui::EF_LEFT_MOUSE_BUTTON);
+ EXPECT_FALSE(ShouldDispatchEvent(xev));
+ }
+ EXPECT_EQ(external_point.ToString(), GetMouseLocation().ToString());
+}
+#endif // defined(USE_X11)
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698