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

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

Issue 206593004: Move TestEventHandler to ui/events/test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
« no previous file with comments | « ui/aura/test/test_event_handler.cc ('k') | ui/aura/window_targeter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/window_event_dispatcher.h" 5 #include "ui/aura/window_event_dispatcher.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/aura/client/event_client.h" 12 #include "ui/aura/client/event_client.h"
13 #include "ui/aura/client/focus_client.h" 13 #include "ui/aura/client/focus_client.h"
14 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
15 #include "ui/aura/test/aura_test_base.h" 15 #include "ui/aura/test/aura_test_base.h"
16 #include "ui/aura/test/env_test_helper.h" 16 #include "ui/aura/test/env_test_helper.h"
17 #include "ui/aura/test/event_generator.h" 17 #include "ui/aura/test/event_generator.h"
18 #include "ui/aura/test/test_cursor_client.h" 18 #include "ui/aura/test/test_cursor_client.h"
19 #include "ui/aura/test/test_event_handler.h"
20 #include "ui/aura/test/test_screen.h" 19 #include "ui/aura/test/test_screen.h"
21 #include "ui/aura/test/test_window_delegate.h" 20 #include "ui/aura/test/test_window_delegate.h"
22 #include "ui/aura/test/test_windows.h" 21 #include "ui/aura/test/test_windows.h"
23 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
24 #include "ui/aura/window_tracker.h" 23 #include "ui/aura/window_tracker.h"
25 #include "ui/base/hit_test.h" 24 #include "ui/base/hit_test.h"
26 #include "ui/events/event.h" 25 #include "ui/events/event.h"
27 #include "ui/events/event_handler.h" 26 #include "ui/events/event_handler.h"
28 #include "ui/events/event_utils.h" 27 #include "ui/events/event_utils.h"
29 #include "ui/events/gestures/gesture_configuration.h" 28 #include "ui/events/gestures/gesture_configuration.h"
30 #include "ui/events/keycodes/keyboard_codes.h" 29 #include "ui/events/keycodes/keyboard_codes.h"
30 #include "ui/events/test/test_event_handler.h"
31 #include "ui/gfx/point.h" 31 #include "ui/gfx/point.h"
32 #include "ui/gfx/rect.h" 32 #include "ui/gfx/rect.h"
33 #include "ui/gfx/screen.h" 33 #include "ui/gfx/screen.h"
34 #include "ui/gfx/transform.h" 34 #include "ui/gfx/transform.h"
35 35
36 namespace aura { 36 namespace aura {
37 namespace { 37 namespace {
38 38
39 bool PlatformSupportsMultipleHosts() { 39 bool PlatformSupportsMultipleHosts() {
40 #if defined(USE_OZONE) 40 #if defined(USE_OZONE)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 int non_client_count_; 78 int non_client_count_;
79 gfx::Point non_client_location_; 79 gfx::Point non_client_location_;
80 int mouse_event_count_; 80 int mouse_event_count_;
81 gfx::Point mouse_event_location_; 81 gfx::Point mouse_event_location_;
82 int mouse_event_flags_; 82 int mouse_event_flags_;
83 83
84 DISALLOW_COPY_AND_ASSIGN(NonClientDelegate); 84 DISALLOW_COPY_AND_ASSIGN(NonClientDelegate);
85 }; 85 };
86 86
87 // A simple event handler that consumes key events. 87 // A simple event handler that consumes key events.
88 class ConsumeKeyHandler : public test::TestEventHandler { 88 class ConsumeKeyHandler : public ui::test::TestEventHandler {
89 public: 89 public:
90 ConsumeKeyHandler() {} 90 ConsumeKeyHandler() {}
91 virtual ~ConsumeKeyHandler() {} 91 virtual ~ConsumeKeyHandler() {}
92 92
93 // Overridden from ui::EventHandler: 93 // Overridden from ui::EventHandler:
94 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE { 94 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
95 test::TestEventHandler::OnKeyEvent(event); 95 ui::test::TestEventHandler::OnKeyEvent(event);
96 event->StopPropagation(); 96 event->StopPropagation();
97 } 97 }
98 98
99 private: 99 private:
100 DISALLOW_COPY_AND_ASSIGN(ConsumeKeyHandler); 100 DISALLOW_COPY_AND_ASSIGN(ConsumeKeyHandler);
101 }; 101 };
102 102
103 bool IsFocusedWindow(aura::Window* window) { 103 bool IsFocusedWindow(aura::Window* window) {
104 return client::GetFocusClient(window)->GetFocusedWindow() == window; 104 return client::GetFocusClient(window)->GetFocusedWindow() == window;
105 } 105 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 291
292 DISALLOW_COPY_AND_ASSIGN(TestEventClient); 292 DISALLOW_COPY_AND_ASSIGN(TestEventClient);
293 }; 293 };
294 294
295 } // namespace 295 } // namespace
296 296
297 TEST_F(WindowEventDispatcherTest, CanProcessEventsWithinSubtree) { 297 TEST_F(WindowEventDispatcherTest, CanProcessEventsWithinSubtree) {
298 TestEventClient client(root_window()); 298 TestEventClient client(root_window());
299 test::TestWindowDelegate d; 299 test::TestWindowDelegate d;
300 300
301 test::TestEventHandler* nonlock_ef = new test::TestEventHandler; 301 ui::test::TestEventHandler* nonlock_ef = new ui::test::TestEventHandler;
302 test::TestEventHandler* lock_ef = new test::TestEventHandler; 302 ui::test::TestEventHandler* lock_ef = new ui::test::TestEventHandler;
303 client.GetNonLockWindow()->SetEventFilter(nonlock_ef); 303 client.GetNonLockWindow()->SetEventFilter(nonlock_ef);
304 client.GetLockWindow()->SetEventFilter(lock_ef); 304 client.GetLockWindow()->SetEventFilter(lock_ef);
305 305
306 Window* w1 = test::CreateTestWindowWithBounds(gfx::Rect(10, 10, 20, 20), 306 Window* w1 = test::CreateTestWindowWithBounds(gfx::Rect(10, 10, 20, 20),
307 client.GetNonLockWindow()); 307 client.GetNonLockWindow());
308 w1->set_id(1); 308 w1->set_id(1);
309 Window* w2 = test::CreateTestWindowWithBounds(gfx::Rect(30, 30, 20, 20), 309 Window* w2 = test::CreateTestWindowWithBounds(gfx::Rect(30, 30, 20, 20),
310 client.GetNonLockWindow()); 310 client.GetNonLockWindow());
311 w2->set_id(2); 311 w2->set_id(2);
312 scoped_ptr<Window> w3( 312 scoped_ptr<Window> w3(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 generator3.PressLeftButton(); 344 generator3.PressLeftButton();
345 EXPECT_EQ(1, lock_ef->num_mouse_events()); 345 EXPECT_EQ(1, lock_ef->num_mouse_events());
346 } 346 }
347 347
348 // Prevent w3 from being deleted by the hierarchy since its delegate is owned 348 // Prevent w3 from being deleted by the hierarchy since its delegate is owned
349 // by this scope. 349 // by this scope.
350 w3->parent()->RemoveChild(w3.get()); 350 w3->parent()->RemoveChild(w3.get());
351 } 351 }
352 352
353 TEST_F(WindowEventDispatcherTest, IgnoreUnknownKeys) { 353 TEST_F(WindowEventDispatcherTest, IgnoreUnknownKeys) {
354 test::TestEventHandler* filter = new ConsumeKeyHandler; 354 ui::test::TestEventHandler* filter = new ConsumeKeyHandler;
355 root_window()->SetEventFilter(filter); // passes ownership 355 root_window()->SetEventFilter(filter); // passes ownership
356 356
357 ui::KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false); 357 ui::KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false);
358 DispatchEventUsingWindowDispatcher(&unknown_event); 358 DispatchEventUsingWindowDispatcher(&unknown_event);
359 EXPECT_FALSE(unknown_event.handled()); 359 EXPECT_FALSE(unknown_event.handled());
360 EXPECT_EQ(0, filter->num_key_events()); 360 EXPECT_EQ(0, filter->num_key_events());
361 361
362 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); 362 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false);
363 DispatchEventUsingWindowDispatcher(&known_event); 363 DispatchEventUsingWindowDispatcher(&known_event);
364 EXPECT_TRUE(known_event.handled()); 364 EXPECT_TRUE(known_event.handled());
365 EXPECT_EQ(1, filter->num_key_events()); 365 EXPECT_EQ(1, filter->num_key_events());
366 } 366 }
367 367
368 TEST_F(WindowEventDispatcherTest, NoDelegateWindowReceivesKeyEvents) { 368 TEST_F(WindowEventDispatcherTest, NoDelegateWindowReceivesKeyEvents) {
369 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); 369 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL));
370 w1->Show(); 370 w1->Show();
371 w1->Focus(); 371 w1->Focus();
372 372
373 test::TestEventHandler handler; 373 ui::test::TestEventHandler handler;
374 w1->AddPreTargetHandler(&handler); 374 w1->AddPreTargetHandler(&handler);
375 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); 375 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false);
376 DispatchEventUsingWindowDispatcher(&key_press); 376 DispatchEventUsingWindowDispatcher(&key_press);
377 EXPECT_TRUE(key_press.handled()); 377 EXPECT_TRUE(key_press.handled());
378 EXPECT_EQ(1, handler.num_key_events()); 378 EXPECT_EQ(1, handler.num_key_events());
379 379
380 w1->RemovePreTargetHandler(&handler); 380 w1->RemovePreTargetHandler(&handler);
381 } 381 }
382 382
383 // Tests that touch-events that are beyond the bounds of the root-window do get 383 // Tests that touch-events that are beyond the bounds of the root-window do get
384 // propagated to the event filters correctly with the root as the target. 384 // propagated to the event filters correctly with the root as the target.
385 TEST_F(WindowEventDispatcherTest, TouchEventsOutsideBounds) { 385 TEST_F(WindowEventDispatcherTest, TouchEventsOutsideBounds) {
386 test::TestEventHandler* filter = new test::TestEventHandler; 386 ui::test::TestEventHandler* filter = new ui::test::TestEventHandler;
387 root_window()->SetEventFilter(filter); // passes ownership 387 root_window()->SetEventFilter(filter); // passes ownership
388 388
389 gfx::Point position = root_window()->bounds().origin(); 389 gfx::Point position = root_window()->bounds().origin();
390 position.Offset(-10, -10); 390 position.Offset(-10, -10);
391 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta()); 391 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta());
392 DispatchEventUsingWindowDispatcher(&press); 392 DispatchEventUsingWindowDispatcher(&press);
393 EXPECT_EQ(1, filter->num_touch_events()); 393 EXPECT_EQ(1, filter->num_touch_events());
394 394
395 position = root_window()->bounds().origin(); 395 position = root_window()->bounds().origin();
396 position.Offset(root_window()->bounds().width() + 10, 396 position.Offset(root_window()->bounds().width() + 10,
397 root_window()->bounds().height() + 10); 397 root_window()->bounds().height() + 10);
398 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta()); 398 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta());
399 DispatchEventUsingWindowDispatcher(&release); 399 DispatchEventUsingWindowDispatcher(&release);
400 EXPECT_EQ(2, filter->num_touch_events()); 400 EXPECT_EQ(2, filter->num_touch_events());
401 } 401 }
402 402
403 // Tests that scroll events are dispatched correctly. 403 // Tests that scroll events are dispatched correctly.
404 TEST_F(WindowEventDispatcherTest, ScrollEventDispatch) { 404 TEST_F(WindowEventDispatcherTest, ScrollEventDispatch) {
405 base::TimeDelta now = ui::EventTimeForNow(); 405 base::TimeDelta now = ui::EventTimeForNow();
406 test::TestEventHandler* filter = new test::TestEventHandler; 406 ui::test::TestEventHandler* filter = new ui::test::TestEventHandler;
407 root_window()->SetEventFilter(filter); 407 root_window()->SetEventFilter(filter);
408 408
409 test::TestWindowDelegate delegate; 409 test::TestWindowDelegate delegate;
410 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); 410 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate));
411 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); 411 w1->SetBounds(gfx::Rect(20, 20, 40, 40));
412 412
413 // A scroll event on the root-window itself is dispatched. 413 // A scroll event on the root-window itself is dispatched.
414 ui::ScrollEvent scroll1(ui::ET_SCROLL, 414 ui::ScrollEvent scroll1(ui::ET_SCROLL,
415 gfx::Point(10, 10), 415 gfx::Point(10, 10),
416 now, 416 now,
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 DispatchEventUsingWindowDispatcher(&touch_moved_event); 746 DispatchEventUsingWindowDispatcher(&touch_moved_event);
747 DispatchEventUsingWindowDispatcher(&touch_released_event); 747 DispatchEventUsingWindowDispatcher(&touch_released_event);
748 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END", 748 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END",
749 EventTypesToString(filter->events())); 749 EventTypesToString(filter->events()));
750 filter->Reset(); 750 filter->Reset();
751 host()->dispatcher()->ReleasePointerMoves(); 751 host()->dispatcher()->ReleasePointerMoves();
752 RunAllPendingInMessageLoop(); 752 RunAllPendingInMessageLoop();
753 EXPECT_TRUE(filter->events().empty()); 753 EXPECT_TRUE(filter->events().empty());
754 } 754 }
755 755
756 class HoldPointerOnScrollHandler : public test::TestEventHandler { 756 class HoldPointerOnScrollHandler : public ui::test::TestEventHandler {
757 public: 757 public:
758 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher, 758 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher,
759 EventFilterRecorder* filter) 759 EventFilterRecorder* filter)
760 : dispatcher_(dispatcher), 760 : dispatcher_(dispatcher),
761 filter_(filter), 761 filter_(filter),
762 holding_moves_(false) { 762 holding_moves_(false) {
763 } 763 }
764 virtual ~HoldPointerOnScrollHandler() {} 764 virtual ~HoldPointerOnScrollHandler() {}
765 765
766 private: 766 private:
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 } 1585 }
1586 1586
1587 // Verifies handling loss of capture by the capture window being destroyed. 1587 // Verifies handling loss of capture by the capture window being destroyed.
1588 TEST_F(WindowEventDispatcherTest, CaptureWindowDestroyed) { 1588 TEST_F(WindowEventDispatcherTest, CaptureWindowDestroyed) {
1589 CaptureWindowTracker capture_window_tracker; 1589 CaptureWindowTracker capture_window_tracker;
1590 capture_window_tracker.CreateCaptureWindow(root_window()); 1590 capture_window_tracker.CreateCaptureWindow(root_window());
1591 capture_window_tracker.reset(); 1591 capture_window_tracker.reset();
1592 EXPECT_EQ(NULL, capture_window_tracker.capture_window()); 1592 EXPECT_EQ(NULL, capture_window_tracker.capture_window());
1593 } 1593 }
1594 1594
1595 class ExitMessageLoopOnMousePress : public test::TestEventHandler { 1595 class ExitMessageLoopOnMousePress : public ui::test::TestEventHandler {
1596 public: 1596 public:
1597 ExitMessageLoopOnMousePress() {} 1597 ExitMessageLoopOnMousePress() {}
1598 virtual ~ExitMessageLoopOnMousePress() {} 1598 virtual ~ExitMessageLoopOnMousePress() {}
1599 1599
1600 protected: 1600 protected:
1601 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { 1601 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
1602 test::TestEventHandler::OnMouseEvent(event); 1602 ui::test::TestEventHandler::OnMouseEvent(event);
1603 if (event->type() == ui::ET_MOUSE_PRESSED) 1603 if (event->type() == ui::ET_MOUSE_PRESSED)
1604 base::MessageLoopForUI::current()->Quit(); 1604 base::MessageLoopForUI::current()->Quit();
1605 } 1605 }
1606 1606
1607 private: 1607 private:
1608 DISALLOW_COPY_AND_ASSIGN(ExitMessageLoopOnMousePress); 1608 DISALLOW_COPY_AND_ASSIGN(ExitMessageLoopOnMousePress);
1609 }; 1609 };
1610 1610
1611 class WindowEventDispatcherTestWithMessageLoop 1611 class WindowEventDispatcherTestWithMessageLoop
1612 : public WindowEventDispatcherTest { 1612 : public WindowEventDispatcherTest {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 test_screen()->SetDeviceScaleFactor(2.f); 1694 test_screen()->SetDeviceScaleFactor(2.f);
1695 } 1695 }
1696 }; 1696 };
1697 1697
1698 TEST_F(WindowEventDispatcherTestInHighDPI, EventLocationTransform) { 1698 TEST_F(WindowEventDispatcherTestInHighDPI, EventLocationTransform) {
1699 test::TestWindowDelegate delegate; 1699 test::TestWindowDelegate delegate;
1700 scoped_ptr<aura::Window> child(test::CreateTestWindowWithDelegate(&delegate, 1700 scoped_ptr<aura::Window> child(test::CreateTestWindowWithDelegate(&delegate,
1701 1234, gfx::Rect(20, 20, 100, 100), root_window())); 1701 1234, gfx::Rect(20, 20, 100, 100), root_window()));
1702 child->Show(); 1702 child->Show();
1703 1703
1704 test::TestEventHandler handler_child; 1704 ui::test::TestEventHandler handler_child;
1705 test::TestEventHandler handler_root; 1705 ui::test::TestEventHandler handler_root;
1706 root_window()->AddPreTargetHandler(&handler_root); 1706 root_window()->AddPreTargetHandler(&handler_root);
1707 child->AddPreTargetHandler(&handler_child); 1707 child->AddPreTargetHandler(&handler_child);
1708 1708
1709 { 1709 {
1710 ui::MouseEvent move(ui::ET_MOUSE_MOVED, 1710 ui::MouseEvent move(ui::ET_MOUSE_MOVED,
1711 gfx::Point(30, 30), gfx::Point(30, 30), 1711 gfx::Point(30, 30), gfx::Point(30, 30),
1712 ui::EF_NONE, ui::EF_NONE); 1712 ui::EF_NONE, ui::EF_NONE);
1713 DispatchEventUsingWindowDispatcher(&move); 1713 DispatchEventUsingWindowDispatcher(&move);
1714 EXPECT_EQ(0, handler_child.num_mouse_events()); 1714 EXPECT_EQ(0, handler_child.num_mouse_events());
1715 EXPECT_EQ(1, handler_root.num_mouse_events()); 1715 EXPECT_EQ(1, handler_root.num_mouse_events());
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 delegate.GetMouseMotionCountsAndReset(); 2000 delegate.GetMouseMotionCountsAndReset();
2001 2001
2002 // Notify both hosts that the cursor is now hidden. This should send a single 2002 // Notify both hosts that the cursor is now hidden. This should send a single
2003 // mouse-exit event to |window|. 2003 // mouse-exit event to |window|.
2004 host()->OnCursorVisibilityChanged(false); 2004 host()->OnCursorVisibilityChanged(false);
2005 second_host->OnCursorVisibilityChanged(false); 2005 second_host->OnCursorVisibilityChanged(false);
2006 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset()); 2006 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset());
2007 } 2007 }
2008 2008
2009 } // namespace aura 2009 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/test_event_handler.cc ('k') | ui/aura/window_targeter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698