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

Side by Side Diff: ui/aura/root_window_unittest.cc

Issue 9788001: Remove stops_event_propagation from Window, since it's broken. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/root_window.h" 5 #include "ui/aura/root_window.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/aura/client/event_client.h"
8 #include "ui/aura/env.h" 9 #include "ui/aura/env.h"
9 #include "ui/aura/event.h" 10 #include "ui/aura/event.h"
11 #include "ui/aura/event_filter.h"
10 #include "ui/aura/test/aura_test_base.h" 12 #include "ui/aura/test/aura_test_base.h"
13 #include "ui/aura/test/event_generator.h"
11 #include "ui/aura/test/test_window_delegate.h" 14 #include "ui/aura/test/test_window_delegate.h"
12 #include "ui/aura/test/test_windows.h" 15 #include "ui/aura/test/test_windows.h"
13 #include "ui/base/hit_test.h" 16 #include "ui/base/hit_test.h"
17 #include "ui/base/keycodes/keyboard_codes.h"
14 #include "ui/gfx/point.h" 18 #include "ui/gfx/point.h"
15 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
16 20
17 namespace aura { 21 namespace aura {
18 namespace { 22 namespace {
19 23
20 // A delegate that always returns a non-client component for hit tests. 24 // A delegate that always returns a non-client component for hit tests.
21 class NonClientDelegate : public test::TestWindowDelegate { 25 class NonClientDelegate : public test::TestWindowDelegate {
22 public: 26 public:
23 NonClientDelegate() 27 NonClientDelegate()
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 EXPECT_EQ("100,100", root.location().ToString()); 160 EXPECT_EQ("100,100", root.location().ToString());
157 EXPECT_EQ("100,100", root.root_location().ToString()); 161 EXPECT_EQ("100,100", root.root_location().ToString());
158 162
159 MouseEvent translated_event( 163 MouseEvent translated_event(
160 root, root_window(), w1.get(), 164 root, root_window(), w1.get(),
161 ui::ET_MOUSE_ENTERED, root.flags()); 165 ui::ET_MOUSE_ENTERED, root.flags());
162 EXPECT_EQ("50,50", translated_event.location().ToString()); 166 EXPECT_EQ("50,50", translated_event.location().ToString());
163 EXPECT_EQ("100,100", translated_event.root_location().ToString()); 167 EXPECT_EQ("100,100", translated_event.root_location().ToString());
164 } 168 }
165 169
170 namespace {
171
172 class TestEventClient : public client::EventClient {
173 public:
174 static const int kNonLockWindowId = 100;
175 static const int kLockWindowId = 200;
176
177 explicit TestEventClient(RootWindow* root_window)
178 : root_window_(root_window),
179 lock_(false) {
180 client::SetEventClient(root_window_, this);
181 Window* lock_window =
182 test::CreateTestWindowWithBounds(root_window_->bounds(), root_window_);
183 lock_window->set_id(kLockWindowId);
184 Window* non_lock_window =
185 test::CreateTestWindowWithBounds(root_window_->bounds(), root_window_);
186 non_lock_window->set_id(kNonLockWindowId);
187 }
188 virtual ~TestEventClient() {
189 client::SetEventClient(root_window_, NULL);
190 }
191
192 // Starts/stops locking. Locking prevents windows other than those inside
193 // the lock container from receiving events, getting focus etc.
194 void Lock() {
195 lock_ = true;
196 }
197 void Unlock() {
198 lock_ = false;
199 }
200
201 Window* GetLockWindow() {
202 return const_cast<Window*>(
203 static_cast<const TestEventClient*>(this)->GetLockWindow());
204 }
205 const Window* GetLockWindow() const {
206 return root_window_->GetChildById(kLockWindowId);
207 }
208 Window* GetNonLockWindow() {
209 return root_window_->GetChildById(kNonLockWindowId);
210 }
211
212 private:
213 // Overridden from client::EventClient:
214 virtual bool CanProcessEventsWithinSubtree(
215 const Window* window) const OVERRIDE {
216 return lock_ ? GetLockWindow()->Contains(window) : true;
217 }
218
219 RootWindow* root_window_;
220 bool lock_;
221
222 DISALLOW_COPY_AND_ASSIGN(TestEventClient);
223 };
224
225 class TestEventFilter : public aura::EventFilter {
226 public:
227 TestEventFilter() {
228 Reset();
229 }
230 virtual ~TestEventFilter() {}
231
232 void Reset() {
233 mouse_event_count_ = 0;
234 }
235
236 int mouse_event_count() const { return mouse_event_count_; }
237
238 private:
239 virtual bool PreHandleKeyEvent(Window* target, KeyEvent* event) OVERRIDE {
240 return true;
241 }
242 virtual bool PreHandleMouseEvent(Window* target, MouseEvent* event) OVERRIDE {
243 ++mouse_event_count_;
244 return true;
245 }
246 virtual ui::TouchStatus PreHandleTouchEvent(Window* target,
247 TouchEvent* event) OVERRIDE {
248 return ui::TOUCH_STATUS_UNKNOWN;
249 }
250 virtual ui::GestureStatus PreHandleGestureEvent(
251 Window* target,
252 GestureEvent* event) OVERRIDE {
253 return ui::GESTURE_STATUS_UNKNOWN;
254 }
255
256 int mouse_event_count_;
257
258 DISALLOW_COPY_AND_ASSIGN(TestEventFilter);
259 };
260
261 } // namespace
262
263 TEST_F(RootWindowTest, CanProcessEventsWithinSubtree) {
264 TestEventClient client(root_window());
265 test::TestWindowDelegate d;
266
267 TestEventFilter* nonlock_ef = new TestEventFilter;
268 TestEventFilter* lock_ef = new TestEventFilter;
269 client.GetNonLockWindow()->SetEventFilter(nonlock_ef);
270 client.GetLockWindow()->SetEventFilter(lock_ef);
271
272 Window* w1 = test::CreateTestWindowWithBounds(gfx::Rect(10, 10, 20, 20),
273 client.GetNonLockWindow());
274 w1->set_id(1);
275 Window* w2 = test::CreateTestWindowWithBounds(gfx::Rect(30, 30, 20, 20),
276 client.GetNonLockWindow());
277 w2->set_id(2);
278 scoped_ptr<Window> w3(
279 test::CreateTestWindowWithDelegate(&d, 3, gfx::Rect(20, 20, 20, 20),
280 client.GetLockWindow()));
281
282 w1->Focus();
283 EXPECT_TRUE(w1->GetFocusManager()->IsFocusedWindow(w1));
284
285 client.Lock();
286
287 // Since we're locked, the attempt to focus w2 will be ignored.
288 w2->Focus();
289 EXPECT_TRUE(w1->GetFocusManager()->IsFocusedWindow(w1));
290 EXPECT_FALSE(w1->GetFocusManager()->IsFocusedWindow(w2));
291
292 {
293 // Attempting to send a key event to w1 (not in the lock container) should
294 // cause focus to be reset.
295 test::EventGenerator generator(root_window());
296 generator.PressKey(ui::VKEY_SPACE, 0);
297 EXPECT_EQ(NULL, w1->GetFocusManager()->GetFocusedWindow());
298 }
299
300 {
301 // Events sent to a window not in the lock container will not be processed.
302 // i.e. never sent to the non-lock container's event filter.
303 test::EventGenerator generator(root_window(), w1);
304 generator.PressLeftButton();
305 EXPECT_EQ(0, nonlock_ef->mouse_event_count());
306
307 // Events sent to a window in the lock container will be processed.
308 test::EventGenerator generator3(root_window(), w3.get());
309 generator3.PressLeftButton();
310 EXPECT_EQ(1, lock_ef->mouse_event_count());
311 }
312
313 // Prevent w3 from being deleted by the hierarchy since its delegate is owned
314 // by this scope.
315 w3->parent()->RemoveChild(w3.get());
316 }
317
318
166 } // namespace aura 319 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698