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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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/wm/maximize_mode/maximize_mode_event_blocker.h"
6
7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/maximize_mode/internal_input_device_list.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/window_tree_host.h"
13
14 #if defined(USE_X11)
15 #include "ash/wm/maximize_mode/internal_input_device_list_x11.h"
16 #include "ui/events/test/events_test_utils_x11.h"
17 #include "ui/events/x/touch_factory_x11.h"
18 #endif
19
20 namespace ash {
21
22 #if defined(USE_X11)
23
24 namespace {
25
26 // Test device ids for a device which is considered internal and external.
27 const int kTestInternalDeviceId = 1;
28 const int kTestExternalDeviceId = 2;
29
30 class TestInternalInputDeviceListX11 : public InternalInputDeviceListX11 {
31 public:
32 TestInternalInputDeviceListX11() {
33 internal_device_ids_.clear();
34 internal_device_ids_.insert(kTestInternalDeviceId);
35 }
36 virtual ~TestInternalInputDeviceListX11() {}
37
38 private:
39 DISALLOW_COPY_AND_ASSIGN(TestInternalInputDeviceListX11);
40 };
41
42 gfx::Point GetMouseLocation() {
43 return aura::Env::GetInstance()->last_mouse_location();
44 }
45
46 void SetMouseLocation(const gfx::Point& location) {
47 Shell::GetInstance()->GetPrimaryRootWindow()->GetHost()->MoveCursorTo(
48 location);
49 }
50
51 } // namespace
52
53 class MaximizeModeEventBlockerX11Test : public test::AshTestBase {
54 public:
55 MaximizeModeEventBlockerX11Test() {
56 }
57 virtual ~MaximizeModeEventBlockerX11Test() {}
58
59 virtual void SetUp() OVERRIDE {
60 test::AshTestBase::SetUp();
61 event_blocker_.reset(new MaximizeModeEventBlocker);
62 event_blocker_->internal_devices_.reset(new TestInternalInputDeviceListX11);
63 std::vector<unsigned int> device_list;
64 device_list.push_back(kTestInternalDeviceId);
65 device_list.push_back(kTestExternalDeviceId);
66 ui::TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list);
67 }
68
69 virtual void TearDown() OVERRIDE {
70 event_blocker_.reset();
71 test::AshTestBase::TearDown();
72 }
73
74 bool ShouldDispatchEvent(const ui::PlatformEvent& event) {
75 return event_blocker_->ShouldDispatchEvent(event);
76 }
77
78 private:
79 scoped_ptr<MaximizeModeEventBlocker> event_blocker_;
80
81 DISALLOW_COPY_AND_ASSIGN(MaximizeModeEventBlockerX11Test);
82 };
83
84 // Tests that the event blocker only blocks internal mouse events.
85 TEST_F(MaximizeModeEventBlockerX11Test, BlocksInternalMouseOnly) {
86 {
87 ui::ScopedXI2Event xev;
88 xev.InitGenericButtonEvent(kTestInternalDeviceId,
89 ui::ET_MOUSE_PRESSED,
90 gfx::Point(),
91 ui::EF_LEFT_MOUSE_BUTTON);
92 EXPECT_FALSE(ShouldDispatchEvent(xev));
93 }
94 {
95 // External mouse events should not be blocked.
96 ui::ScopedXI2Event xev;
97 xev.InitGenericButtonEvent(kTestExternalDeviceId,
98 ui::ET_MOUSE_PRESSED,
99 gfx::Point(),
100 ui::EF_LEFT_MOUSE_BUTTON);
101 EXPECT_TRUE(ShouldDispatchEvent(xev));
102 }
103 {
104 // Internal touch events should not be blocked.
105 ui::ScopedXI2Event xev;
106 std::vector<ui::Valuator> valuators;
107 xev.InitTouchEvent(kTestInternalDeviceId, ui::ET_TOUCH_PRESSED, 1,
108 gfx::Point(), valuators);
109 EXPECT_TRUE(ShouldDispatchEvent(xev));
110 }
111 }
112
113 // Tests that general key press events are blocked.
114 TEST_F(MaximizeModeEventBlockerX11Test, BlocksKeyboard) {
115 ui::ScopedXI2Event xev;
116
117 xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0);
118 EXPECT_FALSE(ShouldDispatchEvent(xev));
119
120 xev.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_ESCAPE, 0);
121 EXPECT_FALSE(ShouldDispatchEvent(xev));
122 }
123
124 // Tests that volume and power keys are still allowed.
125 TEST_F(MaximizeModeEventBlockerX11Test, AllowsVolumeAndPower) {
126 ui::ScopedXI2Event xev;
127
128 xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_UP, 0);
129 EXPECT_TRUE(ShouldDispatchEvent(xev));
130
131 xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_VOLUME_DOWN, 0);
132 EXPECT_TRUE(ShouldDispatchEvent(xev));
133
134 xev.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_POWER, 0);
135 EXPECT_TRUE(ShouldDispatchEvent(xev));
136 }
137
138 // The mouse cursor movement happens before the event is delivered, this tests
139 // that the event blocker attempts to lock the cursor in place when it receives
140 // an internal mouse event.
141 TEST_F(MaximizeModeEventBlockerX11Test, LocksMousePosition) {
142 gfx::Point external_point(100, 0);
143 gfx::Point internal_point(0, 0);
144 // Move the cursor to a position and send an external mouse event.
145 SetMouseLocation(external_point);
146 {
147 ui::ScopedXI2Event xev;
148 xev.InitGenericButtonEvent(kTestExternalDeviceId,
149 ui::ET_MOUSE_PRESSED,
150 external_point,
151 ui::EF_LEFT_MOUSE_BUTTON);
152 EXPECT_TRUE(ShouldDispatchEvent(xev));
153 }
154 EXPECT_EQ(external_point.ToString(), GetMouseLocation().ToString());
155
156 // Move the cursor to another
157 SetMouseLocation(internal_point);
158 {
159 ui::ScopedXI2Event xev;
160 xev.InitGenericButtonEvent(kTestInternalDeviceId,
161 ui::ET_MOUSE_PRESSED,
162 internal_point,
163 ui::EF_LEFT_MOUSE_BUTTON);
164 EXPECT_FALSE(ShouldDispatchEvent(xev));
165 }
166 EXPECT_EQ(external_point.ToString(), GetMouseLocation().ToString());
167 }
168 #endif // defined(USE_X11)
169
170 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698